Added NatPmp option

This commit is contained in:
John Griffith 2018-01-20 18:58:06 +00:00 committed by Wilmer Paulino
parent 0d0078baac
commit 1c3df21d18
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 9 additions and 17 deletions

@ -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"`

@ -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)
}
}