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

Make sure handshake version negotiation always has a timeout #2008

Merged
merged 1 commit into from
Apr 19, 2021

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Apr 14, 2021

Motivation

It's hard to have consistent timeouts when we have to add a timeout() to every send and next during version negotiation. Also, the timeout value was too large.

Solution

  • Refactor handshake version negotiation into its own function
  • Put a single timeout on that function
  • Change the timeout value to the HANDSHAKE_TIMEOUT

The code in this pull request has:

  • Documentation Comments
  • Integration Tests

Review

@dconnolly asked for a timeout value change in #1850, but it was pretty easy to just make it a separate function with a single timeout.

This change blocks some of the upcoming security refactors, so it should be merged soon.

Related Issues

Closes #1994.

@teor2345 teor2345 added C-bug Category: This is a bug A-rust Area: Updates to Rust code C-cleanup Category: This is a cleanup P-Medium labels Apr 14, 2021
@teor2345 teor2345 added this to the 2021 Sprint 7 milestone Apr 14, 2021
@teor2345 teor2345 requested a review from dconnolly April 14, 2021 00:59
@teor2345 teor2345 self-assigned this Apr 14, 2021
As part of this change, refactor handshake version negotiation into its
own function.
@mpguerra mpguerra removed this from the 2021 Sprint 7 milestone Apr 16, 2021
@teor2345 teor2345 added this to the 2021 Sprint 7 milestone Apr 19, 2021
@mpguerra mpguerra removed this from the 2021 Sprint 7 milestone Apr 19, 2021
/// at `addr`, using the connection `peer_conn`.
///
/// We split `Handshake` into its components before calling this function,
/// to avoid infectious `Sync` bounds on the returned future.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'infectious' is a good way to put this 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it, and they just got everywhere

our_services: PeerServices,
relay: bool,
) -> Result<(Version, PeerServices), HandshakeError> {
// Create a random nonce for this connection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +233 to +235
// The protocol works fine if we don't reveal our current block height,
// and not sending it means we don't need to be connected to the chain state.
start_height: block::Height(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥰

let nonce_reuse = {
let mut locked_nonces = nonces.lock().expect("mutex should be unpoisoned");
let nonce_reuse = locked_nonces.contains(&remote_nonce);
// Regardless of whether we observed nonce reuse, clean up the nonce set.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// Disconnect if peer is using an obsolete version.
return Err(HandshakeError::ObsoleteVersion(remote_version));
}
// Wrap the entire initial connection setup in a timeout.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dconnolly dconnolly added this to the 2021 Sprint 7 milestone Apr 19, 2021
@dconnolly dconnolly merged commit ad272f2 into ZcashFoundation:main Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-bug Category: This is a bug C-cleanup Category: This is a cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make sure handshake version negotiation always has a timeout
3 participants