Skip to content

Commit

Permalink
split up dialing in and out of region
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jun 24, 2024
1 parent 59a8859 commit b287eac
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions p2p/pex/pex_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,41 @@ func (r *Reactor) ensurePeersCommon(regionAware bool) {
toDialOutOfRegion[try.ID] = try
}

// Combine the two maps
for id, addr := range toDialInRegion {
toDial[id] = addr
// Dial in-region addresses
successfulDials := 0
for _, addr := range toDialInRegion {
if successfulDials >= numToDialInSameRegion {
break
}
err := r.dialPeer(addr)
if err != nil {
switch err.(type) {
case errMaxAttemptsToDial, errTooEarlyToDial:
r.Logger.Debug(err.Error(), "addr", addr)
default:
r.Logger.Debug(err.Error(), "addr", addr)
}
} else {
successfulDials++
}
}
for id, addr := range toDialOutOfRegion {
toDial[id] = addr

// Dial out-of-region addresses
for _, addr := range toDialOutOfRegion {
if successfulDials >= numToDial {
break
}
err := r.dialPeer(addr)
if err != nil {
switch err.(type) {
case errMaxAttemptsToDial, errTooEarlyToDial:
r.Logger.Debug(err.Error(), "addr", addr)
default:
r.Logger.Debug(err.Error(), "addr", addr)
}
} else {
successfulDials++
}
}
} else {
reserveSize := cmtmath.MaxInt((numToDial+1)/2, 5)
Expand All @@ -552,29 +581,9 @@ func (r *Reactor) ensurePeersCommon(regionAware bool) {
}
toDial[try.ID] = try
}
}

// Dial picked addresses
successfulDials := 0
for _, addr := range toDial {
if successfulDials >= numToDial {
break
}
err := r.dialPeer(addr)
if err != nil {
switch err.(type) {
case errMaxAttemptsToDial, errTooEarlyToDial:
r.Logger.Debug(err.Error(), "addr", addr)
default:
r.Logger.Debug(err.Error(), "addr", addr)
}
} else {
successfulDials++
}
}

// If we still need more addresses, use reserve addresses
if successfulDials < numToDial {
// Dial picked addresses
successfulDials := 0
for _, addr := range toDial {
if successfulDials >= numToDial {
break
Expand Down

0 comments on commit b287eac

Please sign in to comment.