Bug 1322659: log warnings and error for too many STUN/TURN servers. r=bwc draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Thu, 08 Dec 2016 22:38:17 -1000
changeset 448336 5cad28416d6b4fa5635c39b214de949d81d09f8e
parent 447838 650d0350adfef971496a443c3c1610922714d665
child 539273 cbbc20e3a595680a7a5b6b9d5239406eb2b83778
push id38325
push userdrno@ohlmeier.org
push dateFri, 09 Dec 2016 23:12:17 +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.