Expand description
A whole peer connection driven over sockets the driver owns (feature peer, on by
default): its UDP sockets for the ICE host candidates, and the TCP sockets of the engine’s
stream interface through a StreamDriver.
PeerDriver gathers for the application and keeps the gathering right across what makes
a transport lose its candidates. The engine has no sockets, so it tells the application
with RTCPeerConnectionEvent::OnLocalCandidatesNeeded when a transport needs a new set of
local candidates: a new DTLS association over UDP runs on a new 3-tuple (RFC 8842 section
5.1), so after an ICE restart for a new association (automatic SRTP re-keying included) or
on the transport that replaced one an answer closed, the transport’s previous UDP addresses
are refused. The driver reacts by itself: it binds new UDP ports (inside
PeerDriverConfig::udp_port_range, skipping ports the host refuses), adds their host
candidates for the event’s section, ends the generation, and closes the previous sockets
only once a candidate pair on a new one is selected for that transport (and then after
PeerDriverConfig::retired_socket_linger, for what the peer still sends there before its
own selection switches), or the transport is closed: until then the previous path keeps
carrying the transport’s packets. The engine’s
ICE-TCP listener is kept (RFC 8842 asks a new 3-tuple of unordered transports only), and
its server-reflexive and TURN gathering follow the new host candidates by themselves.
With SettingEngineBuilder::with_dtls_new_association_on_previous_addresses(true) the
engine keeps the candidates and fires no event: the driver keeps its sockets and gives their
candidates to each new ICE generation again.
§mDNS
A connection with mDNS on (SettingEngineBuilder::with_multicast_dns_mode) publishes its
host addresses behind .local names and resolves the peer’s: its ICE agents write their
mDNS datagrams from local port 5353. At the first one the driver binds the host’s mDNS
sockets, port 5353 joined to 224.0.0.251 and, where the host has IPv6, to ff02::fb (shared
with other mDNS responders of the host through address reuse), on the interface of every
address of PeerDriverConfig::addresses; it sends the connection’s queries, probes and
answers there and hands what arrives back to the connection. A connection without mDNS
writes none, and the driver binds nothing.
RFC 6762 section 14: a host on several links takes part in mDNS on each, and an answer
carries only addresses valid on the interface it leaves by. The engine names, for each
message, the address it is about (its record’s); the driver sends it by that address’s
interface (Transmit::source: IP_MULTICAST_IF / IPV6_MULTICAST_IF), an IPv6 record’s
on the IPv6 group (and on the IPv4 group of the same interface where the driver has an IPv4
address there), and a query once on each interface.
On Windows, a process that joins the IPv4 mDNS group on the loopback interface (a driver
given 127.0.0.1) and sends to the group there leaves a stale route for the group behind
it: the system’s destination cache holds 224.0.0.251 with source 127.0.0.1 on the
“Loopback Pseudo-Interface” after the process has exited (netsh interface ipv4 show destinationcache address=224.0.0.251), and from then on any process that asks which
address reaches the group (a UDP socket connected to it) gets 127.0.0.1. Measured on
Windows 11 and on GitHub’s Windows image; the joins table entry for the group on the
loopback interface that the join also leaves (show joins, references 0) is not what moves
the answer. A later join, send and leave on the network interface does not clear the
entry; deleting it does, at once: netsh interface ipv4 delete destinationcache interface=<the loopback interface's index> address=224.0.0.251, from an administrator
prompt (measured on Windows 11 and on GitHub’s Windows image). The same may hold for IPv6’s
ff02::fb; that was not measured. So on Windows the driver, by default, takes no part in
IPv4 mDNS on loopback: it does not join 224.0.0.251 on the loopback interface and sends
nothing to the group from a loopback address (the messages about a loopback address’s name
are dropped, counted in PeerDriver::unsent_datagrams); a driver whose only IPv4
addresses are loopback binds no IPv4 mDNS socket and tells the connection that its IPv4
names cannot be published (PeerDriver::mdns_available is false). Loopback candidates
are for local use only (RFC 8445 section 5.1.1.1: “Addresses from a loopback interface MUST
NOT be included in the candidate addresses”), and RFC 6762 asks no mDNS on loopback.
PeerDriverConfig::mdns_on_loopback_on_windows turns it back on, as on other systems;
the driver then logs a warning when it makes such a join, and an application or test host
that does so cleans the entry as above when it is done. The driver changes no host routing
state itself.
Where mDNS cannot be sent (a socket that cannot be bound, or a system that refuses every
send to the group: no multicast route, or a Mac application without the Local Network
permission) the driver tells the application with
PeerDriverEvent::MdnsUnavailable (PeerDriver::poll_driver_event), with the system’s
error, counts it (PeerDriver::mdns_send_failures, PeerDriver::mdns_bind_failures),
and tells the connection that the family’s names cannot be published. It tries again at the
next gathering and, while mDNS datagrams wait, after a back-off; the first send that works
is reported as PeerDriverEvent::MdnsAvailable. The connection itself goes on over its
other candidates, or fails as ICE does.
With QueryAndGather the driver binds the mDNS sockets before it adds the first host
candidates and tells the connection for which address families it has one
(RTCPeerConnection::set_multicast_dns_publishing): a host address of a family without one
cannot have its name published (draft-ietf-mmusic-mdns-ice-candidates section 3.1.1 step
4), and its candidates go out under a .local name that is not published, or not at all
when the connection fails closed (SettingEngineBuilder::with_multicast_dns_fail_closed).
PeerDriverConfig::mdns_sockets false binds none.
Every mDNS datagram takes one message from a budget shared by every driver of the process
(process_mdns_rate_limit, unless PeerDriverConfig::mdns_rate_limit names another):
draft-ietf-mmusic-mdns-ice-candidates section 7.1 requires “an implementation-wide rate
limit” over the mDNS queries and responses of all connections. A datagram the budget refuses
waits in the driver and leaves, in order, when the budget has room.
§The loop
let mut driver = PeerDriver::new(pc, PeerDriverConfig::on(vec![ip]));
// offer / answer through the application's signalling, on driver.pc_mut();
// after the first local description, the driver gathers by itself;
loop {
driver.step(Duration::from_millis(20)).await?;
while let Some(event) = driver.poll_event() {
// signal OnIceCandidateEvent candidates to the peer (the end-of-candidates one
// too: without it the peer's transport is "disconnected", never "failed", when
// the path is lost), answer negotiation-needed, ...
}
while let Some(read) = driver.pc_mut().poll_read() { /* media, data channels */ }
}Structs§
- Mdns
Failure - Why the driver’s mDNS of one address family stopped: what
PeerDriverEvent::MdnsUnavailabletells the application. - Peer
Driver - Drives an
RTCPeerConnectionover sockets of its own (see the module documentation). - Peer
Driver Config - What a
PeerDriverbinds.
Enums§
- Mdns
Stage - What failed in a
MdnsFailure. - Peer
Driver Event - Something the driver itself reports to the application (
PeerDriver::poll_driver_event), beside the connection’s own events.
Constants§
- MDNS_
MULTICAST_ IPV6 - The mDNS IPv6 link-local group (RFC 6762 section 3).
Functions§
- process_
mdns_ rate_ limit - The message budget every
PeerDriverof this process takes its mDNS from, unless its configuration names another (PeerDriverConfig::mdns_rate_limit): 40 messages at once, then 10 a second (MdnsRateLimit::default). One budget for the process is draft-ietf-mmusic-mdns-ice-candidates section 7.1’s “implementation-wide rate limit”. The returned value is a handle: every clone takes from the same budget. - set_
process_ mdns_ rate_ limit - Sets the process’s mDNS budget (
process_mdns_rate_limit) instead of the default, once, before its first use (the first driver that sends mDNS uses it).