tor: short circuit host lookup if connecting to IP

With this commit we avoid calling LookupHost if we already have an IPv4
or IPv6 address, as we can return that directly.
This avoids asking Tor to resolve an IPv6 address, which it cannot do.
This commit is contained in:
Oliver Gugger
2023-06-22 09:43:20 +02:00
parent f1bca2a59c
commit e95720cf3a

View File

@@ -220,12 +220,20 @@ func ResolveTCPAddr(address, socksAddr string) (*net.TCPAddr, error) {
return nil, err
}
ip, err := LookupHost(host, socksAddr)
p, err := strconv.Atoi(port)
if err != nil {
return nil, err
}
p, err := strconv.Atoi(port)
// Do we already have an IP? Then we don't need to look up anything.
if ip := net.ParseIP(host); ip != nil {
return &net.TCPAddr{
IP: ip,
Port: p,
}, nil
}
ip, err := LookupHost(host, socksAddr)
if err != nil {
return nil, err
}