Skip to main content

WsConfig

Struct WsConfig 

Source
#[non_exhaustive]
pub struct WsConfig {
Show 20 fields pub enabled: bool, pub max_connections: usize, pub max_connections_per_user: usize, pub max_connections_per_ip: usize, pub max_pending_connections: usize, pub roles_refresh_secs: u64, pub handshakes_per_ip_per_minute: u32, pub auth_timeout_secs: u64, pub ping_interval_secs: u64, pub idle_timeout_secs: u64, pub request_timeout_secs: u64, pub write_timeout_secs: u64, pub outbox_frames: usize, pub frames_per_second: u32, pub frame_burst: u32, pub max_message_bytes: usize, pub read_buffer_bytes: usize, pub max_rooms_per_connection: usize, pub max_room_members: usize, pub query_token: bool,
}
Expand description

[ws]: the WebSocket hub at /v1/ws (see crate::ws).

The socket buffers are tuned for many idle connections: an 8 KiB read buffer, no write buffering (each frame is written at once) and the protocol’s 1 MiB message limit. Defaults follow the protocol (AUTH_TIMEOUT_SECS, MAX_MESSAGE_BYTES, the chat room caps).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§enabled: bool

Serve the hub at /v1/ws. Default true; when false the path answers 403 (never 400).

§max_connections: usize

The most open sockets (authenticated or not); a handshake over it gets 503 + Retry-After. Default 10 000. Keep it below the process’s open-file limit.

§max_connections_per_user: usize

The most sockets per user; a newer one closes the oldest with 4009 (replaced), the oldest of its own session first. Default 5.

§max_connections_per_ip: usize

The most open sockets per client address (IPv6 by /64), authenticated or not; 429 above. Default 100 (players behind one NAT or at a LAN party share an address).

§max_pending_connections: usize

The most sockets still waiting for their first-message auth (anonymous for up to auth_timeout_secs); 503 above, so they never crowd out authenticated players. Default 1000.

§roles_refresh_secs: u64

How often the hub re-reads the roles of every connected user, in seconds (role changes made by another process, e.g. the command line, reach open sockets within this). Changes made in this process apply at once. Default 60, 0 = off.

§handshakes_per_ip_per_minute: u32

WebSocket handshakes per client address (IPv6 by /64) per minute; 429 above. Default 60, 0 = off.

§auth_timeout_secs: u64

Seconds an unauthenticated socket has to send auth (then close 1008). Default 5 (the protocol’s AUTH_TIMEOUT_SECS).

§ping_interval_secs: u64

Seconds between the server’s pings. Default 20 (the client pings every 15 s itself).

§idle_timeout_secs: u64

Seconds without any frame from the client (data, ping or pong) before the socket counts as dead and is dropped. Default 60 (must exceed ping_interval_secs).

§request_timeout_secs: u64

The time limit of one request handler, in seconds (then 503 unavailable). Default 10.

§write_timeout_secs: u64

How long one frame may take to write before the peer counts as stuck (the socket is dropped), in seconds. Default 10.

§outbox_frames: usize

Frames waiting to be sent per socket (pushes): the largest burst the game may push to one socket at once. While a request handler runs, as many again are held back (they follow its answer). When both are full the socket is closed with 1013 (the client reconnects and resyncs). Raise it for broadcast-heavy games. Default 256.

§frames_per_second: u32

Incoming frames per second per socket (sustained); over it a request is answered rate_limited, and a socket that keeps flooding is closed with 1008. Default 20.

§frame_burst: u32

Incoming frames a socket may send at once (the bucket size). Default 40.

§max_message_bytes: usize

The largest message in either direction, in bytes (a bigger incoming one closes the socket with 1009). Default 1 MiB (the protocol’s MAX_MESSAGE_BYTES and the client’s default).

§read_buffer_bytes: usize

The socket’s read buffer, in bytes. Default 8 KiB (tungstenite’s own default, 128 KiB per socket, costs ~120 KiB more per idle connection).

§max_rooms_per_connection: usize

The most rooms one socket may be in at once (Hub::join). Default 16 (the protocol’s DEFAULT_MAX_JOINED_ROOMS).

§max_room_members: usize

The most sockets in one room unless the room is joined with its own cap. Default 200 (the protocol’s DEFAULT_MAX_ROOM_MEMBERS).

§query_token: bool

Accept the access token as ?token= on the handshake. Default false: reverse proxies (Caddy, nginx) log URLs with their query, so a token there ends up in access logs. Clients that cannot set headers (browsers) use first-message auth instead.

Trait Implementations§

Source§

impl Clone for WsConfig

Source§

fn clone(&self) -> Self

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
Source§

impl Debug for WsConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WsConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for WsConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more