Compare commits
1 Commits
fix/make-c
...
443473e4db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
443473e4db |
4
Makefile
4
Makefile
@@ -18,7 +18,7 @@ fmt:
|
|||||||
goimports -w .
|
goimports -w .
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -v -race -cover -timeout 30s ./...
|
go test -v -race -cover ./...
|
||||||
|
|
||||||
# Check runs all validation without making changes
|
# Check runs all validation without making changes
|
||||||
# Used by CI and Docker build - fails if anything is wrong
|
# Used by CI and Docker build - fails if anything is wrong
|
||||||
@@ -28,7 +28,7 @@ check:
|
|||||||
@echo "==> Running linter..."
|
@echo "==> Running linter..."
|
||||||
golangci-lint run --config .golangci.yml ./...
|
golangci-lint run --config .golangci.yml ./...
|
||||||
@echo "==> Running tests..."
|
@echo "==> Running tests..."
|
||||||
go test -v -race -short -timeout 30s ./...
|
go test -v -race ./...
|
||||||
@echo "==> Building..."
|
@echo "==> Building..."
|
||||||
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/dnswatcher
|
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/dnswatcher
|
||||||
@echo "==> All checks passed!"
|
@echo "==> All checks passed!"
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
queryTimeoutDuration = 5 * time.Second
|
queryTimeoutDuration = 1 * time.Second
|
||||||
maxRetries = 2
|
maxRetries = 2
|
||||||
maxDelegation = 20
|
maxDelegation = 20
|
||||||
timeoutMultiplier = 2
|
timeoutMultiplier = 2
|
||||||
@@ -291,8 +291,17 @@ func (r *Resolver) resolveNSIPs(
|
|||||||
return ips
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveNSRecursive queries for NS records using recursive
|
// publicResolvers returns well-known public recursive DNS resolvers.
|
||||||
// resolution as a fallback for intercepted environments.
|
func publicResolvers() []string {
|
||||||
|
return []string{
|
||||||
|
"1.1.1.1", // Cloudflare
|
||||||
|
"8.8.8.8", // Google
|
||||||
|
"9.9.9.9", // Quad9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveNSRecursive queries for NS records using a public
|
||||||
|
// recursive resolver as a fallback for intercepted environments.
|
||||||
func (r *Resolver) resolveNSRecursive(
|
func (r *Resolver) resolveNSRecursive(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
domain string,
|
domain string,
|
||||||
@@ -302,7 +311,7 @@ func (r *Resolver) resolveNSRecursive(
|
|||||||
msg.SetQuestion(domain, dns.TypeNS)
|
msg.SetQuestion(domain, dns.TypeNS)
|
||||||
msg.RecursionDesired = true
|
msg.RecursionDesired = true
|
||||||
|
|
||||||
for _, ip := range rootServerList()[:3] {
|
for _, ip := range publicResolvers() {
|
||||||
if checkCtx(ctx) != nil {
|
if checkCtx(ctx) != nil {
|
||||||
return nil, ErrContextCanceled
|
return nil, ErrContextCanceled
|
||||||
}
|
}
|
||||||
@@ -323,7 +332,8 @@ func (r *Resolver) resolveNSRecursive(
|
|||||||
return nil, ErrNoNameservers
|
return nil, ErrNoNameservers
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveARecord resolves a hostname to IPv4 addresses.
|
// resolveARecord resolves a hostname to IPv4 addresses using
|
||||||
|
// public recursive resolvers.
|
||||||
func (r *Resolver) resolveARecord(
|
func (r *Resolver) resolveARecord(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
hostname string,
|
hostname string,
|
||||||
@@ -333,7 +343,7 @@ func (r *Resolver) resolveARecord(
|
|||||||
msg.SetQuestion(hostname, dns.TypeA)
|
msg.SetQuestion(hostname, dns.TypeA)
|
||||||
msg.RecursionDesired = true
|
msg.RecursionDesired = true
|
||||||
|
|
||||||
for _, ip := range rootServerList()[:3] {
|
for _, ip := range publicResolvers() {
|
||||||
if checkCtx(ctx) != nil {
|
if checkCtx(ctx) != nil {
|
||||||
return nil, ErrContextCanceled
|
return nil, ErrContextCanceled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,8 @@ func newTestResolver(t *testing.T) *resolver.Resolver {
|
|||||||
func testContext(t *testing.T) context.Context {
|
func testContext(t *testing.T) context.Context {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
if testing.Short() {
|
|
||||||
t.Skip("skipping integration test requiring real DNS")
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(
|
ctx, cancel := context.WithTimeout(
|
||||||
context.Background(), 15*time.Second,
|
context.Background(), 60*time.Second,
|
||||||
)
|
)
|
||||||
t.Cleanup(cancel)
|
t.Cleanup(cancel)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user