Skip to main content

RelayPool

Struct RelayPool 

Source
pub struct RelayPool { /* private fields */ }
Expand description

The relay pool — manages multiple WebSocket connections with bidirectional messaging.

Inbound events flow through an MPSC ring buffer with deduplication. Outbound messages are broadcast to all relay threads via a lock-free broadcast ring.

Implementations§

Source§

impl RelayPool

Source

pub fn new( ring_capacity: usize, cache_size: usize, broadcast_capacity: usize, max_relays: usize, ) -> Self

Create a new relay pool with bidirectional messaging.

§Arguments
  • ring_capacity - MPSC ring buffer size for inbound event throughput
  • cache_size - Deduplication cache size (e.g. 10,000)
  • broadcast_capacity - Broadcast ring buffer size for outbound messages
  • max_relays - Maximum number of relay connections (broadcast consumer slots)
Source

pub fn add_relay(&mut self, relay_url: String)

Add a relay connection to the pool.

Spawns a new thread that connects to the relay, reads inbound events, and sends outbound messages from the broadcast ring.

Automatically cleans up dead connections first to free broadcast slots.

Source

pub fn remove_relay(&mut self, relay_url: &str) -> bool

Remove a relay from the pool by URL.

Signals the relay thread to shut down and blocks until it exits (~1-2ms). The broadcast consumer slot is freed immediately.

Returns true if the relay was found and removed.

Source

pub fn cleanup(&mut self)

Remove dead connections from the pool.

Joins finished threads and frees their broadcast consumer slots. Called automatically by [add_relay], but can be called explicitly to update [connection_count].

Source

pub fn sender(&self) -> PoolSender

Get a cloneable sender handle for broadcasting to all relays.

Multiple threads can hold a PoolSender and send concurrently.

Source

pub fn recv(&mut self) -> PoolMessage

Receive the next event from any relay (blocking)

Source

pub fn try_recv(&mut self) -> Option<PoolMessage>

Receive the next event from any relay (non-blocking)

Source

pub fn connection_count(&self) -> usize

Get the total number of connections (including dead ones not yet cleaned up).

Source

pub fn active_connection_count(&self) -> usize

Get the number of connections whose threads are still running.

Source

pub fn relay_urls(&self) -> Vec<&str>

Get the relay URLs of all connections in the pool.

Source

pub fn active_relay_urls(&self) -> Vec<&str>

Get the relay URLs of only active (thread still running) connections.

Trait Implementations§

Source§

impl Drop for RelayPool

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V