forked from TrueCloudLab/neoneo-go
commit
e19d867d4e
2 changed files with 13 additions and 2 deletions
|
@ -261,6 +261,7 @@ func (d *DefaultDiscovery) tryAddress(addr string) {
|
|||
d.lock.Unlock()
|
||||
if err != nil {
|
||||
d.RegisterBadAddr(addr)
|
||||
time.Sleep(d.dialTimeout)
|
||||
d.RequestRemote(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ const (
|
|||
defaultExtensiblePoolSize = 20
|
||||
defaultBroadcastFactor = 0
|
||||
maxBlockBatch = 200
|
||||
minPoolCount = 30
|
||||
peerTimeFactor = 1000
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -394,6 +394,12 @@ func (s *Server) ConnectedPeers() []string {
|
|||
// run is a goroutine that starts another goroutine to manage protocol specifics
|
||||
// while itself dealing with peers management (handling connects/disconnects).
|
||||
func (s *Server) run() {
|
||||
var (
|
||||
peerCheckTime = s.TimePerBlock * peerTimeFactor
|
||||
peerCheckTimeout bool
|
||||
timer = time.NewTimer(peerCheckTime)
|
||||
)
|
||||
defer timer.Stop()
|
||||
go s.runProto()
|
||||
for loopCnt := 0; ; loopCnt++ {
|
||||
var (
|
||||
|
@ -417,12 +423,16 @@ func (s *Server) run() {
|
|||
s.discovery.RequestRemote(connN)
|
||||
}
|
||||
|
||||
if s.discovery.PoolCount() < minPoolCount {
|
||||
if peerCheckTimeout || s.discovery.PoolCount() < s.AttemptConnPeers {
|
||||
s.broadcastHPMessage(NewMessage(CMDGetAddr, payload.NewNullPayload()))
|
||||
peerCheckTimeout = false
|
||||
}
|
||||
select {
|
||||
case <-s.quit:
|
||||
return
|
||||
case <-timer.C:
|
||||
peerCheckTimeout = true
|
||||
timer.Reset(peerCheckTime)
|
||||
case p := <-s.register:
|
||||
s.lock.Lock()
|
||||
s.peers[p] = true
|
||||
|
|
Loading…
Reference in a new issue