Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

sangaman
Copy link
Collaborator

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.

@sangaman sangaman added bug Something isn't working p2p Peer to peer networking labels Mar 19, 2019
@sangaman sangaman requested review from a user, offerm and moshababo March 19, 2019 06:38
@ghost ghost assigned sangaman Mar 19, 2019
@ghost ghost added the in progress label Mar 19, 2019
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.
@sangaman
Copy link
Collaborator Author

I've been testing this branch quite a bit and it's working fine.

@offerm
Copy link
Contributor

offerm commented Mar 19, 2019 via email

Copy link

@ghost ghost left a 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 :).

@sangaman
Copy link
Collaborator Author

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.

@sangaman
Copy link
Collaborator Author

sangaman commented Mar 19, 2019

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.

@sangaman sangaman closed this Mar 19, 2019
@ghost ghost removed the in progress label Mar 19, 2019
@ghost ghost deleted the p2p/initializing branch March 19, 2019 21:34
@ghost ghost restored the p2p/initializing branch March 19, 2019 21:34
@sangaman sangaman deleted the p2p/initializing branch April 5, 2019 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p2p Peer to peer networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

seed nodes keep disconnecting
2 participants