feat(relay): Operation-based rate limiting + Resolve most recent#185
feat(relay): Operation-based rate limiting + Resolve most recent#185
Conversation
dbfd368 to
ed7d98b
Compare
SeverinAlexB
left a comment
There was a problem hiding this comment.
Need to do a second round later
|
@SeverinAlexB resolved your feedback:
|
SeverinAlexB
left a comment
There was a problem hiding this comment.
Two comments, otherwise looks good.
In the Pubky Core team, we have a convention on how to format PR title. We stick to the conventional commit format.
So for this PR, the title could be: feat(relay): Operation-based rate limiting + Resolve most recent
fb7d396 to
a1dbad2
Compare
|
SeverinAlexB
left a comment
There was a problem hiding this comment.
One NIT, otherwise good to go
|
Actually, should this add the |
|
@SeverinAlexB @SHAcollision Restored DHT rate limiting that was previously removed. Since the DHT can be accessed directly, keeping rate limiting in place is necessary. The implementation is now fully backward compatible. Existing |
* Consolidate simple-dns dependency in workspace root * Bump simple-dns to latest 0.11.2 * Adapt calls to simple-dns methods * pkarr: fix port param lookup * extra: update Endpoint.params type Params type was updated to better match what simple-dns exposes. * Throw error if expected SVCParam type doesn't match * Simplify ipv4 parsing Co-authored-by: DZ <dzdidi@users.noreply.github.com> * Use static lifetine for SVCParam in Endpoint.params * fixed clippy * A few code cleanups * fmt --------- Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com> Co-authored-by: DZ <dzdidi@users.noreply.github.com>
chore: release v6.0.0-rc.0
…most_recent sends ?most_recent=true to relays
2bc52f7 to
0d89091
Compare
86667
left a comment
There was a problem hiding this comment.
Few comments 👍
Also we could have quite a few more unit tests. All behaviour may be tested somewhere but unit tests inline with the code they test are pretty much always worth it these days with how fast AI can write them IMO
| /// Whether to respect the most_recent query parameter in resolve requests | ||
| /// | ||
| /// If true, the most_recent query parameter is respected and will bypass cache. | ||
| /// If false, the most_recent query parameter is ignored and will always load from cache. |
There was a problem hiding this comment.
This feels like difficult behaviour to debug. Did we consider returning an error if most_recent is requested but the relay is configured with resolve_most_recent: false?
| /// Set the operation-based rate limiter configuration. | ||
| /// | ||
| /// Defaults to None (no operation-based rate limiting). | ||
| pub fn rate_limiter_config(&mut self, limits: Option<Vec<OperationLimit>>) -> &mut Self { |
There was a problem hiding this comment.
This may technically be a breaking change. im not sure if we have any other consumers of the module as a lib
| [package] | ||
| name = "pkarr" | ||
| version = "5.0.3" | ||
| version = "6.0.0-rc.0" |
There was a problem hiding this comment.
if so, maybe we can remove the config backwards compatibility logic
There was a problem hiding this comment.
especially concerning is behind_proxy being in two possible places - which takes precedence? If we need to keep backwards compatibility then this should be documented. Quick AI check says that [relay].behind_proxy will infact override [rate_limiter].behind_proxy
| }; | ||
|
|
||
| // Go through all the limits and check if we need to throttle or reject the request. | ||
| for limit in limits.clone() { |
| Operation::Resolve => { | ||
| req.method() == Method::GET | ||
| && Self::is_operation(req.uri().path()) | ||
| && !(resolve_most_recent && Self::has_query_param(req, "most_recent", "true")) |
There was a problem hiding this comment.
Why does the rate limiter need to consider the resolve_most_recent config var here? it cares for rate limiting based on the requests, the process's config is irrelevant
| tracing::debug!("Rate limit of {} exceeded for {:?}", limit.limit.quota, key); | ||
| return Box::pin(async move { | ||
| Ok( | ||
| HttpError::new(StatusCode::TOO_MANY_REQUESTS, Some("Rate limit exceeded")) |
Summary
This PR replaces current rate limiting with an operation-based configuration that maps directly to the relay's three core operations:
publish,resolve, andresolve_most_recent.Configuration Example
Operations in this toml file automatically map to:
If no config.toml file is present, system will use defaults, so this is not a breaking change.