network: add default MinPeers

If there is nothing specified in the configuration, set it to some reasonable
value.
This commit is contained in:
Roman Khimov 2019-11-01 13:29:54 +03:00
parent b46dd295bc
commit e9f8b25776

View file

@ -18,10 +18,11 @@ import (
const (
// peer numbers are arbitrary at the moment.
maxPeers = 20
maxBlockBatch = 200
maxAddrsToSend = 200
minPoolCount = 30
defaultMinPeers = 5
maxPeers = 20
maxBlockBatch = 200
maxAddrsToSend = 200
minPoolCount = 30
)
var (
@ -76,6 +77,14 @@ func NewServer(config ServerConfig, chain core.Blockchainer) *Server {
peers: make(map[Peer]bool),
}
if s.MinPeers <= 0 {
log.WithFields(log.Fields{
"MinPeers configured": s.MinPeers,
"MinPeers actual": defaultMinPeers,
}).Info("bad MinPeers configured, using the default value")
s.MinPeers = defaultMinPeers
}
s.transport = NewTCPTransport(s, fmt.Sprintf(":%d", config.ListenTCP))
s.discovery = NewDefaultDiscovery(
s.DialTimeout,