pub struct RelayServiceWithNotify { /* private fields */ }server only.Expand description
Combines RelayService with a notification token.
This struct implements [Service]. Note that the service has to be called with hyper’s io
argument set to MaybeTlsStream wrapped by [hyper_util::rt::TokioIo], otherwise handling
WebSocket requests at /relay will fail at runtime with ConnectionHandlerError::DowncastUpgrade.
The notification token is triggered once the relay connection is fully established. It can be used to cancel a timeout aborting the TCP connection if no upgrade request is received in some time.
§Example
let service = RelayService::new(
Handlers::default(),
HeaderMap::new(),
None,
KeyCache::new(1024),
Arc::new(AllowAll),
Arc::new(Metrics::default()),
);
let service = RelayServiceWithNotify::with_timeout(
service,
Arc::new(Notify::new()),
Duration::from_secs(30),
);
let listener = TcpListener::bind("127.0.0.1:0").await?;
let (stream, _peer) = listener.accept().await?;
// Wrap the TCP stream in `MaybeTlsStream`, otherwise the relay WebSocket handler will error at runtime
// for all WebSocket requests to `/relay`.
let stream = MaybeTlsStream::Plain(stream);
http1::Builder::new()
.serve_connection(TokioIo::new(stream), service)
.with_upgrades()
.await?;Implementations§
Source§impl RelayServiceWithNotify
impl RelayServiceWithNotify
Sourcepub fn new(service: RelayService, on_establish: Arc<Notify>) -> Self
pub fn new(service: RelayService, on_establish: Arc<Notify>) -> Self
Creates a new service wrapper for a connection.
The on_establish notification is triggered once the connection is passed to the
relay protocol, i.e. after a WebSocket request on /relay is received and established.
Upgraded connections must finish authentication and authorization within 30 seconds
of receiving the upgrade request.
Sourcepub fn with_timeout(
service: RelayService,
on_establish: Arc<Notify>,
timeout: Duration,
) -> Self
pub fn with_timeout( service: RelayService, on_establish: Arc<Notify>, timeout: Duration, ) -> Self
Creates a service wrapper with a relay establishment timeout.
Each upgrade request starts a new timeout covering the WebSocket upgrade, authentication,
and authorization. The on_establish notification is triggered once the connection is
passed to the relay protocol. Established connections are not subject to this timeout.
The caller must separately bound TLS handshakes and HTTP requests before an upgrade request reaches this service.
Trait Implementations§
Source§impl Clone for RelayServiceWithNotify
impl Clone for RelayServiceWithNotify
Source§fn clone(&self) -> RelayServiceWithNotify
fn clone(&self) -> RelayServiceWithNotify
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RelayServiceWithNotify
impl Debug for RelayServiceWithNotify
Source§impl Service<Request<Incoming>> for RelayServiceWithNotify
impl Service<Request<Incoming>> for RelayServiceWithNotify
Source§type Response = Response<Box<dyn Body<Data = Bytes, Error = Infallible> + Unpin + Send>>
type Response = Response<Box<dyn Body<Data = Bytes, Error = Infallible> + Unpin + Send>>
Source§type Future = Ready<Result<<RelayServiceWithNotify as Service<Request<Incoming>>>::Response, <RelayServiceWithNotify as Service<Request<Incoming>>>::Error>>
type Future = Ready<Result<<RelayServiceWithNotify as Service<Request<Incoming>>>::Response, <RelayServiceWithNotify as Service<Request<Incoming>>>::Error>>
Auto Trait Implementations§
impl Freeze for RelayServiceWithNotify
impl !RefUnwindSafe for RelayServiceWithNotify
impl Send for RelayServiceWithNotify
impl Sync for RelayServiceWithNotify
impl Unpin for RelayServiceWithNotify
impl !UnwindSafe for RelayServiceWithNotify
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, B1, B2> HttpService<B1> for T
impl<T, B1, B2> HttpService<B1> for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more