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

feat(iroh-relay): Rate-limit client connections #2961

Merged
merged 19 commits into from
Nov 27, 2024
Merged

Conversation

flub
Copy link
Contributor

@flub flub commented Nov 22, 2024

Description

Add a rate limit to the incoming data from client connections.

Breaking Changes

If not configured there is now a default rate limit for incoming data from client connections: 4KiB/s steady-stream and 16MiB burst capacity.

Notes & open questions

  • The choice here is made to rate-limit the incoming bytes, regardless of what they are. The benefit is that the incoming stream is slowed down, pushing back to the client over the TCP connection. The downside is that someone who is rate-limited will get a fairly bad experience since all DISCO traffic is also delayed.

  • Only rate-limiting non-disco traffic is an option, but it would not push back on the TCP stream, which is worse as then you'd still have to swallow all the incoming traffic. Also it would be open to abuse fairly easy as the detection of disco packets is based on a magic number which could easily be spoofed.

  • Maybe the RateLimitedRelayedStream should live in stream.rs next to the RelayedStream? Not really sure.

TODO

  • Allow rate-limit configuration in the config file.
  • Test config file loading.
  • Set a sensible default rate-limit.
  • Improve tests to more fully test the rate limiting.
  • Metrics when rate limits are hit.

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All breaking changes documented.

This has a hardcoded rate-limiter.  Need to make it configurable.
Copy link

github-actions bot commented Nov 22, 2024

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/iroh/pr/2961/docs/iroh/

Last updated: 2024-11-27T17:27:21Z

Copy link

github-actions bot commented Nov 22, 2024

Netsim report & logs for this PR have been generated and is available at: LOGS
This report will remain available for 3 days.

Last updated for commit: 757be06

iroh-relay/src/server.rs Outdated Show resolved Hide resolved
@flub flub added this to the v0.29.0 milestone Nov 25, 2024
@flub flub self-assigned this Nov 25, 2024
@flub flub marked this pull request as ready for review November 27, 2024 12:01
@flub flub requested review from dignifiedquire and Arqu November 27, 2024 12:01
Copy link
Collaborator

@Arqu Arqu left a comment

Choose a reason for hiding this comment

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

Aside from sad CI, code looks good.
I did add another comment about defaults though :D

iroh-relay/src/protos/relay.rs Show resolved Hide resolved
iroh-relay/src/server.rs Outdated Show resolved Hide resolved
@@ -18,6 +18,9 @@ use tokio_util::codec::{Decoder, Encoder};
/// including its on-wire framing overhead)
pub const MAX_PACKET_SIZE: usize = 64 * 1024;

/// The maximum frame size.
///
/// This is also the minimum burst size that a rate-limiter has to accept.
const MAX_FRAME_SIZE: usize = 1024 * 1024;
Copy link
Contributor

Choose a reason for hiding this comment

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

note to @flub and future self, we should reevaluate if this is a good number

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 think we don't currently do "GSO" or "jumbo datagrams" over the relay protocol, so it's fine until we decide to start doing this I guess?

@flub flub requested review from dignifiedquire and Arqu November 27, 2024 17:12
@flub
Copy link
Contributor Author

flub commented Nov 27, 2024

@Arqu demanded that the rate limiter could be disabled. So please review the new option spaghetti.

@flub flub requested a review from dignifiedquire November 27, 2024 17:24
@flub flub added this pull request to the merge queue Nov 27, 2024
Merged via the queue into main with commit c999770 Nov 27, 2024
25 of 26 checks passed
@flub flub deleted the flub/relay-rate-limit branch November 27, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants