Issue #1991 - backport Mozilla bug 1266667

This commit is contained in:
Basilisk-Dev 2022-08-20 22:08:28 -04:00 committed by roytam1
commit b4c5ebf00a
13 changed files with 85 additions and 7 deletions

View file

@ -335,6 +335,7 @@ PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
, mSTSThread(nullptr)
, mAllowIceLoopback(false)
, mAllowIceLinkLocal(false)
, mForceIceTcp(false)
, mMedia(nullptr)
, mUuidGen(MakeUnique<PCUuidGenerator>())
, mNumAudioStreams(0)
@ -365,6 +366,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));
@ -2260,6 +2263,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) {
@ -3111,7 +3119,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) {
mMedia->UpdateMediaPipelines(*mJsepSession);
InitializeDataChannel();
@ -3273,6 +3281,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

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

View file

@ -457,7 +457,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) {
@ -480,6 +481,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);