webrtcwebrtc-ice-exchange

WebRTC ICE Exchange is handled by SDP Signalling Server not STUN/TURN Server?


Which Server handles the ICE Exchange (exchanging the nodes over potential routes between peers), SDP Signalling Server or STUN Server (or TURN which can also function as STUN)?

MDN WebRTC connectivity shows SDP Signalling Server handles the ICE Exchange.

enter image description here

However, WebRTC.org Getting started with peer connections says STUN or TURN Server handles the ICE exchange.

Since the network conditions can vary depending on a number of factors, an external service is usually used for discovering the possible candidates for connecting to a peer. This service is called ICE and is using either a STUN or a TURN server.

RFC8445 - Interactive Connectivity Establishment (ICE) also indicates it is STUN or TURN to do ICE exchange.

2.1. Gathering Candidates

In order to execute ICE, an ICE agent identifies and gathers one or more address candidates. A candidate has a transport address -- a combination of IP address and port for a particular transport protocol (with only UDP specified here). There are different types of candidates; some are derived from physical or logical network interfaces, and others are discoverable via STUN and TURN.

The first category of candidates are those with a transport address obtained directly from a local interface. Such a candidate is called a "host candidate". The local interface could be Ethernet or Wi-Fi, or it could be one that is obtained through a tunnel mechanism, such as a Virtual Private Network (VPN) or Mobile IP (MIP). In all cases, such a network interface appears to the agent as a local interface from which ports (and thus candidates) can be allocated.

Next, the agent uses STUN or TURN to obtain additional candidates.


Solution

  • There's a difference between obtaining ICE candidates and exchanging ICE candidates. The STUN/TURN servers are used to obtain candidates. A candidate is a potential network path that both peers can use to talk to each other. Each peer discovers what potential paths they're seeing. Then they exchange those candidates and agree on the best one they both share.

    The STUN server is just a helper assisting in poking holes into firewalls and discovering IPs/ports.
    The TURN server is a relay, a potential path in itself.
    The signalling server is the one used to actually exchange those discovered candidates between the two peers.

    Once the exchange has happened and they've agreed on a candidate pair, the communication over one of those IP/port pairs starts to happen.