mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 14:54:25 +00:00
Issue #1991 - backport Mozilla bug 1266667
This commit is contained in:
@@ -44,7 +44,8 @@ parent:
|
||||
// address specified in |localAddr| and |localPort|.
|
||||
async OpenBind(nsCString host, uint16_t port,
|
||||
nsCString localAddr, uint16_t localPort,
|
||||
bool useSSL, bool aUseArrayBuffers, nsCString aFilter);
|
||||
bool useSSL, bool reuseAddrPort,
|
||||
bool aUseArrayBuffers, nsCString aFilter);
|
||||
|
||||
// When child's send() is called, this message requrests parent to send
|
||||
// data and update it's trackingNumber.
|
||||
|
||||
@@ -108,7 +108,7 @@ void
|
||||
TCPSocketChild::SendWindowlessOpenBind(nsITCPSocketCallback* aSocket,
|
||||
const nsACString& aRemoteHost, uint16_t aRemotePort,
|
||||
const nsACString& aLocalHost, uint16_t aLocalPort,
|
||||
bool aUseSSL)
|
||||
bool aUseSSL, bool aReuseAddrPort)
|
||||
{
|
||||
mSocket = aSocket;
|
||||
AddIPDLReference();
|
||||
@@ -117,7 +117,8 @@ TCPSocketChild::SendWindowlessOpenBind(nsITCPSocketCallback* aSocket,
|
||||
aRemotePort);
|
||||
PTCPSocketChild::SendOpenBind(nsCString(aRemoteHost), aRemotePort,
|
||||
nsCString(aLocalHost), aLocalPort,
|
||||
aUseSSL, true, mFilterName);
|
||||
aUseSSL, aReuseAddrPort,
|
||||
true, mFilterName);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
void SendWindowlessOpenBind(nsITCPSocketCallback* aSocket,
|
||||
const nsACString& aRemoteHost, uint16_t aRemotePort,
|
||||
const nsACString& aLocalHost, uint16_t aLocalPort,
|
||||
bool aUseSSL);
|
||||
bool aUseSSL, bool aUseRealtimeOptions);
|
||||
NS_IMETHOD SendSendArray(nsTArray<uint8_t>& aArray,
|
||||
uint32_t aTrackingNumber);
|
||||
void SendSend(const nsACString& aData, uint32_t aTrackingNumber);
|
||||
|
||||
@@ -149,6 +149,7 @@ TCPSocketParent::RecvOpenBind(const nsCString& aRemoteHost,
|
||||
const nsCString& aLocalAddr,
|
||||
const uint16_t& aLocalPort,
|
||||
const bool& aUseSSL,
|
||||
const bool& aReuseAddrPort,
|
||||
const bool& aUseArrayBuffers,
|
||||
const nsCString& aFilter)
|
||||
{
|
||||
@@ -184,6 +185,10 @@ TCPSocketParent::RecvOpenBind(const nsCString& aRemoteHost,
|
||||
return true;
|
||||
}
|
||||
|
||||
// in most cases aReuseAddrPort is false, but ICE TCP needs
|
||||
// sockets options set that allow addr/port reuse
|
||||
socketTransport->SetReuseAddrPort(aReuseAddrPort);
|
||||
|
||||
PRNetAddr prAddr;
|
||||
if (PR_SUCCESS != PR_InitializeNetAddr(PR_IpAddrAny, aLocalPort, &prAddr)) {
|
||||
FireInteralError(this, __LINE__);
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
const nsCString& aLocalAddr,
|
||||
const uint16_t& aLocalPort,
|
||||
const bool& aUseSSL,
|
||||
const bool& aReuseAddrPort,
|
||||
const bool& aUseArrayBuffers,
|
||||
const nsCString& aFilter) override;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -803,6 +803,7 @@ private:
|
||||
|
||||
bool mAllowIceLoopback;
|
||||
bool mAllowIceLinkLocal;
|
||||
bool mForceIceTcp;
|
||||
RefPtr<PeerConnectionMedia> mMedia;
|
||||
|
||||
// The JSEP negotiation session.
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -129,6 +129,11 @@ interface nsISocketTransport : nsITransport
|
||||
unsigned long getTimeout(in unsigned long aType);
|
||||
void setTimeout(in unsigned long aType, in unsigned long aValue);
|
||||
|
||||
/**
|
||||
* True to set addr and port reuse socket options.
|
||||
*/
|
||||
void setReuseAddrPort(in bool reuseAddrPort);
|
||||
|
||||
/**
|
||||
* Values for the aType parameter passed to get/setTimeout.
|
||||
*/
|
||||
|
||||
@@ -738,6 +738,7 @@ nsSocketTransport::nsSocketTransport()
|
||||
, mProxyTransparentResolvesHost(false)
|
||||
, mHttpsProxy(false)
|
||||
, mConnectionFlags(0)
|
||||
, mReuseAddrPort(false)
|
||||
, mState(STATE_CLOSED)
|
||||
, mAttached(false)
|
||||
, mInputClosed(true)
|
||||
@@ -1355,6 +1356,32 @@ nsSocketTransport::InitiateSocket()
|
||||
status = PR_SetSocketOption(fd, &opt);
|
||||
NS_ASSERTION(status == PR_SUCCESS, "unable to make socket non-blocking");
|
||||
|
||||
if (mReuseAddrPort) {
|
||||
SOCKET_LOG((" Setting port/addr reuse socket options\n"));
|
||||
|
||||
// Set ReuseAddr for TCP sockets to enable having several
|
||||
// sockets bound to same local IP and port
|
||||
PRSocketOptionData opt_reuseaddr;
|
||||
opt_reuseaddr.option = PR_SockOpt_Reuseaddr;
|
||||
opt_reuseaddr.value.reuse_addr = PR_TRUE;
|
||||
status = PR_SetSocketOption(fd, &opt_reuseaddr);
|
||||
if (status != PR_SUCCESS) {
|
||||
SOCKET_LOG((" Couldn't set reuse addr socket option: %d\n",
|
||||
status));
|
||||
}
|
||||
|
||||
// And also set ReusePort for platforms supporting this socket option
|
||||
PRSocketOptionData opt_reuseport;
|
||||
opt_reuseport.option = PR_SockOpt_Reuseport;
|
||||
opt_reuseport.value.reuse_port = PR_TRUE;
|
||||
status = PR_SetSocketOption(fd, &opt_reuseport);
|
||||
if (status != PR_SUCCESS
|
||||
&& PR_GetError() != PR_OPERATION_NOT_SUPPORTED_ERROR) {
|
||||
SOCKET_LOG((" Couldn't set reuse port socket option: %d\n",
|
||||
status));
|
||||
}
|
||||
}
|
||||
|
||||
// disable the nagle algorithm - if we rely on it to coalesce writes into
|
||||
// full packets the final packet of a multi segment POST/PUT or pipeline
|
||||
// sequence is delayed a full rtt
|
||||
@@ -2484,6 +2511,13 @@ nsSocketTransport::SetTimeout(uint32_t type, uint32_t value)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSocketTransport::SetReuseAddrPort(bool reuseAddrPort)
|
||||
{
|
||||
mReuseAddrPort = reuseAddrPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSocketTransport::SetQoSBits(uint8_t aQoSBits)
|
||||
{
|
||||
|
||||
@@ -295,6 +295,7 @@ private:
|
||||
bool mProxyTransparentResolvesHost;
|
||||
bool mHttpsProxy;
|
||||
uint32_t mConnectionFlags;
|
||||
bool mReuseAddrPort;
|
||||
|
||||
// The origin attributes are used to create sockets. The first party domain
|
||||
// will eventually be used to isolate OCSP cache and is only non-empty when
|
||||
|
||||
@@ -1685,6 +1685,12 @@ SocketTransportShim::SetTimeout(uint32_t aType, uint32_t aValue)
|
||||
return mWrapped->SetTimeout(aType, aValue);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SocketTransportShim::SetReuseAddrPort(bool aReuseAddrPort)
|
||||
{
|
||||
return mWrapped->SetReuseAddrPort(aReuseAddrPort);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SocketTransportShim::GetQoSBits(uint8_t *aQoSBits)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user