Skip to main content

WsServer

Struct WsServer 

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

WebSocket server adapter that accepts inbound connections.

Listens on a TCP port and spawns a WsConn actor for each incoming WebSocket connection. Optionally serves a web UI on port + 1 for peer ID discovery.

Implementations§

Source§

impl WsServer

Source

pub fn new(config: Config) -> Self

Creates a new WebSocket server with default config.

Source

pub fn new_with_config(config: Config, ws_config: WsServerConfig) -> Self

Creates a new WebSocket server with custom config.

§Arguments
  • config - Node configuration
  • ws_config - WebSocket server config (port, TLS)
Source

pub fn peer_count(&self) -> usize

Returns the current number of connected WebSocket peers.

Test-only helper to poll mesh readiness without relying on blind sleeps. The count reflects the number of WsConn actors that have completed the WebSocket handshake and registered themselves in the server’s client set.

§Use
// Wait for both peers to connect before broadcasting a Put.
while ws_server.peer_count() < 2 {
    sleep(Duration::from_millis(50)).await;
}

Trait Implementations§

Source§

impl Actor for WsServer

Source§

fn handle<'life0, 'life1, 'async_trait>( &'life0 mut self, msg: Arc<Message>, _ctx: &'life1 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Relays wire-format messages (Put, Get, Hi, BatchPut, Flush, RtcSignal) to all connected WebSocket clients except the sender. Internal messages (CheckQuorumTimeouts, RegisterQuorum) are never relayed — they are router-internal and would produce empty or malformed frames on the wire.

Source§

fn subscribe_to_everything(&self) -> bool

WsServer is a relay adapter — it fans out Puts to all connected WebSocket clients. Must return true so the Router adds it to server_peers and relays Put messages through it.

Source§

fn is_relay_server(&self) -> bool

WsServer is a relay server — it accepts incoming connections and fans out to individual WsConn clients. The Router always relays to WsServer (even for messages from remote peers) because the WsServer handles per-connection echo-back via msg.is_from(conn).

Source§

fn pre_start<'life0, 'life1, 'async_trait>( &'life0 mut self, ctx: &'life1 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called once before the actor starts processing messages. Read more
Source§

fn stopping<'life0, 'life1, 'async_trait>( &'life0 mut self, _context: &'life1 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Called once after the actor’s message loop exits. Read more
Source§

fn handle_batch<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, batch: &'life1 mut Vec<Arc<Message>>, context: &'life2 ActorContext, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Handle a batch of messages drained from the mailbox. Read more
Source§

fn try_clone_storage(&self) -> Option<Box<dyn Actor>>

Attempts to produce a clone of this actor for storage read/write splitting. Read more
Source§

impl Clone for WsServer

Source§

fn clone(&self) -> WsServer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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