From 5830936583628c589feb36087ebcaaf7a8020255 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Fri, 22 Sep 2023 15:03:59 +1000 Subject: [PATCH] fix geth rlpx ping command (#5917) * fix geth rlpx ping command Signed-off-by: Stefan --------- Signed-off-by: Stefan --- .../netty/AbstractHandshakeHandler.java | 78 +++++++++---------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/AbstractHandshakeHandler.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/AbstractHandshakeHandler.java index 87826b5f93b..3a827403ec3 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/AbstractHandshakeHandler.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/connections/netty/AbstractHandshakeHandler.java @@ -97,47 +97,47 @@ protected final void channelRead0(final ChannelHandlerContext ctx, final ByteBuf ctx.writeAndFlush(nextMsg.get()); } else if (handshaker.getStatus() != Handshaker.HandshakeStatus.SUCCESS) { LOG.debug("waiting for more bytes"); - } else { - - final Bytes nodeId = handshaker.partyPubKey().getEncodedBytes(); - if (!localNode.isReady()) { - // If we're handling a connection before the node is fully up, just disconnect - LOG.debug("Rejecting connection because local node is not ready {}", nodeId); - disconnect(ctx, DisconnectMessage.DisconnectReason.UNKNOWN); - return; - } + return; + } - LOG.trace("Sending framed hello"); - - // Exchange keys done - final Framer framer = this.framerProvider.buildFramer(handshaker.secrets()); - - final ByteToMessageDecoder deFramer = - new DeFramer( - framer, - subProtocols, - localNode, - expectedPeer, - connectionEventDispatcher, - connectionFuture, - metricsSystem, - inboundInitiated); - - ctx.channel() - .pipeline() - .replace(this, "DeFramer", deFramer) - .addBefore("DeFramer", "validate", new ValidateFirstOutboundMessage(framer)); - - ctx.writeAndFlush(new OutboundMessage(null, HelloMessage.create(localNode.getPeerInfo()))) - .addListener( - ff -> { - if (ff.isSuccess()) { - LOG.trace("Successfully wrote hello message"); - } - }); - msg.retain(); - ctx.fireChannelRead(msg); + final Bytes nodeId = handshaker.partyPubKey().getEncodedBytes(); + if (!localNode.isReady()) { + // If we're handling a connection before the node is fully up, just disconnect + LOG.debug("Rejecting connection because local node is not ready {}", nodeId); + disconnect(ctx, DisconnectMessage.DisconnectReason.UNKNOWN); + return; } + + LOG.trace("Sending framed hello"); + + // Exchange keys done + final Framer framer = this.framerProvider.buildFramer(handshaker.secrets()); + + final ByteToMessageDecoder deFramer = + new DeFramer( + framer, + subProtocols, + localNode, + expectedPeer, + connectionEventDispatcher, + connectionFuture, + metricsSystem, + inboundInitiated); + + ctx.channel() + .pipeline() + .replace(this, "DeFramer", deFramer) + .addBefore("DeFramer", "validate", new ValidateFirstOutboundMessage(framer)); + + ctx.writeAndFlush(new OutboundMessage(null, HelloMessage.create(localNode.getPeerInfo()))) + .addListener( + ff -> { + if (ff.isSuccess()) { + LOG.trace("Successfully wrote hello message"); + } + }); + msg.retain(); + ctx.fireChannelRead(msg); } private void disconnect(