Skip to content

feat: rate limiting in irpc and irpc-iroh#94

Open
rklaehn wants to merge 6 commits intomainfrom
better-server-side
Open

feat: rate limiting in irpc and irpc-iroh#94
rklaehn wants to merge 6 commits intomainfrom
better-server-side

Conversation

@rklaehn
Copy link
Collaborator

@rklaehn rklaehn commented Feb 13, 2026

This implements hooks to implement rate limiting for irpc and iroh. You can rate limit / filter based on SocketAddr (for irpc) and SocketAddr and EndpointId (for irpc-iroh).

You can filter by SocketAddr even before the SocketAddr is validated, but you should usually wait until it is validated, otherwise somebody could send you spoofed packets and rate limit valid clients.

There is also a system in place to allow for per-request rate limiting and filtering. This is the same for irpc and irpc-iroh.

@Frando
Copy link
Member

Frando commented Feb 13, 2026

Is the irpc-iroh rate limiter compatible with using a Router? I pretty much always use irpc with a router (and n0des, where this feature request comes from, does too).

@rklaehn
Copy link
Collaborator Author

rklaehn commented Feb 16, 2026

I just looked at the n0des code. For per request filtering I think there isn't that much you can do. n0des calls read_request manually, you could just apply a filter immediately afterwards. You could use the new RequestFilter trait for that, but it doesn't add that much value.

let Some(first_request) = read_request::<N0desProtocol>(&connection).await? else {
    return Ok(());
};
/// apply stateful per request filter
if !filter.accept(first_request) {
  return Ok(());
}

For per SocketAddr and per EndpointId filtering in the router, that would be a feature in the iroh router. You could even throw in per ALPN filtering. I guess we could do a PR in iroh instead and reuse that part from here.

@rklaehn
Copy link
Collaborator Author

rklaehn commented Feb 16, 2026

Ah, never mind. We now have on_accepting, so we can intercept very early...

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