Conversation
Fix couple of old fields and add nonce field to Ping/Pong so that the protocol is slightly more robust when accepting a Pong from remote peer.
Ping/Pong is used to test the aliveness of the remote peer and it works by periodically sending a Ping message and expecting a response to it within some predefined time period. This commit implements this functionality as a state machine on top of the asynchronous protocol by introducing substates to the default listening state of the `PeerState` enum. This allows the Ping/Pong functionality to follow a certain path and catch errors where appropriate while still allowing the remote peer to essentially send anything they want, as long as they reply to the Ping message in time and with correct nonce.
altonen
requested review from
TheQuantumPhysicist,
erubboli,
iljakuklic,
muursh and
zorvan
as code owners
January 13, 2022 05:53
muursh
reviewed
Jan 13, 2022
muursh
reviewed
Jan 13, 2022
muursh
reviewed
Jan 13, 2022
TheQuantumPhysicist
approved these changes
Jan 14, 2022
TheQuantumPhysicist
left a comment
Contributor
There was a problem hiding this comment.
Other than the few comments I made, it looks fine.
Instead of matching both state and message type at the same time, match the state first, then call an appropriate function for that state and match the message type in that function to handle the (state, message type) combination. Additionally, add some comments, reword an error message and rename a few tests functions to be more descriptive.
muursh
approved these changes
Jan 17, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the Ping/Pong functionality and it's implemented as a state machine on top of the async protocol, i.e., the remote peer can send messages that don't relate to the Ping/Pong functionality in any way but as long as they sent the Pong in time, the connectivity check is concluded as successful. If the remote doesn't respond in time or it responds each time with an invalid nonce, the connection is closed as unresponsive.
This is once again quite a big PR but there's no meaningful way to split it into parts and if it's any solace, there's almost 800 lines of tests and a lot of comments.