spreed/docs/TURN.md

12 KiB
Исходник Ответственный История

Background

The configuration of Nextcloud Talk mainly depends on your desired usage:

  • As long as it shall be used only within one local network, besides the app, nothing else should be required. Just verify that all browsers support the underlying WebRTC protocol - most contemporary browsers do with current versions, though mobile browsers tend to lag behind a little - and you should be good to go. Browser support can be tested for example here: https://test.webrtc.org/

  • Talk tries to establish a direct peer-to-peer (P2P) connection, thus on connections beyond the local network (behind a NAT or router), clients do not only need to know each others public IP, but the participants local IPs as well. Processing this, is the job of a STUN server. As there is one preconfigured for Nextcloud Talk that is operated by Nextcloud GmbH, for this case nothing else needs to be done.

  • But in many cases, especially in combination with firewalls or symmetric NAT, a direct P2P connection is not possible, even with the help of a STUN server. For this a so called TURN server needs to be configured additionally.

  • Nextcloud Talk will try direct P2P in the first place, use STUN if needed and TURN as last resort fallback. Thus to be most flexible and guarantee functionality of your Nextcloud Talk instance in all possible connection cases, you would want to setup a TURN server.

Install and setup coTURN as TURN server

It is recommended to install the latest coTURN version; at the very minimum coTURN 4.5.0.8 should be used. In previous versions there is a bug that causes the IPv6 UDP sockets created by coTURN not to be freed. Due to this the turn process ends not being able to open new ports and thus not being able to serve new connections. Moreover, when that happens, even if there are no connections a high CPU load will be caused by the turn process. Therefore, if you can not install coTURN 4.5.0.8 or a later version you should restart the turn process periodically to work around that issue.

1. Download and install

2. Make coturn run as daemon on startup

  • On Debian and Ubuntu you just need to enable the deployed sysvinit service by adjusting the related environment variable:

    sudo sed -i '/TURNSERVER_ENABLED/c\TURNSERVER_ENABLED=1' /etc/default/coturn
    
  • Since Debian Buster and Ubuntu disco the package ships a systemd unit, which does not use /etc/default/coturn but is enabled automatically on install. To check whether a systemd unit is available:

    ls -l /lib/systemd/system/coturn.service
    
  • If you installed coTURN manually, you may want to create an sysvinit service or systemd unit, or use another method to run the following during boot:

    /path/to/turnserver -c /path/to/turnserver.conf -o
    
  • -o starts the server in daemon mode, -c defines the path to the config file.

  • There is also an official example available at https://github.com/coturn/coturn/blob/master/examples/etc/coturn.service

3. Configure turnserver.conf for usage with Nextcloud Talk

  • Next you need to adjust the coTURN configuration file to work with Nextcloud Talk.

  • Choose the listening port (default is 3478) and an authentication secret, where a random hex is recommended

    openssl rand -hex 32
    
  • Then uncomment/edit the following settings accordingly:

listening-port=<yourChosenPortNumber>
fingerprint
lt-cred-mech # Only on coTURN below v4.5.0.8!
use-auth-secret
static-auth-secret=<yourChosen/GeneratedSecret>
realm=your.domain.org
total-quota=0
bps-capacity=0
stale-nonce
no-loopback-peers # Only on coTURN below v4.5.1.0!
no-multicast-peers

!!! note

(D)TLS is currently not supported by Nextcloud Talk and does not have any real security benefit anyway. See the following discussions why (D)TLS for TURN has no real security benefit and why Nextcloud Talk is not supporting it:

- [https://github.com/coturn/coturn/issues/33](https://github.com/coturn/coturn/issues/33)
- [https://github.com/nextcloud/spreed/issues/257](https://github.com/nextcloud/spreed/issues/257)
  • The total-quota parameter limits the number of allowed simultaneous connections to the TURN server. Along with max-bps and bps-capacity it can be used to limit the effects of a DoS attack against the TURN server. The value of 0 shown above means unlimited; if a connection limit is desired it should be adjusted depending on your specific setup.

    Please note that the number of allowed simultaneous connections limited by total-quota are not only fully established connections, but also the connections being tested during the negotiation phase used to establish the actual connection. During the negotiation phase each peer generates several candidates (an IP address and port) that can be used to establish a connection with that peer. Then the peers try to establish a connection between them with different candidate combinations until a valid one is found. If there is a TURN server then the client will connect to the TURN server too and it will generate additional candidates with the IP address of the TURN server (the so called "relay" candidates). Each of those relay candidates will try to connect to the candidates of the other peer, and each of those connection attempts allocates a slot in the available quota of the TURN server. If there are no more available slots "Allocation Quota Reached" message is written to coTURN logs.

    In most cases the candidates that will be generated, and thus the connections to the TURN server during the negotiation phase, can not be known beforehand. When Janus is used the number of candidate combinations is reduced, as the Janus candidates can be known, but the number of relay candidates that will be generated by the client may still be unknown. For example, it seems that browsers generate one relay candidate for each host candidate. Host candidates are those with the IP address known to the client, so typically there will be one for each network device in the system; in the case of Firefox host candidates are also generated for the IP addresses of local bridge network devices.

    You should take all that into account if you intend to set a specific value to the total-quota parameter, but for maximum availability an unlimited quota is recommended.

  • If your TURN server is running not behind a NAT, but with direct www connection and static public IP, than you can limit the IPs it listens at and answers with, by setting those as listening-ip and relay-ip. On larger deployments it is recommended to run your TURN server on a dedicated machine that is directly accessible from the internet.

  • The following settings can be used to adjust the logging behaviour. On SBCs with SDcards you may want to adjust this, as by default coTURN logs very verbose. The config file explains everything very well:

no-stdout-log
log-file=...
syslog
simple-log
  • sudo systemctl restart coturn or corresponding restart method

4. Configure Nextcloud Talk to use your TURN server

  • Go to Nextcloud admin panel > Talk settings. Btw. if you already have your own TURN server, you can and may want to use it as STUN server as well:

    • STUN servers: your.domain.org:
    • TURN server: your.domain.org:
    • TURN secret: <yourChosen/GeneratedSecret>
    • Protocol: UDP and TCP
  • Do not add http(s):// or turn(s):// protocol prefix here, just enter the bare domain:port. Nextcloud Talk adds the required turn:// protocol internally to the request.

5. Port opening/forwarding

  • The TURN server on <yourChosenPortNumber> needs to be accessible for all Talk participants, so you need to open it to the web and if your TURN server is running behind a NAT, forward it to the related machine. Also make sure to set the --external-ip option when your TURN server is in a private network.

6. Testing the TURN server

When the TURN server is set in the Talk settings a basic test against the TURN server is performed. You can perform a deeper test by forcing your browser to send the media of a call only through the TURN server:

  • Join a call
  • Open your browser console
  • Type OCA.Talk.SimpleWebRTC.webrtc.config.peerConnectionConfig.iceTransportPolicy = 'relay' in the console and press Enter
  • Leave the call
  • Join the call again

Now, in that browser, the media sent to and received from other participants in the call should go through the TURN server. If the call works then the TURN server should work.

Differences between Firefox and Chromium

Firefox and Chromium handle iceTransportPolicy = 'relay' in slightly different ways. When relay candidates are forced Firefox will use only relay candidates, but Chromium will also take into account peer reflexive candidates that refer to the TURN server. Due to this in the above test, in some specific cases, a connection could be established in Chromium but not in Firefox.

For example, if a Janus gateway is used too, the TURN server is in the same server as the Janus gateway and both are behind a firewall (not recommended), relay candidates could have the public IP address of the server while peer reflexive candidates could have the internal one. If the firewall drops connections between the public IP address and the public IP address the connection between coTURN and Janus may not be established (but without failing either), which would cause that Firefox establishes a connection with the TURN server, but the TURN server does not send or receive any packet to or from Janus. In Chromium, on the other hand, the connection would work as it would use the internal IP address of the server from the peer reflexive candidate.

However, in the scenario above Firefox would not be able to establish a connection only if relay candidates are forced. With a standard Firefox configuration it would take into account peer reflexive candidates too and thus it should work without issues. Nevertheless, note that although using iceTransportPolicy = 'relay' in the browser console is just a temporary setting there is a persistent setting in Firefox configuration (about:config) to force relay candidates, media.peerconnection.ice.relay_only. This setting is targeted towards privacy-minded people, so you may want to test the TURN server with Firefox to ensure that it works even with the most restrictive configurations.

What else

Nextcloud Talk´s WebRTC handling is still mostly based on the one from the Spreed.ME WebRTC solution. For this reason, all guides about how to configure coTURN for it, applies to Nextcloud Talk too.

If you need to use Talk with more than 5-10 users in the same call, you will need the Spreed High Performance Back-end from Nextcloud GmbH. Check the website for details.

Further reference