diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdater.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdater.java index a446ee32df5..6cf66491121 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdater.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/EthSynchronizerUpdater.java @@ -33,7 +33,7 @@ public EthSynchronizerUpdater(final EthPeers ethPeers) { @Override public void updatePeerChainState( final long knownBlockNumber, final PeerConnection peerConnection) { - final EthPeer ethPeer = ethPeers.peer(peerConnection); + final EthPeer ethPeer = ethPeers.peer(peerConnection.getPeer().getId()); if (ethPeer == null) { LOG.debug("Received message from a peer with no corresponding EthPeer."); return; diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java index 9268def8ded..fa0ab47b774 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java @@ -36,6 +36,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.tuweni.bytes.Bytes; + public class EthPeers { public static final Comparator TOTAL_DIFFICULTY = Comparator.comparing(((final EthPeer p) -> p.chainState().getEstimatedTotalDifficulty())); @@ -49,7 +51,7 @@ public class EthPeers { Comparator.comparing(EthPeer::outstandingRequests) .thenComparing(EthPeer::getLastRequestTimestamp); - private final Map connections = new ConcurrentHashMap<>(); + private final Map connections = new ConcurrentHashMap<>(); private final String protocolName; private final Clock clock; private final List permissioningProviders; @@ -93,11 +95,11 @@ public void registerConnection( peerValidators, clock, permissioningProviders); - connections.putIfAbsent(peerConnection, peer); + connections.putIfAbsent(peerConnection.getPeer().getId(), peer); } public void registerDisconnect(final PeerConnection connection) { - final EthPeer peer = connections.remove(connection); + final EthPeer peer = connections.remove(connection.getPeer().getId()); if (peer != null) { disconnectCallbacks.forEach(callback -> callback.onDisconnect(peer)); peer.handleDisconnect(); @@ -118,8 +120,8 @@ private void abortPendingRequestsAssignedToDisconnectedPeers() { } } - public EthPeer peer(final PeerConnection peerConnection) { - return connections.get(peerConnection); + public EthPeer peer(final Bytes peerId) { + return connections.get(peerId); } public PendingPeerRequest executePeerRequest( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 716f426edf0..3ab008260e7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -234,7 +234,7 @@ public void processMessage(final Capability cap, final Message message) { final MessageData messageData = message.getData(); final int code = messageData.getCode(); LOG.trace("Process message {}, {}", cap, code); - final EthPeer ethPeer = ethPeers.peer(message.getConnection()); + final EthPeer ethPeer = ethPeers.peer(message.getConnection().getPeer().getId()); if (ethPeer == null) { LOG.debug( "Ignoring message received from unknown peer connection: " + message.getConnection()); @@ -306,7 +306,7 @@ public void processMessage(final Capability cap, final Message message) { @Override public void handleNewConnection(final PeerConnection connection) { ethPeers.registerConnection(connection, peerValidators); - final EthPeer peer = ethPeers.peer(connection); + final EthPeer peer = ethPeers.peer(connection.getPeer().getId()); if (peer.statusHasBeenSentToPeer()) { return; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java index b6873a76808..1c5f60e92a4 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapProtocolManager.java @@ -93,7 +93,7 @@ public void processMessage(final Capability cap, final Message message) { final MessageData messageData = AbstractSnapMessageData.create(message); final int code = messageData.getCode(); LOG.trace("Process snap message {}, {}", cap, code); - final EthPeer ethPeer = ethPeers.peer(message.getConnection()); + final EthPeer ethPeer = ethPeers.peer(message.getConnection().getPeer().getId()); if (ethPeer == null) { LOG.debug( "Ignoring message received from unknown peer connection: " + message.getConnection()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java index 3774b63dc68..43e06bc5c83 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/RespondingEthPeer.java @@ -124,7 +124,7 @@ private static RespondingEthPeer create( new MockPeerConnection( caps, (cap, msg, conn) -> outgoingMessages.add(new OutgoingMessage(cap, msg))); ethPeers.registerConnection(peerConnection, peerValidators); - final EthPeer peer = ethPeers.peer(peerConnection); + final EthPeer peer = ethPeers.peer(peerConnection.getPeer().getId()); peer.registerStatusReceived(chainHeadHash, totalDifficulty, 63); estimatedHeight.ifPresent(height -> peer.chainState().update(chainHeadHash, height)); peer.registerStatusSent(); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java index bb03e0075a8..e357a6c65ef 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/VertxPeerDiscoveryAgent.java @@ -106,7 +106,7 @@ protected AsyncExecutor createWorkerExecutor() { @Override protected CompletableFuture listenForConnections() { - CompletableFuture future = new CompletableFuture<>(); + final CompletableFuture future = new CompletableFuture<>(); vertx .createDatagramSocket(new DatagramSocketOptions().setIpV6(NetworkUtility.isIPv6Available())) .listen( @@ -135,8 +135,7 @@ protected void handleListenerSetup( this.socket = listenResult.result(); // TODO: when using wildcard hosts (0.0.0.0), we need to handle multiple addresses by - // selecting - // the correct 'announce' address. + // selecting the correct 'announce' address. final String effectiveHost = socket.localAddress().host(); final int effectivePort = socket.localAddress().port(); @@ -148,7 +147,7 @@ protected void handleListenerSetup( socket.exceptionHandler(this::handleException); socket.handler(this::handlePacket); - InetSocketAddress address = + final InetSocketAddress address = new InetSocketAddress(socket.localAddress().host(), socket.localAddress().port()); addressFuture.complete(address); } @@ -156,7 +155,7 @@ protected void handleListenerSetup( @Override protected CompletableFuture sendOutgoingPacket( final DiscoveryPeer peer, final Packet packet) { - CompletableFuture result = new CompletableFuture<>(); + final CompletableFuture result = new CompletableFuture<>(); socket.send( packet.encode(), peer.getEndpoint().getUdpPort(), diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java index cb6465349bf..e0582f0e96d 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java @@ -108,12 +108,12 @@ public static EnodeURL fromURI(final URI uri, final EnodeDnsConfiguration enodeD "Invalid node ID: node ID must have exactly 128 hexadecimal characters and should not include any '0x' hex prefix."); final Bytes id = Bytes.fromHexString(uri.getUserInfo()); - String host = uri.getHost(); - int tcpPort = uri.getPort(); + final String host = uri.getHost(); + final int tcpPort = uri.getPort(); // Parse discport if it exists Optional discoveryPort = Optional.empty(); - String query = uri.getQuery(); + final String query = uri.getQuery(); if (query != null) { final Matcher discPortMatcher = DISCPORT_QUERY_STRING_REGEX.matcher(query); if (discPortMatcher.matches()) { @@ -322,11 +322,11 @@ private void validate() { checkState(ip != null, "Ip address must be configured."); } - public Builder configureFromEnode(final EnodeURL enode) { - return this.nodeId(enode.getNodeId()) - .listeningPort(enode.getListeningPort()) - .discoveryPort(enode.getDiscoveryPort()) - .ipAddress(enode.getIp()); + public Builder configureFromEnode(final EnodeURL enodeURL) { + return this.nodeId(enodeURL.getNodeId()) + .listeningPort(enodeURL.getListeningPort()) + .discoveryPort(enodeURL.getDiscoveryPort()) + .ipAddress(enodeURL.getIp()); } public Builder nodeId(final Bytes nodeId) {