1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Distributed rate limiting for Rust services: one global limit across a
//! fleet, no datastore, no network call on the request path.
//!
//! Every instance of the service runs a [`Guard`]. The nodes find each other
//! over UDP and agree, every 200 ms, on how the limit is shared out; each
//! request is then decided locally, with no I/O and no lock shared with the
//! network.
//!
//! ```no_run
//! use rateguard::{Decision, Guard};
//!
//! # async fn run() -> Result<(), rateguard::Error> {
//! let guard = Guard::builder()
//! .bind("0.0.0.0:7946")
//! .advertise("10.0.0.3:7946")
//! .seeds(["10.0.0.1:7946", "10.0.0.2:7946"])
//! .limit(1_000) // per key, across the whole fleet, per second
//! .spawn()?;
//!
//! match guard.check("api:tenant-42") {
//! Decision::Allow => { /* serve */ }
//! Decision::Deny { retry_after } => { /* 429, Retry-After */ }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! The gossip is not encrypted, and by default not authenticated either:
//! run the nodes on a network you trust, or have them sign it with a
//! shared secret, see [`Builder::gossip_auth`].
pub use ;
pub use ;
pub use ;
pub use KeyLimit;
pub use Limit;
pub use ;
pub use ;
pub use Transport;