Bug 1322659: log warnings and error for too many STUN/TURN servers. r=bwc
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Thu, 08 Dec 2016 22:38:17 -1000
changeset 325568 de0d1099b71e76c44b0dfeb205f017e56b4a0ad7
parent 325567 35209805acb4e4fc08876c829f78c233f5c5d7b8
child 325569 a82b89786b41666d5339a44c70bb7ca8d7d69fbc
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersbwc
bugs1322659
milestone53.0a1
Bug 1322659: log warnings and error for too many STUN/TURN servers. r=bwc MozReview-Commit-ID: DrMqSjyfn6
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -589,16 +589,18 @@ RTCPeerConnection.prototype = {
       try {
         return ios.newURI(uriStr, null, null);
       } catch (e if (e.result == Cr.NS_ERROR_MALFORMED_URI)) {
         throw new this._win.DOMException(msg + " - malformed URI: " + uriStr,
                                          "SyntaxError");
       }
     };
 
+    var stunServers = 0;
+
     rtcConfig.iceServers.forEach(server => {
       if (!server.urls) {
         throw new this._win.DOMException(msg + " - missing urls", "InvalidAccessError");
       }
       server.urls.forEach(urlStr => {
         let url = nicerNewURI(urlStr);
         if (url.scheme in { turn:1, turns:1 }) {
           if (server.username == undefined) {
@@ -611,27 +613,34 @@ RTCPeerConnection.prototype = {
           }
           if (server.credentialType != "password") {
             this.logWarning("RTCConfiguration TURN credentialType \""+
                             server.credentialType +
                             "\" is not yet implemented. Treating as password."+
                             " https://bugzil.la/1247616");
           }
           this._hasTurnServer = true;
+          stunServers += 1;
         }
         else if (url.scheme in { stun:1, stuns:1 }) {
           this._hasStunServer = true;
+          stunServers += 1;
         }
         else if (!(url.scheme in { stun:1, stuns:1 })) {
           throw new this._win.DOMException(msg + " - improper scheme: " + url.scheme,
                                            "SyntaxError");
         }
         if (url.scheme in { stuns:1, turns:1 }) {
           this.logWarning(url.scheme.toUpperCase() + " is not yet supported.");
         }
+        if (stunServers >= 5) {
+          this.logError("Using five or more STUN/TURN servers causes problems");
+        } else if (stunServers > 2) {
+          this.logWarning("Using more than two STUN/TURN servers slows down discovery");
+        }
       });
     });
   },
 
   // Ideally, this should be of the form _checkState(state),
   // where the state is taken from an enumeration containing
   // the valid peer connection states defined in the WebRTC
   // spec. See Bug 831756.