Skip to main content

StreamTable

Struct StreamTable 

Source
pub struct StreamTable { /* private fields */ }
Expand description

The engine’s side of its stream transports: listeners, connections, framing, the optional security layer and back-pressure. See the module documentation.

The tag given to listen and connect is the owner’s: one table can serve several users (ICE-TCP and a TURN client, say), each finding its connections by tag.

Implementations§

Source§

impl StreamTable

Source

pub fn new(config: StreamConfig) -> Self

An empty table.

Source

pub fn config(&self) -> StreamConfig

Its limits.

Source

pub fn listen( &mut self, local: SocketAddr, framing: Framing, tag: u32, reuse_address: bool, ) -> ListenerId

Asks the driver to listen on local; connections it accepts get framing and tag.

Source

pub fn resolve(&mut self, host: String, port: u16) -> u64

Asks the driver to resolve host; the answer comes as StreamNotice::Resolved with the returned query id.

Source

pub fn resolve_records(&mut self, name: String, kind: RecordKind) -> u64

Asks the driver for the kind records of name; the answer comes as StreamNotice::ResolvedRecords with the returned query id (ids are shared with resolve).

Source

pub fn stop_listening(&mut self, listener: ListenerId)

Asks the driver to close the listener. Unknown listeners are ignored.

Source

pub fn listener_address(&self, listener: ListenerId) -> Option<SocketAddr>

The address a listener is bound to, once the driver said so.

Source

pub fn listeners( &self, ) -> impl Iterator<Item = (ListenerId, u32, SocketAddr, Option<SocketAddr>)> + '_

The listeners: id, tag, requested and bound address.

Source

pub fn connect( &mut self, local: SocketAddr, remote: SocketAddr, framing: Framing, tag: u32, reuse_address: bool, layer: Option<Box<dyn StreamLayer>>, ) -> Result<StreamId>

Asks the driver for a connection from local (port 0: ephemeral) to remote. Messages can be sent at once; they wait for the connection. With a layer, what it writes first (a TLS ClientHello) is sent first, and messages wait for its handshake.

§Errors

Error::ErrBufferFull when the table holds StreamConfig::max_connections; an error of the layer.

Source

pub fn accept( &mut self, listener: ListenerId, local: SocketAddr, remote: SocketAddr, ) -> Option<StreamId>

The driver accepted a connection from remote on listener, arriving on local. Returns its id, or None when the listener is unknown or the table is full: the driver closes the socket then.

Source

pub fn send(&mut self, id: StreamId, message: &[u8]) -> Result<bool>

Queues message on the connection, framed (and encrypted with its layer). Returns false when back-pressure dropped it: the connection already holds StreamConfig::max_queued bytes.

§Errors

Error::ErrUnknownStream, Error::ErrStreamConnectionClosed (closing), Error::ErrStreamMessageTooLong, or an error of the layer.

Source

pub fn read(&mut self, id: StreamId, data: &[u8]) -> Result<Vec<Vec<u8>>>

Bytes the driver read from the connection, in whatever piece: returns the messages they complete, in order.

§Errors

Error::ErrUnknownStream; a stream that is not of its framing (TURN) or a layer error: the connection is then reset (StreamCommand::Reset is issued) and reported StreamNotice::Closed.

Source

pub fn close(&mut self, id: StreamId)

Closes the connection in order: what is queued is still handed out, then StreamCommand::Close is issued. A connection still connecting is reset instead. Unknown ids are ignored.

Source

pub fn reset(&mut self, id: StreamId)

Aborts the connection: StreamCommand::Reset is issued and the id forgotten. Unknown ids are ignored.

Source

pub fn handle_event(&mut self, event: StreamEvent) -> Result<()>

Takes an event from the driver. Events for ids the table no longer knows (a connection it reset, a listener it stopped) are ignored: they cross on the way.

§Errors

An error of a connection’s layer once it is established.

Source

pub fn poll_command(&mut self) -> Option<StreamCommand>

The next command for the driver.

Source

pub fn poll_notice(&mut self) -> Option<StreamNotice>

The next notice for the owner.

Source

pub fn poll_transmit(&mut self) -> Option<StreamTransmit>

The next bytes to write, connections taking turns. Only established connections transmit, each within its window.

Source

pub fn info(&self, id: StreamId) -> Option<StreamInfo>

A connection’s description, while the table knows it.

Source

pub fn connections(&self) -> impl Iterator<Item = StreamInfo> + '_

Every connection.

Source

pub fn find( &self, tag: u32, local: SocketAddr, remote: SocketAddr, local_ip_only: bool, ) -> Option<StreamId>

A connection of tag to remote from local that can still carry data (not closing), an established one before one still connecting. With local_ip_only, any local port on local’s address matches (an RFC 6544 active candidate, whose connections each get an ephemeral port).

Source

pub fn has_output(&self) -> bool

Whether anything is waiting for the driver: a command or a transmit it may take.

Trait Implementations§

Source§

impl Debug for StreamTable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StreamTable

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.