mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Remove DNS lookup timeouts
This commit is contained in:
parent
df2e29b74d
commit
be7705efc3
1 changed files with 3 additions and 12 deletions
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TCP_BUFFER_SIZE is the maximum packet size
|
// TCP_BUFFER_SIZE is the maximum packet size
|
||||||
|
@ -20,9 +19,6 @@ var (
|
||||||
INTERNAL_DNS = false
|
INTERNAL_DNS = false
|
||||||
)
|
)
|
||||||
|
|
||||||
// lookupTimeout for DNS requests
|
|
||||||
const lookupTimeout = time.Second
|
|
||||||
|
|
||||||
// publicDns are servers to be queried if a local lookup fails
|
// publicDns are servers to be queried if a local lookup fails
|
||||||
var publicDns = []string{
|
var publicDns = []string{
|
||||||
"1.0.0.1", // Cloudflare
|
"1.0.0.1", // Cloudflare
|
||||||
|
@ -86,10 +82,7 @@ func lookup(address string) (ipaddress string, err error) {
|
||||||
|
|
||||||
// localLookupIP returns a host's IP address based on the local resolver.
|
// localLookupIP returns a host's IP address based on the local resolver.
|
||||||
func localLookupIP(address string) (ipaddress string, err error) {
|
func localLookupIP(address string) (ipaddress string, err error) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), lookupTimeout)
|
ip, err := net.LookupHost(address)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
ip, err := net.DefaultResolver.LookupHost(ctx, address)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -102,10 +95,8 @@ func remoteLookupIP(address, dns string) (ipaddress string, err error) {
|
||||||
r := &net.Resolver{
|
r := &net.Resolver{
|
||||||
PreferGo: true,
|
PreferGo: true,
|
||||||
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
d := net.Dialer{
|
d := new(net.Dialer)
|
||||||
Timeout: lookupTimeout,
|
return d.DialContext(ctx, network, dns+":53")
|
||||||
}
|
|
||||||
return d.DialContext(ctx, "udp", dns+":53")
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ip, err := r.LookupHost(context.Background(), address)
|
ip, err := r.LookupHost(context.Background(), address)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue