Disconnect on Message Over 10MB (#2485)

Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>
pull/2486/head
Ratan (Rai) Sur 3 years ago committed by GitHub
parent 55cde86507
commit d5300771b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  2. 5
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java
  3. 20
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java

@ -2391,12 +2391,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
// Loopback IP is used by default as this is how smokeTests require it to be
// and it's probably a good security behaviour to default only on the localhost.
private InetAddress autoDiscoverDefaultIP() {
if (autoDiscoveredDefaultIP != null) {
return autoDiscoveredDefaultIP;
}
autoDiscoveredDefaultIP = InetAddress.getLoopbackAddress();
autoDiscoveredDefaultIP =
Optional.ofNullable(autoDiscoveredDefaultIP).orElseGet(InetAddress::getLoopbackAddress);
return autoDiscoveredDefaultIP;
}

@ -235,6 +235,11 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver {
return;
}
if (message.getData().getSize() > 10 * 1_000_000 /*10MB*/) {
LOG.debug("Received message over 10MB. Disconnecting from {}", peer);
peer.disconnect(DisconnectReason.BREACH_OF_PROTOCOL);
}
// Handle STATUS processing
if (message.getData().getCode() == EthPV62.STATUS) {
handleStatusMessage(peer, message.getData());

@ -22,6 +22,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.Blockchain;
@ -180,6 +181,25 @@ public final class EthProtocolManagerTest {
}
}
@Test
public void disconnectOnVeryLargeMessage() {
try (final EthProtocolManager ethManager =
EthProtocolManagerTestUtil.create(
blockchain,
() -> false,
protocolContext.getWorldStateArchive(),
transactionPool,
EthProtocolConfiguration.defaultConfig())) {
final MessageData messageData = mock(MessageData.class);
when(messageData.getSize()).thenReturn(10 * 1_000_000 + 1 /* just over 10MB*/);
when(messageData.getCode()).thenReturn(EthPV62.TRANSACTIONS);
final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {});
ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(peer, messageData));
assertThat(peer.isDisconnected()).isTrue();
}
}
@Test
public void disconnectOnWrongGenesisHash() {
try (final EthProtocolManager ethManager =

Loading…
Cancel
Save