private peers

Refs #1126
This commit is contained in:
Anton Kaliaev 2018-03-06 14:51:16 +04:00
parent 244d88dfda
commit 8bef3eb1f4
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
10 changed files with 36 additions and 11 deletions

View File

@ -37,6 +37,9 @@ IMPROVEMENTS:
(`persistent_kvstore`) (name "dummy" is deprecated and will not work in (`persistent_kvstore`) (name "dummy" is deprecated and will not work in
release after this one) 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) ## 0.16.0 (February 20th, 2017)
BREAKING CHANGES: BREAKING CHANGES:

View File

@ -31,11 +31,12 @@ func AddNodeFlags(cmd *cobra.Command) {
// p2p flags // 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.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.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.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.skip_upnp", config.P2P.SkipUPNP, "Skip UPNP configuration")
cmd.Flags().Bool("p2p.pex", config.P2P.PexReactor, "Enable/disable Peer-Exchange") 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().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 // 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") 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")

View File

@ -250,8 +250,7 @@ type P2PConfig struct {
// We only use these if we cant connect to peers in the addrbook // We only use these if we cant connect to peers in the addrbook
Seeds string `mapstructure:"seeds"` Seeds string `mapstructure:"seeds"`
// Comma separated list of persistent peers to connect to // Comma separated list of nodes to keep persistent connections to
// We always connect to these
PersistentPeers string `mapstructure:"persistent_peers"` PersistentPeers string `mapstructure:"persistent_peers"`
// Skip UPNP port forwarding // Skip UPNP port forwarding
@ -289,6 +288,9 @@ type P2PConfig struct {
// Authenticated encryption // Authenticated encryption
AuthEnc bool `mapstructure:"auth_enc"` 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 // DefaultP2PConfig returns a default configuration for the peer-to-peer layer

View File

@ -162,6 +162,9 @@ seed_mode = {{ .P2P.SeedMode }}
# Authenticated encryption # Authenticated encryption
auth_enc = {{ .P2P.AuthEnc }} 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 configuration options #####
[mempool] [mempool]

View File

@ -124,6 +124,9 @@ like the file below, however, double check by inspecting the
# Authenticated encryption # Authenticated encryption
auth_enc = true 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 configuration options #####
[mempool] [mempool]

View File

@ -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 // start tx indexer
return n.indexerService.Start() return n.indexerService.Start()
} }

View File

@ -88,8 +88,8 @@ func (Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
return core.UnsafeDialSeeds(seeds) return core.UnsafeDialSeeds(seeds)
} }
func (Local) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { func (Local) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) {
return core.UnsafeDialPeers(peers, persistent) return core.UnsafeDialPeers(peers, persistent, private)
} }
func (Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { func (Local) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {

View File

@ -110,8 +110,8 @@ func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
return core.UnsafeDialSeeds(seeds) return core.UnsafeDialSeeds(seeds)
} }
func (c Client) DialPeers(peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { func (c Client) DialPeers(peers []string, persistent bool, private bool) (*ctypes.ResultDialPeers, error) {
return core.UnsafeDialPeers(peers, persistent) return core.UnsafeDialPeers(peers, persistent, private)
} }
func (c Client) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) { func (c Client) BlockchainInfo(minHeight, maxHeight int64) (*ctypes.ResultBlockchainInfo, error) {

View File

@ -2,6 +2,7 @@ package core
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
p2p "github.com/tendermint/tendermint/p2p"
ctypes "github.com/tendermint/tendermint/rpc/core/types" 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 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 { if len(peers) == 0 {
return &ctypes.ResultDialPeers{}, errors.New("No peers provided") return &ctypes.ResultDialPeers{}, errors.New("No peers provided")
} }
// starts go routines to dial each peer after random delays // starts go routines to dial each peer after random delays
logger.Info("DialPeers", "addrBook", addrBook, "peers", peers, "persistent", persistent) 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 { if err != nil {
return &ctypes.ResultDialPeers{}, err return &ctypes.ResultDialPeers{}, err
} }

View File

@ -39,7 +39,7 @@ var Routes = map[string]*rpc.RPCFunc{
func AddUnsafeRoutes() { func AddUnsafeRoutes() {
// control API // control API
Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds") 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, "") Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "")
// profiler API // profiler API