|
|
@ -15,7 +15,6 @@ |
|
|
|
package org.hyperledger.besu.ethereum.eth.manager; |
|
|
|
package org.hyperledger.besu.ethereum.eth.manager; |
|
|
|
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkArgument; |
|
|
|
import static com.google.common.base.Preconditions.checkArgument; |
|
|
|
import static org.hyperledger.besu.util.Slf4jLambdaHelper.traceLambda; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.hyperledger.besu.datatypes.Hash; |
|
|
|
import org.hyperledger.besu.datatypes.Hash; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
|
import org.hyperledger.besu.ethereum.core.BlockHeader; |
|
|
@ -211,7 +210,7 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void recordUselessResponse(final String requestType) { |
|
|
|
public void recordUselessResponse(final String requestType) { |
|
|
|
LOG.debug("Received useless response for {} from peer {}", requestType, this); |
|
|
|
LOG.debug("Received useless response for request type {} from peer {}", requestType, this); |
|
|
|
reputation.recordUselessResponse(System.currentTimeMillis()).ifPresent(this::disconnect); |
|
|
|
reputation.recordUselessResponse(System.currentTimeMillis()).ifPresent(this::disconnect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -231,15 +230,13 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
final MessageData messageData, final String protocolName) throws PeerNotConnected { |
|
|
|
final MessageData messageData, final String protocolName) throws PeerNotConnected { |
|
|
|
if (connection.getAgreedCapabilities().stream() |
|
|
|
if (connection.getAgreedCapabilities().stream() |
|
|
|
.noneMatch(capability -> capability.getName().equalsIgnoreCase(protocolName))) { |
|
|
|
.noneMatch(capability -> capability.getName().equalsIgnoreCase(protocolName))) { |
|
|
|
LOG.debug("Protocol {} unavailable for this peer ", protocolName); |
|
|
|
LOG.debug("Protocol {} unavailable for this peer {}", protocolName, this); |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
if (permissioningProviders.stream() |
|
|
|
if (permissioningProviders.stream() |
|
|
|
.anyMatch(p -> !p.isMessagePermitted(connection.getRemoteEnode(), messageData.getCode()))) { |
|
|
|
.anyMatch(p -> !p.isMessagePermitted(connection.getRemoteEnode(), messageData.getCode()))) { |
|
|
|
LOG.info( |
|
|
|
LOG.info( |
|
|
|
"Permissioning blocked sending of message code {} to {}", |
|
|
|
"Permissioning blocked sending of message code {} to {}", messageData.getCode(), this); |
|
|
|
messageData.getCode(), |
|
|
|
|
|
|
|
connection.getRemoteEnode()); |
|
|
|
|
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
LOG.debug( |
|
|
|
LOG.debug( |
|
|
|
"Permissioning blocked by providers {}", |
|
|
|
"Permissioning blocked by providers {}", |
|
|
@ -256,7 +253,7 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
LOG.error( |
|
|
|
LOG.error( |
|
|
|
"Sending {} message to peer ({}) which exceeds local message size limit of {} bytes. Message code: {}, Message Size: {}", |
|
|
|
"Sending {} message to peer ({}) which exceeds local message size limit of {} bytes. Message code: {}, Message Size: {}", |
|
|
|
protocolName, |
|
|
|
protocolName, |
|
|
|
connection.getRemoteEnode(), |
|
|
|
this, |
|
|
|
maxMessageSize, |
|
|
|
maxMessageSize, |
|
|
|
messageData.getCode(), |
|
|
|
messageData.getCode(), |
|
|
|
messageData.getSize()); |
|
|
|
messageData.getSize()); |
|
|
@ -389,9 +386,10 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
requestManager -> requestManager.dispatchResponse(ethMessage), |
|
|
|
requestManager -> requestManager.dispatchResponse(ethMessage), |
|
|
|
() -> { |
|
|
|
() -> { |
|
|
|
LOG.trace( |
|
|
|
LOG.trace( |
|
|
|
"Message {} not expected has just been received for {} ", |
|
|
|
"Message {} not expected has just been received for protocol {}, peer {} ", |
|
|
|
messageCode, |
|
|
|
messageCode, |
|
|
|
protocolName); |
|
|
|
protocolName, |
|
|
|
|
|
|
|
this); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -424,8 +422,7 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void handleDisconnect() { |
|
|
|
void handleDisconnect() { |
|
|
|
traceLambda( |
|
|
|
LOG.debug("handleDisconnect - EthPeer {}", this); |
|
|
|
LOG, "handleDisconnect - peer... {}, {}", this::getShortNodeId, this::getReputation); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requestManagers.forEach( |
|
|
|
requestManagers.forEach( |
|
|
|
(protocolName, map) -> map.forEach((code, requestManager) -> requestManager.close())); |
|
|
|
(protocolName, map) -> map.forEach((code, requestManager) -> requestManager.close())); |
|
|
@ -554,8 +551,14 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String toString() { |
|
|
|
public String toString() { |
|
|
|
return String.format( |
|
|
|
return String.format( |
|
|
|
"Peer %s... %s, validated? %s, disconnected? %s", |
|
|
|
"PeerId %s, reputation %s, validated? %s, disconnected? %s, client: %s, connection %s, enode %s", |
|
|
|
getShortNodeId(), reputation, isFullyValidated(), isDisconnected()); |
|
|
|
nodeId(), |
|
|
|
|
|
|
|
reputation, |
|
|
|
|
|
|
|
isFullyValidated(), |
|
|
|
|
|
|
|
isDisconnected(), |
|
|
|
|
|
|
|
connection.getPeerInfo().getClientId(), |
|
|
|
|
|
|
|
System.identityHashCode(connection), |
|
|
|
|
|
|
|
connection.getPeer().getEnodeURLString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Nonnull |
|
|
|
@Nonnull |
|
|
@ -565,10 +568,10 @@ public class EthPeer implements Comparable<EthPeer> { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public int compareTo(final @Nonnull EthPeer ethPeer) { |
|
|
|
public int compareTo(final @Nonnull EthPeer ethPeer) { |
|
|
|
int repCompare = this.reputation.compareTo(ethPeer.reputation); |
|
|
|
final int repCompare = this.reputation.compareTo(ethPeer.reputation); |
|
|
|
if (repCompare != 0) return repCompare; |
|
|
|
if (repCompare != 0) return repCompare; |
|
|
|
|
|
|
|
|
|
|
|
int headStateCompare = |
|
|
|
final int headStateCompare = |
|
|
|
Long.compare( |
|
|
|
Long.compare( |
|
|
|
this.chainHeadState.getBestBlock().getNumber(), |
|
|
|
this.chainHeadState.getBestBlock().getNumber(), |
|
|
|
ethPeer.chainHeadState.getBestBlock().getNumber()); |
|
|
|
ethPeer.chainHeadState.getBestBlock().getNumber()); |
|
|
|