From 1c3df21d189fd12fb2f0f95506050fe53157c173 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Sat, 20 Jan 2018 18:58:06 +0000 Subject: [PATCH] Added NatPmp option --- config.go | 3 ++- server.go | 23 +++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/config.go b/config.go index 55960acf..05ebdf9b 100644 --- a/config.go +++ b/config.go @@ -196,7 +196,8 @@ type config struct { UnsafeDisconnect bool `long:"unsafe-disconnect" description:"Allows the rpcserver to intentionally disconnect from peers with open channels. USED FOR TESTING ONLY."` UnsafeReplay bool `long:"unsafe-replay" description:"Causes a link to replay the adds on its commitment txn after starting up, this enables testing of the sphinx replay logic."` MaxPendingChannels int `long:"maxpendingchannels" description:"The maximum number of incoming pending channels permitted per peer."` - UpnpSupport bool `long:"upnpsupport" description:"Toggle Upnp support for auto network discovery"` + UpnpSupport bool `long:"upnp" description:"Toggle Upnp support for auto network discovery"` + NatPmp bool `long:"natpmp" description:"Toggle Nat Pmp support for auto network discovery"` Bitcoin *chainConfig `group:"Bitcoin" namespace:"bitcoin"` BtcdMode *btcdConfig `group:"btcd" namespace:"btcd"` diff --git a/server.go b/server.go index 1ac44279..2db82909 100644 --- a/server.go +++ b/server.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "context" "crypto/rand" "crypto/sha256" "encoding/hex" @@ -16,7 +15,6 @@ import ( "sync/atomic" "time" - upnp "github.com/NebulousLabs/go-upnp" "github.com/coreos/bbolt" "github.com/go-errors/errors" "github.com/lightningnetwork/lightning-onion" @@ -307,25 +305,18 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl, if cfg.UpnpSupport { - // Connect to router - d, err := upnp.DiscoverCtx(context.Background()) + externalIP, err := configureUpnp() if err != nil { - srvrLog.Errorf("Upnp: Unable to discover router %v\n", err) + externalIPs = append(externalIPs, externalIP) } - // Get external IP - ip, err := d.ExternalIP() - if err != nil { - srvrLog.Errorf("Upnp: Unable to get external ip %v\n", err) - } + } - // Forward peer port - err = d.Forward(uint16(cfg.PeerPort), "lnd peer port") + if cfg.NatPmp { + + externalIP, err := configureNatPmp() if err != nil { - srvrLog.Errorf("Upnp: Unable to forward pear port ip %v\n", err) - } else { - srvrLog.Infof("Your external IP is: %s", ip) - externalIPs = append(externalIPs, ip) + externalIPs = append(externalIPs, externalIP) } }