diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index fe1ab1526..054037c21 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -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); diff --git a/netwerk/base/nsISocketTransportService.idl b/netwerk/base/nsISocketTransportService.idl index 06350b532..8e3bdd44d 100644 --- a/netwerk/base/nsISocketTransportService.idl +++ b/netwerk/base/nsISocketTransportService.idl @@ -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 diff --git a/netwerk/base/nsIStreamTransportService.idl b/netwerk/base/nsIStreamTransportService.idl index cd39f9cba..0babc2b7d 100644 --- a/netwerk/base/nsIStreamTransportService.idl +++ b/netwerk/base/nsIStreamTransportService.idl @@ -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 { /** diff --git a/netwerk/base/nsPISocketTransportService.idl b/netwerk/base/nsPISocketTransportService.idl index 75d84bcea..f8cce154f 100644 --- a/netwerk/base/nsPISocketTransportService.idl +++ b/netwerk/base/nsPISocketTransportService.idl @@ -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 { diff --git a/netwerk/base/nsProtocolProxyService.cpp b/netwerk/base/nsProtocolProxyService.cpp index dfb5357e4..b33492731 100644 --- a/netwerk/base/nsProtocolProxyService.cpp +++ b/netwerk/base/nsProtocolProxyService.cpp @@ -1290,6 +1290,16 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags nsCOMPtr pi; bool usePACThread; + // adapt to realtime changes in the system proxy service + if (mProxyConfig == PROXYCONFIG_SYSTEM) { + nsCOMPtr 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 diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp index fcf3165e0..0b5ccde8b 100644 --- a/netwerk/protocol/http/Http2Session.cpp +++ b/netwerk/protocol/http/Http2Session.cpp @@ -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; diff --git a/netwerk/protocol/http/Http2Session.h b/netwerk/protocol/http/Http2Session.h index 2e9a09c61..06f8728a9 100644 --- a/netwerk/protocol/http/Http2Session.h +++ b/netwerk/protocol/http/Http2Session.h @@ -510,7 +510,10 @@ private: bool mAttemptingEarlyData; // The ID(s) of the stream(s) that we are getting 0RTT data from. - nsTArray m0RTTStreams; + nsTArray> 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> mCannotDo0RTTStreams; private: /// connect tunnels diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp index 9f0abb37b..e35e816d4 100644 --- a/netwerk/protocol/http/nsHttpChannel.cpp +++ b/netwerk/protocol/http/nsHttpChannel.cpp @@ -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 cacheStorageService = - do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr cacheStorageService(services::GetCacheStorageService()); + if (!cacheStorageService) { + return NS_ERROR_NOT_AVAILABLE; + } nsCOMPtr cacheStorage; nsCOMPtr openURI; @@ -4058,8 +4057,8 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi nsCOMPtr transport; nsCOMPtr wrapper; - nsCOMPtr sts = - do_GetService(kStreamTransportServiceCID, &rv); + nsCOMPtr 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 cacheIOTarget; if (!CacheObserver::UseNewCache()) { - nsCOMPtr serv = - do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr 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 channelClassifier = new nsChannelClassifier(); if (mLoadFlags & LOAD_CLASSIFY_URI) { - nsCOMPtr classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID); + nsCOMPtr 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 cacheStorageService = - do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv); + nsCOMPtr cacheStorageService(services::GetCacheStorageService()); + rv = cacheStorageService ? NS_OK : NS_ERROR_FAILURE; nsCOMPtr cacheStorage; if (NS_SUCCEEDED(rv)) { diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index eb444fd02..b64b2b179 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -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 sts; - nsCOMPtr ioService = do_GetIOService(&rv); - if (NS_SUCCEEDED(rv)) - sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv); + nsCOMPtr ioService = services::GetIOService(); + if (ioService) { + nsCOMPtr 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 usedSpeculativeConn; ++usedSpeculativeConn; @@ -1408,6 +1412,7 @@ nsHttpConnectionMgr::MakeNewConnection(nsConnectionEntry *ent, Telemetry::AutoCounter 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 totalSpeculativeConn; - ++totalSpeculativeConn; + //Telemetry::AutoCounter totalSpeculativeConn; + //++totalSpeculativeConn; if (isFromPredictor) { sock->SetIsFromPredictor(true); - Telemetry::AutoCounter totalPreconnectsCreated; - ++totalPreconnectsCreated; + //Telemetry::AutoCounter totalPreconnectsCreated; + //++totalPreconnectsCreated; } } @@ -3090,8 +3097,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport, nsCOMPtr socketTransport; nsCOMPtr 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 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 unusedSpeculativeConn; ++unusedSpeculativeConn; @@ -3976,6 +3988,7 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen) ++totalPreconnectsUnused; } } +#endif MOZ_ASSERT(gHttpHandler->ConnMgr()->mNumHalfOpenConns); if (gHttpHandler->ConnMgr()->mNumHalfOpenConns) { // just in case diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index 5a7344340..e36396489 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -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); diff --git a/security/manager/ssl/nsNSSIOLayer.cpp b/security/manager/ssl/nsNSSIOLayer.cpp index 18b6bb92e..e8e7ffb86 100644 --- a/security/manager/ssl/nsNSSIOLayer.cpp +++ b/security/manager/ssl/nsNSSIOLayer.cpp @@ -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(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(chosenAlpn), - chosenAlpnLen); + SSLNextProtoState alpnState; + unsigned char chosenAlpn[MAX_ALPN_LENGTH]; + unsigned int chosenAlpnLen; + rv = SSL_GetNextProto(mFd, &alpnState, chosenAlpn, &chosenAlpnLen, + AssertedCast(ArrayLength(chosenAlpn))); + + if (rv != SECSuccess) { + return NS_ERROR_NOT_AVAILABLE; + } + + if (alpnState == SSL_NEXT_PROTO_EARLY_VALUE) { + aAlpnSelected.Assign(BitwiseCast(chosenAlpn), + chosenAlpnLen); + } + return NS_OK; } diff --git a/xpcom/build/ServiceList.h b/xpcom/build/ServiceList.h index 0a382c503..8b3535366 100644 --- a/xpcom/build/ServiceList.h +++ b/xpcom/build/ServiceList.h @@ -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 { diff --git a/xpcom/build/Services.cpp b/xpcom/build/Services.cpp index b38539849..886bcc5d6 100644 --- a/xpcom/build/Services.cpp +++ b/xpcom/build/Services.cpp @@ -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"