librice is a Rust library implementing RFC 8445 (Interactive Connectivity
Establishment (ICE): A Protocol for Network Address Translator (NAT) Traversal)
that answers the question of how to efficiently discover the optimal connection
between two peers. Most importantly, ICE is used by WebRTC and other media-based
protocols (e.g. SIP) in order to set up the communication channel between two
(or more) peers.
librice and the sans-IO counterpart rice-proto have gained a number of
new features over the past year or so which includes, but is not limited to:
1. TURN support in all widely used variants. This includes
RFC 5766 - Traversal Using Relays around NAT (TURN)
RFC 5766 builds on top of the STUN RFC 5389 in order to support a server forwarding data on behalf of client. It supports the TURN server allocating a UDP socket for the client and the client can connect to the server over UDP, TCP, and TLS over TCP.
RFC 6062 - Traversal Using Relays around NAT (TURN) Extensions for TCP Allocations
Builds on top of RFC 5766 by adding functionality to support the TURN server providing a TCP allocation. The TURN client can connect over TCP or TLS over TCP when using a TCP allocation.
RFC 6156 - Traversal Using Relays around NAT (TURN) Extension for IPv6
Build on top of RFC 5766 (and optionally RFC 6062) allowing the TURN server to create an allocation with an IPv6 address.
RFC 8656 - Traversal Using Relays around NAT (TURN): Relay Extensions to Session Traversal Utilities for NAT (STUN)
Supersedes the 3 previous TURN RFCs and includes some extra functionality:
- DTLS over UDP between the client and server for UDP allocations
- Builds upon the STUN [RFC 8489] which adds support for SHA-256 integrity for increased security of STUN messages and anonymous usernames (SHA-256 hashed).
- Dual IPv4/IPv6 allocation support from a single control channel instead of requiring two separate client control channels.
Reusable crate
All of the above functionality specified in the above RFCs has been implemented
in the Rust crate turn-client-proto. TLS backends for turn-client-proto
are available from crates such as turn-client-rustls, turn-client-openssl, and
turn-client-dimpl.
Thanks
Thanks to The NLnet Foundation for funding the work on TURN.
2. Improved zerocopy support for sent and received data where possible.
As of this change for UDP and
this change for TCP zerocopy of
data sent and received over the ICE connection does not perform and copies of
the media data within rice-proto. Sending TCP still currently requires a copy
to add the necessary ICE-TCP frame headers.
Thanks
Thanks to Pexip for funding the work on improved zerocopy support.
3. ICE-restart
Usually, once ICE completes and a connection is established, there is no easy way to update the currently configured connection. ICE-restart allows rerunning the connectivity checks with an optionally updated set of local and remove candidates. This can be used when e.g. the set of network interfaces or addresses associated with those network interfaces changes. This is the RFC and standard way of changing the selected pair and there is a proposal for ICE renomination but that is still in draft stage.
Thanks
Thanks to Pexip for funding the work on ICE-Restart.
4. ICE-lite support.
If the ICE agent is in an environment where the host candidate is publicly accessible, the full ICE process is not needed in order to find a viable connection with a peer. This can use the ICE-lite variant of ICE however there are some requirements before this is viable:
- Only single host candidate for IPv4 or a single host candidate per interface for IPv6.
- Connectivity checks are never initiated from any ICE-lite agent.
librice supports ICE-lite in this manner with a ICE-full peer. rice-proto
can also support running multiple ICE-lite agents on the same socket in the same
process through the addition of 'ignorable errors'. The idea is that each
ICE-lite agent that is running on the same port attempts to handling an incoming
STUN message or data message and can either handle it or produce an ignorable
error. If no agents handle the incoming data, the 'ignorable error' can
optionally be sent to the originating peer.
Thanks
Thanks to The NLnet Foundation for funding the work for ICE-lite.
5. Consent Freshness - RFC 7675
Once ICE has discovered a connection, there is no active keep alive mechanism with the peer. As the connection may be sent over UDP, there is no guarantee that the an agent is able to detect when a peer disappears through e.g. ICMP messages. The existing keep alive mechanism with BINDING indications are designed to keep allocations across NATs alive and no response to an indication is allowed.
Instead, a request/response BINDING transaction is used for a liveness check in order to ensure that the peer is actively able to receive the data we send. This is also backwards compatible with agents that do not support consent freshness as all ICE agents must response to BINDING requests with the appropriate response at all times.
rice-proto supports consent freshness as outlined in RFC 7675.
Thanks
Thanks to The NLnet Foundation for funding the work for consent freshness.
6. Increased configuration options
A smaller selection of configuration that is supported by rice-proto includes.
Increased configuration options for STUN transaction retransmissions count and timeouts. i.e. reducing the number of retransmissions or delays between resends before a transaction is considered failed.
Async runtime support in librice now supports smol, tokio, and custom
runtime implementations through an implementable Runtime trait.
Community use of librice
The initial user of librice has been GStreamer through the newly introduced
webrtcbin2 plugin containing the webrtcsend and webrtcrecv elements.
You can read more about webrtcbin2 in a previous
post.
Another user was Webkit's WebRTC backend using GStreamer where the sans-IO design allows marshalling the actual IO over networks sockets to be performed in a separate process from the ICE state machine providing the required sandboxing of different resources that many modern web browsers implement.
rice-proto has also been
integrated into a FreeSWITCH fork
for communication with peers that commmunicate using WebRTC.
Funding
Thanks to The NLnet Foundation for funding some of the work on librice through the NGI0 Commons
Fund, a fund established by NLnet with financial support from the European Commission's
Next Generation Internet programme.
The NLnet Foundation supported the following functionality:
- TURN support
- ICE-lite
- Consent Freshness RFC 7675
Also, thanks to Pexip for supporting work on ICE-Restart and improving the performance sending and receiving data.
Try it out
All of these improvements are in the main branch of
librice and will be included in the
upcoming 0.5.0 release.
If you have any network environment using WebRTC/SIP that is not currently
supported by rice-proto, or would like to support ongoing maintenence and development,
please get in touch.