-
Notifications
You must be signed in to change notification settings - Fork 186
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
Conversation
This has a hardcoded rate-limiter. Need to make it configurable.
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 |
This makes misusing the state harder as the interactions are enforced more on the type-level.
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.
Aside from sad CI, code looks good.
I did add another comment about defaults though :D
@@ -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; |
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.
note to @flub and future self, we should reevaluate if this is a good number
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 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?
@Arqu demanded that the rate limiter could be disabled. So please review the new option spaghetti. |
That *is* a bit nicer to use.
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 instream.rs
next to theRelayedStream
? Not really sure.TODO
Change checklist