mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 14:21:22 +00:00
rename private_peers to private_peer_ids to distinguish from peers
This commit is contained in:
@ -38,7 +38,7 @@ IMPROVEMENTS:
|
|||||||
release after this one)
|
release after this one)
|
||||||
|
|
||||||
FEATURES:
|
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)
|
## 0.16.0 (February 20th, 2017)
|
||||||
|
|
||||||
|
@ -31,12 +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 ID@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 ID@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")
|
cmd.Flags().String("p2p.private_peer_ids", config.P2P.PrivatePeerIDs, "Comma-delimited private peer IDs")
|
||||||
|
|
||||||
// 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")
|
||||||
|
@ -289,8 +289,8 @@ 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
|
// Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
|
||||||
PrivatePeers string `mapstructure:"private_peers"`
|
PrivatePeerIDs string `mapstructure:"private_peer_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultP2PConfig returns a default configuration for the peer-to-peer layer
|
// DefaultP2PConfig returns a default configuration for the peer-to-peer layer
|
||||||
|
@ -162,8 +162,8 @@ 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
|
# Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
|
||||||
private_peers = {{ .P2P.PrivatePeers }}
|
private_peer_ids = {{ .P2P.PrivatePeerIDs }}
|
||||||
|
|
||||||
##### mempool configuration options #####
|
##### mempool configuration options #####
|
||||||
[mempool]
|
[mempool]
|
||||||
|
@ -124,8 +124,8 @@ 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
|
# Comma separated list of peer IDs to keep private (will not be gossiped to other peers)
|
||||||
private_peers = ""
|
private_peer_ids = ""
|
||||||
|
|
||||||
##### mempool configuration options #####
|
##### mempool configuration options #####
|
||||||
[mempool]
|
[mempool]
|
||||||
|
42
node/node.go
42
node/node.go
@ -281,8 +281,15 @@ func NewNode(config *cfg.Config,
|
|||||||
if config.P2P.Seeds != "" {
|
if config.P2P.Seeds != "" {
|
||||||
seeds = strings.Split(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,
|
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)
|
pexReactor.SetLogger(p2pLogger)
|
||||||
sw.AddReactor("PEX", pexReactor)
|
sw.AddReactor("PEX", pexReactor)
|
||||||
}
|
}
|
||||||
@ -415,18 +422,39 @@ func (n *Node) OnStart() error {
|
|||||||
|
|
||||||
// Always connect to persistent peers
|
// Always connect to persistent peers
|
||||||
if n.config.P2P.PersistentPeers != "" {
|
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?
|
||||||
if err != nil {
|
persistentPeers := []string{}
|
||||||
return err
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always connect to private peers, but do not add them to addrbook
|
err = n.sw.DialPeersAsync(n.addrBook, persistentPeers, true)
|
||||||
if n.config.P2P.PrivatePeers != "" {
|
|
||||||
err = n.sw.DialPeersAsync(nil, strings.Split(n.config.P2P.PrivatePeers, ","), true)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// start tx indexer
|
||||||
|
@ -74,6 +74,10 @@ type PEXReactorConfig struct {
|
|||||||
// Seeds is a list of addresses reactor may use
|
// Seeds is a list of addresses reactor may use
|
||||||
// if it can't connect to peers in the addrbook.
|
// if it can't connect to peers in the addrbook.
|
||||||
Seeds []string
|
Seeds []string
|
||||||
|
|
||||||
|
// PrivatePeerIDs is a list of peer IDs, which must not be gossiped to other
|
||||||
|
// peers.
|
||||||
|
PrivatePeerIDs []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type _attemptsToDial struct {
|
type _attemptsToDial struct {
|
||||||
@ -152,9 +156,11 @@ func (r *PEXReactor) AddPeer(p Peer) {
|
|||||||
// Let the ensurePeersRoutine handle asking for more
|
// Let the ensurePeersRoutine handle asking for more
|
||||||
// peers when we need - we don't trust inbound peers as much.
|
// peers when we need - we don't trust inbound peers as much.
|
||||||
addr := p.NodeInfo().NetAddress()
|
addr := p.NodeInfo().NetAddress()
|
||||||
|
if !isAddrPrivate(addr, r.config.PrivatePeerIDs) {
|
||||||
r.book.AddAddress(addr, addr)
|
r.book.AddAddress(addr, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RemovePeer implements Reactor.
|
// RemovePeer implements Reactor.
|
||||||
func (r *PEXReactor) RemovePeer(p Peer, reason interface{}) {
|
func (r *PEXReactor) RemovePeer(p Peer, reason interface{}) {
|
||||||
@ -251,7 +257,10 @@ func (r *PEXReactor) ReceiveAddrs(addrs []*p2p.NetAddress, src Peer) error {
|
|||||||
|
|
||||||
srcAddr := src.NodeInfo().NetAddress()
|
srcAddr := src.NodeInfo().NetAddress()
|
||||||
for _, netAddr := range addrs {
|
for _, netAddr := range addrs {
|
||||||
if netAddr != nil {
|
if netAddr == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !isAddrPrivate(netAddr, r.config.PrivatePeerIDs) {
|
||||||
r.book.AddAddress(netAddr, srcAddr)
|
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
|
// Messages
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user