mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
network: do getaddr requests periodically, fix #2745
Every 1000 blocks seems to be OK for big networks (that only had done some initial requests previously and then effectively never requested addresses again because there was a sufficient number of addresses), won't hurt smaller ones as well (that effectively keep doing this on every connect/disconnect, peer changes are very rare there, but when they happen we want to have some quick reaction to these changes).
This commit is contained in:
parent
9d6b18adec
commit
28f54d352a
1 changed files with 12 additions and 1 deletions
|
@ -38,6 +38,7 @@ const (
|
|||
defaultExtensiblePoolSize = 20
|
||||
defaultBroadcastFactor = 0
|
||||
maxBlockBatch = 200
|
||||
peerTimeFactor = 1000
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -393,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 (
|
||||
|
@ -416,12 +423,16 @@ func (s *Server) run() {
|
|||
s.discovery.RequestRemote(connN)
|
||||
}
|
||||
|
||||
if s.discovery.PoolCount() < s.AttemptConnPeers {
|
||||
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