Decrease failedConnectionAttempts onConnection

Rename method
This commit is contained in:
chimp1984 2020-10-07 21:18:28 -05:00
parent 351db88992
commit 2fd010498d
No known key found for this signature in database
GPG Key ID: 9801B4EC591F90E3
2 changed files with 13 additions and 4 deletions

View File

@ -208,6 +208,11 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
stopped = false;
listeners.forEach(Listener::onNewConnectionAfterAllConnectionsLost);
}
if (connection.getPeersNodeAddressOptional().isPresent()) {
findPeer(connection.getPeersNodeAddressOptional().get())
.ifPresent(Peer::onConnection);
}
}
@Override
@ -253,16 +258,16 @@ public final class PeerManager implements ConnectionListener, PersistedDataHost
}
public void handleConnectionFault(NodeAddress nodeAddress, @Nullable Connection connection) {
log.debug("handleConnectionFault called: nodeAddress=" + nodeAddress);
boolean doRemovePersistedPeer = false;
removeReportedPeer(nodeAddress);
Optional<Peer> persistedPeerOptional = findPersistedPeer(nodeAddress);
if (persistedPeerOptional.isPresent()) {
Peer persistedPeer = persistedPeerOptional.get();
persistedPeer.increaseFailedConnectionAttempts();
persistedPeer.onDisconnect();
doRemovePersistedPeer = persistedPeer.tooManyFailedConnectionAttempts();
}
doRemovePersistedPeer = doRemovePersistedPeer || (connection != null && connection.getRuleViolation() != null);
boolean ruleViolation = connection != null && connection.getRuleViolation() != null;
doRemovePersistedPeer = doRemovePersistedPeer || ruleViolation;
if (doRemovePersistedPeer)
removePersistedPeer(nodeAddress);

View File

@ -80,10 +80,14 @@ public final class Peer implements HasCapabilities, NetworkPayload, PersistableP
// API
///////////////////////////////////////////////////////////////////////////////////////////
public void increaseFailedConnectionAttempts() {
public void onDisconnect() {
this.failedConnectionAttempts++;
}
public void onConnection() {
this.failedConnectionAttempts--;
}
public boolean tooManyFailedConnectionAttempts() {
return failedConnectionAttempts >= MAX_FAILED_CONNECTION_ATTEMPTS;
}