pub struct WebSocketRelayService<S = MirrorService> { /* private fields */ }Expand description
A utility that can be used by MITM services such as transparent proxies, in order to relay WebSocket messages.
By default they get mirrored but the logic is fully up to you.
This service accepts both a raw BridgeIo and an established
WebSocketBridge. Direct raw-I/O use remains convenient and backwards
compatible. To install message-level layers, wrap this service in those
layers and then place WebSocketRelayIoService around the result.
§KISS
This service is for simple DPI purposes.
Ping and pong are handled locally on each of the two independent WebSocket connections and are not exposed to middleware. A ping is acknowledged on its source connection and also produces an unsolicited pong heartbeat on the opposite connection, so activity on one leg keeps both legs alive without coupling their ping round trips. Other pongs are not forwarded. An incoming close starts coordinated shutdown; data received while closing is discarded rather than passed to middleware.
Middleware is processed independently per direction. Its future can be cancelled when either peer starts closing, so it must be cancel-safe. A failure to send middleware-produced data terminates the relay.
Use WebSocketRelayEventService when middleware also needs to observe
control messages. Fork or create your own relay service for lower-level
purposes such as preserving raw frame boundaries.
Implementations§
Source§impl<S> WebSocketRelayService<S>
impl<S> WebSocketRelayService<S>
Sourcepub fn new(middleware: S) -> Self
pub fn new(middleware: S) -> Self
Create a new WebSocketRelayService
Sourcepub fn with_close_handshake_timeout(self, timeout: Duration) -> Self
pub fn with_close_handshake_timeout(self, timeout: Duration) -> Self
Set how long the relay waits for both peers to finish a coordinated close handshake before dropping the connections.
The default is five seconds. Both connections and their relay state remain alive until the handshake finishes or this timeout expires.
Sourcepub fn set_close_handshake_timeout(&mut self, timeout: Duration) -> &mut Self
pub fn set_close_handshake_timeout(&mut self, timeout: Duration) -> &mut Self
Set how long the relay waits for both peers to finish a coordinated close handshake before dropping the connections.
The default is five seconds. Both connections and their relay state remain alive until the handshake finishes or this timeout expires.
Trait Implementations§
Source§impl<S: Clone> Clone for WebSocketRelayService<S>
impl<S: Clone> Clone for WebSocketRelayService<S>
Source§fn clone(&self) -> WebSocketRelayService<S>
fn clone(&self) -> WebSocketRelayService<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S: Debug> Debug for WebSocketRelayService<S>
impl<S: Debug> Debug for WebSocketRelayService<S>
Source§impl<S, Ingress, Egress> Service<BridgeIo<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput, Output: Into<WebSocketRelayOutput>, Error: Into<BoxError>>,
Ingress: Io + Unpin + ExtensionsRef,
Egress: Io + Unpin + ExtensionsRef,
impl<S, Ingress, Egress> Service<BridgeIo<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput, Output: Into<WebSocketRelayOutput>, Error: Into<BoxError>>,
Ingress: Io + Unpin + ExtensionsRef,
Egress: Io + Unpin + ExtensionsRef,
Source§impl<S, Ingress, Egress> Service<WebSocketBridge<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput, Output: Into<WebSocketRelayOutput>, Error: Into<BoxError>>,
Ingress: WebSocketIo,
Egress: WebSocketIo,
impl<S, Ingress, Egress> Service<WebSocketBridge<Ingress, Egress>> for WebSocketRelayService<S>where
S: Service<WebSocketRelayInput, Output: Into<WebSocketRelayOutput>, Error: Into<BoxError>>,
Ingress: WebSocketIo,
Egress: WebSocketIo,
Auto Trait Implementations§
impl<S> Freeze for WebSocketRelayService<S>where
S: Freeze,
impl<S> RefUnwindSafe for WebSocketRelayService<S>where
S: RefUnwindSafe,
impl<S> Send for WebSocketRelayService<S>where
S: Send,
impl<S> Sync for WebSocketRelayService<S>where
S: Sync,
impl<S> Unpin for WebSocketRelayService<S>where
S: Unpin,
impl<S> UnsafeUnpin for WebSocketRelayService<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for WebSocketRelayService<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S, Input, Connection> ConnectorService<Input> for Swhere
S: Service<Input, Output = EstablishedClientConnection<Connection, Input>>,
<S as Service<Input>>::Error: Into<ConnectionError>,
Connection: Send + ExtensionsRef,
impl<S, Input, Connection> ConnectorService<Input> for Swhere
S: Service<Input, Output = EstablishedClientConnection<Connection, Input>>,
<S as Service<Input>>::Error: Into<ConnectionError>,
Connection: Send + ExtensionsRef,
Source§type Connection = Connection
type Connection = Connection
ConnectorServiceSource§fn connect(
&self,
input: Input,
) -> impl Future<Output = Result<EstablishedClientConnection<<S as ConnectorService<Input>>::Connection, Input>, ConnectionError>> + Send
fn connect( &self, input: Input, ) -> impl Future<Output = Result<EstablishedClientConnection<<S as ConnectorService<Input>>::Connection, Input>, ConnectionError>> + Send
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
Source§impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
U: RamaTryFrom<T, CrateMarker>,
type Error = <U as RamaTryFrom<T, CrateMarker>>::Error
fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writerSource§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writerSource§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writerSource§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writerSource§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer