#632: M1362498 M1397686 M136178 M1320252 M1355875

This commit is contained in:
Cameron Kaiser 2020-11-21 15:57:20 -08:00
parent d87db7e160
commit 82cb3b59e5
13 changed files with 117 additions and 50 deletions

View File

@ -1415,7 +1415,7 @@ pref("network.http.spdy.enabled.http2", true);
pref("network.http.spdy.enabled.deps", true);
pref("network.http.spdy.enforce-tls-profile", true);
pref("network.http.spdy.chunk-size", 16000);
pref("network.http.spdy.timeout", 180);
pref("network.http.spdy.timeout", 170);
pref("network.http.spdy.coalesce-hostnames", true);
pref("network.http.spdy.persistent-settings", false);
pref("network.http.spdy.ping-threshold", 58);

View File

@ -18,7 +18,7 @@ struct PRFileDesc;
[ptr] native PRFileDescPtr(PRFileDesc);
[ptr] native nsASocketHandlerPtr(nsASocketHandler);
[scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
[builtinclass, scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
interface nsISocketTransportService : nsISupports
{
/**
@ -119,7 +119,7 @@ interface nsISocketTransportService : nsISupports
[noscript] void notifyWhenCanAttachSocket(in nsIRunnable aEvent);
};
[scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
[builtinclass, scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
interface nsIRoutedSocketTransportService : nsISocketTransportService
{
// use this instead of createTransport when you have a transport

View File

@ -15,7 +15,7 @@ interface nsIOutputStream;
* into a fully asynchronous stream that can be read/written without
* blocking the main thread.
*/
[scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
[builtinclass, scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
interface nsIStreamTransportService : nsISupports
{
/**

View File

@ -10,7 +10,7 @@
* This is a private interface used by the internals of the networking library.
* It will never be frozen. Do not use it in external code.
*/
[scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
[builtinclass, scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
interface nsPISocketTransportService : nsIRoutedSocketTransportService
{

View File

@ -1290,6 +1290,16 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags
nsCOMPtr<nsIProxyInfo> pi;
bool usePACThread;
// adapt to realtime changes in the system proxy service
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
nsCOMPtr<nsISystemProxySettings> sp2 =
do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
if (sp2 != mSystemProxySettings) {
mSystemProxySettings = sp2;
ResetPACThread();
}
}
// SystemProxySettings and PAC files can block the main thread
// but if neither of them are in use, we can just do the work
// right here and directly invoke the callback

View File

@ -2369,6 +2369,9 @@ Http2Session::ReadSegmentsAgain(nsAHttpSegmentReader *reader,
this, stream, stream->StreamID()));
FlushOutputQueue();
SetWriteCallbacks();
if (!mCannotDo0RTTStreams.Contains(stream)) {
mCannotDo0RTTStreams.AppendElement(stream);
}
// We can still send our preamble
*countRead = mOutputQueueUsed - mOutputQueueSent;
return *countRead ? NS_OK : NS_BASE_STREAM_WOULD_BLOCK;
@ -2396,10 +2399,10 @@ Http2Session::ReadSegmentsAgain(nsAHttpSegmentReader *reader,
*countRead += earlyDataUsed;
}
if (mAttemptingEarlyData && !m0RTTStreams.Contains(stream->StreamID())) {
if (mAttemptingEarlyData && !m0RTTStreams.Contains(stream)) {
LOG3(("Http2Session::ReadSegmentsAgain adding stream %d to m0RTTStreams\n",
stream->StreamID()));
m0RTTStreams.AppendElement(stream->StreamID());
m0RTTStreams.AppendElement(stream);
}
// Not every permutation of stream->ReadSegents produces data (and therefore
@ -2966,9 +2969,8 @@ Http2Session::Finish0RTT(bool aRestart, bool aAlpnChanged)
// the transaction rewind and read it all over again. We only need to rewind
// the transaction if we're switching to a new protocol, because our buffer
// won't get used in that case.
Http2Stream *stream = mStreamIDHash.Get(m0RTTStreams[i]);
if (stream) {
stream->Finish0RTT(aAlpnChanged, aAlpnChanged);
if (m0RTTStreams[i]) {
m0RTTStreams[i]->Finish0RTT(aRestart, aAlpnChanged);
}
}
@ -2990,15 +2992,27 @@ Http2Session::Finish0RTT(bool aRestart, bool aAlpnChanged)
// This is the easy case - early data failed, but we're speaking h2, so
// we just need to rewind to the beginning of the preamble and try again.
mOutputQueueSent = 0;
for (size_t i = 0; i < mCannotDo0RTTStreams.Length(); ++i) {
if (mCannotDo0RTTStreams[i] && VerifyStream(mCannotDo0RTTStreams[i])) {
TransactionHasDataToWrite(mCannotDo0RTTStreams[i]);
}
}
}
} else {
// 0RTT succeeded
for (size_t i = 0; i < mCannotDo0RTTStreams.Length(); ++i) {
if (mCannotDo0RTTStreams[i] && VerifyStream(mCannotDo0RTTStreams[i])) {
TransactionHasDataToWrite(mCannotDo0RTTStreams[i]);
}
}
// Make sure we look for any incoming data in repsonse to our early data.
ResumeRecv();
}
mAttemptingEarlyData = false;
m0RTTStreams.Clear();
mCannotDo0RTTStreams.Clear();
RealignOutputQueue();
return NS_OK;

View File

@ -510,7 +510,10 @@ private:
bool mAttemptingEarlyData;
// The ID(s) of the stream(s) that we are getting 0RTT data from.
nsTArray<uint32_t> m0RTTStreams;
nsTArray<WeakPtr<Http2Stream>> m0RTTStreams;
// The ID(s) of the stream(s) that are not able to send 0RTT data. We need to
// remember them put them into mReadyForWrite queue when 0RTT finishes.
nsTArray<WeakPtr<Http2Stream>> mCannotDo0RTTStreams;
private:
/// connect tunnels

View File

@ -114,8 +114,6 @@ static uint64_t gNumIntercepted = 0;
(result) == NS_ERROR_OUT_OF_MEMORY)
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
static NS_DEFINE_CID(kStreamTransportServiceCID,
NS_STREAMTRANSPORTSERVICE_CID);
enum CacheDisposition {
kCacheHit = 1,
@ -2998,9 +2996,10 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
}
}
nsCOMPtr<nsICacheStorageService> cacheStorageService =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
if (!cacheStorageService) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsICacheStorage> cacheStorage;
nsCOMPtr<nsIURI> openURI;
@ -4058,8 +4057,8 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi
nsCOMPtr<nsITransport> transport;
nsCOMPtr<nsIInputStream> wrapper;
nsCOMPtr<nsIStreamTransportService> sts =
do_GetService(kStreamTransportServiceCID, &rv);
nsCOMPtr<nsIStreamTransportService> sts(services::GetStreamTransportService());
rv = sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
if (NS_SUCCEEDED(rv)) {
rv = sts->CreateInputTransport(stream, int64_t(-1), int64_t(-1),
true, getter_AddRefs(transport));
@ -4579,9 +4578,10 @@ nsHttpChannel::InstallCacheListener(int64_t offset)
nsCOMPtr<nsIEventTarget> cacheIOTarget;
if (!CacheObserver::UseNewCache()) {
nsCOMPtr<nsICacheStorageService> serv =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheStorageService> serv(services::GetCacheStorageService());
if (!serv) {
return NS_ERROR_NOT_AVAILABLE;
}
serv->GetIoTarget(getter_AddRefs(cacheIOTarget));
}
@ -5288,7 +5288,7 @@ nsHttpChannel::BeginConnect()
// Check to see if this principal exists on local blocklists.
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier();
if (mLoadFlags & LOAD_CLASSIFY_URI) {
nsCOMPtr<nsIURIClassifier> classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID);
nsCOMPtr<nsIURIClassifier> classifier(services::GetURIClassifier());
bool tpEnabled = false;
channelClassifier->ShouldEnableTrackingProtection(this, &tpEnabled);
if (classifier && tpEnabled) {
@ -7004,8 +7004,8 @@ nsHttpChannel::DoInvalidateCacheEntry(nsIURI* aURI)
LOG(("DoInvalidateCacheEntry [channel=%p key=%s]", this, key.get()));
nsCOMPtr<nsICacheStorageService> cacheStorageService =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
rv = cacheStorageService ? NS_OK : NS_ERROR_FAILURE;
nsCOMPtr<nsICacheStorage> cacheStorage;
if (NS_SUCCEEDED(rv)) {

View File

@ -23,6 +23,7 @@
#include "mozilla/net/DNS.h"
#include "nsISocketTransport.h"
#include "nsISSLSocketControl.h"
#include "mozilla/Services.h"
#include "mozilla/Telemetry.h"
#include "mozilla/net/DashboardTypes.h"
#include "NullHttpTransaction.h"
@ -101,11 +102,13 @@ nsHttpConnectionMgr::~nsHttpConnectionMgr()
nsresult
nsHttpConnectionMgr::EnsureSocketThreadTarget()
{
nsresult rv;
nsCOMPtr<nsIEventTarget> sts;
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
if (NS_SUCCEEDED(rv))
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIIOService> ioService = services::GetIOService();
if (ioService) {
nsCOMPtr<nsISocketTransportService> realSTS =
services::GetSocketTransportService();
sts = do_QueryInterface(realSTS);
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -115,7 +118,7 @@ nsHttpConnectionMgr::EnsureSocketThreadTarget()
mSocketThreadTarget = sts;
return rv;
return sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}
nsresult
@ -853,7 +856,7 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry)
"with %s connections. rv=%x isJoined=%d",
preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(),
rv, isJoined));
Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, false);
//Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, false);
return nullptr;
}
@ -863,7 +866,7 @@ nsHttpConnectionMgr::GetSpdyPreferredEnt(nsConnectionEntry *aOriginalEntry)
"so %s will be coalesced with %s",
preferred->mConnInfo->Origin(), aOriginalEntry->mConnInfo->Origin(),
aOriginalEntry->mConnInfo->Origin(), preferred->mConnInfo->Origin()));
Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, true);
//Telemetry::Accumulate(Telemetry::SPDY_NPN_JOIN, true);
return preferred;
}
@ -1401,6 +1404,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
transport->SetConnectionFlags(flags);
}
#if(0)
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_USED_SPECULATIVE_CONN> usedSpeculativeConn;
++usedSpeculativeConn;
@ -1408,6 +1412,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent,
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_USED> totalPreconnectsUsed;
++totalPreconnectsUsed;
}
#endif
// return OK because we have essentially opened a new connection
// by converting a speculative half-open to general use
@ -2053,6 +2058,7 @@ nsHttpConnectionMgr::BuildPipeline(nsConnectionEntry *ent,
void
nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent)
{
#if(0)
enum { PROXY_NONE = 1, PROXY_HTTP = 2, PROXY_SOCKS = 3, PROXY_HTTPS = 4 };
if (!ent->mConnInfo->UsingProxy())
@ -2063,6 +2069,7 @@ nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent)
Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_HTTP);
else
Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_SOCKS);
#endif
}
nsresult
@ -2110,7 +2117,7 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
ent = preferredEntry;
}
ReportProxyTelemetry(ent);
//ReportProxyTelemetry(ent);
// Check if the transaction already has a sticky reference to a connection.
// If so, then we can just use it directly by transferring its reference
@ -2210,13 +2217,13 @@ nsHttpConnectionMgr::CreateTransport(nsConnectionEntry *ent,
if (speculative) {
sock->SetSpeculative(true);
sock->SetAllow1918(allow1918);
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn;
++totalSpeculativeConn;
//Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_TOTAL_SPECULATIVE_CONN> totalSpeculativeConn;
//++totalSpeculativeConn;
if (isFromPredictor) {
sock->SetIsFromPredictor(true);
Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated;
++totalPreconnectsCreated;
//Telemetry::AutoCounter<Telemetry::PREDICTOR_TOTAL_PRECONNECTS_CREATED> totalPreconnectsCreated;
//++totalPreconnectsCreated;
}
}
@ -3090,8 +3097,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
nsCOMPtr<nsISocketTransport> socketTransport;
nsCOMPtr<nsISocketTransportService> sts;
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
sts = services::GetSocketTransportService();
if (!sts) {
return NS_ERROR_NOT_AVAILABLE;
}
LOG(("nsHalfOpenSocket::SetupStreams [this=%p ent=%s] "
"setup routed transport to origin %s:%d via %s:%d\n",
@ -3167,8 +3176,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
rv = socketTransport->SetSecurityCallbacks(this);
NS_ENSURE_SUCCESS(rv, rv);
/*
Telemetry::Accumulate(Telemetry::HTTP_CONNECTION_ENTRY_CACHE_HIT_1,
mEnt->mUsedForConnection);
*/
mEnt->mUsedForConnection = true;
nsCOMPtr<nsIOutputStream> sout;
@ -3967,6 +3978,7 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
// will result in it not being present in the halfopen table. That's expected.
if (mHalfOpens.RemoveElement(halfOpen)) {
#if(0)
if (halfOpen->IsSpeculative()) {
Telemetry::AutoCounter<Telemetry::HTTPCONNMGR_UNUSED_SPECULATIVE_CONN> unusedSpeculativeConn;
++unusedSpeculativeConn;
@ -3976,6 +3988,7 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
++totalPreconnectsUnused;
}
}
#endif
MOZ_ASSERT(gHttpHandler->ConnMgr()->mNumHalfOpenConns);
if (gHttpHandler->ConnMgr()->mNumHalfOpenConns) { // just in case

View File

@ -26,7 +26,6 @@
#include "nsStringStream.h"
#include "nsComponentManagerUtils.h" // do_CreateInstance
#include "nsServiceManagerUtils.h" // do_GetService
#include "nsIHttpActivityObserver.h"
#include "nsSocketTransportService2.h"
#include "nsICancelable.h"
@ -235,8 +234,10 @@ nsHttpTransaction::Init(uint32_t caps,
MOZ_ASSERT(requestHead);
MOZ_ASSERT(target);
mActivityDistributor = do_GetService(NS_HTTPACTIVITYDISTRIBUTOR_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
mActivityDistributor = services::GetActivityDistributor();
if (!mActivityDistributor) {
return NS_ERROR_NOT_AVAILABLE;
}
bool activityDistributorActive;
rv = mActivityDistributor->GetIsActive(&activityDistributorActive);

View File

@ -322,23 +322,34 @@ nsNSSSocketInfo::GetNegotiatedNPN(nsACString& aNegotiatedNPN)
NS_IMETHODIMP
nsNSSSocketInfo::GetAlpnEarlySelection(nsACString& aAlpnSelected)
{
aAlpnSelected.Truncate();
nsNSSShutDownPreventionLock locker;
if (isAlreadyShutDown() || isPK11LoggedOut()) {
return NS_ERROR_NOT_AVAILABLE;
}
SSLNextProtoState alpnState;
unsigned char chosenAlpn[MAX_ALPN_LENGTH];
unsigned int chosenAlpnLen;
SECStatus rv = SSL_GetNextProto(mFd, &alpnState, chosenAlpn, &chosenAlpnLen,
AssertedCast<unsigned int>(ArrayLength(chosenAlpn)));
if (rv != SECSuccess || alpnState != SSL_NEXT_PROTO_EARLY_VALUE ||
chosenAlpnLen == 0) {
SSLPreliminaryChannelInfo info;
SECStatus rv = SSL_GetPreliminaryChannelInfo(mFd, &info, sizeof(info));
if (rv != SECSuccess || !info.canSendEarlyData) {
return NS_ERROR_NOT_AVAILABLE;
}
aAlpnSelected.Assign(BitwiseCast<char*, unsigned char*>(chosenAlpn),
chosenAlpnLen);
SSLNextProtoState alpnState;
unsigned char chosenAlpn[MAX_ALPN_LENGTH];
unsigned int chosenAlpnLen;
rv = SSL_GetNextProto(mFd, &alpnState, chosenAlpn, &chosenAlpnLen,
AssertedCast<unsigned int>(ArrayLength(chosenAlpn)));
if (rv != SECSuccess) {
return NS_ERROR_NOT_AVAILABLE;
}
if (alpnState == SSL_NEXT_PROTO_EARLY_VALUE) {
aAlpnSelected.Assign(BitwiseCast<char*, unsigned char*>(chosenAlpn),
chosenAlpnLen);
}
return NS_OK;
}

View File

@ -40,6 +40,16 @@ MOZ_SERVICE(UUIDGenerator, nsIUUIDGenerator,
"@mozilla.org/uuid-generator;1");
MOZ_SERVICE(GfxInfo, nsIGfxInfo,
"@mozilla.org/gfx/info;1");
MOZ_SERVICE(SocketTransportService, nsISocketTransportService,
"@mozilla.org/network/socket-transport-service;1");
MOZ_SERVICE(StreamTransportService, nsIStreamTransportService,
"@mozilla.org/network/stream-transport-service;1");
MOZ_SERVICE(CacheStorageService, nsICacheStorageService,
"@mozilla.org/netwerk/cache-storage-service;1");
MOZ_SERVICE(URIClassifier, nsIURIClassifier,
"@mozilla.org/uriclassifierservice");
MOZ_SERVICE(ActivityDistributor, nsIHttpActivityDistributor,
"@mozilla.org/network/http-activity-distributor;1");
#ifdef MOZ_USE_NAMESPACE
namespace mozilla {

View File

@ -26,6 +26,11 @@
#include "inIDOMUtils.h"
#include "nsIPermissionManager.h"
#include "nsIServiceWorkerManager.h"
#include "nsICacheStorageService.h"
#include "nsIStreamTransportService.h"
#include "nsISocketTransportService.h"
#include "nsIURIClassifier.h"
#include "nsIHttpActivityObserver.h"
#include "nsIAsyncShutdown.h"
#include "nsIUUIDGenerator.h"
#include "nsIGfxInfo.h"