Struct wtransport::endpoint::Endpoint

source ·
pub struct Endpoint<Side> { /* private fields */ }
Expand description

Entrypoint for creating client or server connections.

A single endpoint can be used to accept or connect multiple connections. Each endpoint internally binds an UDP socket.

§Server

Use Endpoint::server for creating a server-side endpoint. Afterwards use the method Endpoint::accept for awaiting on incoming session request.

use wtransport::Endpoint;

let server = Endpoint::server(config)?;
loop {
    let incoming_session = server.accept().await;
    // Spawn task that handles client incoming session...
}

§Client

Use Endpoint::client for creating a client-side endpoint and use Endpoint::connect to connect to a server specifying the URL.

use wtransport::ClientConfig;
use wtransport::Endpoint;

let connection = Endpoint::client(ClientConfig::default())?
    .connect("https://localhost:4433")
    .await?;

Implementations§

source§

impl<Side> Endpoint<Side>

source

pub fn close(&self, error_code: VarInt, reason: &[u8])

Closes all of this endpoint’s connections immediately and cease accepting new connections.

source

pub async fn wait_idle(&self)

Waits for all connections on the endpoint to be cleanly shut down.

source

pub fn local_addr(&self) -> Result<SocketAddr>

Gets the local SocketAddr the underlying socket is bound to.

source§

impl Endpoint<Server>

source

pub fn server(server_config: ServerConfig) -> Result<Self>

Constructs a server endpoint.

source

pub async fn accept(&self) -> IncomingSession

Get the next incoming connection attempt from a client.

source

pub fn reload_config( &self, server_config: ServerConfig, rebind: bool ) -> Result<()>

Reloads the server configuration.

Useful for e.g. refreshing TLS certificates without disrupting existing connections.

§Arguments
  • server_config - The new configuration for the server.
  • rebind - A boolean indicating whether the server should rebind its socket. If true, the server will bind to a new socket with the provided configuration. If false, the bind address configuration will be ignored.
source

pub fn reject_new_connections(&self)

Rejects new incoming connections without affecting existing connections

source§

impl Endpoint<Client>

source

pub fn client(client_config: ClientConfig) -> Result<Self>

Constructs a client endpoint.

source

pub async fn connect<O>( &self, options: O ) -> Result<Connection, ConnectingError>

Establishes a WebTransport connection to a specified URL.

This method initiates a WebTransport connection to the specified URL. It validates the URL, and performs necessary steps to establish a secure connection.

§Arguments
  • options - Connection options specifying the URL and additional headers. It can be simply an URL string representing the WebTransport endpoint to connect to. It must have an https scheme. The URL can specify either an IP address or a hostname. When specifying a hostname, the method will internally perform DNS resolution, configured with ClientConfigBuilder::dns_resolver.
§Examples

Connect using a URL with a hostname (DNS resolution is performed):

let url = "https://example.com:4433/webtransport";
let connection = endpoint.connect(url).await?;

Connect using a URL with an IP address:

let url = "https://127.0.0.1:4343/webtransport";
let connection = endpoint.connect(url).await?;

Connect adding an additional header:

let options = ConnectOptions::builder("https://example.com:4433/webtransport")
    .add_header("Authorization", "AuthToken")
    .build();
let connection = endpoint.connect(options).await?;

Auto Trait Implementations§

§

impl<Side> Freeze for Endpoint<Side>
where Side: Freeze,

§

impl<Side> !RefUnwindSafe for Endpoint<Side>

§

impl<Side> Send for Endpoint<Side>
where Side: Send,

§

impl<Side> Sync for Endpoint<Side>
where Side: Sync,

§

impl<Side> Unpin for Endpoint<Side>
where Side: Unpin,

§

impl<Side> !UnwindSafe for Endpoint<Side>

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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