4

When passing multiple TURN options to RTCPeerConnection, and assuming that several of them are technically usable, how is the actual server selected?

Does network performance play a role at all?

1 Answer 1

3
+50

ICE RFC doesn't specify what happens when multiple TURN servers are available:

This specification only considers usage of a single STUN or TURN server. When there are multiple choices for that single STUN or TURN server (when, for example, they are learned through DNS records and multiple results are returned), an agent SHOULD use a single STUN or TURN server (based on its IP address) for all candidates for a particular session. This improves the performance of ICE. The result is a set of pairs of host candidates with STUN or TURN servers. The agent then chooses one pair, and sends a Binding or Allocate request to the server from that host candidate.

So any particular behavior shouldn't be expected.

Currently WebRTC chooses first server which matches the given criteria. E.g. first server which supports UDP for UDP connection.

basicportallocator.cc:

void AllocationSequence::CreateUDPPorts() {
...
  // If STUN is not disabled, setting stun server address to port.
  if (!IsFlagSet(PORTALLOCATOR_DISABLE_STUN)) {
    // If config has stun_address, use it to get server reflexive candidate
    // otherwise use first TURN server which supports UDP.
    if (config_ && !config_->stun_address.IsNil()) {
      LOG(LS_INFO) << "AllocationSequence: UDPPort will be handling the "
                   <<  "STUN candidate generation.";
      port->set_server_addr(config_->stun_address);
    } else if (config_ &&
               config_->SupportsProtocol(RELAY_TURN, PROTO_UDP)) {
      port->set_server_addr(config_->GetFirstRelayServerAddress(
          RELAY_TURN, PROTO_UDP));
      LOG(LS_INFO) << "AllocationSequence: TURN Server address will be "
                   << " used for generating STUN candidate.";
    }
  }
...
3
  • I did award the bounty, because it expires in four hours and your answer is the only one. :-) Though I'm not entirely sure if it is correct. We currently run two TURN servers for an application (US and EU hosted). Since the code for adding the turn servers is always the same, only one TURN server should be used. However, both see a similar amount of usage. (The app is Chrome only) ... There is definitely a selection process. The question is how it works.
    – Mantriur
    Jun 29, 2014 at 18:05
  • Thank you for the bounty. I looked at WebRTC code because according to RFC, behavior with multiple TURN servers is undefined. Based on WebRTC code it seems that first matching server should be picked up, however there can be something else going on which I missed. To get a better answer you could try to send this question to the WebRTC dev mailing list. By the way are both of your TURN servers using the same transport protocol?
    – grekasius
    Jun 29, 2014 at 19:42
  • I think the issue is that this function is just for collecting STUN responses, which TURN servers can also do. It just uses the next best turn server when no stun server is available. The relaying decision is more complex apparently: stackoverflow.com/questions/26342589/… ;-)
    – Mantriur
    Feb 18, 2015 at 20:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .