Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions networks/p2p/dialsched.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,14 @@ func (ds *DialSched) getCandidates() (candidates []*discover.Node, needRefresh b
// 2. Add all static nodes, even if they are already connected or in the dialing list. Those will be filtered out later.
// Since static nodes are exempt from the connTargets nor peer limits, all static nodes are going to be dialed even if needs[] is zero.
candidates = ds.static.all()
numConnectedAll, numStatic := ds.connectedAll.len(), ds.static.len()
numOutbound, numDialing := ds.connectedOutbound.len(), ds.dialing.len()
ds.mu.RUnlock()

// 3. Dynamic nodes — skip when already at total peer capacity.
// Even if we want more outbound peers (needs > 0), the total capacity might be reached (maxPeers) due to inbound peers.
// Static dials (added above) bypass this check, mirroring the Server's capacity check.
if ds.maxPeers == 0 || ds.connectedAll.len() < ds.maxPeers {
if ds.maxPeers == 0 || numConnectedAll < ds.maxPeers {
for targetType, need := range needs {
dynamicNodes, refresh := ds.getDynamicCandidates(targetType, need)
candidates = append(candidates, dynamicNodes...)
Expand All @@ -346,8 +348,8 @@ func (ds *DialSched) getCandidates() (candidates []*discover.Node, needRefresh b
}

if len(candidates) > 0 {
logger.Debug("Dialing candidates", "needs", needs, "static", ds.static.len(),
"connectedOutbound", ds.connectedOutbound.len(), "dialing", ds.dialing.len(), "candidates", len(candidates))
logger.Debug("Dialing candidates", "needs", needs, "static", numStatic,
"connectedOutbound", numOutbound, "dialing", numDialing, "candidates", len(candidates))
}
return candidates, needRefresh
}
Expand Down
Loading