Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type config struct {
DisableDNSSeed bool `long:"nodnsseed" description:"DEPRECATED: use --noseeders"`
ExternalIPs []string `long:"externalip" description:"Add a public-facing IP to the list of local external IPs that dcrd will advertise to other peers"`
NoDiscoverIP bool `long:"nodiscoverip" description:"Disable automatic network address discovery of local external IPs"`
Upnp bool `long:"upnp" description:"Use UPnP to map our listening port outside of NAT"`
Upnp bool `long:"upnp" description:"REMOVED: This feature is no longer available and this flag will be removed in a future version"`

// Banning options.
DisableBanning bool `long:"nobanning" description:"Disable banning of misbehaving peers"`
Expand Down
6 changes: 6 additions & 0 deletions dcrd.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func dcrdMain() error {
dcrdLog.Info("File logging disabled")
}

if cfg.Upnp {
dcrdLog.Warnf("The --upnp option is no longer supported. Make sure " +
"to manually map the listening port on your router if you are " +
"behind NAT and wish to receive inbound connections")
}

// Block and transaction processing can cause bursty allocations. This
// limits the garbage collector from excessively overallocating during
// bursts. It does this by tweaking the soft memory limit.
Expand Down
1 change: 0 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ Application Options:
peers
--nodiscoverip Disable automatic network address discovery of
local external IPs
--upnp Use UPnP to map our listening port outside of NAT
--nobanning Disable banning of misbehaving peers
--banduration= How long to ban misbehaving peers. Valid time
units are {s, m, h}. Minimum 1 second (default:
Expand Down
9 changes: 3 additions & 6 deletions docs/default_ports.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ While dcrd is highly configurable when it comes to the network configuration,
the following is intended to be a quick reference for the default ports used so
port forwarding can be configured as required.

dcrd provides a `--upnp` flag which can be used to automatically map the Decred
peer-to-peer listening port if your router supports UPnP. If your router does
not support UPnP, or you don't wish to use it, please note that only the Decred
peer-to-peer port should be forwarded unless you specifically want to allow RPC
access to your dcrd from external sources such as in more advanced network
configurations.
Please note that only the Decred peer-to-peer port should be forwarded unless
you specifically want to allow RPC access to your dcrd from external sources
such as in more advanced network configurations.

|Name|Port|
|----|----|
Expand Down
95 changes: 7 additions & 88 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ type server struct {
peerState peerState
relayInv chan relayMsg
broadcast chan broadcastMsg
nat *upnpNAT
db database.DB
timeSource blockchain.MedianTimeSource
services wire.ServiceFlag
Expand Down Expand Up @@ -2747,12 +2746,11 @@ func (s *server) handleAddPeer(sp *serverPeer) bool {
// - There is an external IP explicitly set (--externalip)
// - Listening has been disabled (--nolisten, listen disabled because of
// --connect, etc)
// - Universal Plug and Play is enabled (--upnp)
// - The active network is simnet or regnet
if (cfg.Proxy != "" || cfg.OnionProxy != "") ||
cfg.NoDiscoverIP ||
len(cfg.ExternalIPs) > 0 ||
(cfg.DisableListen || len(cfg.Listeners) == 0) || cfg.Upnp ||
(cfg.DisableListen || len(cfg.Listeners) == 0) ||
s.chainParams.Name == simNetParams.Name ||
s.chainParams.Name == regNetParams.Name {

Expand Down Expand Up @@ -3586,14 +3584,6 @@ func (s *server) Run(ctx context.Context) {
wg.Done()
}()

if s.nat != nil {
wg.Add(1)
go func() {
s.upnpUpdateThread(ctx)
wg.Done()
}()
}

if !cfg.DisableRPC {
// Start the RPC server and rebroadcast handler which ensures
// transactions submitted to the RPC server are rebroadcast until being
Expand Down Expand Up @@ -3690,64 +3680,6 @@ func parseListeners(addrs []string) ([]net.Addr, error) {
return netAddrs, nil
}

func (s *server) upnpUpdateThread(ctx context.Context) {
// Go off immediately to prevent code duplication, thereafter we renew
// lease every 15 minutes.
timer := time.NewTimer(0 * time.Second)
lport, _ := strconv.ParseInt(s.chainParams.DefaultPort, 10, 16)

first := true
out:
for {
select {
case <-timer.C:
// TODO: pick external port more cleverly
// TODO: know which ports we are listening to on an external net.
// TODO: if specific listen port doesn't work then ask for wildcard
// listen port?
// XXX this assumes timeout is in seconds.
listenPort, err := s.nat.AddPortMapping("tcp", int(lport), int(lport),
"dcrd listen port", 20*60)
if err != nil {
srvrLog.Warnf("can't add UPnP port mapping: %v", err)
}
if first && err == nil {
// TODO: look this up periodically to see if upnp domain changed
// and so did ip.
externalip, err := s.nat.GetExternalAddress()
if err != nil {
srvrLog.Warnf("UPnP can't get external address: %v", err)
continue out
}
localAddr := addrmgr.NewNetAddressFromIPPort(externalip,
uint16(listenPort), s.services)
err = s.addrManager.AddLocalAddress(localAddr, addrmgr.UpnpPrio)
if err != nil {
srvrLog.Warnf("Failed to add UPnP local address %s: %v",
localAddr, err)
} else {
srvrLog.Warnf("Successfully bound via UPnP to %s",
localAddr)
first = false
}
}
timer.Reset(time.Minute * 15)

case <-ctx.Done():
break out
}
}

timer.Stop()

err := s.nat.DeletePortMapping("tcp", int(lport), int(lport))
if err != nil {
srvrLog.Warnf("unable to remove UPnP port mapping: %v", err)
} else {
srvrLog.Debugf("successfully disestablished UPnP port mapping")
}
}

// standardScriptVerifyFlags returns the script flags that should be used when
// executing transaction scripts to enforce additional checks which are required
// for the script to be considered standard. Note these flags are different
Expand Down Expand Up @@ -4104,10 +4036,9 @@ func newServer(ctx context.Context, profiler *profileServer,
services := defaultServices

var listeners []net.Listener
var nat *upnpNAT
if !cfg.DisableListen {
var err error
listeners, nat, err = initListeners(ctx, chainParams, amgr, listenAddrs,
listeners, err = initListeners(ctx, chainParams, amgr, listenAddrs,
services)
if err != nil {
return nil, err
Expand All @@ -4131,7 +4062,6 @@ func newServer(ctx context.Context, profiler *profileServer,
relayInv: make(chan relayMsg, cfg.MaxPeers),
broadcast: make(chan broadcastMsg, cfg.MaxPeers),
modifyRebroadcastInv: make(chan any),
nat: nat,
db: db,
timeSource: blockchain.NewMedianTime(),
services: services,
Expand Down Expand Up @@ -4616,13 +4546,12 @@ func newServer(ctx context.Context, profiler *profileServer,
}

// initListeners initializes the configured net listeners and adds any bound
// addresses to the address manager. Returns the listeners and a NAT interface,
// which is non-nil if UPnP is in use.
func initListeners(ctx context.Context, params *chaincfg.Params, amgr *addrmgr.AddrManager, listenAddrs []string, services wire.ServiceFlag) ([]net.Listener, *upnpNAT, error) {
// addresses to the address manager. Returns the listeners.
func initListeners(ctx context.Context, params *chaincfg.Params, amgr *addrmgr.AddrManager, listenAddrs []string, services wire.ServiceFlag) ([]net.Listener, error) {
// Listen for TCP connections at the configured addresses
netAddrs, err := parseListeners(listenAddrs)
if err != nil {
return nil, nil, err
return nil, err
}

var notifyAddrServer boundAddrEventServer
Expand All @@ -4642,13 +4571,12 @@ func initListeners(ctx context.Context, params *chaincfg.Params, amgr *addrmgr.A
notifyAddrServer.notifyP2PAddress(listener.Addr().String())
}

var nat *upnpNAT
if len(cfg.ExternalIPs) != 0 {
defaultPort, err := strconv.ParseUint(params.DefaultPort, 10, 16)
if err != nil {
srvrLog.Errorf("Can not parse default port %s for active chain: %v",
params.DefaultPort, err)
return nil, nil, err
return nil, err
}

for _, sip := range cfg.ExternalIPs {
Expand Down Expand Up @@ -4679,15 +4607,6 @@ func initListeners(ctx context.Context, params *chaincfg.Params, amgr *addrmgr.A
}
}
} else {
if cfg.Upnp {
var err error
nat, err = discover(ctx)
if err != nil {
srvrLog.Warnf("Can't discover upnp: %v", err)
}
// nil nat here is fine, just means no upnp on network.
}

// Add bound addresses to address manager to be advertised to peers.
for _, listener := range listeners {
addr := listener.Addr().String()
Expand All @@ -4698,7 +4617,7 @@ func initListeners(ctx context.Context, params *chaincfg.Params, amgr *addrmgr.A
}
}

return listeners, nat, nil
return listeners, nil
}

// addrStringToNetAddr takes an address in the form of 'host:port' and returns
Expand Down
Loading