Bug 864118 - add verification that TURN server is used when provided. r=bwc

This commit is contained in:
Nils Ohlmeier [:drno] 2014-11-11 15:37:00 +01:00
parent 27b1be7dc4
commit 1993359d0d
3 changed files with 75 additions and 0 deletions

View File

@ -2582,6 +2582,48 @@ PeerConnectionWrapper.prototype = {
}
},
/**
* Compares the Ice server configured for this PeerConnectionWrapper
* with the ICE candidates received in the RTCP stats.
*
* @param {object} stats
* The stats to be verified for relayed vs. direct connection.
*/
checkStatsIceConnectionType : function PCW_checkStatsIceConnectionType(stats)
{
var lId;
var rId;
Object.keys(stats).forEach(function(name) {
if ((stats[name].type === "candidatepair") &&
(stats[name].selected)) {
lId = stats[name].localCandidateId;
rId = stats[name].remoteCandidateId;
}
});
info("checkStatsIceConnectionType verifying: local=" +
JSON.stringify(stats[lId]) + " remote=" + JSON.stringify(stats[rId]));
if ((typeof stats[lId] === 'undefined') ||
(typeof stats[rId] === 'undefined')) {
info("checkStatsIceConnectionType failed to find candidatepair IDs");
return;
}
var lType = stats[lId].candidateType;
var rType = stats[rId].candidateType;
var lIp = stats[lId].ipAddress;
var rIp = stats[rId].ipAddress;
if ((this.configuration) && (typeof this.configuration.iceServers !== 'undefined')) {
info("Ice Server configured");
// Note: the IP comparising is a workaround for bug 1097333
// And this will fail if a TURN server address is a DNS name!
var serverIp = this.configuration.iceServers[0].url.split(':')[1];
ok((lType === "relayed" || rType === "relayed") ||
(lIp === serverIp || rIp === serverIp), "One peer uses a relay");
} else {
info("P2P configured");
ok(((lType !== "relayed") && (rType !== "relayed")), "Pure peer to peer call without a relay");
}
},
/**
* Property-matching function for finding a certain stat in passed-in stats
*

View File

@ -24,6 +24,17 @@ function dumpSdp(test) {
dump("ERROR: SDP answer: " + test._remote_answer.sdp.replace(/[\r]/g, ''));
}
if ((test.pcLocal) && (typeof test.pcLocal._local_ice_candidates !== 'undefined')) {
dump("pcLocal._local_ice_candidates: " + JSON.stringify(test.pcLocal._local_ice_candidates) + "\n");
dump("pcLocal._remote_ice_candidates: " + JSON.stringify(test.pcLocal._remote_ice_candidates) + "\n");
dump("pcLocal._ice_candidates_to_add: " + JSON.stringify(test.pcLocal._ice_candidates_to_add) + "\n");
}
if ((test.pcRemote) && (typeof test.pcRemote._local_ice_candidates !== 'undefined')) {
dump("pcRemote._local_ice_candidates: " + JSON.stringify(test.pcRemote._local_ice_candidates) + "\n");
dump("pcRemote._remote_ice_candidates: " + JSON.stringify(test.pcRemote._remote_ice_candidates) + "\n");
dump("pcRemote._ice_candidates_to_add: " + JSON.stringify(test.pcRemote._ice_candidates_to_add) + "\n");
}
if ((test.pcLocal) && (typeof test.pcLocal.iceConnectionLog !== 'undefined')) {
dump("pcLocal ICE connection state log: " + test.pcLocal.iceConnectionLog + "\n");
}
@ -492,6 +503,24 @@ var commandsPeerConnection = [
});
}
],
[
'PC_LOCAL_CHECK_ICE_CONNECTION_TYPE',
function (test) {
test.pcLocal.getStats(null, function(stats) {
test.pcLocal.checkStatsIceConnectionType(stats);
test.next();
});
}
],
[
'PC_REMOTE_CHECK_ICE_CONNECTION_TYPE',
function (test) {
test.pcRemote.getStats(null, function(stats) {
test.pcRemote.checkStatsIceConnectionType(stats);
test.next();
});
}
],
[
'PC_LOCAL_CHECK_GETSTATS_AUDIOTRACK_OUTBOUND',
function (test) {

View File

@ -3,6 +3,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* An example of how to specify two TURN server configs:
*
* Note: If turn URL uses FQDN rather then an IP address the TURN relay
* verification step in checkStatsIceConnectionType might fail.
*
* var turnServers = {
* local: { iceServers: [{"username":"mozilla","credential":"mozilla","url":"turn:10.0.0.1"}] },
* remote: { iceServers: [{"username":"firefox","credential":"firefox","url":"turn:10.0.0.2"}] }