Bug 891551 - Part 10: added user pref to turn of ICE TCP. r=mt

This commit is contained in:
Nils Ohlmeier [:drno] 2015-06-18 23:02:33 -07:00
parent 167d64dec2
commit 06d83d3241
8 changed files with 102 additions and 58 deletions

View File

@ -379,7 +379,8 @@ void NrIceCtx::trickle_cb(void *arg, nr_ice_ctx *ice_ctx,
RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
bool offerer,
bool set_interface_priorities,
bool allow_loopback) {
bool allow_loopback,
bool tcp_enabled) {
RefPtr<NrIceCtx> ctx = new NrIceCtx(name, offerer);
@ -466,6 +467,8 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
NR_reg_set_int4((char *)NR_ICE_REG_ICE_TCP_LISTEN_BACKLOG,
ice_tcp_listen_backlog);
NR_reg_set_char((char *)NR_ICE_REG_ICE_TCP_DISABLE, !tcp_enabled);
if (allow_loopback) {
NR_reg_set_char((char *)NR_STUN_REG_PREF_ALLOW_LOOPBACK_ADDRS, 1);
}

View File

@ -211,7 +211,8 @@ class NrIceCtx {
static RefPtr<NrIceCtx> Create(const std::string& name,
bool offerer,
bool set_interface_priorities = true,
bool allow_loopback = false);
bool allow_loopback = false,
bool tcp_enabled = true);
// Deinitialize all ICE global state. Used only for testing.
static void internal_DeinitializeGlobal();

View File

@ -63,9 +63,11 @@ bool stream_added = false;
static unsigned int kDefaultTimeout = 7000;
const std::string kDefaultStunServerAddress((char *)"107.23.150.92");
//TODO(nils@mozilla.com): This should get replaced with some non-external
//solution like discussed in bug 860775.
const std::string kDefaultStunServerAddress((char *)"52.11.16.249");
const std::string kDefaultStunServerHostname(
(char *)"stun.stunprotocol.org");
(char *)"global.stun.twilio.com");
const std::string kBogusStunServerHostname(
(char *)"stun-server-nonexistent.invalid");
const uint16_t kDefaultStunServerPort=3478;
@ -250,9 +252,10 @@ class IceTestPeer : public sigslot::has_slots<> {
public:
IceTestPeer(const std::string& name, bool offerer, bool set_priorities,
bool allow_loopback = false) :
bool allow_loopback = false, bool enable_tcp = true) :
name_(name),
ice_ctx_(NrIceCtx::Create(name, offerer, set_priorities, allow_loopback)),
ice_ctx_(NrIceCtx::Create(name, offerer, set_priorities, allow_loopback,
enable_tcp)),
streams_(),
candidates_(),
gathering_complete_(false),
@ -1232,7 +1235,7 @@ class IceConnectTest : public ::testing::Test {
}
void AddStream(const std::string& name, int components) {
Init(false, false);
Init(false, false, false);
p1_->AddStream(components);
p2_->AddStream(components);
}
@ -1242,16 +1245,18 @@ class IceConnectTest : public ::testing::Test {
p2_->RemoveStream(index);
}
void Init(bool set_priorities, bool allow_loopback) {
void Init(bool set_priorities, bool allow_loopback, bool enable_tcp) {
if (!initted_) {
p1_ = new IceTestPeer("P1", true, set_priorities, allow_loopback);
p2_ = new IceTestPeer("P2", false, set_priorities, allow_loopback);
p1_ = new IceTestPeer("P1", true, set_priorities, allow_loopback,
enable_tcp);
p2_ = new IceTestPeer("P2", false, set_priorities, allow_loopback,
enable_tcp);
}
initted_ = true;
}
bool Gather(unsigned int waitTime = kDefaultTimeout) {
Init(false, false);
Init(false, false, false);
if (use_nat_) {
// If we enable nat simulation, but still use a real STUN server somewhere
// on the internet, we will see failures if there is a real NAT in
@ -1744,6 +1749,15 @@ TEST_F(IceGatherTest, TestGatherAllowLoopback) {
ASSERT_TRUE(StreamHasMatchingCandidate(0, "127.0.0.1"));
}
TEST_F(IceGatherTest, TestGatherTcpDisabled) {
// Set up peer with tcp disabled.
peer_ = new IceTestPeer("P1", true, false, false, false);
peer_->AddStream(1);
Gather();
ASSERT_FALSE(StreamHasMatchingCandidate(0, " TCP "));
ASSERT_TRUE(StreamHasMatchingCandidate(0, " UDP "));
}
// Verify that a bogus candidate doesn't cause crashes on the
// main thread. See bug 856433.
TEST_F(IceGatherTest, TestBogusCandidate) {
@ -1820,8 +1834,14 @@ TEST_F(IceConnectTest, TestGather) {
ASSERT_TRUE(Gather());
}
TEST_F(IceConnectTest, TestGatherTcp) {
Init(false, false, true);
AddStream("first", 1);
ASSERT_TRUE(Gather());
}
TEST_F(IceConnectTest, TestGatherAutoPrioritize) {
Init(false, false);
Init(false, false, false);
AddStream("first", 1);
ASSERT_TRUE(Gather());
}
@ -1834,6 +1854,7 @@ TEST_F(IceConnectTest, TestConnect) {
}
TEST_F(IceConnectTest, TestConnectTcp) {
Init(false, false, true);
AddStream("first", 1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpCandidate);
@ -1845,6 +1866,7 @@ TEST_F(IceConnectTest, TestConnectTcp) {
//TCP SO tests works on localhost only with delay applied:
// tc qdisc add dev lo root netem delay 10ms
TEST_F(IceConnectTest, DISABLED_TestConnectTcpSo) {
Init(false, false, true);
AddStream("first", 1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpSoCandidate);
@ -1854,7 +1876,7 @@ TEST_F(IceConnectTest, DISABLED_TestConnectTcpSo) {
}
TEST_F(IceConnectTest, TestLoopbackOnlySortOf) {
Init(false, true);
Init(false, true, false);
AddStream("first", 1);
SetCandidateFilter(IsLoopbackCandidate);
ASSERT_TRUE(Gather());
@ -1938,7 +1960,7 @@ TEST_F(IceConnectTest, TestGatherFullCone) {
}
TEST_F(IceConnectTest, TestGatherFullConeAutoPrioritize) {
Init(false, true);
Init(false, true, false);
AddStream("first", 1);
UseNat();
SetFilteringType(TestNat::ENDPOINT_INDEPENDENT);
@ -2120,7 +2142,7 @@ TEST_F(IceConnectTest, TestConnectP2ThenP1TrickleTwoComponents) {
}
TEST_F(IceConnectTest, TestConnectAutoPrioritize) {
Init(false, false);
Init(false, false, false);
AddStream("first", 1);
ASSERT_TRUE(Gather());
Connect();
@ -2303,6 +2325,7 @@ TEST_F(IceConnectTest, TestSendReceive) {
}
TEST_F(IceConnectTest, TestSendReceiveTcp) {
Init(false, false, true);
AddStream("first", 1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpCandidate);
@ -2315,6 +2338,7 @@ TEST_F(IceConnectTest, TestSendReceiveTcp) {
//TCP SO tests works on localhost only with delay applied:
// tc qdisc add dev lo root netem delay 10ms
TEST_F(IceConnectTest, DISABLED_TestSendReceiveTcpSo) {
Init(false, false, true);
AddStream("first", 1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpSoCandidate);

View File

@ -504,7 +504,7 @@ int main(int argc, char **argv)
std::string dummy("dummy");
RUN_ON_THREAD(test_utils->sts_target(),
WrapRunnableNM(&NrIceCtx::Create,
dummy, false, false, false),
dummy, false, false, false, false),
NS_DISPATCH_SYNC);
// Start the tests

View File

@ -386,6 +386,7 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
int r,_status;
int so_sock_ct=0;
int backlog=10;
char ice_tcp_disabled=1;
r_log(LOG_ICE,LOG_DEBUG,"nr_ice_component_initialize_tcp");
@ -399,6 +400,11 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
ABORT(r);
}
if ((r=NR_reg_get_char(NR_ICE_REG_ICE_TCP_DISABLE, &ice_tcp_disabled))) {
if (r != R_NOT_FOUND)
ABORT(r);
}
for(i=0;i<addr_ct;i++){
char suppress;
nr_ice_socket *isock_psv=0;
@ -413,44 +419,46 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
continue;
}
/* passive host candidate */
if ((r=nr_ice_component_create_tcp_host_candidate(ctx, component, &addrs[i].addr,
TCP_TYPE_PASSIVE, backlog, 0, lufrag, pwd, &isock_psv)))
ABORT(r);
/* active host candidate */
if ((r=nr_ice_component_create_tcp_host_candidate(ctx, component, &addrs[i].addr,
TCP_TYPE_ACTIVE, 0, 0, lufrag, pwd, NULL)))
ABORT(r);
/* simultaneous-open host candidate */
if (so_sock_ct) {
if (!ice_tcp_disabled) {
/* passive host candidate */
if ((r=nr_ice_component_create_tcp_host_candidate(ctx, component, &addrs[i].addr,
TCP_TYPE_SO, 0, so_sock_ct, lufrag, pwd, &isock_so)))
TCP_TYPE_PASSIVE, backlog, 0, lufrag, pwd, &isock_psv)))
ABORT(r);
}
/* And srvrflx candidates for each STUN server */
for(j=0;j<ctx->stun_server_ct;j++){
if (ctx->stun_servers[j].transport!=IPPROTO_TCP)
continue;
if(r=nr_ice_candidate_create(ctx,component,
isock_psv,isock_psv->sock,SERVER_REFLEXIVE,TCP_TYPE_PASSIVE,
&ctx->stun_servers[j],component->component_id,&cand))
/* active host candidate */
if ((r=nr_ice_component_create_tcp_host_candidate(ctx, component, &addrs[i].addr,
TCP_TYPE_ACTIVE, 0, 0, lufrag, pwd, NULL)))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
/* simultaneous-open host candidate */
if (so_sock_ct) {
if ((r=nr_ice_component_create_tcp_host_candidate(ctx, component, &addrs[i].addr,
TCP_TYPE_SO, 0, so_sock_ct, lufrag, pwd, &isock_so)))
ABORT(r);
}
/* And srvrflx candidates for each STUN server */
for(j=0;j<ctx->stun_server_ct;j++){
if (ctx->stun_servers[j].transport!=IPPROTO_TCP)
continue;
if(r=nr_ice_candidate_create(ctx,component,
isock_so,isock_so->sock,SERVER_REFLEXIVE,TCP_TYPE_SO,
isock_psv,isock_psv->sock,SERVER_REFLEXIVE,TCP_TYPE_PASSIVE,
&ctx->stun_servers[j],component->component_id,&cand))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
if (so_sock_ct) {
if(r=nr_ice_candidate_create(ctx,component,
isock_so,isock_so->sock,SERVER_REFLEXIVE,TCP_TYPE_SO,
&ctx->stun_servers[j],component->component_id,&cand))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
}
}
}
@ -467,23 +475,25 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
if (ctx->turn_servers[j].turn_server.transport != IPPROTO_TCP)
continue;
/* Use TURN server to get srflx candidates */
if(r=nr_ice_candidate_create(ctx,component,
isock_psv,isock_psv->sock,SERVER_REFLEXIVE,TCP_TYPE_PASSIVE,
&ctx->turn_servers[j].turn_server,component->component_id,&cand))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
if (so_sock_ct) {
if (!ice_tcp_disabled) {
/* Use TURN server to get srflx candidates */
if(r=nr_ice_candidate_create(ctx,component,
isock_so,isock_so->sock,SERVER_REFLEXIVE,TCP_TYPE_SO,
isock_psv,isock_psv->sock,SERVER_REFLEXIVE,TCP_TYPE_PASSIVE,
&ctx->turn_servers[j].turn_server,component->component_id,&cand))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
if (so_sock_ct) {
if(r=nr_ice_candidate_create(ctx,component,
isock_so,isock_so->sock,SERVER_REFLEXIVE,TCP_TYPE_SO,
&ctx->turn_servers[j].turn_server,component->component_id,&cand))
ABORT(r);
TAILQ_INSERT_TAIL(&component->candidates,cand,entry_comp);
component->candidate_ct++;
cand=0;
}
}
/* Create relay candidate */
@ -584,10 +594,7 @@ int nr_ice_component_initialize(struct nr_ice_ctx_ *ctx,nr_ice_component *compon
ABORT(r);
/* And the TCP candidates */
if (r=nr_ice_component_initialize_tcp(ctx, component, addrs, addr_ct, lufrag, &pwd))
/* TODO: This will fail when NrSocketIpc is used, therefore we ignore this result.
Remove this error ignore once there will be pref to turn off TCP */
if (r != R_REJECTED)
ABORT(r);
ABORT(r);
/* count the candidates that will be initialized */
cand=TAILQ_FIRST(&component->candidates);

View File

@ -63,6 +63,7 @@ extern "C" {
#define NR_ICE_REG_TURN_SRV_USERNAME "username"
#define NR_ICE_REG_TURN_SRV_PASSWORD "password"
#define NR_ICE_REG_ICE_TCP_DISABLE "ice.tcp.disable"
#define NR_ICE_REG_ICE_TCP_SO_SOCK_COUNT "ice.tcp.so_sock_count"
#define NR_ICE_REG_ICE_TCP_LISTEN_BACKLOG "ice.tcp.listen_backlog"

View File

@ -300,12 +300,19 @@ nsresult PeerConnectionMedia::Init(const std::vector<NrIceStunServer>& stun_serv
}
#endif // defined(MOZILLA_XPCOMRT_API)
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
bool ice_tcp = Preferences::GetBool("media.peerconnection.ice.tcp", false);
#else
bool ice_tcp = false;
#endif
// TODO(ekr@rtfm.com): need some way to set not offerer later
// Looks like a bug in the NrIceCtx API.
mIceCtx = NrIceCtx::Create("PC:" + mParentName,
true, // Offerer
true, // Explicitly set priorities
mAllowIceLoopback);
mAllowIceLoopback,
ice_tcp);
if(!mIceCtx) {
CSFLogError(logTag, "%s: Failed to create Ice Context", __FUNCTION__);
return NS_ERROR_FAILURE;

View File

@ -372,6 +372,7 @@ pref("media.peerconnection.video.max_bitrate", 2000);
pref("media.navigator.permission.disabled", false);
pref("media.peerconnection.default_iceservers", "[]");
pref("media.peerconnection.ice.loopback", false); // Set only for testing in offline environments.
pref("media.peerconnection.ice.tcp", false);
pref("media.peerconnection.use_document_iceservers", true);
pref("media.peerconnection.identity.enabled", true);
pref("media.peerconnection.identity.timeout", 10000);