Improve choosing which peer to connect to

This commit is contained in:
catbref 2019-08-21 09:45:41 +01:00
parent f7c6978151
commit a9122cc6cb

View File

@ -591,7 +591,10 @@ public class Network extends Thread {
// Don't consider peers with recent connection failures
final long lastAttemptedThreshold = now - CONNECT_FAILURE_BACKOFF;
peers.removeIf(peerData -> peerData.getLastAttempted() != null && peerData.getLastAttempted() > lastAttemptedThreshold);
peers.removeIf(peerData -> peerData.getLastAttempted() != null &&
peerData.getLastConnected() != null &&
peerData.getLastConnected() < peerData.getLastAttempted() &&
peerData.getLastAttempted() > lastAttemptedThreshold);
// Don't consider peers that we know loop back to ourself
Predicate<PeerData> isSelfPeer = peerData -> {