From b1d6deaf0b1d10d72ca953ecf88318106d425249 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Thu, 28 Jun 2018 00:09:39 -0700 Subject: [PATCH] config: rename skip_upnp to upnp (#1827) * config: rename skip_upnp to upnp Change default option to enable upnp. Closes #1806 * doc updates - fix comment and set UPNP to false in TestP2PConfig - add UPNP to config template - update changelog --- CHANGELOG.md | 9 ++++----- cmd/tendermint/commands/run_node.go | 2 +- config/config.go | 6 +++--- config/toml.go | 3 +++ docs/specification/configuration.md | 3 +++ node/node.go | 4 ++-- p2p/listener.go | 6 +++--- p2p/listener_test.go | 2 +- p2p/pex/pex_reactor_test.go | 4 ++-- 9 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7e595227..76fac1875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,18 +3,17 @@ ## TBD BUG FIXES: - - [rpc] limited number of HTTP/WebSocket connections (`rpc.max_open_connections`) and gRPC connections (`rpc.grpc_max_open_connections`). Check out [Running In Production](https://tendermint.readthedocs.io/en/master/running-in-production.html) guide if you want to increase them. - -## 0.21.2 -IMPROVEMENT +BREAKING CHANGES: +- [config] Rename `skip_upnp` to `upnp`, and turn it off by default. -- [rpc/client] Supports https and wss now +IMPROVEMENT +- [rpc/client] Supports https and wss now. ## 0.21.0 diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 0d50f9e4b..542e5c991 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -33,7 +33,7 @@ func AddNodeFlags(cmd *cobra.Command) { cmd.Flags().String("p2p.laddr", config.P2P.ListenAddress, "Node listen address. (0.0.0.0:0 means any interface, any port)") cmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma-delimited ID@host:port seed nodes") cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma-delimited ID@host:port persistent peers") - cmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration") + cmd.Flags().Bool("p2p.upnp", config.P2P.UPNP, "Enable/disable UPNP port forwarding") cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable/disable Peer-Exchange") cmd.Flags().Bool("p2p.seed_mode", config.P2P.SeedMode, "Enable/disable seed mode") cmd.Flags().String("p2p.private_peer_ids", config.P2P.PrivatePeerIDs, "Comma-delimited private peer IDs") diff --git a/config/config.go b/config/config.go index e86b0e871..e081056fa 100644 --- a/config/config.go +++ b/config/config.go @@ -284,8 +284,8 @@ type P2PConfig struct { // Do not add private peers to this list if you don't want them advertised PersistentPeers string `mapstructure:"persistent_peers"` - // Skip UPNP port forwarding - SkipUPNP bool `mapstructure:"skip_upnp"` + // UPNP port forwarding + UPNP bool `mapstructure:"upnp"` // Path to address book AddrBook string `mapstructure:"addr_book_file"` @@ -341,6 +341,7 @@ type P2PConfig struct { func DefaultP2PConfig() *P2PConfig { return &P2PConfig{ ListenAddress: "tcp://0.0.0.0:26656", + UPNP: false, AddrBook: defaultAddrBookPath, AddrBookStrict: true, MaxNumPeers: 50, @@ -363,7 +364,6 @@ func DefaultP2PConfig() *P2PConfig { func TestP2PConfig() *P2PConfig { cfg := DefaultP2PConfig() cfg.ListenAddress = "tcp://0.0.0.0:36656" - cfg.SkipUPNP = true cfg.FlushThrottleTimeout = 10 cfg.AllowDuplicateIP = true return cfg diff --git a/config/toml.go b/config/toml.go index c0840e440..4d892339a 100644 --- a/config/toml.go +++ b/config/toml.go @@ -149,6 +149,9 @@ seeds = "{{ .P2P.Seeds }}" # Do not add private peers to this list if you don't want them advertised persistent_peers = "{{ .P2P.PersistentPeers }}" +# UPNP port forwarding +upnp = {{ .P2P.UPNP }} + # Path to address book addr_book_file = "{{ js .P2P.AddrBook }}" diff --git a/docs/specification/configuration.md b/docs/specification/configuration.md index 59de9767b..1cf661200 100644 --- a/docs/specification/configuration.md +++ b/docs/specification/configuration.md @@ -103,6 +103,9 @@ seeds = "" # Do not add private peers to this list if you don't want them advertised persistent_peers = "" +# UPNP port forwarding +upnp = false + # Path to address book addr_book_file = "addrbook.json" diff --git a/node/node.go b/node/node.go index bd3ac4645..6e4f7df04 100644 --- a/node/node.go +++ b/node/node.go @@ -10,8 +10,8 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" - abci "github.com/tendermint/tendermint/abci/types" amino "github.com/tendermint/go-amino" + abci "github.com/tendermint/tendermint/abci/types" cmn "github.com/tendermint/tmlibs/common" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/tmlibs/log" @@ -427,7 +427,7 @@ func (n *Node) OnStart() error { // Create & add listener protocol, address := cmn.ProtocolAndAddress(n.config.P2P.ListenAddress) - l := p2p.NewDefaultListener(protocol, address, n.config.P2P.SkipUPNP, n.Logger.With("module", "p2p")) + l := p2p.NewDefaultListener(protocol, address, n.config.P2P.UPNP, n.Logger.With("module", "p2p")) n.sw.AddListener(l) // Generate node PrivKey diff --git a/p2p/listener.go b/p2p/listener.go index e698765cd..3d2fae741 100644 --- a/p2p/listener.go +++ b/p2p/listener.go @@ -47,8 +47,8 @@ func splitHostPort(addr string) (host string, port int) { return host, port } -// skipUPNP: If true, does not try getUPNPExternalAddress() -func NewDefaultListener(protocol string, lAddr string, skipUPNP bool, logger log.Logger) Listener { +// UPNP: If false, does not try getUPNPExternalAddress() +func NewDefaultListener(protocol string, lAddr string, UPNP bool, logger log.Logger) Listener { // Local listen IP & port lAddrIP, lAddrPort := splitHostPort(lAddr) @@ -79,7 +79,7 @@ func NewDefaultListener(protocol string, lAddr string, skipUPNP bool, logger log // Determine external address... var extAddr *NetAddress - if !skipUPNP { + if UPNP { // If the lAddrIP is INADDR_ANY, try UPnP if lAddrIP == "" || lAddrIP == "0.0.0.0" { extAddr = getUPNPExternalAddress(lAddrPort, listenerPort, logger) diff --git a/p2p/listener_test.go b/p2p/listener_test.go index 92018e0aa..1aa0a93a8 100644 --- a/p2p/listener_test.go +++ b/p2p/listener_test.go @@ -9,7 +9,7 @@ import ( func TestListener(t *testing.T) { // Create a listener - l := NewDefaultListener("tcp", ":8001", true, log.TestingLogger()) + l := NewDefaultListener("tcp", ":8001", false, log.TestingLogger()) // Dial the listener lAddr := l.ExternalAddress() diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index f4251e869..e8231c180 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -109,7 +109,7 @@ func TestPEXReactorRunning(t *testing.T) { addOtherNodeAddrToAddrBook(2, 1) for i, sw := range switches { - sw.AddListener(p2p.NewDefaultListener("tcp", sw.NodeInfo().ListenAddr, true, logger.With("pex", i))) + sw.AddListener(p2p.NewDefaultListener("tcp", sw.NodeInfo().ListenAddr, false, logger.With("pex", i))) err := sw.Start() // start switch and reactors require.Nil(t, err) @@ -232,7 +232,7 @@ func TestPEXReactorUsesSeedsIfNeeded(t *testing.T) { p2p.NewDefaultListener( "tcp", seed.NodeInfo().ListenAddr, - true, + false, log.TestingLogger(), ), )