refactor to check for null peer (#6841)

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/6843/head
Sally MacFarlane 8 months ago committed by GitHub
parent 464cd2606a
commit a2ef6c49da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 17
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java

@ -177,14 +177,21 @@ public class EthPeers {
public boolean registerDisconnect(final PeerConnection connection) {
final EthPeer peer = peer(connection);
return registerDisconnect(peer.getId(), peer, connection);
return registerDisconnect(peer, connection);
}
private boolean registerDisconnect(
final Bytes id, final EthPeer peer, final PeerConnection connection) {
private boolean registerDisconnect(final EthPeer peer, final PeerConnection connection) {
incompleteConnections.invalidate(connection);
boolean removed = false;
if (peer != null && peer.getConnection().equals(connection)) {
if (peer == null) {
LOG.atTrace()
.setMessage("attempt to remove null peer with connection {}")
.addArgument(connection)
.log();
return false;
}
if (peer.getConnection().equals(connection)) {
final Bytes id = peer.getId();
if (!peerHasIncompleteConnection(id)) {
removed = completeConnections.remove(id, peer);
disconnectCallbacks.forEach(callback -> callback.onDisconnect(peer));
@ -297,7 +304,7 @@ public class EthPeers {
.forEach(
ep -> {
if (ep.isDisconnected()) {
registerDisconnect(ep.getId(), ep, ep.getConnection());
registerDisconnect(ep, ep.getConnection());
}
});
}

Loading…
Cancel
Save