Skip to content

Commit

Permalink
Add comments to a couple of the the EthPeer methods to clarify their …
Browse files Browse the repository at this point in the history
…behaviour (hyperledger#6733)

Signed-off-by: Matthew Whitehead <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
matthew1001 and macfarla authored Mar 15, 2024
1 parent 2ce2a55 commit b239fb6
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ private RequestManager.ResponseStream sendRequest(
messageData);
}

/**
* Determines the validity of a message received from a peer. A message is considered valid if
* either of the following conditions are met: 1) The message is a request type message (e.g.
* GET_BLOCK_HEADERS), or 2) The message is a response type message (e.g. BLOCK_HEADERS), the node
* has made at least 1 request for that type of message (i.e. it has sent at least 1
* GET_BLOCK_HEADERS request), and it has at least 1 outstanding request of that type which it
* expects to receive a response for.
*
* @param message The message being validated
* @param protocolName The protocol type of the message
* @return true if the message is valid as per the above logic, otherwise false.
*/
public boolean validateReceivedMessage(final EthMessage message, final String protocolName) {
checkArgument(message.getPeer().equals(this), "Mismatched message sent to peer for dispatch");
return getRequestManager(protocolName, message.getData().getCode())
Expand Down Expand Up @@ -442,6 +454,16 @@ void dispatch(final EthMessage ethMessage) {
dispatch(ethMessage, protocolName);
}

/**
* Attempt to get a request manager for a received response-type message e.g. BLOCK_HEADERS. If
* the message is a request-type message e.g. GET_BLOCK_HEADERS no request manager will exist so
* Optional.empty() will be returned.
*
* @param protocolName the type of protocol the message is for
* @param code the message code
* @return a request manager for the received response messsage, or Optional.empty() if this is a
* request message
*/
private Optional<RequestManager> getRequestManager(final String protocolName, final int code) {
if (requestManagers.containsKey(protocolName)) {
final Map<Integer, RequestManager> managers = requestManagers.get(protocolName);
Expand Down

0 comments on commit b239fb6

Please sign in to comment.