SessionClient

Struct SessionClient 

Source
pub struct SessionClient<C: Connection> { /* private fields */ }
Expand description

A high-level, cloneable client for quic-reverse sessions.

SessionClient wraps a SessionHandle and provides a more convenient API for working with quic-reverse sessions. It:

  • Is cloneable, allowing use from multiple tasks
  • Automatically processes incoming messages in a background task
  • Delivers events via a channel for handling incoming requests

§Usage

For the relay (stream opener) side:

let client = SessionClient::new(handle);
let (send, recv) = client.open("echo", Metadata::Empty).await?;

For the edge (stream acceptor) side:

let (client, mut events) = SessionClient::with_events(handle);
while let Some(event) = events.recv().await {
    if let ClientEvent::OpenRequest { request_id, service, .. } = event {
        let stream_id = 1;
        client.accept_open(request_id, stream_id).await?;
        let (send, recv) = connection.open_bi().await?;
        // Handle the stream...
    }
}

Implementations§

Source§

impl<C: Connection> SessionClient<C>

Source

pub fn new(handle: SessionHandle<C>) -> Self

Creates a new session client from a session handle.

This spawns a background task to process incoming messages. Use with_events if you need to handle incoming stream requests (edge device role).

Source

pub fn with_events(handle: SessionHandle<C>) -> (Self, Receiver<ClientEvent>)

Creates a new session client with an event channel.

Returns the client and a receiver for incoming events. Use this when you need to handle incoming stream requests (edge device role).

Source

pub fn state(&self) -> State

Returns the current session state.

Source

pub fn is_ready(&self) -> bool

Returns true if the session is ready for operations.

Source

pub fn connection(&self) -> &C

Returns a reference to the underlying connection.

Source

pub async fn open( &self, service: impl Into<ServiceId>, metadata: Metadata, ) -> Result<(C::SendStream, C::RecvStream), Error>

Opens a stream to a service on the peer.

Sends an OpenRequest and waits for the peer to accept and open a data stream back.

§Errors

Returns an error if:

  • The session is not ready
  • The request limit has been reached
  • The peer rejects the request
  • The request times out
Source

pub async fn accept_open( &self, request_id: u64, logical_stream_id: u64, ) -> Result<(), Error>

Accepts an incoming open request.

Call this in response to a ClientEvent::OpenRequest event. After calling this, open a data stream back to the peer using the underlying connection.

§Errors

Returns an error if sending the response fails.

Source

pub async fn reject_open( &self, request_id: u64, code: RejectCode, reason: Option<String>, ) -> Result<(), Error>

Rejects an incoming open request.

Call this in response to a ClientEvent::OpenRequest event when you cannot or do not want to handle the request.

§Errors

Returns an error if sending the response fails.

Source

pub async fn bind_stream<S: AsyncWriteExt + Unpin>( &self, send: &mut S, logical_stream_id: u64, ) -> Result<(), Error>

Binds a data stream to a logical stream ID.

After accepting an open request with accept_open, open a bidirectional stream and call this method to bind it to the logical stream ID you provided. The peer will verify the binding before using the stream.

§Errors

Returns an error if writing the bind frame fails.

§Example
// After receiving ClientEvent::OpenRequest { request_id, service, .. }
client.accept_open(request_id, stream_id).await?;

// Open the data stream and bind it
let (mut send, recv) = connection.open_bi().await?;
client.bind_stream(&mut send, stream_id).await?;

// Now the stream is ready for use
Source

pub async fn ping(&self) -> Result<Duration, Error>

Sends a ping and waits for the pong response.

Returns the round-trip time on success.

§Errors

Returns an error if the session is closed, sending fails, or the ping times out.

Source

pub async fn close( &self, code: CloseCode, reason: Option<String>, ) -> Result<(), Error>

Closes the session gracefully.

§Errors

Returns an error if sending the close message fails.

Source

pub async fn close_stream( &self, logical_stream_id: u64, code: CloseCode, reason: Option<String>, ) -> Result<(), Error>

Notifies the peer that a stream has been closed.

§Errors

Returns an error if sending the close message fails.

Trait Implementations§

Source§

impl<C: Connection> Clone for SessionClient<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<C: Connection> Drop for SessionClient<C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for SessionClient<C>

§

impl<C> !RefUnwindSafe for SessionClient<C>

§

impl<C> Send for SessionClient<C>

§

impl<C> Sync for SessionClient<C>

§

impl<C> Unpin for SessionClient<C>

§

impl<C> !UnwindSafe for SessionClient<C>

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

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