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

Refactor handshake rate limiting to not store a Sleep type #2915

Merged
merged 2 commits into from
Oct 21, 2021

Conversation

jvff
Copy link
Contributor

@jvff jvff commented Oct 20, 2021

Motivation

This is part of the update to use Tokio version 1 (#2200), but can be merged separately.

In newer Tokio versions the Sleep type doesn't implement Unpin, so it's a little more complicated to use it.

Solution

In this case it was easier to refactor the code to not store the Sleep type instead of wrapping it in a Pin type.

Review

Since this might be a security issue if not implemented correctly, I'd like @teor2345 to take a look at it.

Reviewer Checklist

  • Code implements Specs and Designs
  • Tests for Expected Behaviour
  • Tests for Errors

Follow Up Work

In newer Tokio versions the `Sleep` type doesn't implement `Unpin`, so
it's a little more complicated to use it. In this case it was easier to
refactor the code to not store the `Sleep` type instead of wrapping it
in a `Pin` type.
@jvff jvff requested a review from teor2345 October 20, 2021 19:11
@zfnd-bot zfnd-bot bot assigned jvff Oct 20, 2021
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

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

This looks good, it's a straightforward refactor that maintains the security conditions:

  • if we don't connect to a peer, we don't add any wait time
  • if we do connect to a peer, we wait at least MIN_PEER_CONNECTION_INTERVAL before the next peer
  • we don't have any really long delays

This is a very low risk change, so I'm happy to merge it now.

The docs say that sleep(duration) is:

Equivalent to sleep_until(Instant::now() + duration).

https://docs.rs/tokio/1.12.0/tokio/time/fn.sleep.html

@jvff jvff enabled auto-merge (squash) October 21, 2021 11:14
@jvff jvff merged commit 192a45c into ZcashFoundation:main Oct 21, 2021
@jvff jvff deleted the refactor-handshake-rate-limiting branch October 21, 2021 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants