Merge pull request #468 from nspcc-dev/configurable-minpeers

network: make minpeers configurable
This commit is contained in:
Roman Khimov 2019-10-31 15:12:09 +03:00 committed by GitHub
commit e5205d26a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 17 additions and 3 deletions

View file

@ -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"`
}

View file

@ -48,6 +48,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 5
Monitoring:
Enabled: true
Port: 2112

View file

@ -36,6 +36,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 3
Monitoring:
Enabled: true
Port: 2112

View file

@ -33,6 +33,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 3
Monitoring:
Enabled: true
Port: 2112

View file

@ -33,6 +33,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 3
Monitoring:
Enabled: true
Port: 2112

View file

@ -33,6 +33,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 3
Monitoring:
Enabled: true
Port: 2112

View file

@ -39,6 +39,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 3
Monitoring:
Enabled: true
Port: 2112

View file

@ -48,6 +48,7 @@ ApplicationConfiguration:
DialTimeout: 3
ProtoTickInterval: 2
MaxPeers: 50
MinPeers: 5
Monitoring:
Enabled: true
Port: 2112

View file

@ -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

View file

@ -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 {

View file

@ -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,
}
}