Skip to content

Commit

Permalink
Merge pull request #2863 from HenrikJannsen/improve-peer-exchange-str…
Browse files Browse the repository at this point in the history
…ategy

Add seed nodes after if there are no candidates at extending peer group.
  • Loading branch information
HenrikJannsen authored Sep 29, 2024
2 parents 656c36e + 1dd6553 commit 2de7e5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
@Slf4j
@Getter
public class PeerExchangeService implements Node.Listener {
private static final int MAX_RETRY_ATTEMPTS = 10;

private final Node node;
private final PeerExchangeStrategy peerExchangeStrategy;

Expand Down Expand Up @@ -218,8 +220,8 @@ private void retryPeerExchange() {
log.info("We have a pending retryPeerExchangeAttempt. We ignore the retryPeerExchange call.");
return;
}
if (numRetryAttempts.get() > 10) {
log.warn("We have retried the peer exchange 10 times without success and give up.");
if (numRetryAttempts.get() > MAX_RETRY_ATTEMPTS) {
log.warn("We have retried the peer exchange {} times without success and give up.", MAX_RETRY_ATTEMPTS);
return;
}
long delay = 1000L * numRetryAttempts.get() * numRetryAttempts.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ List<Address> getAddressesForRetryPeerExchange() {

// After bootstrap, we might want to add more connections and use the peer exchange protocol for that.
// We do not want to use seed nodes or already existing connections in that case.
// Only if we do not have any candidates we add seed nodes.
List<Address> getAddressesForExtendingPeerGroup() {
List<Address> candidates = getCandidates(getPriorityListForExtendingPeerGroup());
if (candidates.isEmpty()) {
// It can be that we don't have peers anymore which we have not already connected in the past.
// We reset the usedAddresses and try again. It is likely that some peers have different peers to
// send now.
// send now. We also add the seed nodes to get better chances for fresh nodes.
log.debug("We reset the usedAddresses and try again to connect to peers we tried in the past.");
usedAddresses.clear();
candidates = getCandidates(getPriorityListForExtendingPeerGroup());
candidates.addAll(getSeedAddresses());
}
usedAddresses.addAll(candidates);
return candidates;
Expand Down

0 comments on commit 2de7e5a

Please sign in to comment.