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
impl StreamTable
Sourcepub fn new(config: StreamConfig) -> Self
pub fn new(config: StreamConfig) -> Self
An empty table.
Sourcepub fn config(&self) -> StreamConfig
pub fn config(&self) -> StreamConfig
Its limits.
Sourcepub fn listen(
&mut self,
local: SocketAddr,
framing: Framing,
tag: u32,
reuse_address: bool,
) -> ListenerId
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.
Sourcepub fn resolve(&mut self, host: String, port: u16) -> u64
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.
Sourcepub fn resolve_records(&mut self, name: String, kind: RecordKind) -> u64
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).
Sourcepub fn stop_listening(&mut self, listener: ListenerId)
pub fn stop_listening(&mut self, listener: ListenerId)
Asks the driver to close the listener. Unknown listeners are ignored.
Sourcepub fn listener_address(&self, listener: ListenerId) -> Option<SocketAddr>
pub fn listener_address(&self, listener: ListenerId) -> Option<SocketAddr>
The address a listener is bound to, once the driver said so.
Sourcepub fn listeners(
&self,
) -> impl Iterator<Item = (ListenerId, u32, SocketAddr, Option<SocketAddr>)> + '_
pub fn listeners( &self, ) -> impl Iterator<Item = (ListenerId, u32, SocketAddr, Option<SocketAddr>)> + '_
The listeners: id, tag, requested and bound address.
Sourcepub fn connect(
&mut self,
local: SocketAddr,
remote: SocketAddr,
framing: Framing,
tag: u32,
reuse_address: bool,
layer: Option<Box<dyn StreamLayer>>,
) -> Result<StreamId>
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.
Sourcepub fn accept(
&mut self,
listener: ListenerId,
local: SocketAddr,
remote: SocketAddr,
) -> Option<StreamId>
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.
Sourcepub fn send(&mut self, id: StreamId, message: &[u8]) -> Result<bool>
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.
Sourcepub fn read(&mut self, id: StreamId, data: &[u8]) -> Result<Vec<Vec<u8>>>
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.
Sourcepub fn close(&mut self, id: StreamId)
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.
Sourcepub fn reset(&mut self, id: StreamId)
pub fn reset(&mut self, id: StreamId)
Aborts the connection: StreamCommand::Reset is issued and the id forgotten. Unknown
ids are ignored.
Sourcepub fn handle_event(&mut self, event: StreamEvent) -> Result<()>
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.
Sourcepub fn poll_command(&mut self) -> Option<StreamCommand>
pub fn poll_command(&mut self) -> Option<StreamCommand>
The next command for the driver.
Sourcepub fn poll_notice(&mut self) -> Option<StreamNotice>
pub fn poll_notice(&mut self) -> Option<StreamNotice>
The next notice for the owner.
Sourcepub fn poll_transmit(&mut self) -> Option<StreamTransmit>
pub fn poll_transmit(&mut self) -> Option<StreamTransmit>
The next bytes to write, connections taking turns. Only established connections transmit, each within its window.
Sourcepub fn info(&self, id: StreamId) -> Option<StreamInfo>
pub fn info(&self, id: StreamId) -> Option<StreamInfo>
A connection’s description, while the table knows it.
Sourcepub fn connections(&self) -> impl Iterator<Item = StreamInfo> + '_
pub fn connections(&self) -> impl Iterator<Item = StreamInfo> + '_
Every connection.
Sourcepub fn find(
&self,
tag: u32,
local: SocketAddr,
remote: SocketAddr,
local_ip_only: bool,
) -> Option<StreamId>
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).
Sourcepub fn has_output(&self) -> bool
pub fn has_output(&self) -> bool
Whether anything is waiting for the driver: a command or a transmit it may take.