Bug 1266667: added user-pref to force ICE TCP. r=bwc,jesup

MozReview-Commit-ID: D0jZcqWkNdV

--HG--
extra : rebase_source : c9c98027df9a3aff752ca56ea7a686c9b66227be
This commit is contained in:
Nils Ohlmeier [:drno] 2016-12-21 23:40:45 -08:00
parent 54ada30c75
commit 2ba616e82f
4 changed files with 27 additions and 3 deletions

View File

@ -334,6 +334,7 @@ PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
, mSTSThread(nullptr)
, mAllowIceLoopback(false)
, mAllowIceLinkLocal(false)
, mForceIceTcp(false)
, mMedia(nullptr)
, mUuidGen(MakeUnique<PCUuidGenerator>())
, mNumAudioStreams(0)
@ -364,6 +365,8 @@ PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
"media.peerconnection.ice.loopback", false);
mAllowIceLinkLocal = Preferences::GetBool(
"media.peerconnection.ice.link_local", false);
mForceIceTcp = Preferences::GetBool(
"media.peerconnection.ice.force_ice_tcp", false);
#endif
memset(mMaxReceiving, 0, sizeof(mMaxReceiving));
memset(mMaxSending, 0, sizeof(mMaxSending));
@ -2235,6 +2238,11 @@ NS_IMETHODIMP
PeerConnectionImpl::AddIceCandidate(const char* aCandidate, const char* aMid, unsigned short aLevel) {
PC_AUTO_ENTER_API_CALL(true);
if (mForceIceTcp && std::string::npos != std::string(aCandidate).find(" UDP ")) {
CSFLogError(logTag, "Blocking remote UDP candidate: %s", aCandidate);
return NS_OK;
}
JSErrorResult rv;
RefPtr<PeerConnectionObserver> pco = do_QueryObjectReferent(mPCObserver);
if (!pco) {
@ -3170,7 +3178,7 @@ PeerConnectionImpl::SetSignalingState_m(PCImplSignalingState aSignalingState,
mNegotiationNeeded = false;
// If we're rolling back a local offer, we might need to remove some
// transports, but nothing further needs to be done.
mMedia->ActivateOrRemoveTransports(*mJsepSession);
mMedia->ActivateOrRemoveTransports(*mJsepSession, mForceIceTcp);
if (!rollback) {
if (NS_FAILED(mMedia->UpdateMediaPipelines(*mJsepSession))) {
CSFLogError(logTag, "Error Updating MediaPipelines");
@ -3339,6 +3347,11 @@ PeerConnectionImpl::CandidateReady(const std::string& candidate,
uint16_t level) {
PC_AUTO_ENTER_API_CALL_VOID_RETURN(false);
if (mForceIceTcp && std::string::npos != candidate.find(" UDP ")) {
CSFLogError(logTag, "Blocking local UDP candidate: %s", candidate.c_str());
return;
}
std::string mid;
bool skipped = false;
nsresult res = mJsepSession->AddLocalIceCandidate(candidate,

View File

@ -813,6 +813,7 @@ private:
bool mAllowIceLoopback;
bool mAllowIceLinkLocal;
bool mForceIceTcp;
RefPtr<PeerConnectionMedia> mMedia;
// The JSEP negotiation session.

View File

@ -468,7 +468,8 @@ PeerConnectionMedia::EnsureTransport_s(size_t aLevel, size_t aComponentCount)
}
void
PeerConnectionMedia::ActivateOrRemoveTransports(const JsepSession& aSession)
PeerConnectionMedia::ActivateOrRemoveTransports(const JsepSession& aSession,
const bool forceIceTcp)
{
auto transports = aSession.GetTransports();
for (size_t i = 0; i < transports.size(); ++i) {
@ -491,6 +492,14 @@ PeerConnectionMedia::ActivateOrRemoveTransports(const JsepSession& aSession)
RemoveTransportFlow(i, true);
}
if (forceIceTcp) {
candidates.erase(std::remove_if(candidates.begin(),
candidates.end(),
[](const std::string & s) {
return s.find(" UDP "); }),
candidates.end());
}
RUN_ON_THREAD(
GetSTSThread(),
WrapRunnable(RefPtr<PeerConnectionMedia>(this),

View File

@ -270,7 +270,8 @@ class PeerConnectionMedia : public sigslot::has_slots<> {
// Activate or remove ICE transports at the conclusion of offer/answer,
// or when rollback occurs.
void ActivateOrRemoveTransports(const JsepSession& aSession);
void ActivateOrRemoveTransports(const JsepSession& aSession,
const bool forceIceTcp);
// Start ICE checks.
void StartIceChecks(const JsepSession& session);