Skip to content

Commit

Permalink
Removed preferIPv4
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Oct 6, 2023
1 parent 28fbe61 commit 918db44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 69 deletions.
22 changes: 14 additions & 8 deletions custom_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@ import (
// Returns a dialer that uses custom DNS servers to resolve the host.
func customDNSDialer(dnsServers []string, timeout time.Duration) (func(context.Context, string, string) (net.Conn, error), error) {
resolvers := make([]*net.Resolver, 0, len(dnsServers))
for _, _dnsServer := range dnsServers {
dnsServer := _dnsServer
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return netx.DialContext(ctx, "udp", dnsServer)
},
if len(dnsServers) == 0 {
log.Debug("Will resolve DNS using system DNS servers")
resolvers = append(resolvers, net.DefaultResolver)
} else {
log.Debugf("Will resolve DNS using %v", dnsServers)
for _, _dnsServer := range dnsServers {
dnsServer := _dnsServer
r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
return netx.DialContext(ctx, "udp", dnsServer)
},
}
resolvers = append(resolvers, r)
}
resolvers = append(resolvers, r)
}

dial := func(ctx context.Context, network, addr string) (net.Conn, error) {
Expand Down
13 changes: 3 additions & 10 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,16 +609,9 @@ func (p *Proxy) createFilterChain(bl *blacklist.Blacklist) (filters.Chain, proxy
}
filterChain = filterChain.Append(instrumentedProxyPingFilter)

var dialer func(context.Context, string, string) (net.Conn, error)
if len(p.DNSServers) == 0 {
log.Debug("Will resolve DNS using system DNS servers")
dialer = preferIPV4Dialer(timeoutToDialOriginSite)
} else {
log.Debugf("Will resolve DNS using %v", p.DNSServers)
dialer, err = customDNSDialer(p.DNSServers, timeoutToDialOriginSite)
if err != nil {
return nil, nil, err
}
dialer, err := customDNSDialer(p.DNSServers, timeoutToDialOriginSite)
if err != nil {
return nil, nil, err
}
dialerForPforward := dialer

Expand Down
51 changes: 0 additions & 51 deletions prefer_ipv4.go

This file was deleted.

0 comments on commit 918db44

Please sign in to comment.