Resolve PTR names over DNS-over-HTTPS and cache them for the record TTL (closes #238)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
`internal/ptr` asks Google, Cloudflare, AdGuard and Quad9 in turn, 2 seconds in all per address. It keeps answers in memory and writes them through to `cache.db`, opened by the new `internal/cachedb`. A reserved address is not sent to the resolvers. Judgement calls: - Each resolver gets an equal share of the time left, so a hung resolver does not use up the 2 seconds. - The negative TTL is the smaller of the SOA minimum and the SOA's own TTL (RFC 2308). - Names that are not host names are dropped, as `net.Resolver.LookupAddr` does. Model: opus-5-5
This commit is contained in:
1 parent
3204b7ee4b
commit
a749d7abe6
20 files changed
+1811
-67
No files matched your search
@@ -56,6 +56,39 @@ func TestPrefix(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddr(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
addr string
|
||||
// want is why the address is reserved, or "" when it is not.
|
||||
want string
|
||||
}{
|
||||
{"10.0.0.1", "Private-Use (10.0.0.0/8)"},
|
||||
{"fd00::1", "Unique-Local (fc00::/7)"},
|
||||
// An IPv4 address written in IPv6 form counts as the IPv4 address.
|
||||
{"::ffff:10.0.0.1", "Private-Use (10.0.0.0/8)"},
|
||||
{"::ffff:8.8.8.8", ""},
|
||||
// An address that may be announced, inside a reserved block.
|
||||
{"192.0.0.9", ""},
|
||||
// Addresses anyone may announce.
|
||||
{"8.8.8.8", ""},
|
||||
{"2001:4860:4860::8888", ""},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.addr, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
reason, reserved := bogon.Addr(netip.MustParseAddr(tc.addr))
|
||||
if reason != tc.want || reserved != (tc.want != "") {
|
||||
t.Errorf("Addr(%s) = %q, %v; want %q", tc.addr, reason,
|
||||
reserved, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestASN(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in new issue
Block a user