Merge pull request #468 from nspcc-dev/configurable-minpeers
network: make minpeers configurable
This commit is contained in:
commit
e5205d26a3
11 changed files with 17 additions and 3 deletions
|
@ -73,6 +73,7 @@ type (
|
|||
DialTimeout time.Duration `yaml:"DialTimeout"`
|
||||
ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"`
|
||||
MaxPeers int `yaml:"MaxPeers"`
|
||||
MinPeers int `yaml:"MinPeers"`
|
||||
Monitoring metrics.PrometheusConfig `yaml:"Monitoring"`
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 5
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -36,6 +36,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 3
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 3
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 3
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 3
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -39,6 +39,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 3
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -48,6 +48,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 5
|
||||
Monitoring:
|
||||
Enabled: true
|
||||
Port: 2112
|
||||
|
|
|
@ -38,6 +38,7 @@ ApplicationConfiguration:
|
|||
DialTimeout: 3
|
||||
ProtoTickInterval: 2
|
||||
MaxPeers: 50
|
||||
MinPeers: 1
|
||||
Monitoring:
|
||||
Enabled: false #since it's not useful for unit tests.
|
||||
Port: 2112
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
|
||||
const (
|
||||
// peer numbers are arbitrary at the moment.
|
||||
minPeers = 5
|
||||
maxPeers = 20
|
||||
maxBlockBatch = 200
|
||||
maxAddrsToSend = 200
|
||||
|
@ -71,7 +70,7 @@ func NewServer(config ServerConfig, chain core.Blockchainer) *Server {
|
|||
bQueue: newBlockQueue(maxBlockBatch, chain),
|
||||
id: rand.Uint32(),
|
||||
quit: make(chan struct{}),
|
||||
addrReq: make(chan *Message, minPeers),
|
||||
addrReq: make(chan *Message, config.MinPeers),
|
||||
register: make(chan Peer),
|
||||
unregister: make(chan peerDrop),
|
||||
peers: make(map[Peer]bool),
|
||||
|
@ -129,7 +128,7 @@ func (s *Server) BadPeers() []string {
|
|||
func (s *Server) run() {
|
||||
for {
|
||||
c := s.PeerCount()
|
||||
if c < minPeers {
|
||||
if c < s.ServerConfig.MinPeers {
|
||||
s.discovery.RequestRemote(maxPeers - c)
|
||||
}
|
||||
if s.discovery.PoolCount() < minPoolCount {
|
||||
|
|
|
@ -10,6 +10,11 @@ import (
|
|||
type (
|
||||
// ServerConfig holds the server configuration.
|
||||
ServerConfig struct {
|
||||
// MinPeers is the minimum number of peers for normal operation,
|
||||
// when the node has less than this number of peers it tries to
|
||||
// connect with some new ones.
|
||||
MinPeers int
|
||||
|
||||
// MaxPeers it the maximum numbers of peers that can
|
||||
// be connected to the server.
|
||||
MaxPeers int
|
||||
|
@ -59,5 +64,6 @@ func NewServerConfig(cfg config.Config) ServerConfig {
|
|||
DialTimeout: appConfig.DialTimeout * time.Second,
|
||||
ProtoTickInterval: appConfig.ProtoTickInterval * time.Second,
|
||||
MaxPeers: appConfig.MaxPeers,
|
||||
MinPeers: appConfig.MinPeers,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue