Skip to content

Commit

Permalink
Make test fn resolveAllDNS better
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 1, 2024
1 parent 8d7f2c5 commit 67d5a9b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,28 @@ func TestResolveOnlyOnce(t *testing.T) {
}

func resolveAllDNS(ctx context.Context, resolver *Resolver, in ma.Multiaddr) ([]ma.Multiaddr, error) {
var inAddrs []ma.Multiaddr
outAddrs := []ma.Multiaddr{in}

for len(inAddrs) != len(outAddrs) {
inAddrs = outAddrs
outAddrs = nil
for _, inAddr := range inAddrs {
addrs, err := resolver.Resolve(ctx, inAddr)
if !Matches(in) {
return []ma.Multiaddr{in}, nil
}
var outAddrs []ma.Multiaddr
toResolve := []ma.Multiaddr{in}

for len(toResolve) > 0 {
var nextToResolve []ma.Multiaddr
for _, a := range toResolve {
addrs, err := resolver.Resolve(ctx, a)
if err != nil {
return nil, err
}
outAddrs = append(outAddrs, addrs...)
for _, addr := range addrs {
if Matches(addr) {
nextToResolve = append(nextToResolve, addr)
} else {
outAddrs = append(outAddrs, addr)
}
}
}
toResolve = nextToResolve
}
return outAddrs, nil
}
Expand Down

0 comments on commit 67d5a9b

Please sign in to comment.