Bound the IP lookup's address list and name lookups (closes #110)
check / check (push) Canceled after 0s

An IP lookup took any number of addresses and host names, gave each PTR
lookup until the request's 30-second limit, and looked up and named
every address a host name resolved to. It now answers 400 for more than
10 entries, or more than 10 addresses once the names are resolved,
before reading the database. Each PTR lookup gets 2 seconds; one that
runs out leaves the address's result without PTR names. Of a host
name's addresses only public ones are kept: global unicast and not
private. A name with none is reported as having no public address. The
tests give the server a fake resolver.

Model: opus-5-5
This commit is contained in:
2026-10-20 00:16:05 +00:00
parent 09d3073fa5
commit 10464cfe8b
4 changed files with 401 additions and 34 deletions
+12
View File
@@ -32,6 +32,13 @@ type ASNFetcher interface {
GetStats() ASNFetcherStats
}
// dnsResolver looks up the addresses of host names and the names of addresses
// in DNS, as *net.Resolver does.
type dnsResolver interface {
LookupHost(ctx context.Context, host string) ([]string, error)
LookupAddr(ctx context.Context, addr string) ([]string, error)
}
// Server provides HTTP endpoints for status monitoring
type Server struct {
router *chi.Mux
@@ -45,6 +52,10 @@ type Server struct {
// trustedProxies are the reverse proxies whose X-Forwarded-For header
// RealIPMiddleware believes
trustedProxies []netip.Prefix
// resolver makes the IP lookup's DNS lookups: net.DefaultResolver, or a
// fake in tests
resolver dnsResolver
}
// New creates a new HTTP server
@@ -60,6 +71,7 @@ func New(
logger: logger,
port: cfg.Port,
trustedProxies: cfg.TrustedProxies,
resolver: net.DefaultResolver,
}
s.setupRoutes()