From 3fcce9959b38b22b477cb5e270bf45e19761e984 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 5 Feb 2018 18:36:11 -0800 Subject: [PATCH] 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. --- chainregistry.go | 21 +++++++++++++++++++++ lnd.go | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/chainregistry.go b/chainregistry.go index 9bd09b55..7cbed86e 100644 --- a/chainregistry.go +++ b/chainregistry.go @@ -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 diff --git a/lnd.go b/lnd.go index 09532fb6..9f4e10f8 100644 --- a/lnd.go +++ b/lnd.go @@ -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,