From 4affab7bd7d5a01b401f2713c87bc7614657fd99 Mon Sep 17 00:00:00 2001 From: MeshCollider Date: Tue, 23 Jan 2018 00:48:59 +1300 Subject: [PATCH] multi: Addressing Tor support review comments --- brontide/listener.go | 2 -- config.go | 22 +++++++++++++--------- rpcserver.go | 2 +- server.go | 2 ++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/brontide/listener.go b/brontide/listener.go index 98de432e..1cc171f6 100644 --- a/brontide/listener.go +++ b/brontide/listener.go @@ -24,8 +24,6 @@ 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) diff --git a/config.go b/config.go index c36f462b..0a6b07a5 100644 --- a/config.go +++ b/config.go @@ -133,6 +133,11 @@ type autoPilotConfig struct { Allocation float64 `long:"allocation" description:"The percentage of total funds that should be committed to automatic channel establishment"` } +type torConfig struct { + Socks string `long:"socks" description:"The port that Tor's exposed SOCKS5 proxy is listening on. Using Tor allows outbound-only connections (listening will be disabled) -- NOTE port must be between 1024 and 65535"` + DNS string `long:"dns" description:"The DNS server as IP:PORT that Tor will use for SRV queries - NOTE must have TCP resolution enabled"` +} + // config defines the configuration options for lnd. // // See loadConfig for further details regarding the configuration @@ -161,9 +166,6 @@ type config struct { Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"` - TorSocks string `long:"torsocks" description:"The port that Tor's exposed SOCKS5 proxy is listening on -- NOTE port must be between 1024 and 65535"` - TorDNS string `long:"tordns" description:"The DNS server as IP:PORT that Tor will use for SRV queries - NOTE must have TCP resolution enabled"` - DebugHTLC bool `long:"debughtlc" description:"Activate the debug htlc mode. With the debug HTLC mode, all payments sent use a pre-determined R-Hash. Additionally, all HTLCs sent to a node with the debug HTLC R-Hash are immediately settled in the next available state transition."` HodlHTLC bool `long:"hodlhtlc" description:"Activate the hodl HTLC mode. With hodl HTLC mode, all incoming HTLCs will be accepted by the receiving node, but no attempt will be made to settle the payment with the sender."` MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."` @@ -178,6 +180,8 @@ type config struct { Autopilot *autoPilotConfig `group:"autopilot" namespace:"autopilot"` + Tor *torConfig `group:"Tor" namespace:"tor"` + NoNetBootstrap bool `long:"nobootstrap" description:"If true, then automatic network bootstrapping will not be attempted."` NoEncryptWallet bool `long:"noencryptwallet" description:"If set, wallet will be encrypted using the default passphrase."` @@ -298,9 +302,9 @@ func loadConfig() (*config, error) { // the proxy specific dial function and the DNS resolution functions use // Tor. cfg.net = &torsvc.MultiNet{Tor: false} - if cfg.TorSocks != "" && cfg.TorDNS != "" { + if cfg.Tor.Socks != "" && cfg.Tor.DNS != "" { // Validate Tor port number - torport, err := strconv.Atoi(cfg.TorSocks) + torport, err := strconv.Atoi(cfg.Tor.Socks) if err != nil || torport < 1024 || torport > 65535 { str := "%s: The tor socks5 port must be between 1024 and 65535" err := fmt.Errorf(str, funcName) @@ -319,16 +323,16 @@ func loadConfig() (*config, error) { return nil, err } - cfg.net.TorDNS = cfg.TorDNS - cfg.net.TorSocks = cfg.TorSocks + cfg.net.TorDNS = cfg.Tor.DNS + cfg.net.TorSocks = cfg.Tor.Socks // If we are using Tor, since we only want connections routed // through Tor, listening is disabled. cfg.DisableListen = true - } else if cfg.TorSocks != "" || cfg.TorDNS != "" { + } else if cfg.Tor.Socks != "" || cfg.Tor.DNS != "" { // Both TorSocks and TorDNS must be set. - str := "%s: Both the torsocks and the tordns flags must be set" + + str := "%s: Both the tor.socks and the tor.dns flags must be set" + "to properly route connections and avoid DNS leaks while" + "using Tor" err := fmt.Errorf(str, funcName) diff --git a/rpcserver.go b/rpcserver.go index 910d41ad..5c9ebba8 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -589,7 +589,7 @@ func (r *rpcServer) ConnectPeer(ctx context.Context, addr = in.Addr.Host } - // We use lndResolveTCP here in case we wish to resolve hosts over Tor. + // We use ResolveTCPAddr here in case we wish to resolve hosts over Tor. host, err := cfg.net.ResolveTCPAddr("tcp", addr) if err != nil { return nil, err diff --git a/server.go b/server.go index cfacf5ee..60b513e5 100644 --- a/server.go +++ b/server.go @@ -131,6 +131,8 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl, listeners := make([]net.Listener, len(listenAddrs)) for i, addr := range listenAddrs { + // Note: though brontide.NewListener uses ResolveTCPAddr, it doesn't need to call the + // general lndResolveTCP function since we are resolving a local address. listeners[i], err = brontide.NewListener(privKey, addr) if err != nil { return nil, err