lnd: pass through the custom dialer+DNS to neutrino

In this commit, we modify our initialization of neutrino to also pass
in the custom dialer and name resolver function. With this change, if
lnd is configured to use Tor, then neutrino will as well. This means
that *both* the Bitcoin P2P as well as the Lightning P2P traffic will
be proxied over Tor.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-05 18:36:11 -08:00
parent 076b676195
commit 3fcce9959b
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 28 additions and 0 deletions

View File

@ -174,6 +174,27 @@ func newChainControlFromConfig(cfg *config, chanDB *channeldb.DB,
ChainParams: *activeNetParams.Params,
AddPeers: cfg.NeutrinoMode.AddPeers,
ConnectPeers: cfg.NeutrinoMode.ConnectPeers,
Dialer: func(addr net.Addr) (net.Conn, error) {
return cfg.net.Dial(addr.Network(), addr.String())
},
NameResolver: func(host string) ([]net.IP, error) {
addrs, err := cfg.net.LookupHost(host)
if err != nil {
return nil, err
}
ips := make([]net.IP, 0, len(addrs))
for _, strIP := range addrs {
ip := net.ParseIP(strIP)
if ip == nil {
continue
}
ips = append(ips, ip)
}
return ips, nil
},
}
neutrino.WaitForMoreCFHeaders = time.Second * 1
neutrino.MaxPeers = 8

7
lnd.go
View File

@ -251,6 +251,13 @@ func lndMain() error {
}
idPrivKey.Curve = btcec.S256()
if cfg.Tor.Socks != "" && cfg.Tor.DNS != "" {
srvrLog.Infof("Proxying all network traffic via Tor "+
"(stream_isolation=%v)! NOTE: If running with a full-node "+
"backend, ensure that is proxying over Tor as well",
cfg.Tor.StreamIsolation)
}
// Set up the core server which will listen for incoming peer
// connections.
server, err := newServer(cfg.Listeners, chanDB, activeChainControl,