Bug 1297416 - Part 3: Add proxy-only mode and pref. r=drno

MozReview-Commit-ID: D1e9f3OkVsU

--HG--
extra : rebase_source : 65784601918246f47d51888f64d90a7a0c580bc9
This commit is contained in:
Byron Campen [:bwc] 2016-08-23 15:15:33 -05:00
Родитель 02cf82bf1a
Коммит 7eafad9670
9 изменённых файлов: 50 добавлений и 9 удалений

Просмотреть файл

@ -835,7 +835,7 @@ abort:
return NS_OK;
}
nsresult NrIceCtx::StartGathering(bool default_route_only) {
nsresult NrIceCtx::StartGathering(bool default_route_only, bool proxy_only) {
ASSERT_ON_THREAD(sts_target_);
if (policy_ == ICE_POLICY_NONE) {
return NS_OK;
@ -848,6 +848,12 @@ nsresult NrIceCtx::StartGathering(bool default_route_only) {
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_ONLY_DEFAULT_ADDRS);
}
if (proxy_only) {
nr_ice_ctx_add_flags(ctx_, NR_ICE_CTX_FLAGS_ONLY_PROXY);
} else {
nr_ice_ctx_remove_flags(ctx_, NR_ICE_CTX_FLAGS_ONLY_PROXY);
}
// This might start gathering for the first time, or again after
// renegotiation, or might do nothing at all if gathering has already
// finished.

Просмотреть файл

@ -307,7 +307,7 @@ class NrIceCtx {
nsresult SetProxyServer(const NrIceProxyServer& proxy_server);
// Start ICE gathering
nsresult StartGathering(bool default_route_only);
nsresult StartGathering(bool default_route_only, bool proxy_only);
// Start checking
nsresult StartChecks();

Просмотреть файл

@ -540,7 +540,8 @@ class IceTestPeer : public sigslot::has_slots<> {
WrapRunnableRet(&res,
ice_ctx_->ctx(),
&NrIceCtx::StartGathering,
default_route_only),
default_route_only,
false),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));

Просмотреть файл

@ -643,6 +643,7 @@ class TransportTestPeer : public sigslot::has_slots<> {
WrapRunnableRet(&res,
ice_ctx_->ctx(),
&NrIceCtx::StartGathering,
false,
false),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));

Просмотреть файл

@ -207,6 +207,11 @@ static int nr_ice_component_initialize_udp(struct nr_ice_ctx_ *ctx,nr_ice_compon
int j;
int r,_status;
if(ctx->flags & NR_ICE_CTX_FLAGS_ONLY_PROXY) {
/* No UDP support if we must use a proxy */
return 0;
}
/* Now one ice_socket for each address */
for(i=0;i<addr_ct;i++){
char suppress;
@ -429,8 +434,9 @@ static int nr_ice_component_initialize_tcp(struct nr_ice_ctx_ *ctx,nr_ice_compon
if (r != R_NOT_FOUND)
ABORT(r);
}
if (ctx->flags & NR_ICE_CTX_FLAGS_RELAY_ONLY) {
r_log(LOG_ICE,LOG_WARNING,"ICE(%s): relay only option results in ICE TCP being disabled",ctx->label);
if ((ctx->flags & NR_ICE_CTX_FLAGS_RELAY_ONLY) ||
(ctx->flags & NR_ICE_CTX_FLAGS_ONLY_PROXY)) {
r_log(LOG_ICE,LOG_WARNING,"ICE(%s): relay/proxy only option results in ICE TCP being disabled",ctx->label);
ice_tcp_disabled = 1;
}
@ -1089,6 +1095,12 @@ int nr_ice_component_pair_candidates(nr_ice_peer_ctx *pctx, nr_ice_component *lc
/* Create the candidate pairs */
lcand=TAILQ_FIRST(&lcomp->candidates);
if (!lcand) {
/* No local candidates, initialized or not! */
ABORT(R_FAILED);
}
while(lcand){
if (lcand->state == NR_ICE_CAND_STATE_INITIALIZED) {
if ((r = nr_ice_component_pair_candidate(pctx, pcomp, lcand, 0)))

Просмотреть файл

@ -165,6 +165,7 @@ int nr_ice_ctx_create_with_credentials(char *label, UINT4 flags, char* ufrag, ch
#define NR_ICE_CTX_FLAGS_RELAY_ONLY (1<<4)
#define NR_ICE_CTX_FLAGS_HIDE_HOST_CANDIDATES (1<<5)
#define NR_ICE_CTX_FLAGS_ONLY_DEFAULT_ADDRS (1<<6)
#define NR_ICE_CTX_FLAGS_ONLY_PROXY (1<<7)
void nr_ice_ctx_add_flags(nr_ice_ctx *ctx, UINT4 flags);
void nr_ice_ctx_remove_flags(nr_ice_ctx *ctx, UINT4 flags);

Просмотреть файл

@ -790,6 +790,18 @@ PeerConnectionMedia::GetPrefDefaultAddressOnly() const
return default_address_only;
}
bool
PeerConnectionMedia::GetPrefProxyOnly() const
{
ASSERT_ON_THREAD(mMainThread); // will crash on STS thread
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
return Preferences::GetBool("media.peerconnection.ice.proxy_only", false);
#else
return false;
#endif
}
void
PeerConnectionMedia::ConnectSignals(NrIceCtx *aCtx, NrIceCtx *aOldCtx)
{
@ -887,21 +899,27 @@ PeerConnectionMedia::GatherIfReady() {
nsCOMPtr<nsIRunnable> runnable(WrapRunnable(
RefPtr<PeerConnectionMedia>(this),
&PeerConnectionMedia::EnsureIceGathering_s,
GetPrefDefaultAddressOnly()));
GetPrefDefaultAddressOnly(),
GetPrefProxyOnly()));
PerformOrEnqueueIceCtxOperation(runnable);
}
void
PeerConnectionMedia::EnsureIceGathering_s(bool aDefaultRouteOnly) {
PeerConnectionMedia::EnsureIceGathering_s(bool aDefaultRouteOnly,
bool aProxyOnly) {
if (mProxyServer) {
mIceCtxHdlr->ctx()->SetProxyServer(*mProxyServer);
} else if (aProxyOnly) {
IceGatheringStateChange_s(mIceCtxHdlr->ctx().get(),
NrIceCtx::ICE_CTX_GATHER_COMPLETE);
return;
}
// Start gathering, but only if there are streams
for (size_t i = 0; i < mIceCtxHdlr->ctx()->GetStreamCount(); ++i) {
if (mIceCtxHdlr->ctx()->GetStream(i)) {
mIceCtxHdlr->ctx()->StartGathering(aDefaultRouteOnly);
mIceCtxHdlr->ctx()->StartGathering(aDefaultRouteOnly, aProxyOnly);
return;
}
}

Просмотреть файл

@ -474,7 +474,7 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
void GatherIfReady();
void FlushIceCtxOperationQueueIfReady();
void PerformOrEnqueueIceCtxOperation(nsIRunnable* runnable);
void EnsureIceGathering_s(bool aDefaultRouteOnly);
void EnsureIceGathering_s(bool aDefaultRouteOnly, bool aProxyOnly);
void StartIceChecks_s(bool aIsControlling,
bool aIsIceLite,
const std::vector<std::string>& aIceOptionsList);
@ -483,6 +483,7 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
void FinalizeIceRestart_s();
void RollbackIceRestart_s();
bool GetPrefDefaultAddressOnly() const;
bool GetPrefProxyOnly() const;
void ConnectSignals(NrIceCtx *aCtx, NrIceCtx *aOldCtx=nullptr);

Просмотреть файл

@ -473,6 +473,7 @@ pref("media.peerconnection.ice.stun_client_maximum_transmits", 7);
pref("media.peerconnection.ice.trickle_grace_period", 5000);
pref("media.peerconnection.ice.no_host", false);
pref("media.peerconnection.ice.default_address_only", false);
pref("media.peerconnection.ice.proxy_only", false);
// These values (aec, agc, and noice) are from media/webrtc/trunk/webrtc/common_types.h
// kXxxUnchanged = 0, kXxxDefault = 1, and higher values are specific to each