CI / test (pull_request) Failing after 2m40s
Add core traversal engine with iterative resolution from root servers: - referral.go: Referral struct with name, type, bailiwick, addresses, state - cache.go: Chained InfoCache with parent inheritance for NS and glue records - stack.go: LIFO stack with configurable max depth enforcement - response.go: Response classifier (referral, answer, CNAME follow, NODATA, NXDOMAIN, SERVFAIL) with child referral generation and probability splitting - traverser.go: Traverser orchestrates full traversal from root to leaf, following all referral branches, handling CNAME chains, and respecting max depth limits Add IterativeQuery/IterativeQueryWithExchange to dns package (RD=false queries). 57 new tests covering all acceptance criteria: traversal from root to leaf, comprehensive branch following, max depth enforcement, probability distribution, chained cache behavior, CNAME following, NXDOMAIN/SERVFAIL handling, context cancellation, and concurrent access. Co-authored-by: multica-agent <github@multica.ai>
59 lines
876 B
Go
59 lines
876 B
Go
package traverse
|
|
|
|
const DefaultMaxDepth = 20
|
|
|
|
type Stack struct {
|
|
items []*Referral
|
|
maxDepth int
|
|
}
|
|
|
|
func NewStack(maxDepth int) *Stack {
|
|
if maxDepth <= 0 {
|
|
maxDepth = DefaultMaxDepth
|
|
}
|
|
return &Stack{
|
|
items: make([]*Referral, 0),
|
|
maxDepth: maxDepth,
|
|
}
|
|
}
|
|
|
|
func (s *Stack) Push(r *Referral) bool {
|
|
if r == nil {
|
|
return false
|
|
}
|
|
if r.Depth >= s.maxDepth {
|
|
return false
|
|
}
|
|
s.items = append(s.items, r)
|
|
return true
|
|
}
|
|
|
|
func (s *Stack) Pop() *Referral {
|
|
if len(s.items) == 0 {
|
|
return nil
|
|
}
|
|
idx := len(s.items) - 1
|
|
item := s.items[idx]
|
|
s.items = s.items[:idx]
|
|
return item
|
|
}
|
|
|
|
func (s *Stack) Peek() *Referral {
|
|
if len(s.items) == 0 {
|
|
return nil
|
|
}
|
|
return s.items[len(s.items)-1]
|
|
}
|
|
|
|
func (s *Stack) Len() int {
|
|
return len(s.items)
|
|
}
|
|
|
|
func (s *Stack) MaxDepth() int {
|
|
return s.maxDepth
|
|
}
|
|
|
|
func (s *Stack) IsEmpty() bool {
|
|
return len(s.items) == 0
|
|
}
|