Skip to content

Commit

Permalink
network: take into account good known peers when thinking of GetAddr
Browse files Browse the repository at this point in the history
They will be returned to pool when disconnected anyway. On a smaller network
this can make a difference because there are not a lot of addresses in the
pool usually.

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Dec 6, 2024
1 parent 2bc41db commit 2f5ca86
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (s *Server) run() {
var (
netSize = s.discovery.NetworkSize()
// "Optimal" number of peers.
optimalN = min(s.discovery.GetFanOut()*2, netSize-1)
optimalN = s.discovery.GetFanOut() * 2
// Real number of peers.
peerN = s.HandshakedPeersCount()
// Timeout value for the next peerTimer, long one by default.
Expand All @@ -493,13 +493,13 @@ func (s *Server) run() {
s.discovery.RequestRemote(s.AttemptConnPeers)
// Check/retry new connections soon.
peerT = s.ProtoTickInterval
} else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers {
} else if s.MinPeers > 0 && loopCnt%s.MinPeers == 0 && optimalN > peerN && optimalN < s.MaxPeers && optimalN < netSize {
// Having some number of peers, but probably can get some more, the network is big.
// It also allows to start picking up new peers proactively, before we suddenly have <s.MinPeers of them.
s.discovery.RequestRemote(min(s.AttemptConnPeers, optimalN-peerN))
}

if addrCheckTimeout || s.discovery.PoolCount() < s.AttemptConnPeers {
if addrCheckTimeout || s.discovery.PoolCount()+peerN < s.AttemptConnPeers {
s.broadcastHPMessage(NewMessage(CMDGetAddr, payload.NewNullPayload()))
addrCheckTimeout = false
}
Expand Down

0 comments on commit 2f5ca86

Please sign in to comment.