Rust

database

Module

Fixed-window counters as documents of an abuse collection: one per key and window, unique on both.

Contents

use utopia_abuse::time_limit::database::Database;
Rust
pub struct Database<D>

Counters as documents of the abuse collection: one per key and window, with its count.

Rust
use utopia_abuse::{TimeLimit, time_limit};

let store = time_limit::Database::new(std::sync::Arc::new(time_limit::Memory::new()));
store.setup().await?;
let limit = TimeLimit::new("ip:{ip}", 1, 60, store)?.with_param("{ip}", "203.0.113.7");
assert!(!limit.check_at(1_700_000_000).await?.limited);
assert!(limit.check_at(1_700_000_001).await?.limited);
use utopia_abuse::time_limit::database::Entry;
Rust
pub struct Entry

One counter document of the abuse collection.

use utopia_abuse::time_limit::database::Memory;
Rust
pub struct Memory

A Documents store in memory, for tests and single-process use. Ids are sequential ("1", "2", ...).

use utopia_abuse::time_limit::database::Documents;
Rust
pub trait Documents: Send + Sync

The document operations Database needs, all on the abuse collection and bypassing authorization.

Implemented byArcMemory
Rust
pub const COLLECTION: &str = "abuse"

The collection Database counts in.