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:
Cuong Manh Le
2025-08-06 15:20:50 +07:00
committed by Cuong Manh Le
parent b187ec98a3
commit 5bc8da6470
14 changed files with 90 additions and 7 deletions
+5 -2
View File
@@ -126,10 +126,11 @@ func InitializeOsResolver(ctx context.Context, guardAgainstNoNameservers bool) [
// - First available LAN servers are saved and store.
// - Later calls, if no LAN servers available, the saved servers above will be used.
func initializeOsResolver(servers []string) []string {
var lanNss, publicNss []string
// First categorize servers
// Categorize DNS servers into LAN and public servers
// This is needed because LAN servers should be tried first for better performance,
// while public servers serve as fallback for external queries
for _, ns := range servers {
addr, err := netip.ParseAddr(ns)
if err != nil {
@@ -143,6 +144,8 @@ func initializeOsResolver(servers []string) []string {
}
}
// Ensure we have at least one public DNS server as fallback
// This prevents DNS resolution failures when no public servers are configured
if len(publicNss) == 0 {
publicNss = []string{controldPublicDnsWithPort}
}