pub struct SrtListener { /* private fields */ }tokio only.Expand description
An SRT listener that accepts incoming Caller connections.
§One socket, many connections (issue #1029)
Every connection this listener accepts shares its single bound socket —
unlike SrtSocket::connect, which binds a fresh, unshared socket per
connection. recv_from on a shared socket delivers each datagram to
whichever waiting caller happens to be polled next, not whichever
caller the datagram is actually addressed to: if both this listener’s own
accept loop and one or more accepted connections’ driver tasks each
called recv_from on the same socket, a datagram belonging to one
connection could be handed to a completely different one (which would
then just discard it as foreign), silently losing it for its rightful
recipient. So exactly one task ever calls recv_from on udp: the
routing pump spawned once in SrtListener::bind. It demultiplexes the
way libsrt does (item 2, draft §4.3.1): a Destination Socket ID of 0
(every handshake packet this crate’s Caller ever sends, per the
dest_socket_id fix in caller.rs) always means “not yet an established
connection” and goes to unrouted_rx (accept’s own input); any other ID
must match an entry in routes and that entry’s accepted source
address, or the datagram is dropped — a stray packet naming an ID that was
never accepted (or accepted from a different address) has nowhere
legitimate to go.
A repeated CONCLUSION from an already-accepted Caller (its copy of our
response was lost) carries Destination Socket ID 0 too, so it reaches
the listener’s background task, which answers it again — no one has to be
polling accept for that.
§Lifetime (defect 3)
Handshakes advance in a tracked background task, not inside
accept; the routing pump is a second tracked task. Both end
on a CancellationToken, fired when the last of {this handle, every
accepted SrtSocket} is dropped — so an idle listener releases its UDP
port the moment the handle is dropped, while connections it already
accepted keep being routed until they too are gone.
Implementations§
Source§impl SrtListener
impl SrtListener
Sourcepub async fn bind<A: ToSocketAddrs>(
addr: A,
config: HandshakeConfig,
) -> Result<Self>
pub async fn bind<A: ToSocketAddrs>( addr: A, config: HandshakeConfig, ) -> Result<Self>
Bind an SRT listener on addr.
§Encryption
A listener configured without a passphrase rejects any peer that asks
for encryption (a Key Material extension or a non-zero Encryption Field). A listener configured with one negotiates keys and encrypts /
decrypts the data path.
Sourcepub async fn bind_with<A: ToSocketAddrs>(
addr: A,
config: HandshakeConfig,
io: IoConfig,
) -> Result<Self>
pub async fn bind_with<A: ToSocketAddrs>( addr: A, config: HandshakeConfig, io: IoConfig, ) -> Result<Self>
Like Self::bind, with explicit timeouts and datagram size.
Sourcepub fn unrouted_dropped(&self) -> u64
pub fn unrouted_dropped(&self) -> u64
Datagrams dropped because the candidate-new-connection queue was full
(item 4) — a handshake flood outrunning the listener’s handshake task —
or because they exceeded IoConfig::max_datagram.
Sourcepub fn accept_overflow_dropped(&self) -> u64
pub fn accept_overflow_dropped(&self) -> u64
Connections that completed their handshake but were dropped because
accept was not keeping up (the pending-accept queue
holds 64); each dropped peer is sent a SHUTDOWN.
Sourcepub fn send_errors(&self) -> u64
pub fn send_errors(&self) -> u64
Send failures the background task met while answering peers (for
example an unreachable spoofed source). They are counted here and never
surface from accept, so a flood of them cannot displace
finished connections or end an accept loop.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
The local socket address the listener is bound to.
Sourcepub async fn accept(&mut self) -> Result<SrtSocket>
pub async fn accept(&mut self) -> Result<SrtSocket>
Accept the next incoming SRT connection.
Handshakes progress in the background whether or not this is being
polled; this only waits for a finished one. Send errors met while
answering peers are counted (send_errors), not
returned.