Merge pull request #2761 from nspcc-dev/fancy-getaddr

Fancy getaddr
This commit is contained in:
Roman Khimov 2022-10-25 16:51:38 +07:00 committed by GitHub
commit e19d867d4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -261,6 +261,7 @@ func (d *DefaultDiscovery) tryAddress(addr string) {
d.lock.Unlock() d.lock.Unlock()
if err != nil { if err != nil {
d.RegisterBadAddr(addr) d.RegisterBadAddr(addr)
time.Sleep(d.dialTimeout)
d.RequestRemote(1) d.RequestRemote(1)
} }
} }

View file

@ -38,7 +38,7 @@ const (
defaultExtensiblePoolSize = 20 defaultExtensiblePoolSize = 20
defaultBroadcastFactor = 0 defaultBroadcastFactor = 0
maxBlockBatch = 200 maxBlockBatch = 200
minPoolCount = 30 peerTimeFactor = 1000
) )
var ( var (
@ -394,6 +394,12 @@ func (s *Server) ConnectedPeers() []string {
// run is a goroutine that starts another goroutine to manage protocol specifics // run is a goroutine that starts another goroutine to manage protocol specifics
// while itself dealing with peers management (handling connects/disconnects). // while itself dealing with peers management (handling connects/disconnects).
func (s *Server) run() { func (s *Server) run() {
var (
peerCheckTime = s.TimePerBlock * peerTimeFactor
peerCheckTimeout bool
timer = time.NewTimer(peerCheckTime)
)
defer timer.Stop()
go s.runProto() go s.runProto()
for loopCnt := 0; ; loopCnt++ { for loopCnt := 0; ; loopCnt++ {
var ( var (
@ -417,12 +423,16 @@ func (s *Server) run() {
s.discovery.RequestRemote(connN) s.discovery.RequestRemote(connN)
} }
if s.discovery.PoolCount() < minPoolCount { if peerCheckTimeout || s.discovery.PoolCount() < s.AttemptConnPeers {
s.broadcastHPMessage(NewMessage(CMDGetAddr, payload.NewNullPayload())) s.broadcastHPMessage(NewMessage(CMDGetAddr, payload.NewNullPayload()))
peerCheckTimeout = false
} }
select { select {
case <-s.quit: case <-s.quit:
return return
case <-timer.C:
peerCheckTimeout = true
timer.Reset(peerCheckTime)
case p := <-s.register: case p := <-s.register:
s.lock.Lock() s.lock.Lock()
s.peers[p] = true s.peers[p] = true