refactor(sessionresolver): adapt to changing network conditions (#238)
* feat(sessionresolver): try many and use what works * fix(sessionresolver): make sure we can use quic * fix: the config struct is unnecessary * fix: make kvstore optional * feat: write simple integration test * feat: start adding tests * feat: continue writing tests * fix(sessionresolver): add more unit tests * fix(sessionresolver): finish adding tests * refactor(sessionresolver): changes after code review
This commit is contained in:
parent
12e1164940
commit
034db78f94
19 changed files with 1260 additions and 66 deletions
27
internal/engine/internal/sessionresolver/childresolver.go
Normal file
27
internal/engine/internal/sessionresolver/childresolver.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package sessionresolver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// childResolver is the DNS client that this package uses
|
||||
// to perform individual domain name resolutions.
|
||||
type childResolver interface {
|
||||
// LookupHost performs a DNS lookup.
|
||||
LookupHost(ctx context.Context, domain string) ([]string, error)
|
||||
|
||||
// CloseIdleConnections closes idle connections.
|
||||
CloseIdleConnections()
|
||||
}
|
||||
|
||||
// timeLimitedLookup performs a time-limited lookup using the given re.
|
||||
func (r *Resolver) timeLimitedLookup(ctx context.Context, re childResolver, hostname string) ([]string, error) {
|
||||
// Algorithm similar to Firefox TRR2 mode. See:
|
||||
// https://wiki.mozilla.org/Trusted_Recursive_Resolver#DNS-over-HTTPS_Prefs_in_Firefox
|
||||
// We use a higher timeout than Firefox's timeout (1.5s) to be on the safe side
|
||||
// and therefore see to use DoH more often.
|
||||
ctx, cancel := context.WithTimeout(ctx, 4*time.Second)
|
||||
defer cancel()
|
||||
return re.LookupHost(ctx, hostname)
|
||||
}
|
||||
Loading…
Reference in a new issue