diff --git a/crates/ptth_relay/src/relay_state.rs b/crates/ptth_relay/src/relay_state.rs index 96d3a98..f718e84 100644 --- a/crates/ptth_relay/src/relay_state.rs +++ b/crates/ptth_relay/src/relay_state.rs @@ -70,13 +70,6 @@ impl Default for ServerStatus { } } -#[derive (Clone)] -pub struct RejectedServer { - pub name: String, - pub tripcode: blake3::Hash, - pub seen: DateTime , -} - pub struct RelayState { pub config: RwLock , @@ -94,6 +87,34 @@ pub struct RelayState { pub unregistered_servers: RwLock >, } +pub struct BoundedVec { + bound: usize, + v: RwLock >, +} + +impl BoundedVec { + pub async fn to_vec (&self) -> Vec { + let guard = self.v.read ().await; + (*guard).clone () + } + + pub async fn push (&mut self, x: T) { + let mut guard = self.v.write ().await; + guard.push (x); + + while guard.len () > self.bound { + guard.remove (0); + } + } +} + +#[derive (Clone)] +pub struct RejectedServer { + pub name: String, + pub tripcode: blake3::Hash, + pub seen: DateTime , +} + impl TryFrom for RelayState { type Error = RelayError;