feat: rework engine and CLI for dnstraverse parity
Port the traversal engine to the Ruby dnstraverse model so behaviour and output match dns.squish.net: - dns: single RD=0 query path (RD=1 only for upstream root discovery), per-run packet cache, EDNS0 512-fallback with warnings, UDP->TCP on truncation; fix --retries 0 and --root-server IP-literal handling; drop all hardcoded 127.0.0.1:53 resolvers - traverse: hierarchical per-branch InfoCache, 7-step response classification with the full 10-status vocabulary, bailiwick partitioning, strictly-deeper lame-referral rule, refid grammar with .0 resolve subtrees and childset digits, per-IP branching at 1/n weight, cache-based glue resolution with noglue/loop dead ends, CNAME restarts from the deepest cached zone, fast-mode memoization, probability aggregation with Ruby-identical stats keys (sums to 1.0) - output: byte-for-byte reference text format pinned by a golden test, reference CLI defaults, working --quiet/--show-X=false, TTY-aware colour, deduplicated deterministic JSON - web: adapt API/SPA to the new engine, SSE events carry refid/status, fix subscribe/snapshot duplicate-event race and a statusCls TDZ bug, align SPA type list with the backend - delete the old engine and dead code (net -4,350 lines) Verified against live runs of the reference Ruby engine across five domains (answers, NXDOMAIN, null MX, CNAME restart, glueless resolve) with no divergences beyond the documented typo fixes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
af15c9c2d4
commit
d71c7fbef2
+46
-76
@@ -17,17 +17,17 @@ func main() {
|
||||
cfg := config.DefaultConfig()
|
||||
|
||||
queryType := flag.String("type", cfg.QueryType, "Record type (A, AAAA, NS, CNAME, MX, TXT, SOA, PTR, ANY)")
|
||||
rootServer := flag.String("root-server", cfg.RootServer, "Override root server")
|
||||
allRootServers := flag.Bool("all-root-servers", cfg.AllRootServers, "Use all 13 root servers")
|
||||
rootAAAA := flag.Bool("root-aaaa", cfg.RootAAAA, "Include IPv6 root addresses")
|
||||
followAAAA := flag.Bool("follow-aaaa", cfg.FollowAAAA, "Only follow AAAA for referrals")
|
||||
rootServer := flag.String("root-server", cfg.RootServer, "Initial root server (hostname or IP)")
|
||||
allRootServers := flag.Bool("all-root-servers", cfg.AllRootServers, "Traverse from all root servers")
|
||||
rootAAAA := flag.Bool("root-aaaa", cfg.RootAAAA, "Include IPv6 root addresses (not implemented yet)")
|
||||
followAAAA := flag.Bool("follow-aaaa", cfg.FollowAAAA, "Only follow AAAA for referrals (not implemented yet)")
|
||||
dnsUpstream := flag.String("dns-upstream", cfg.DNSUpstream, "Upstream resolver for root discovery (e.g. 8.8.8.8:53, default: system)")
|
||||
udpSize := flag.Int("udp-size", cfg.UDPSize, "EDNS0 buffer size (512-4096)")
|
||||
udpSize := flag.Int("udp-size", cfg.UDPSize, "EDNS0 buffer size (512-4096; 512 turns EDNS0 off)")
|
||||
allowTCP := flag.Bool("allow-tcp", cfg.AllowTCP, "TCP fallback on truncation")
|
||||
alwaysTCP := flag.Bool("always-tcp", cfg.AlwaysTCP, "Always use TCP")
|
||||
maxDepth := flag.Int("max-depth", cfg.MaxDepth, "Max traversal depth (1-100)")
|
||||
retries := flag.Int("retries", cfg.Retries, "Retry count (0-10)")
|
||||
fast := flag.Bool("fast", cfg.Fast, "Fast mode: reuse earlier branch cache")
|
||||
retries := flag.Int("retries", cfg.Retries, "Number of 2s retries before timing out (0-10)")
|
||||
fast := flag.Bool("fast", cfg.Fast, "Fast mode; turn off to be more accurate")
|
||||
jsonOutput := flag.Bool("json", false, "Output results as JSON")
|
||||
|
||||
// Verbose: long and short form share the same variable.
|
||||
@@ -35,27 +35,31 @@ func main() {
|
||||
flag.BoolVar(&verboseVal, "verbose", cfg.Verbose, "Verbose output")
|
||||
flag.BoolVar(&verboseVal, "v", cfg.Verbose, "Verbose output (shorthand)")
|
||||
|
||||
// Debug: -d sets level 1, -dd sets level 2 (library debug).
|
||||
// Debug: -d prints debug diagnostics; -dd additionally enables library
|
||||
// debug (the Go flag package cannot stack -d -d like the Ruby CLI).
|
||||
var dFlag, ddFlag bool
|
||||
flag.BoolVar(&dFlag, "d", false, "Debug mode (stackable: -dd for library debug)")
|
||||
flag.BoolVar(&dFlag, "debug", false, "Debug mode")
|
||||
flag.BoolVar(&ddFlag, "dd", false, "Library debug mode (equivalent to -d -d)")
|
||||
flag.BoolVar(&dFlag, "d", false, "Print debug diagnostics to stderr")
|
||||
flag.BoolVar(&dFlag, "debug", false, "Print debug diagnostics to stderr")
|
||||
flag.BoolVar(&ddFlag, "dd", false, "Like -d plus library-level debug")
|
||||
|
||||
// Quiet: long and short form share the same variable.
|
||||
var quietVal bool
|
||||
flag.BoolVar(&quietVal, "quiet", cfg.Quiet, "Suppress supplementary info")
|
||||
flag.BoolVar(&quietVal, "q", cfg.Quiet, "Suppress supplementary info (shorthand)")
|
||||
flag.BoolVar(&quietVal, "quiet", cfg.Quiet, "Suppress the header block")
|
||||
flag.BoolVar(&quietVal, "q", cfg.Quiet, "Suppress the header block (shorthand)")
|
||||
|
||||
// Each show flag defaults to the config default, so --show-X and
|
||||
// --show-X=false both take effect directly; the --no-show-X aliases force
|
||||
// the value off, matching the Ruby --[no-]show-X switches.
|
||||
showProgress := flag.Bool("show-progress", cfg.ShowProgress, "Show traversal progress")
|
||||
noShowProgress := flag.Bool("no-show-progress", false, "Hide traversal progress")
|
||||
showResolves := flag.Bool("show-resolves", cfg.ShowResolves, "Show glue resolution details")
|
||||
noShowResolves := flag.Bool("no-show-resolves", false, "Hide glue resolution details")
|
||||
showServers := flag.Bool("show-servers", cfg.ShowServers, "Show servers queried")
|
||||
noShowServers := flag.Bool("no-show-servers", false, "Hide servers queried")
|
||||
showVersions := flag.Bool("show-versions", cfg.ShowVersions, "Show server versions")
|
||||
noShowVersions := flag.Bool("no-show-versions", false, "Hide server versions")
|
||||
showAllStats := flag.Bool("show-all-stats", cfg.ShowAllStats, "Show all statistics")
|
||||
noShowAllStats := flag.Bool("no-show-all-stats", false, "Hide all statistics")
|
||||
showResolves := flag.Bool("show-resolves", cfg.ShowResolves, "Show glue resolution progress")
|
||||
noShowResolves := flag.Bool("no-show-resolves", false, "Hide glue resolution progress")
|
||||
showServers := flag.Bool("show-servers", cfg.ShowServers, "Show servers encountered")
|
||||
noShowServers := flag.Bool("no-show-servers", false, "Hide servers encountered")
|
||||
showVersions := flag.Bool("show-versions", cfg.ShowVersions, "Show server version fingerprints")
|
||||
noShowVersions := flag.Bool("no-show-versions", false, "Hide server version fingerprints")
|
||||
showAllStats := flag.Bool("show-all-stats", cfg.ShowAllStats, "Show statistics after every node")
|
||||
noShowAllStats := flag.Bool("no-show-all-stats", false, "Hide per-node statistics")
|
||||
showResults := flag.Bool("show-results", cfg.ShowResults, "Show query results")
|
||||
noShowResults := flag.Bool("no-show-results", false, "Hide query results")
|
||||
showSummaryResults := flag.Bool("show-summary-results", cfg.ShowSummaryResults, "Show summary of results")
|
||||
@@ -83,41 +87,13 @@ func main() {
|
||||
cfg.Debug = config.ParseDebugLevel(dFlag, ddFlag)
|
||||
cfg.Quiet = quietVal
|
||||
|
||||
if *noShowProgress {
|
||||
cfg.ShowProgress = false
|
||||
} else if *showProgress {
|
||||
cfg.ShowProgress = true
|
||||
}
|
||||
if *noShowResolves {
|
||||
cfg.ShowResolves = false
|
||||
} else if *showResolves {
|
||||
cfg.ShowResolves = true
|
||||
}
|
||||
if *noShowServers {
|
||||
cfg.ShowServers = false
|
||||
} else if *showServers {
|
||||
cfg.ShowServers = true
|
||||
}
|
||||
if *noShowVersions {
|
||||
cfg.ShowVersions = false
|
||||
} else if *showVersions {
|
||||
cfg.ShowVersions = true
|
||||
}
|
||||
if *noShowAllStats {
|
||||
cfg.ShowAllStats = false
|
||||
} else if *showAllStats {
|
||||
cfg.ShowAllStats = true
|
||||
}
|
||||
if *noShowResults {
|
||||
cfg.ShowResults = false
|
||||
} else if *showResults {
|
||||
cfg.ShowResults = true
|
||||
}
|
||||
if *noShowSummaryResults {
|
||||
cfg.ShowSummaryResults = false
|
||||
} else if *showSummaryResults {
|
||||
cfg.ShowSummaryResults = true
|
||||
}
|
||||
cfg.ShowProgress = *showProgress && !*noShowProgress
|
||||
cfg.ShowResolves = *showResolves && !*noShowResolves
|
||||
cfg.ShowServers = *showServers && !*noShowServers
|
||||
cfg.ShowVersions = *showVersions && !*noShowVersions
|
||||
cfg.ShowAllStats = *showAllStats && !*noShowAllStats
|
||||
cfg.ShowResults = *showResults && !*noShowResults
|
||||
cfg.ShowSummaryResults = *showSummaryResults && !*noShowSummaryResults
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
@@ -130,26 +106,15 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
rootIP, err := cfg.ParseRootServer()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: invalid root server: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
queryTypeValue, err := config.ParseQueryType(cfg.QueryType)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var rootServerAddr string
|
||||
if rootIP != nil {
|
||||
rootServerAddr = rootIP.String()
|
||||
}
|
||||
|
||||
queryConfig := &dns.QueryConfig{
|
||||
UDPSize: cfg.UDPSize,
|
||||
Timeout: 5 * time.Second,
|
||||
Timeout: 2 * time.Second,
|
||||
Retries: cfg.Retries,
|
||||
UseTCP: cfg.AlwaysTCP,
|
||||
AllowTCP: cfg.AllowTCP,
|
||||
@@ -157,9 +122,11 @@ func main() {
|
||||
|
||||
rootConfig := &dns.RootDiscoveryConfig{
|
||||
IncludeAAAA: cfg.RootAAAA,
|
||||
Server: rootServerAddr,
|
||||
AllRoots: cfg.AllRootServers,
|
||||
Resolver: cfg.DNSUpstream,
|
||||
// --root-server accepts a hostname or an IP literal.
|
||||
Server: cfg.RootServer,
|
||||
AllRoots: cfg.AllRootServers,
|
||||
Resolver: cfg.DNSUpstream,
|
||||
Query: queryConfig,
|
||||
}
|
||||
|
||||
traverserConfig := &traverse.TraverserConfig{
|
||||
@@ -187,10 +154,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if !cfg.Quiet && !*jsonOutput {
|
||||
fmt.Printf("ExploreDNS - exploring: %s (type: %s)\n", domain, cfg.QueryType)
|
||||
}
|
||||
|
||||
outFmt := output.FormatText
|
||||
if *jsonOutput {
|
||||
outFmt = output.FormatJSON
|
||||
@@ -200,6 +163,13 @@ func main() {
|
||||
Format: outFmt,
|
||||
Domain: domain,
|
||||
QueryType: cfg.QueryType,
|
||||
Fast: cfg.Fast,
|
||||
AllRootServers: cfg.AllRootServers,
|
||||
UDPSize: cfg.UDPSize,
|
||||
Retries: cfg.Retries,
|
||||
MaxDepth: cfg.MaxDepth,
|
||||
AllowTCP: cfg.AllowTCP,
|
||||
AlwaysTCP: cfg.AlwaysTCP,
|
||||
ShowProgress: cfg.ShowProgress,
|
||||
ShowResolves: cfg.ShowResolves,
|
||||
ShowServers: cfg.ShowServers,
|
||||
@@ -209,7 +179,7 @@ func main() {
|
||||
ShowSummaryResults: cfg.ShowSummaryResults,
|
||||
Verbose: cfg.Verbose,
|
||||
Quiet: cfg.Quiet,
|
||||
Color: os.Getenv("NO_COLOR") == "",
|
||||
Color: output.ColorEnabled(os.Stdout),
|
||||
Debug: cfg.Debug,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user