lib/dialer: Bring back address faking connection (fixes #6289) (#6363)

This commit is contained in:
Audrius Butkevicius
2020-02-26 12:37:23 +01:00
committed by GitHub
parent 10af09e4b4
commit 71aecc5cd4
2 changed files with 45 additions and 1 deletions
+34
View File
@@ -7,6 +7,7 @@
package dialer
import (
"net"
"net/http"
"net/url"
"os"
@@ -58,3 +59,36 @@ func socksDialerFunction(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error)
return proxy.SOCKS5("tcp", u.Host, auth, forward)
}
// dialerConn is needed because proxy dialed connections have RemoteAddr() pointing at the proxy,
// which then screws up various things such as IsLAN checks, and "let's populate the relay invitation address from
// existing connection" shenanigans.
type dialerConn struct {
net.Conn
addr net.Addr
}
func (c dialerConn) RemoteAddr() net.Addr {
return c.addr
}
func newDialerAddr(network, addr string) net.Addr {
netAddr, err := net.ResolveIPAddr(network, addr)
if err == nil {
return netAddr
}
return fallbackAddr{network, addr}
}
type fallbackAddr struct {
network string
addr string
}
func (a fallbackAddr) Network() string {
return a.network
}
func (a fallbackAddr) String() string {
return a.addr
}