From c9c47b3a5165935efd5b5e3e712c1f6e456b0116 Mon Sep 17 00:00:00 2001 From: Yaacov Akiba Slama Date: Tue, 3 Jul 2018 07:54:17 +0300 Subject: [PATCH] Fix the ability to disable p2p listening --- config.go | 69 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/config.go b/config.go index 949f2503..ba5ada38 100644 --- a/config.go +++ b/config.go @@ -812,13 +812,6 @@ func loadConfig() (*config, error) { return nil, err } - // Remove the listening addresses specified if listening is disabled. - if cfg.DisableListen { - ltndLog.Infof("Listening on the p2p interface is disabled!") - cfg.Listeners = nil - cfg.ExternalIPs = nil - } - // Add default port to all RPC listener addresses if needed and remove // duplicate addresses. cfg.RPCListeners, err = lncfg.NormalizeAddresses( @@ -839,36 +832,44 @@ func loadConfig() (*config, error) { return nil, err } - // Add default port to all listener addresses if needed and remove - // duplicate addresses. - cfg.Listeners, err = lncfg.NormalizeAddresses( - cfg.RawListeners, strconv.Itoa(defaultPeerPort), - cfg.net.ResolveTCPAddr, - ) - if err != nil { - return nil, err - } + // Remove the listening addresses specified if listening is disabled. + if cfg.DisableListen { + ltndLog.Infof("Listening on the p2p interface is disabled!") + cfg.Listeners = nil + cfg.ExternalIPs = nil + } else { - // Add default port to all external IP addresses if needed and remove - // duplicate addresses. - cfg.ExternalIPs, err = lncfg.NormalizeAddresses( - cfg.RawExternalIPs, strconv.Itoa(defaultPeerPort), - cfg.net.ResolveTCPAddr, - ) - if err != nil { - return nil, err - } - - // For the p2p port it makes no sense to listen to an Unix socket. - // Also, we would need to refactor the brontide listener to support - // that. - for _, p2pListener := range cfg.Listeners { - if lncfg.IsUnix(p2pListener) { - err := fmt.Errorf("unix socket addresses cannot be "+ - "used for the p2p connection listener: %s", - p2pListener) + // Add default port to all listener addresses if needed and remove + // duplicate addresses. + cfg.Listeners, err = lncfg.NormalizeAddresses( + cfg.RawListeners, strconv.Itoa(defaultPeerPort), + cfg.net.ResolveTCPAddr, + ) + if err != nil { return nil, err } + + // Add default port to all external IP addresses if needed and remove + // duplicate addresses. + cfg.ExternalIPs, err = lncfg.NormalizeAddresses( + cfg.RawExternalIPs, strconv.Itoa(defaultPeerPort), + cfg.net.ResolveTCPAddr, + ) + if err != nil { + return nil, err + } + + // For the p2p port it makes no sense to listen to an Unix socket. + // Also, we would need to refactor the brontide listener to support + // that. + for _, p2pListener := range cfg.Listeners { + if lncfg.IsUnix(p2pListener) { + err := fmt.Errorf("unix socket addresses cannot be "+ + "used for the p2p connection listener: %s", + p2pListener) + return nil, err + } + } } // Finally, ensure that we are only listening on localhost if Tor