Don't intentionally disconnect peers if we are currently syncing with them.

This commit is contained in:
CalDescent 2021-06-19 13:12:16 +01:00
parent 73cc3dcb92
commit 78237fcd11
3 changed files with 19 additions and 2 deletions

View File

@ -722,6 +722,7 @@ public class Controller extends Thread {
hasStatusChanged = true;
}
}
peer.setSyncInProgress(true);
if (hasStatusChanged)
updateSysTray();
@ -801,6 +802,7 @@ public class Controller extends Thread {
return syncResult;
} finally {
isSynchronizing = false;
peer.setSyncInProgress(false);
}
}

View File

@ -645,10 +645,15 @@ public class Network {
}
// Find peers that have reached their maximum connection age, and disconnect them
List<Peer> peersToDisconnect = this.connectedPeers.stream().filter(peer -> peer.hasReachedMaxConnectionAge()).collect(Collectors.toList());
List<Peer> peersToDisconnect = this.connectedPeers.stream()
.filter(peer -> !peer.isSyncInProgress())
.filter(peer -> peer.hasReachedMaxConnectionAge())
.collect(Collectors.toList());
if (peersToDisconnect != null && peersToDisconnect.size() > 0) {
for (Peer peer : peersToDisconnect) {
LOGGER.debug("Forcing disconnect of peer {} because connection age ({} ms) has reached the maximum ({} ms)", peer, peer.getConnectionAge(), peer.getMaxConnectionAge());
LOGGER.info("Forcing disconnection of peer {} because connection age ({} ms) " +
"has reached the maximum ({} ms)", peer, peer.getConnectionAge(), peer.getMaxConnectionAge());
peer.disconnect("Connection age too old");
}
}

View File

@ -97,6 +97,8 @@ public class Peer {
byte[] ourChallenge;
private boolean syncInProgress = false;
// Versioning
public static final Pattern VERSION_PATTERN = Pattern.compile(Controller.VERSION_PREFIX
+ "(\\d{1,3})\\.(\\d{1,5})\\.(\\d{1,5})");
@ -340,6 +342,14 @@ public class Peer {
}
}
public boolean isSyncInProgress() {
return this.syncInProgress;
}
public void setSyncInProgress(boolean syncInProgress) {
this.syncInProgress = syncInProgress;
}
@Override
public String toString() {
// Easier, and nicer output, than peer.getRemoteSocketAddress()