Conversation
Also add example using governor
Also introduce error code for rate limiting.
|
Is the irpc-iroh rate limiter compatible with using a |
|
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. |
|
Ah, never mind. We now have on_accepting, so we can intercept very early... Actually no, on_accepting is 1. not quite early enough to deal with direct addresses in the cheapest way possible, and 2. Accepting does not even have the remote_addr. |
|
OK, so the plan is to
|
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.