mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-29 01:18:48 +02:00
Add explanatory comments for variable overwrites and code flow decisions
This commit adds detailed explanatory comments throughout the codebase to explain WHY certain logic is needed, not just WHAT the code does. This improves code maintainability and helps developers understand the reasoning behind complex decisions. Key improvements: - Version string processing: Explain why "v" prefix is added for semantic versioning - Control-D configuration: Explain why config is reset to prevent mixing of settings - DNS server categorization: Explain LAN vs public server handling for performance - Listener configuration: Document complex fallback logic for port/IP selection - MAC address normalization: Explain cross-platform compatibility needs - IPv6 address processing: Document Unix-specific interface suffix handling - Log content truncation: Explain why large content is limited to prevent flooding - IP address categorization: Document RFC1918 prioritization logic - IPv4/IPv6 separation: Explain network stack compatibility needs - DNS priority logic: Document different priority levels for different scenarios - Domain controller processing: Explain Windows API prefix handling - Reverse mapping creation: Document API encoding/decoding needs - Default value fallbacks: Explain why defaults prevent system failures - IP stack configuration: Document different defaults for different upstream types These comments help future developers understand the reasoning behind complex business logic, making the codebase more maintainable and reducing the risk of incorrect modifications during maintenance.
This commit is contained in:
@@ -99,9 +99,13 @@ type Table struct {
|
||||
|
||||
func NewTable(cfg *ctrld.Config, selfIP, cdUID string, ns []string, logger *ctrld.Logger) *Table {
|
||||
refreshInterval := cfg.Service.DiscoverRefreshInterval
|
||||
// Set default refresh interval if not configured
|
||||
// This ensures client discovery continues to work even without explicit configuration
|
||||
if refreshInterval <= 0 {
|
||||
refreshInterval = 2 * 60 // 2 minutes
|
||||
}
|
||||
// Use no-op logger if none provided
|
||||
// This prevents nil pointer dereferences when logging is not configured
|
||||
if logger == nil {
|
||||
logger = ctrld.NopLogger
|
||||
}
|
||||
@@ -274,6 +278,7 @@ func (t *Table) init() {
|
||||
host, port = h, p
|
||||
}
|
||||
// Only use valid ip:port pair.
|
||||
// Invalid nameservers can cause PTR discovery to fail silently
|
||||
if _, portErr := strconv.Atoi(port); portErr == nil && port != "0" && net.ParseIP(host) != nil {
|
||||
nss = append(nss, net.JoinHostPort(host, port))
|
||||
} else {
|
||||
@@ -465,6 +470,7 @@ func (t *Table) ListClients() []*Client {
|
||||
for _, c := range ipMap {
|
||||
// If we found a client with empty hostname, use hostname from
|
||||
// an existed client which has the same MAC address.
|
||||
// This helps fill in missing hostnames when multiple IPs share the same MAC
|
||||
if cFromMac := clientsByMAC[c.Mac]; cFromMac != nil && c.Hostname == "" {
|
||||
c.Hostname = cFromMac.Hostname
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user