Skip to content

Commit

Permalink
refactor to check for null peer (hyperledger#6841)
Browse files Browse the repository at this point in the history
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored and matthew1001 committed Jun 7, 2024
1 parent c18d447 commit 090bf1e
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,21 @@ private List<PeerConnection> getIncompleteConnections(final Bytes id) {

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));
Expand Down Expand Up @@ -297,7 +304,7 @@ private void removeDisconnectedPeers() {
.forEach(
ep -> {
if (ep.isDisconnected()) {
registerDisconnect(ep.getId(), ep, ep.getConnection());
registerDisconnect(ep, ep.getConnection());
}
});
}
Expand Down

0 comments on commit 090bf1e

Please sign in to comment.