Skip to main content

UdpClientTransport

Struct UdpClientTransport 

Source
pub struct UdpClientTransport { /* private fields */ }
Available on crate feature std and non-WebAssembly only.

Implementations§

Source§

impl UdpClientTransport

Source

pub async fn connect(server: SocketAddr) -> Result<Self, CoreError>

Bind a fresh UNCONNECTED UDP socket for talking to server, choosing a random lifetime connection-ID. The socket is left unconnected (no socket.connect) so the client can recv_from any source — the precondition for hearing, and later following, a server that migrates to a new address. Datagrams are sent with send_to(server_addr).

Source

pub async fn migrate_to( &self, new_local_addr: SocketAddr, ) -> Result<(), CoreError>

Rebind to a fresh local socket and route subsequent traffic through it (Phase 4 / P4.2b — embedder-triggered migration). Best-effort and non-blocking on validation: it binds a fresh unconnected socket (sends still send_to the tracked server_addr), then atomically swaps it in as the active socket while KEEPING the old one for the overlap (the recv loop listens on both until the new path shows life, then drops the old — broken-rebind safety / D7). Subsequent app data + L1 retransmits go out the new socket, so the server detects the new source (P4.1) and challenges → validates → swaps its peer. The caller is responsible for bumping the session send path_id (Session::next_migration_path_id).

A bind/connect failure returns Err WITHOUT touching the active socket, so a migration to a dead/invalid address never tears the session down — the session keeps running on the old socket.

Typed core of the migration; the SocketAddr-free SessionTransport::migrate trait entry parses a String and delegates here.

Trait Implementations§

Source§

impl SessionTransport for UdpClientTransport

Source§

async fn migrate(&self, local_addr: String) -> Result<(), CoreError>

SocketAddr-free trait entry for connection migration (Phase 4 / P4.2c). Parses the embedder-supplied local bind address and delegates to the typed migrate_to. A malformed address is a clean Err that leaves the session on its existing socket (best-effort, never fatal).

Source§

async fn send_bytes(&self, data: &[u8]) -> Result<(), CoreError>

Send raw bytes to the peer. Read more
Source§

async fn recv_bytes(&self) -> Result<Bytes, CoreError>

Receive the next message from the peer. The returned Bytes is a refcounted view over an opaque buffer; subsequent clone()s are cheap.
Source§

fn set_frame_phase(&self, phase: FramePhase)

Move the transport to a new FramePhase, adjusting the receive frame-size cap (WIRE-001). Default no-op — transports that do not length-prefix / buffer, or are inherently bounded, need not implement it. Called once by the session machinery at the handshake → data-pump boundary. Adding this defaulted method is source-compatible for every existing impl.
Source§

fn set_outbound_cid(&self, cid: [u8; 8])

Stamp this transport’s outbound routing CID (ε / WIRE v5). Called once by the session machinery at the handshake → data-pump boundary with the session’s current_outbound_cid() (the rotating CID_0), switching the transport off the bootstrap ConnId onto the chain. Default no-op — socket-routed transports (TCP / WebSocket / WASI / Embedded) carry no on-wire CID and ignore it. Source-compatible for every existing impl.
Source§

fn confirm_authenticated_source(&self)

Commit the most-recently-received frame’s source as the migration candidate — call ONLY from the post-decrypt path, i.e. once that frame has been AEAD-verified (M-1). On the address-aware UDP server this is the migration-integrity fix: the candidate (and hence the server’s PATH_CHALLENGE target) is only ever an AEAD-authenticated source, so a spoofed CID-matched datagram (which never decrypts) cannot clobber the candidate slot and misdirect / stall a legitimate migration. SocketAddr-free — the address stays inside the concrete transport. Default no-op for transports without migration.
Source§

fn has_migration_candidate(&self) -> bool

Whether the transport has observed an unvalidated candidate source for this session — a connection-migration signal (Phase 4). Only an address-aware transport (the UDP server) ever returns true; stream transports (TCP / WebSocket / WASI / Embedded) have no migration and use the default false. Deliberately SocketAddr-free so the generic data pump that calls it stays no_std-clean (std::net::SocketAddr does not exist in core/alloc); the candidate address is held inside the concrete transport.
Source§

async fn send_to_candidate(&self, data: &[u8]) -> Result<bool, CoreError>

Send data — an already-encrypted PATH_VALIDATION challenge built by the session — to the transport’s internally-tracked candidate source, distinct from the established peer, under the transport’s own anti-amplification cap (RFC 9000 §8.2). Returns Ok(true) if a candidate existed and the send was within budget, Ok(false) otherwise (no candidate, or the 3× cap was hit). Default (non-address transports): a no-op Ok(false). The candidate address never crosses this boundary, keeping the trait no_std-safe.
Source§

fn promote_candidate(&self) -> bool

Promote the migration candidate to the established peer (Phase 4, the switch): after the candidate’s path validates, subsequent app data and retransmits go to it instead of the old peer. Returns true if a candidate was promoted. Default no-op (false) for transports without migration. SocketAddr-free — the address is internal to the concrete transport.
Source§

fn migrate_server( &self, _local_addr: String, ) -> impl Future<Output = Result<(), CoreError>> + Send

Migrate the server side of this transport to a new local send address — the mirror of migrate for the accepting peer. The server binds a fresh local socket, sends subsequent server→client datagrams from it (so the client sees a new s2c source and follows it), and receives on it too (so once the client switches its send target the c2s frames are delivered transparently). The address crosses as a String to keep the trait SocketAddr-free / no_std-clean. Best-effort: a parse / bind failure returns Err and the session keeps running on the old socket. Default no-op Ok(()) — only the native UDP server implements it. Kept distinct from migrate so the FFI-exported client migrate() cannot trigger a server migration.

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

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
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> 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, 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