Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba74640c85 |
No files matched your search
@@ -458,21 +458,26 @@ One address's lookup gets 2 seconds across all four. Each resolver gets an equal
|
|||||||
share of the time left, so one that does not answer leaves time for the next.
|
share of the time left, so one that does not answer leaves time for the next.
|
||||||
When none answers in time, the address's `ptr` is an empty list.
|
When none answers in time, the address's `ptr` is an empty list.
|
||||||
|
|
||||||
|
A reserved address, one whose `is_bogon` flag is true, is not sent to the
|
||||||
|
resolvers. Its `ptr` is an empty list.
|
||||||
|
|
||||||
What goes outside: each resolver asked receives the address being looked up. For
|
What goes outside: each resolver asked receives the address being looked up. For
|
||||||
`/ip/` and the home page, that address is the visitor's own. A lookup answered
|
`/ip/` and the home page, that address is the visitor's own. A lookup answered
|
||||||
from the cache sends nothing.
|
from the cache sends nothing.
|
||||||
|
|
||||||
How RouteWatch keeps the answers:
|
How RouteWatch keeps the answers:
|
||||||
|
|
||||||
- It holds every answer in memory. An answer that has not expired is served from
|
- It holds answers in memory. An answer that has not expired is served from
|
||||||
there.
|
there.
|
||||||
- It writes new answers every 5 seconds to `cache.db` in the state directory
|
- It writes new answers every 5 seconds to `cache.db` in the state directory
|
||||||
(see Configuration), and loads them from there at startup.
|
(see Configuration), and loads them from there at startup.
|
||||||
- An answer expires after the TTL of its records, the shortest one when there
|
- An answer expires after the TTL of its records, the shortest one when there
|
||||||
are several. RouteWatch keeps it for at least 60 seconds and at most 24 hours.
|
are several. RouteWatch keeps it for at least 60 seconds and at most 24 hours.
|
||||||
- An answer that an address has no PTR names expires after the SOA record's
|
- When an address has no PTR names, that answer expires after the SOA record's
|
||||||
minimum field, or the record's own TTL when that is shorter. RouteWatch keeps
|
minimum field, or the record's own TTL when that is shorter. RouteWatch keeps
|
||||||
it for at most 1 hour.
|
it for at most 1 hour.
|
||||||
|
- An answer with no PTR names and no SOA record is not kept. Neither is one
|
||||||
|
whose SOA record has a TTL or minimum field of 0.
|
||||||
- A failed lookup is not kept, so the next lookup of the address asks again.
|
- A failed lookup is not kept, so the next lookup of the address asks again.
|
||||||
- Every 10 minutes it deletes expired answers from memory and from `cache.db`.
|
- Every 10 minutes it deletes expired answers from memory and from `cache.db`.
|
||||||
|
|
||||||
|
|||||||
+14
-4
@@ -16,6 +16,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.eeqj.de/sneak/routewatch/internal/bogon"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ type entry struct {
|
|||||||
type Cache struct {
|
type Cache struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
resolvers []string
|
resolvers []string
|
||||||
|
timeLimit time.Duration
|
||||||
logger *slog.Logger
|
logger *slog.Logger
|
||||||
client *http.Client
|
client *http.Client
|
||||||
now func() time.Time
|
now func() time.Time
|
||||||
@@ -73,6 +75,7 @@ func New(params Params) *Cache {
|
|||||||
return &Cache{
|
return &Cache{
|
||||||
db: params.DB,
|
db: params.DB,
|
||||||
resolvers: params.Resolvers,
|
resolvers: params.Resolvers,
|
||||||
|
timeLimit: LookupTimeout,
|
||||||
logger: params.Logger.With("component", "ptr"),
|
logger: params.Logger.With("component", "ptr"),
|
||||||
client: &http.Client{},
|
client: &http.Client{},
|
||||||
now: time.Now,
|
now: time.Now,
|
||||||
@@ -83,16 +86,23 @@ func New(params Params) *Cache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LookupAddr returns the PTR names of addr, fully qualified, or none when it
|
// LookupAddr returns the PTR names of addr, fully qualified, or none when it
|
||||||
// has none. It takes at most LookupTimeout. A cached answer makes no outside
|
// has none. A reserved address has none, and is not sent to the resolvers. A
|
||||||
// request. It returns an error when no resolver answered, and nothing is
|
// lookup takes at most LookupTimeout. A cached answer makes no outside request.
|
||||||
// cached then.
|
// It returns an error when no resolver answered, and nothing is cached then.
|
||||||
func (c *Cache) LookupAddr(ctx context.Context, addr string) ([]string, error) {
|
func (c *Cache) LookupAddr(ctx context.Context, addr string) ([]string, error) {
|
||||||
parsed, err := netip.ParseAddr(addr)
|
parsed, err := netip.ParseAddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("parsing the address: %w", err)
|
return nil, fmt.Errorf("parsing the address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
address := parsed.Unmap().String()
|
parsed = parsed.Unmap()
|
||||||
|
|
||||||
|
_, reserved := bogon.Prefix(netip.PrefixFrom(parsed, parsed.BitLen()))
|
||||||
|
if reserved {
|
||||||
|
return []string{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
address := parsed.String()
|
||||||
|
|
||||||
cached, ok := c.current(address)
|
cached, ok := c.current(address)
|
||||||
if ok {
|
if ok {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ptr
|
package ptr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@@ -8,30 +9,40 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"testing/synctest"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.eeqj.de/sneak/routewatch/internal/cachedb"
|
"git.eeqj.de/sneak/routewatch/internal/cachedb"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// These addresses are public, because a reserved address is not sent to the
|
||||||
|
// resolvers. That rules out the documentation ranges.
|
||||||
const (
|
const (
|
||||||
testAddress = "192.0.2.1"
|
testAddress = "8.8.4.4"
|
||||||
testReverse = "1.2.0.192.in-addr.arpa."
|
testReverse = "4.4.8.8.in-addr.arpa."
|
||||||
testName = "host.example.com."
|
mappedAddress = "::ffff:" + testAddress
|
||||||
otherName = "other.example.com."
|
otherAddress = "8.8.8.8"
|
||||||
testV6Address = "2001:db8::1"
|
testV6Address = "2606:4700:4700::1111"
|
||||||
testV6Reverse = "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0." +
|
testV6Reverse = "1.1.1.1.0.0.0.0.0.0.0.0.0.0.0.0." +
|
||||||
"0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa."
|
"0.0.0.0.0.0.7.4.0.0.7.4.6.0.6.2.ip6.arpa."
|
||||||
|
)
|
||||||
|
|
||||||
// timingAllowance is how far past its limit a loaded machine may run a
|
const (
|
||||||
// lookup that has a time limit.
|
testName = "host.example.com."
|
||||||
timingAllowance = 8 * time.Second
|
otherName = "other.example.com."
|
||||||
|
|
||||||
|
// testTimeLimit replaces LookupTimeout in the tests that use a real
|
||||||
|
// server. A stall on a busy host cannot use it up, and no test waits for
|
||||||
|
// it.
|
||||||
|
testTimeLimit = 2 * time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// classlessOwner is the name that holds the PTR records of a CNAME chain.
|
// classlessOwner is the name that holds the PTR records of a CNAME chain.
|
||||||
const classlessOwner = "1.0-25.2.0.192.in-addr.arpa."
|
const classlessOwner = "4.0-25.4.8.8.in-addr.arpa."
|
||||||
|
|
||||||
// fixedTime returns the time a test's clock starts at.
|
// fixedTime returns the time a test's clock starts at.
|
||||||
func fixedTime() time.Time {
|
func fixedTime() time.Time {
|
||||||
@@ -231,7 +242,7 @@ func (c *testClock) advance(d time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newTestCache returns a Cache that asks the resolvers in order, reads the
|
// newTestCache returns a Cache that asks the resolvers in order, reads the
|
||||||
// time from a clock the test holds, and is not started.
|
// time from a clock the test holds, has testTimeLimit, and is not started.
|
||||||
func newTestCache(
|
func newTestCache(
|
||||||
t *testing.T, db *sql.DB, resolvers ...*fakeResolver,
|
t *testing.T, db *sql.DB, resolvers ...*fakeResolver,
|
||||||
) (*Cache, *testClock) {
|
) (*Cache, *testClock) {
|
||||||
@@ -245,10 +256,57 @@ func newTestCache(
|
|||||||
cache := New(Params{DB: db, Resolvers: urls, Logger: slog.Default()})
|
cache := New(Params{DB: db, Resolvers: urls, Logger: slog.Default()})
|
||||||
clock := &testClock{now: fixedTime()}
|
clock := &testClock{now: fixedTime()}
|
||||||
cache.now = clock.time
|
cache.now = clock.time
|
||||||
|
cache.timeLimit = testTimeLimit
|
||||||
|
|
||||||
return cache, clock
|
return cache, clock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handlerTransport hands each request to the fake resolver for its host, with
|
||||||
|
// no network between them. A test in a synctest bubble needs this: the bubble's
|
||||||
|
// clock stands still while one of its goroutines waits on a real connection. As
|
||||||
|
// over a network, a request whose time is up is not sent.
|
||||||
|
type handlerTransport map[string]*fakeResolver
|
||||||
|
|
||||||
|
func (h handlerTransport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
|
||||||
|
if r.Context().Err() == nil {
|
||||||
|
h[r.URL.Host].serve(recorder, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := r.Context().Err()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return recorder.Result(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// newBubbleCache returns a Cache with the real time limit, for a test in a
|
||||||
|
// synctest bubble. It has one fake resolver for each reply, in order, reached
|
||||||
|
// through a handlerTransport.
|
||||||
|
func newBubbleCache(
|
||||||
|
replies ...func(http.ResponseWriter, *http.Request, *dns.Msg),
|
||||||
|
) (*Cache, []*fakeResolver) {
|
||||||
|
transport := make(handlerTransport, len(replies))
|
||||||
|
resolvers := make([]*fakeResolver, 0, len(replies))
|
||||||
|
urls := make([]string, 0, len(replies))
|
||||||
|
|
||||||
|
for i, reply := range replies {
|
||||||
|
host := "resolver" + strconv.Itoa(i) + ".example.com"
|
||||||
|
resolver := &fakeResolver{reply: reply}
|
||||||
|
|
||||||
|
transport[host] = resolver
|
||||||
|
resolvers = append(resolvers, resolver)
|
||||||
|
urls = append(urls, "https://"+host+"/dns-query")
|
||||||
|
}
|
||||||
|
|
||||||
|
cache := New(Params{Resolvers: urls, Logger: slog.Default()})
|
||||||
|
cache.client = &http.Client{Transport: transport}
|
||||||
|
|
||||||
|
return cache, resolvers
|
||||||
|
}
|
||||||
|
|
||||||
// lookupOK looks up address and fails the test on an error.
|
// lookupOK looks up address and fails the test on an error.
|
||||||
func lookupOK(t *testing.T, cache *Cache, address string) []string {
|
func lookupOK(t *testing.T, cache *Cache, address string) []string {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -283,7 +341,7 @@ func TestLookupAsksForTheReverseName(t *testing.T) {
|
|||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{testAddress, testReverse},
|
{testAddress, testReverse},
|
||||||
{"::ffff:" + testAddress, testReverse},
|
{mappedAddress, testReverse},
|
||||||
{testV6Address, testV6Reverse},
|
{testV6Address, testV6Reverse},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,6 +370,42 @@ func TestLookupAsksForTheReverseName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestOnlyPublicAddressesAreSentToTheResolvers gives every resolver an answer
|
||||||
|
// to send, which a reserved address must not get.
|
||||||
|
func TestOnlyPublicAddressesAreSentToTheResolvers(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
address string
|
||||||
|
want []string
|
||||||
|
requests int
|
||||||
|
}{
|
||||||
|
{"private IPv4", "10.0.0.1", []string{}, 0},
|
||||||
|
{"documentation IPv4", "192.0.2.1", []string{}, 0},
|
||||||
|
{"private IPv4 in IPv6 form", "::ffff:10.0.0.1", []string{}, 0},
|
||||||
|
{"unique-local IPv6", "fd00::1", []string{}, 0},
|
||||||
|
{"documentation IPv6", "2001:db8::1", []string{}, 0},
|
||||||
|
{"public IPv4", testAddress, []string{testName}, 1},
|
||||||
|
{"public IPv4 in IPv6 form", mappedAddress, []string{testName}, 1},
|
||||||
|
{"public IPv6", testV6Address, []string{testName}, 1},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
resolver := newFakeResolver(t, ptrReply(300, testName))
|
||||||
|
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolver)
|
||||||
|
|
||||||
|
names := lookupOK(t, cache, tt.address)
|
||||||
|
if names == nil || !slices.Equal(names, tt.want) {
|
||||||
|
t.Errorf("%s: names %#v, want %#v", tt.name, names, tt.want)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := resolver.requestCount(); got != tt.requests {
|
||||||
|
t.Errorf("%s: %d requests, want %d", tt.name, got, tt.requests)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestResolversAreTriedInOrderUntilOneAnswers has the first two resolvers fail,
|
// TestResolversAreTriedInOrderUntilOneAnswers has the first two resolvers fail,
|
||||||
// in different ways, and the third answer. The fourth is not asked.
|
// in different ways, and the third answer. The fourth is not asked.
|
||||||
func TestResolversAreTriedInOrderUntilOneAnswers(t *testing.T) {
|
func TestResolversAreTriedInOrderUntilOneAnswers(t *testing.T) {
|
||||||
@@ -355,51 +449,59 @@ func TestResolversAreTriedInOrderUntilOneAnswers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TestResolverThatNeverAnswersLeavesTimeForTheNext would fail if the first
|
// TestResolverThatNeverAnswersLeavesTimeForTheNext would fail if the first
|
||||||
// resolver could take the whole time limit.
|
// resolver could take the whole time limit. The first gets half of it, the
|
||||||
|
// share of one resolver in two. The test runs in a synctest bubble, whose clock
|
||||||
|
// is fake, so a stall on the host uses none of the limit.
|
||||||
func TestResolverThatNeverAnswersLeavesTimeForTheNext(t *testing.T) {
|
func TestResolverThatNeverAnswersLeavesTimeForTheNext(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()),
|
synctest.Test(t, func(t *testing.T) {
|
||||||
newFakeResolver(t, hangingReply),
|
cache, _ := newBubbleCache(hangingReply, ptrReply(300, testName))
|
||||||
newFakeResolver(t, ptrReply(300, testName)))
|
|
||||||
|
|
||||||
names := lookupOK(t, cache, testAddress)
|
start := time.Now()
|
||||||
if !slices.Equal(names, []string{testName}) {
|
names := lookupOK(t, cache, testAddress)
|
||||||
t.Errorf("names %v, want %s", names, testName)
|
elapsed := time.Since(start)
|
||||||
}
|
|
||||||
|
if !slices.Equal(names, []string{testName}) {
|
||||||
|
t.Errorf("names %v, want %s", names, testName)
|
||||||
|
}
|
||||||
|
|
||||||
|
if elapsed != time.Second {
|
||||||
|
t.Errorf("took %s, want 1s", elapsed)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLookupStopsAtTheTimeLimit has no resolver answer. The lookup fails once
|
// TestLookupStopsAtTheTimeLimit has no resolver answer. The lookup fails when
|
||||||
// LookupTimeout has passed, having asked every resolver.
|
// 2 seconds have passed, having asked every resolver. The test runs in a
|
||||||
|
// synctest bubble, whose clock is fake, so a stall on the host uses none of the
|
||||||
|
// limit.
|
||||||
func TestLookupStopsAtTheTimeLimit(t *testing.T) {
|
func TestLookupStopsAtTheTimeLimit(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
resolvers := []*fakeResolver{
|
synctest.Test(t, func(t *testing.T) {
|
||||||
newFakeResolver(t, hangingReply),
|
cache, resolvers := newBubbleCache(
|
||||||
newFakeResolver(t, hangingReply),
|
hangingReply, hangingReply, hangingReply, hangingReply)
|
||||||
newFakeResolver(t, hangingReply),
|
|
||||||
newFakeResolver(t, hangingReply),
|
|
||||||
}
|
|
||||||
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolvers...)
|
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
_, err := cache.LookupAddr(t.Context(), testAddress)
|
_, err := cache.LookupAddr(t.Context(), testAddress)
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
if err == nil {
|
if !errors.Is(err, context.DeadlineExceeded) {
|
||||||
t.Error("LookupAddr succeeded with no resolver answering")
|
t.Errorf("error %v, want %v", err, context.DeadlineExceeded)
|
||||||
}
|
|
||||||
|
|
||||||
if elapsed < LookupTimeout || elapsed > LookupTimeout+timingAllowance {
|
|
||||||
t.Errorf("took %s, want about %s", elapsed, LookupTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, resolver := range resolvers {
|
|
||||||
if resolver.requestCount() != 1 {
|
|
||||||
t.Errorf("resolver %d asked %d times, want once",
|
|
||||||
i, resolver.requestCount())
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if elapsed != 2*time.Second {
|
||||||
|
t.Errorf("took %s, want 2s", elapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, resolver := range resolvers {
|
||||||
|
if resolver.requestCount() != 1 {
|
||||||
|
t.Errorf("resolver %d asked %d times, want once",
|
||||||
|
i, resolver.requestCount())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestAnswerIsServedFromMemoryUntilItExpires makes a second lookup within the
|
// TestAnswerIsServedFromMemoryUntilItExpires makes a second lookup within the
|
||||||
@@ -437,7 +539,7 @@ func TestAnAddressHasOneCacheEntryHoweverItIsWritten(t *testing.T) {
|
|||||||
resolver := newFakeResolver(t, ptrReply(300, testName))
|
resolver := newFakeResolver(t, ptrReply(300, testName))
|
||||||
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolver)
|
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolver)
|
||||||
|
|
||||||
lookupOK(t, cache, "::ffff:"+testAddress)
|
lookupOK(t, cache, mappedAddress)
|
||||||
lookupOK(t, cache, testAddress)
|
lookupOK(t, cache, testAddress)
|
||||||
|
|
||||||
if got := resolver.requestCount(); got != 1 {
|
if got := resolver.requestCount(); got != 1 {
|
||||||
@@ -445,15 +547,17 @@ func TestAnAddressHasOneCacheEntryHoweverItIsWritten(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCallerCannotChangeACachedAnswer changes the list a lookup returned, as
|
// TestCallerCannotChangeACachedAnswer changes the list each lookup returned, as
|
||||||
// the server does when it removes the trailing dots.
|
// the server does when it removes the trailing dots. The second lookup is the
|
||||||
|
// first answered from the cache. The third shows that the cached list did not
|
||||||
|
// change with the list the second returned.
|
||||||
func TestCallerCannotChangeACachedAnswer(t *testing.T) {
|
func TestCallerCannotChangeACachedAnswer(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
resolver := newFakeResolver(t, ptrReply(300, testName))
|
resolver := newFakeResolver(t, ptrReply(300, testName))
|
||||||
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolver)
|
cache, _ := newTestCache(t, openTestDB(t, t.TempDir()), resolver)
|
||||||
|
|
||||||
for range 2 {
|
for range 3 {
|
||||||
names := lookupOK(t, cache, testAddress)
|
names := lookupOK(t, cache, testAddress)
|
||||||
if !slices.Equal(names, []string{testName}) {
|
if !slices.Equal(names, []string{testName}) {
|
||||||
t.Errorf("names %v, want %s", names, testName)
|
t.Errorf("names %v, want %s", names, testName)
|
||||||
@@ -640,8 +744,6 @@ func TestCacheSurvivesARestart(t *testing.T) {
|
|||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
db := openTestDB(t, dir)
|
db := openTestDB(t, dir)
|
||||||
|
|
||||||
const noNamesAddress = "192.0.2.2"
|
|
||||||
|
|
||||||
resolver := newFakeResolver(t,
|
resolver := newFakeResolver(t,
|
||||||
func(w http.ResponseWriter, r *http.Request, query *dns.Msg) {
|
func(w http.ResponseWriter, r *http.Request, query *dns.Msg) {
|
||||||
if query.Question[0].Name == testReverse {
|
if query.Question[0].Name == testReverse {
|
||||||
@@ -661,7 +763,7 @@ func TestCacheSurvivesARestart(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lookupOK(t, cache, testAddress)
|
lookupOK(t, cache, testAddress)
|
||||||
lookupOK(t, cache, noNamesAddress)
|
lookupOK(t, cache, otherAddress)
|
||||||
cache.Stop(t.Context())
|
cache.Stop(t.Context())
|
||||||
|
|
||||||
err = db.Close()
|
err = db.Close()
|
||||||
@@ -685,7 +787,7 @@ func TestCacheSurvivesARestart(t *testing.T) {
|
|||||||
t.Errorf("names after restart %v", names)
|
t.Errorf("names after restart %v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
if names := lookupOK(t, restarted, noNamesAddress); len(names) != 0 {
|
if names := lookupOK(t, restarted, otherAddress); len(names) != 0 {
|
||||||
t.Errorf("names of the address with none after restart: %v", names)
|
t.Errorf("names of the address with none after restart: %v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,7 +815,7 @@ func TestSweepDeletesExpiredRows(t *testing.T) {
|
|||||||
cache, clock := newTestCache(t, db, resolver)
|
cache, clock := newTestCache(t, db, resolver)
|
||||||
|
|
||||||
lookupOK(t, cache, testAddress)
|
lookupOK(t, cache, testAddress)
|
||||||
lookupOK(t, cache, "192.0.2.2")
|
lookupOK(t, cache, otherAddress)
|
||||||
cache.flush(t.Context())
|
cache.flush(t.Context())
|
||||||
|
|
||||||
if got := countRows(t, db); got != 2 {
|
if got := countRows(t, db); got != 2 {
|
||||||
|
|||||||
+2
-2
@@ -59,9 +59,9 @@ type answer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lookup asks the resolvers in turn for the PTR names of the reverse name
|
// lookup asks the resolvers in turn for the PTR names of the reverse name
|
||||||
// until one answers. It fails when none has answered within LookupTimeout.
|
// until one answers. It fails when none has answered within the time limit.
|
||||||
func (c *Cache) lookup(ctx context.Context, reverseName string) (answer, error) {
|
func (c *Cache) lookup(ctx context.Context, reverseName string) (answer, error) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, LookupTimeout)
|
ctx, cancel := context.WithTimeout(ctx, c.timeLimit)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
query := new(dns.Msg).SetQuestion(reverseName, dns.TypePTR)
|
query := new(dns.Msg).SetQuestion(reverseName, dns.TypePTR)
|
||||||
|
|||||||
Reference in new issue
Block a user