Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions features/routing/dns/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ import (
// ResolvableContext is an implementation of routing.Context, with domain resolving capability.
type ResolvableContext struct {
routing.Context
dnsClient dns.Client
resolvedIPs []net.IP
dnsClient dns.Client
cacheIPs []net.IP
hasError bool
}

// GetTargetIPs overrides original routing.Context's implementation.
func (ctx *ResolvableContext) GetTargetIPs() []net.IP {
if len(ctx.resolvedIPs) > 0 {
return ctx.resolvedIPs
if len(ctx.cacheIPs) > 0 {
return ctx.cacheIPs
}

if ctx.hasError {
return nil
}

if domain := ctx.GetTargetDomain(); len(domain) != 0 {
Expand All @@ -29,16 +34,18 @@ func (ctx *ResolvableContext) GetTargetIPs() []net.IP {
FakeEnable: false,
})
if err == nil {
ctx.resolvedIPs = ips
ctx.cacheIPs = ips
return ips
}
errors.LogInfoInner(context.Background(), err, "resolve ip for ", domain)
}

if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 {
ctx.cacheIPs = ips
return ips
}

ctx.hasError = true
return nil
}

Expand Down