From 8bef3eb1f46c0a4539ecfe94b6130cbfb74f6840 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 6 Mar 2018 14:51:16 +0400 Subject: [PATCH 1/6] private peers Refs #1126 --- CHANGELOG.md | 3 +++ cmd/tendermint/commands/run_node.go | 5 +++-- config/config.go | 6 ++++-- config/toml.go | 3 +++ docs/specification/configuration.rst | 3 +++ node/node.go | 8 ++++++++ rpc/client/localclient.go | 4 ++-- rpc/client/mock/client.go | 4 ++-- rpc/core/net.go | 9 +++++++-- rpc/core/routes.go | 2 +- 10 files changed, 36 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bece3471..decf8506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,9 @@ IMPROVEMENTS: (`persistent_kvstore`) (name "dummy" is deprecated and will not work in release after this one) +FEATURES: +- [config] added the `--p2p.private_peers` flag and `PrivatePeers` config variable (see config for description) + ## 0.16.0 (February 20th, 2017) BREAKING CHANGES: diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 0e18be03..45a502c3 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -31,11 +31,12 @@ func AddNodeFlags(cmd *cobra.Command) { // p2p flags 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 host:port seed nodes") - cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma delimited host:port persistent peers") + cmd.Flags().String("p2p.seeds", config.P2P.Seeds, "Comma-delimited host:port seed nodes") + cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma-delimited host:port persistent peers") cmd.Flags().Bool("p2p.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration") 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_peers", config.P2P.PrivatePeers, "Comma-delimited host:port private peers") // consensus flags cmd.Flags().Bool("consensus.create_empty_blocks", config.Consensus.CreateEmptyBlocks, "Set this to false to only produce blocks when there are txs or when the AppHash changes") diff --git a/config/config.go b/config/config.go index a433047f..fd77a9db 100644 --- a/config/config.go +++ b/config/config.go @@ -250,8 +250,7 @@ type P2PConfig struct { // We only use these if we can’t connect to peers in the addrbook Seeds string `mapstructure:"seeds"` - // Comma separated list of persistent peers to connect to - // We always connect to these + // Comma separated list of nodes to keep persistent connections to PersistentPeers string `mapstructure:"persistent_peers"` // Skip UPNP port forwarding @@ -289,6 +288,9 @@ type P2PConfig struct { // Authenticated encryption AuthEnc bool `mapstructure:"auth_enc"` + + // Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to + PrivatePeers string `mapstructure:"private_peers"` } // DefaultP2PConfig returns a default configuration for the peer-to-peer layer diff --git a/config/toml.go b/config/toml.go index 35e0985f..38c5a333 100644 --- a/config/toml.go +++ b/config/toml.go @@ -162,6 +162,9 @@ seed_mode = {{ .P2P.SeedMode }} # Authenticated encryption auth_enc = {{ .P2P.AuthEnc }} +# Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to +private_peers = {{ .P2P.PrivatePeers }} + ##### mempool configuration options ##### [mempool] diff --git a/docs/specification/configuration.rst b/docs/specification/configuration.rst index 983ac87c..33f9657f 100644 --- a/docs/specification/configuration.rst +++ b/docs/specification/configuration.rst @@ -124,6 +124,9 @@ like the file below, however, double check by inspecting the # Authenticated encryption auth_enc = true + # Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to + private_peers = "" + ##### mempool configuration options ##### [mempool] diff --git a/node/node.go b/node/node.go index d40322fa..13a60c44 100644 --- a/node/node.go +++ b/node/node.go @@ -421,6 +421,14 @@ func (n *Node) OnStart() error { } } + // Always connect to private peers, but do not add them to addrbook + if n.config.P2P.PrivatePeers != "" { + err = n.sw.DialPeersAsync(nil, strings.Split(n.config.P2P.PrivatePeers, ","), true) + if err != nil { + return err + } + } + // start tx indexer return n.indexerService.Start() } diff --git a/rpc/client/localclient.go b/rpc/client/localclient.go index be989ee1..f5f6d7da 100644 --- a/rpc/client/localclient.go +++ b/rpc/client/localclient.go @@ -88,8 +88,8 @@ func (Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return core.UnsafeDialSeeds(seeds) } -func (Local) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { - return core.UnsafeDialPeers(peers, persistent) +func (Local) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { + return core.UnsafeDialPeers(peers, persistent, private) } func (Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { diff --git a/rpc/client/mock/client.go b/rpc/client/mock/client.go index 6af9abb2..8c9b8ad7 100644 --- a/rpc/client/mock/client.go +++ b/rpc/client/mock/client.go @@ -110,8 +110,8 @@ func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return core.UnsafeDialSeeds(seeds) } -func (c Client) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { - return core.UnsafeDialPeers(peers, persistent) +func (c Client) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { + return core.UnsafeDialPeers(peers, persistent, private) } func (c Client) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { diff --git a/rpc/core/net.go b/rpc/core/net.go index 14e7389d..abe7f7a2 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -2,6 +2,7 @@ package core import ( "github.com/pkg/errors" + p2p "github.com/tendermint/tendermint/p2p" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) @@ -66,13 +67,17 @@ func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return &ctypes.ResultDialSeeds{"Dialing seeds in progress. See /net_info for details"}, nil } -func UnsafeDialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { +func UnsafeDialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { if len(peers) == 0 { return &ctypes.ResultDialPeers{}, errors.New("No peers provided") } // starts go routines to dial each peer after random delays logger.Info("DialPeers", "addrBook", addrBook, "peers", peers, "persistent", persistent) - err := p2pSwitch.DialPeersAsync(addrBook, peers, persistent) + var ab p2p.AddrBook + if !private { + ab = addrBook + } + err := p2pSwitch.DialPeersAsync(ab, peers, persistent) if err != nil { return &ctypes.ResultDialPeers{}, err } diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 3ea7aa08..e4343cf4 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -39,7 +39,7 @@ var Routes = map[string]*rpc.RPCFunc{ func AddUnsafeRoutes() { // control API Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds") - Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent") + Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent,private") Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "") // profiler API From a39aec0bae100fe950a3993404ddf09ff84f9231 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 7 Mar 2018 12:14:53 +0400 Subject: [PATCH 2/6] rename private_peers to private_peer_ids to distinguish from peers --- CHANGELOG.md | 2 +- cmd/tendermint/commands/run_node.go | 6 ++-- config/config.go | 4 +-- config/toml.go | 4 +-- docs/specification/configuration.rst | 4 +-- node/node.go | 44 +++++++++++++++++++++++----- p2p/pex/pex_reactor.go | 23 +++++++++++++-- 7 files changed, 67 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index decf8506..d528c95e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,7 +38,7 @@ IMPROVEMENTS: release after this one) FEATURES: -- [config] added the `--p2p.private_peers` flag and `PrivatePeers` config variable (see config for description) +- [config] added the `--p2p.private_peer_ids` flag and `PrivatePeerIDs` config variable (see config for description) ## 0.16.0 (February 20th, 2017) diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 45a502c3..0fcab3e3 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -31,12 +31,12 @@ func AddNodeFlags(cmd *cobra.Command) { // p2p flags 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 host:port seed nodes") - cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "Comma-delimited host:port persistent peers") + 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.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_peers", config.P2P.PrivatePeers, "Comma-delimited host:port private peers") + cmd.Flags().String("p2p.private_peer_ids", config.P2P.PrivatePeerIDs, "Comma-delimited private peer IDs") // consensus flags cmd.Flags().Bool("consensus.create_empty_blocks", config.Consensus.CreateEmptyBlocks, "Set this to false to only produce blocks when there are txs or when the AppHash changes") diff --git a/config/config.go b/config/config.go index fd77a9db..64da6373 100644 --- a/config/config.go +++ b/config/config.go @@ -289,8 +289,8 @@ type P2PConfig struct { // Authenticated encryption AuthEnc bool `mapstructure:"auth_enc"` - // Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to - PrivatePeers string `mapstructure:"private_peers"` + // Comma separated list of peer IDs to keep private (will not be gossiped to other peers) + PrivatePeerIDs string `mapstructure:"private_peer_ids"` } // DefaultP2PConfig returns a default configuration for the peer-to-peer layer diff --git a/config/toml.go b/config/toml.go index 38c5a333..e40fe8fd 100644 --- a/config/toml.go +++ b/config/toml.go @@ -162,8 +162,8 @@ seed_mode = {{ .P2P.SeedMode }} # Authenticated encryption auth_enc = {{ .P2P.AuthEnc }} -# Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to -private_peers = {{ .P2P.PrivatePeers }} +# Comma separated list of peer IDs to keep private (will not be gossiped to other peers) +private_peer_ids = {{ .P2P.PrivatePeerIDs }} ##### mempool configuration options ##### [mempool] diff --git a/docs/specification/configuration.rst b/docs/specification/configuration.rst index 33f9657f..31490507 100644 --- a/docs/specification/configuration.rst +++ b/docs/specification/configuration.rst @@ -124,8 +124,8 @@ like the file below, however, double check by inspecting the # Authenticated encryption auth_enc = true - # Comma separated list of nodes to keep private (will not be gossiped to other peers) connections to - private_peers = "" + # Comma separated list of peer IDs to keep private (will not be gossiped to other peers) + private_peer_ids = "" ##### mempool configuration options ##### [mempool] diff --git a/node/node.go b/node/node.go index 13a60c44..94616b0c 100644 --- a/node/node.go +++ b/node/node.go @@ -281,8 +281,15 @@ func NewNode(config *cfg.Config, if config.P2P.Seeds != "" { seeds = strings.Split(config.P2P.Seeds, ",") } + var privatePeerIDs []string + if config.P2P.PrivatePeerIDs != "" { + privatePeerIDs = strings.Split(config.P2P.PrivatePeerIDs, ",") + } pexReactor := pex.NewPEXReactor(addrBook, - &pex.PEXReactorConfig{Seeds: seeds, SeedMode: config.P2P.SeedMode}) + &pex.PEXReactorConfig{ + Seeds: seeds, + SeedMode: config.P2P.SeedMode, + PrivatePeerIDs: privatePeerIDs}) pexReactor.SetLogger(p2pLogger) sw.AddReactor("PEX", pexReactor) } @@ -415,17 +422,38 @@ func (n *Node) OnStart() error { // Always connect to persistent peers if n.config.P2P.PersistentPeers != "" { - err = n.sw.DialPeersAsync(n.addrBook, strings.Split(n.config.P2P.PersistentPeers, ","), true) + // are any of the persistent peers private? + persistentPeers := []string{} + persistentAndPrivatePeers := []string{} + var privatePeerIDs []string + if n.config.P2P.PrivatePeerIDs != "" { + privatePeerIDs = strings.Split(n.config.P2P.PrivatePeerIDs, ",") + } + PP_LOOP: + for _, peer := range strings.Split(n.config.P2P.PersistentPeers, ",") { + spl := strings.Split(peer, "@") + if len(spl) == 2 { + for _, ppID := range privatePeerIDs { + if spl[0] == ppID { + persistentAndPrivatePeers = append(persistentAndPrivatePeers, peer) + continue PP_LOOP + } + } + } + persistentPeers = append(persistentPeers, peer) + } + + err = n.sw.DialPeersAsync(n.addrBook, persistentPeers, true) if err != nil { return err } - } - // Always connect to private peers, but do not add them to addrbook - if n.config.P2P.PrivatePeers != "" { - err = n.sw.DialPeersAsync(nil, strings.Split(n.config.P2P.PrivatePeers, ","), true) - if err != nil { - return err + // if any of the persistent peers are private, do not add them to addrbook + if len(persistentAndPrivatePeers) > 0 { + err = n.sw.DialPeersAsync(nil, persistentAndPrivatePeers, true) + if err != nil { + return err + } } } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 193efc88..cb9e62bf 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -74,6 +74,10 @@ type PEXReactorConfig struct { // Seeds is a list of addresses reactor may use // if it can't connect to peers in the addrbook. Seeds []string + + // PrivatePeerIDs is a list of peer IDs, which must not be gossiped to other + // peers. + PrivatePeerIDs []string } type _attemptsToDial struct { @@ -152,7 +156,9 @@ func (r *PEXReactor) AddPeer(p Peer) { // Let the ensurePeersRoutine handle asking for more // peers when we need - we don't trust inbound peers as much. addr := p.NodeInfo().NetAddress() - r.book.AddAddress(addr, addr) + if !isAddrPrivate(addr, r.config.PrivatePeerIDs) { + r.book.AddAddress(addr, addr) + } } } @@ -251,7 +257,10 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error { srcAddr := src.NodeInfo().NetAddress() for _, netAddr := range addrs { - if netAddr != nil { + if netAddr == nil { + continue + } + if !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) { r.book.AddAddress(netAddr, srcAddr) } } @@ -579,6 +588,16 @@ func (r *PEXReactor) attemptDisconnects() { } } +// isAddrPrivate returns true if addr is private. +func isAddrPrivate(addr *p2p.NetAddress, privatePeerIDs []string) bool { + for _, id := range privatePeerIDs { + if string(addr.ID) == id { + return true + } + } + return false +} + //----------------------------------------------------------------------------- // Messages From 736ea055a8a6157e4867485c5d2e1c50dd2810f9 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 7 Mar 2018 12:25:31 +0400 Subject: [PATCH 3/6] add a test for pex reactor --- p2p/pex/pex_reactor_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index f5d81503..41eb2e8d 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -268,6 +268,25 @@ func TestPEXReactorCrawlStatus(t *testing.T) { // TODO: test } +func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) { + pexR, book := createReactor(&PEXReactorConfig{PrivatePeerIDs: []string{string(peer.NodeInfo().ID())}}) + defer teardownReactor(book) + + peer := p2p.CreateRandomPeer(false) + + // we have to send a request to receive responses + r.RequestAddrs(peer) + + size := book.Size() + addrs := []*p2p.NetAddress{peer.NodeInfo().NetAddress()} + msg := wire.BinaryBytes(struct{ PexMessage }{&pexAddrsMessage{Addrs: addrs}}) + r.Receive(PexChannel, peer, msg) + assert.Equal(t, size, book.Size()) + + r.AddPeer(peer) + assert.Equal(t, size, book.Size()) +} + func TestPEXReactorDialPeer(t *testing.T) { pexR, book := createReactor(&PEXReactorConfig{}) defer teardownReactor(book) From 31deaa4a79cb9c0d0cd27ccd332ca3abe3556586 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 13 Mar 2018 10:30:24 +0400 Subject: [PATCH 4/6] fix broken merge --- p2p/pex/pex_reactor.go | 5 +---- p2p/pex/pex_reactor_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index cb9e62bf..5b53d3f4 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -257,10 +257,7 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error { srcAddr := src.NodeInfo().NetAddress() for _, netAddr := range addrs { - if netAddr == nil { - continue - } - if !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) { + if netAddr != nil && !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) { r.book.AddAddress(netAddr, srcAddr) } } diff --git a/p2p/pex/pex_reactor_test.go b/p2p/pex/pex_reactor_test.go index 41eb2e8d..95cedfea 100644 --- a/p2p/pex/pex_reactor_test.go +++ b/p2p/pex/pex_reactor_test.go @@ -269,21 +269,21 @@ func TestPEXReactorCrawlStatus(t *testing.T) { } func TestPEXReactorDoesNotAddPrivatePeersToAddrBook(t *testing.T) { + peer := p2p.CreateRandomPeer(false) + pexR, book := createReactor(&PEXReactorConfig{PrivatePeerIDs: []string{string(peer.NodeInfo().ID())}}) defer teardownReactor(book) - peer := p2p.CreateRandomPeer(false) - // we have to send a request to receive responses - r.RequestAddrs(peer) + pexR.RequestAddrs(peer) size := book.Size() addrs := []*p2p.NetAddress{peer.NodeInfo().NetAddress()} msg := wire.BinaryBytes(struct{ PexMessage }{&pexAddrsMessage{Addrs: addrs}}) - r.Receive(PexChannel, peer, msg) + pexR.Receive(PexChannel, peer, msg) assert.Equal(t, size, book.Size()) - r.AddPeer(peer) + pexR.AddPeer(peer) assert.Equal(t, size, book.Size()) } @@ -395,7 +395,7 @@ func createReactor(config *PEXReactorConfig) (r *PEXReactor, book *addrBook) { book = NewAddrBook(filepath.Join(dir, "addrbook.json"), true) book.SetLogger(log.TestingLogger()) - r = NewPEXReactor(book, &PEXReactorConfig{}) + r = NewPEXReactor(book, config) r.SetLogger(log.TestingLogger()) return } From a40518c7da5866b02bdd3c60377e77b13f001e57 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 13 Mar 2018 10:30:45 +0400 Subject: [PATCH 5/6] revert adding dial_peers's private flag --- rpc/client/localclient.go | 4 ++-- rpc/client/mock/client.go | 4 ++-- rpc/core/net.go | 10 +++------- rpc/core/routes.go | 2 +- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/rpc/client/localclient.go b/rpc/client/localclient.go index f5f6d7da..be989ee1 100644 --- a/rpc/client/localclient.go +++ b/rpc/client/localclient.go @@ -88,8 +88,8 @@ func (Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return core.UnsafeDialSeeds(seeds) } -func (Local) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { - return core.UnsafeDialPeers(peers, persistent, private) +func (Local) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { + return core.UnsafeDialPeers(peers, persistent) } func (Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { diff --git a/rpc/client/mock/client.go b/rpc/client/mock/client.go index 8c9b8ad7..6af9abb2 100644 --- a/rpc/client/mock/client.go +++ b/rpc/client/mock/client.go @@ -110,8 +110,8 @@ func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return core.UnsafeDialSeeds(seeds) } -func (c Client) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { - return core.UnsafeDialPeers(peers, persistent, private) +func (c Client) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { + return core.UnsafeDialPeers(peers, persistent) } func (c Client) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { diff --git a/rpc/core/net.go b/rpc/core/net.go index abe7f7a2..9b04926a 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -2,7 +2,7 @@ package core import ( "github.com/pkg/errors" - p2p "github.com/tendermint/tendermint/p2p" + ctypes "github.com/tendermint/tendermint/rpc/core/types" ) @@ -67,17 +67,13 @@ func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { return &ctypes.ResultDialSeeds{"Dialing seeds in progress. See /net_info for details"}, nil } -func UnsafeDialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) { +func UnsafeDialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { if len(peers) == 0 { return &ctypes.ResultDialPeers{}, errors.New("No peers provided") } // starts go routines to dial each peer after random delays logger.Info("DialPeers", "addrBook", addrBook, "peers", peers, "persistent", persistent) - var ab p2p.AddrBook - if !private { - ab = addrBook - } - err := p2pSwitch.DialPeersAsync(ab, peers, persistent) + err := p2pSwitch.DialPeersAsync(addrBook, peers, persistent) if err != nil { return &ctypes.ResultDialPeers{}, err } diff --git a/rpc/core/routes.go b/rpc/core/routes.go index e4343cf4..3ea7aa08 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -39,7 +39,7 @@ var Routes = map[string]*rpc.RPCFunc{ func AddUnsafeRoutes() { // control API Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds") - Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent,private") + Routes["dial_peers"] = rpc.NewRPCFunc(UnsafeDialPeers, "peers,persistent") Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "") // profiler API From 2a258a2c3f1c87bf2a3dbb991bef9c6dc85074c3 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 13 Mar 2018 10:57:21 +0400 Subject: [PATCH 6/6] revert removing private peers from persistent --- config/config.go | 1 + config/toml.go | 1 + docs/specification/configuration.rst | 1 + node/node.go | 31 +--------------------------- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/config/config.go b/config/config.go index 64da6373..6b3f87b5 100644 --- a/config/config.go +++ b/config/config.go @@ -251,6 +251,7 @@ type P2PConfig struct { Seeds string `mapstructure:"seeds"` // Comma separated list of nodes to keep persistent connections to + // Do not add private peers to this list if you don't want them advertised PersistentPeers string `mapstructure:"persistent_peers"` // Skip UPNP port forwarding diff --git a/config/toml.go b/config/toml.go index e40fe8fd..305e98d1 100644 --- a/config/toml.go +++ b/config/toml.go @@ -127,6 +127,7 @@ laddr = "{{ .P2P.ListenAddress }}" seeds = "" # Comma separated list of nodes to keep persistent connections to +# Do not add private peers to this list if you don't want them advertised persistent_peers = "" # Path to address book diff --git a/docs/specification/configuration.rst b/docs/specification/configuration.rst index 31490507..2a9ad794 100644 --- a/docs/specification/configuration.rst +++ b/docs/specification/configuration.rst @@ -89,6 +89,7 @@ like the file below, however, double check by inspecting the seeds = "" # Comma separated list of nodes to keep persistent connections to + # Do not add private peers to this list if you don't want them advertised persistent_peers = "" # Path to address book diff --git a/node/node.go b/node/node.go index 94616b0c..9d60f3d0 100644 --- a/node/node.go +++ b/node/node.go @@ -422,39 +422,10 @@ func (n *Node) OnStart() error { // Always connect to persistent peers if n.config.P2P.PersistentPeers != "" { - // are any of the persistent peers private? - persistentPeers := []string{} - persistentAndPrivatePeers := []string{} - var privatePeerIDs []string - if n.config.P2P.PrivatePeerIDs != "" { - privatePeerIDs = strings.Split(n.config.P2P.PrivatePeerIDs, ",") - } - PP_LOOP: - for _, peer := range strings.Split(n.config.P2P.PersistentPeers, ",") { - spl := strings.Split(peer, "@") - if len(spl) == 2 { - for _, ppID := range privatePeerIDs { - if spl[0] == ppID { - persistentAndPrivatePeers = append(persistentAndPrivatePeers, peer) - continue PP_LOOP - } - } - } - persistentPeers = append(persistentPeers, peer) - } - - err = n.sw.DialPeersAsync(n.addrBook, persistentPeers, true) + err = n.sw.DialPeersAsync(n.addrBook, strings.Split(n.config.P2P.PersistentPeers, ","), true) if err != nil { return err } - - // if any of the persistent peers are private, do not add them to addrbook - if len(persistentAndPrivatePeers) > 0 { - err = n.sw.DialPeersAsync(nil, persistentAndPrivatePeers, true) - if err != nil { - return err - } - } } // start tx indexer