-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(p2p): handle packets received during handshake #841
Conversation
This commit addresses an edge case bug whereby one peer finishes the handshake before the other and begins sending regular packets. It is possible for the other peer to attempt to process these regular packets while it is executing asynchronous code to complete the handshake, which results in the regular packets being discarded as "unsolicited." This makes two changes: 1. Moves the logic to asynchronously send a `GetNodesPacket` until after we mark the peer as `opened`. 2. Add an `initializing` flag that is set to true once we receive a `SessionAckPacket`. This is an indicator that any subsequent packets we receive should not be acted upon until the handshake is complete. If we receive packets while `opened` is false but `initializing` is true, we wait to see which of the `open` or `close` events fire first to either accept or discard a packet, respectively. Fixes #839.
5910510
to
32ad2cc
Compare
I've been testing this branch quite a bit and it's working fine. |
Did you consider to mark the connection open before sending the ack?
…On Tue, 19 Mar 2019 at 10:01 Daniel McNally ***@***.***> wrote:
I've been testing this branch quite a bit and it's working fine.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#841 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJQ0crC_6IwK-ug9aZu-1--Fqex0Ryteks5vYKdbgaJpZM4b7Y4B>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been testing this branch quite a bit and it's working fine.
Tested manually as well. Seems to work :).
Not exactly, although I'm thinking that would work too and be simpler. The only thing is for that approach, we'd need to make all our checks as to whether the peer is valid (not banned, node pub key matches the advertised one, not ourselves, etc) before responding with the ack, which is already something being discussed as part of #825. We can talk about the best way forward on the call. |
I took a totally different approach (following offer's comment) that I think makes some good structural improvements to the code and solves the same issue. Since it's very different from this PR, I'm closing this one and opening a separate one shortly. |
This commit addresses an edge case bug whereby one peer finishes the handshake before the other and begins sending regular packets. It is possible for the other peer to attempt to process these regular packets while it is executing asynchronous code to complete the handshake, which results in the regular packets being discarded as "unsolicited."
This makes two changes:
GetNodesPacket
until after we mark the peer asopened
.initializing
flag that is set to true once we receive aSessionAckPacket
. This is an indicator that any subsequent packets we receive should not be acted upon until the handshake is complete. Ifwe receive packets while
opened
is false butinitializing
is true, we wait to see which of theopen
orclose
events fire first to either accept or discard a packet, respectively.Fixes #839.