multi: Added Tor support

This commit adds Tor support. Users can set the --TorSocks flag
to specify which port Tor's SOCKS5 proxy is listening on so that
lnd can connect to it. When this flag is set, ALL traffic gets
routed over Tor including DNS traffic. Special functions for
DNS lookups were added, and since Tor doesn't natively support
SRV requests, the proxySRV function routes connects us to
a DNS server via Tor and SRV requests can be issued directly
to the DNS server.

Co-authored-by: MeshCollider <dobsonsa68@gmail.com>
This commit is contained in:
nsa
2017-10-20 17:45:23 -04:00
committed by Olaoluwa Osuntokun
parent 18741831dd
commit e2142c778f
8 changed files with 314 additions and 27 deletions

View File

@@ -32,9 +32,19 @@ var _ net.Conn = (*Conn)(nil)
// remote peer located at address which has remotePub as its long-term static
// public key. In the case of a handshake failure, the connection is closed and
// a non-nil error is returned.
func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress) (*Conn, error) {
func Dial(localPriv *btcec.PrivateKey, netAddr *lnwire.NetAddress,
dialer ...func(string, string) (net.Conn, error)) (*Conn, error) {
ipAddr := netAddr.Address.String()
conn, err := net.Dial("tcp", ipAddr)
var conn net.Conn
var err error
if dialer == nil {
// A Tor proxy dial function WAS NOT passed in.
conn, err = net.Dial("tcp", ipAddr)
} else {
// A Tor proxy dial function WAS passed in so we use it instead
// of golang's net.Dial.
conn, err = dialer[0]("tcp", ipAddr)
}
if err != nil {
return nil, err
}

View File

@@ -24,6 +24,8 @@ var _ net.Listener = (*Listener)(nil)
// NewListener returns a new net.Listener which enforces the Brontide scheme
// during both initial connection establishment and data transfer.
// Note: though this function uses ResolveTCPAddr, we don't need to call the
// general lndResolveTCP function since we are resolving a local address.
func NewListener(localStatic *btcec.PrivateKey, listenAddr string) (*Listener,
error) {
addr, err := net.ResolveTCPAddr("tcp", listenAddr)