forked from TrueCloudLab/neoneo-go
network: make minpeers configurable
Without it node in privnet tries to reconnect to four existing nodes indefinitely for no good reason.
This commit is contained in:
parent
2f6e678a19
commit
b12a68994d
11 changed files with 17 additions and 3 deletions
|
@ -73,6 +73,7 @@ type (
|
||||||
DialTimeout time.Duration `yaml:"DialTimeout"`
|
DialTimeout time.Duration `yaml:"DialTimeout"`
|
||||||
ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"`
|
ProtoTickInterval time.Duration `yaml:"ProtoTickInterval"`
|
||||||
MaxPeers int `yaml:"MaxPeers"`
|
MaxPeers int `yaml:"MaxPeers"`
|
||||||
|
MinPeers int `yaml:"MinPeers"`
|
||||||
Monitoring metrics.PrometheusConfig `yaml:"Monitoring"`
|
Monitoring metrics.PrometheusConfig `yaml:"Monitoring"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 5
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -36,6 +36,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 3
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 3
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 3
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -33,6 +33,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 3
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -39,6 +39,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 3
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -48,6 +48,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 5
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -38,6 +38,7 @@ ApplicationConfiguration:
|
||||||
DialTimeout: 3
|
DialTimeout: 3
|
||||||
ProtoTickInterval: 2
|
ProtoTickInterval: 2
|
||||||
MaxPeers: 50
|
MaxPeers: 50
|
||||||
|
MinPeers: 1
|
||||||
Monitoring:
|
Monitoring:
|
||||||
Enabled: false #since it's not useful for unit tests.
|
Enabled: false #since it's not useful for unit tests.
|
||||||
Port: 2112
|
Port: 2112
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// peer numbers are arbitrary at the moment.
|
// peer numbers are arbitrary at the moment.
|
||||||
minPeers = 5
|
|
||||||
maxPeers = 20
|
maxPeers = 20
|
||||||
maxBlockBatch = 200
|
maxBlockBatch = 200
|
||||||
maxAddrsToSend = 200
|
maxAddrsToSend = 200
|
||||||
|
@ -71,7 +70,7 @@ func NewServer(config ServerConfig, chain core.Blockchainer) *Server {
|
||||||
bQueue: newBlockQueue(maxBlockBatch, chain),
|
bQueue: newBlockQueue(maxBlockBatch, chain),
|
||||||
id: rand.Uint32(),
|
id: rand.Uint32(),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
addrReq: make(chan *Message, minPeers),
|
addrReq: make(chan *Message, config.MinPeers),
|
||||||
register: make(chan Peer),
|
register: make(chan Peer),
|
||||||
unregister: make(chan peerDrop),
|
unregister: make(chan peerDrop),
|
||||||
peers: make(map[Peer]bool),
|
peers: make(map[Peer]bool),
|
||||||
|
@ -129,7 +128,7 @@ func (s *Server) BadPeers() []string {
|
||||||
func (s *Server) run() {
|
func (s *Server) run() {
|
||||||
for {
|
for {
|
||||||
c := s.PeerCount()
|
c := s.PeerCount()
|
||||||
if c < minPeers {
|
if c < s.ServerConfig.MinPeers {
|
||||||
s.discovery.RequestRemote(maxPeers - c)
|
s.discovery.RequestRemote(maxPeers - c)
|
||||||
}
|
}
|
||||||
if s.discovery.PoolCount() < minPoolCount {
|
if s.discovery.PoolCount() < minPoolCount {
|
||||||
|
|
|
@ -10,6 +10,11 @@ import (
|
||||||
type (
|
type (
|
||||||
// ServerConfig holds the server configuration.
|
// ServerConfig holds the server configuration.
|
||||||
ServerConfig struct {
|
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
|
// MaxPeers it the maximum numbers of peers that can
|
||||||
// be connected to the server.
|
// be connected to the server.
|
||||||
MaxPeers int
|
MaxPeers int
|
||||||
|
@ -59,5 +64,6 @@ func NewServerConfig(cfg config.Config) ServerConfig {
|
||||||
DialTimeout: appConfig.DialTimeout * time.Second,
|
DialTimeout: appConfig.DialTimeout * time.Second,
|
||||||
ProtoTickInterval: appConfig.ProtoTickInterval * time.Second,
|
ProtoTickInterval: appConfig.ProtoTickInterval * time.Second,
|
||||||
MaxPeers: appConfig.MaxPeers,
|
MaxPeers: appConfig.MaxPeers,
|
||||||
|
MinPeers: appConfig.MinPeers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue