ooni-probe-cli/internal/engine/netx/resolver/bogon.go
Simone Basso f91de2ecd6
cleanup: move bogon checking code in netxlite (#562)
I develop this diff while working on https://github.com/ooni/probe/issues/1803#issuecomment-957323297.

While there, make sure we don't have duplicate bogon code
and always use the code inside netxlite.
2021-11-02 12:20:04 +01:00

32 lines
771 B
Go

package resolver
import (
"context"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
// BogonResolver is a bogon aware resolver. When a bogon is encountered in
// a reply, this resolver will return an error.
//
// Deprecation warning
//
// This resolver is deprecated. The right thing to do would be to check
// for bogons right after a domain name resolution in the nettest.
type BogonResolver struct {
Resolver
}
// LookupHost implements Resolver.LookupHost
func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
addrs, err := r.Resolver.LookupHost(ctx, hostname)
for _, addr := range addrs {
if netxlite.IsBogon(addr) {
return nil, netxlite.ErrDNSBogon
}
}
return addrs, err
}
var _ Resolver = BogonResolver{}