mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-01 18:50:09 +02:00
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:
parent
f1bca2a59c
commit
e95720cf3a
12
tor/tor.go
12
tor/tor.go
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user