Bug 1525640 - Pass TRR status from sockettransport to channel r=dragana
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 06 May 2019 16:47:14 +0000
changeset 531606 406e4a9a3f758ae2c030b7b9437b8e0835876028
parent 531605 39077226dac335e743f7465fb91349d76ded1922
child 531607 3b43b5e97f9e60f110a98869ca748956c47cda5a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1525640
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1525640 - Pass TRR status from sockettransport to channel r=dragana Differential Revision: https://phabricator.services.mozilla.com/D26882
media/mtransport/test/webrtcproxychannel_unittest.cpp
netwerk/base/nsISocketTransport.idl
netwerk/base/nsSocketTransport2.cpp
netwerk/base/nsSocketTransport2.h
netwerk/protocol/http/TunnelUtils.cpp
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/http/nsHttpTransaction.h
--- a/media/mtransport/test/webrtcproxychannel_unittest.cpp
+++ b/media/mtransport/test/webrtcproxychannel_unittest.cpp
@@ -177,16 +177,20 @@ class FakeSocketTransportProvider : publ
       bool* aResetIPFamilyPreference) override {
     MOZ_ASSERT(false);
     return NS_OK;
   }
   NS_IMETHOD GetEsniUsed(bool* aEsniUsed) override {
     MOZ_ASSERT(false);
     return NS_OK;
   }
+  NS_IMETHOD ResolvedByTRR(bool* _retval) override {
+    MOZ_ASSERT(false);
+    return NS_OK;
+  }
 
   // nsITransport
   NS_IMETHOD OpenInputStream(uint32_t aFlags, uint32_t aSegmentSize,
                              uint32_t aSegmentCount,
                              nsIInputStream** _retval) override {
     MOZ_ASSERT(false);
     return NS_OK;
   }
--- a/netwerk/base/nsISocketTransport.idl
+++ b/netwerk/base/nsISocketTransport.idl
@@ -309,9 +309,14 @@ interface nsISocketTransport : nsITransp
      */
     readonly attribute boolean resetIPFamilyPreference;
 
     /**
      * This attribute holds information whether esni has been used.
      * The value is set after PR_Connect is called.
      */
    readonly attribute boolean esniUsed;
+
+    /**
+     * IP address resolved using TRR.
+     */
+    bool resolvedByTRR();
 };
--- a/netwerk/base/nsSocketTransport2.cpp
+++ b/netwerk/base/nsSocketTransport2.cpp
@@ -707,16 +707,17 @@ nsSocketTransport::nsSocketTransport()
       mAttached(false),
       mInputClosed(true),
       mOutputClosed(true),
       mResolving(false),
       mDNSLookupStatus(NS_OK),
       mDNSARequestFinished(0),
       mEsniQueried(false),
       mEsniUsed(false),
+      mResolvedByTRR(false),
       mNetAddrIsSet(false),
       mSelfAddrIsSet(false),
       mLock("nsSocketTransport.mLock"),
       mFD(this),
       mFDref(0),
       mFDconnected(false),
       mFDFastOpenInProgress(false),
       mSocketTransportService(gSocketTransportService),
@@ -1798,16 +1799,17 @@ bool nsSocketTransport::RecoverFromError
       // connection entry
       mResetFamilyPreference = true;
       tryAgain = true;
     }
 
     // try next ip address only if past the resolver stage...
     if (mState == STATE_CONNECTING && mDNSRecord) {
       nsresult rv = mDNSRecord->GetNextAddr(SocketPort(), &mNetAddr);
+      mDNSRecord->IsTRR(&mResolvedByTRR);
       if (NS_SUCCEEDED(rv)) {
         SOCKET_LOG(("  trying again with next ip address\n"));
         tryAgain = true;
       } else if (mConnectionFlags & RETRY_WITH_DIFFERENT_IP_FAMILY) {
         SOCKET_LOG(("  failed to connect, trying with opposite ip family\n"));
         // Drop state to closed.  This will trigger new round of DNS
         // resolving bellow.
         mState = STATE_CLOSED;
@@ -2091,16 +2093,17 @@ void nsSocketTransport::OnSocketEvent(ui
         SendStatus(NS_NET_STATUS_RESOLVED_HOST);
       }
 
       SOCKET_LOG(("  MSG_DNS_LOOKUP_COMPLETE\n"));
       mDNSRequest = nullptr;
       mDNSTxtRequest = nullptr;
       if (mDNSRecord) {
         mDNSRecord->GetNextAddr(SocketPort(), &mNetAddr);
+        mDNSRecord->IsTRR(&mResolvedByTRR);
       }
       // status contains DNS lookup status
       if (NS_FAILED(status)) {
         // When using a HTTP proxy, NS_ERROR_UNKNOWN_HOST means the HTTP
         // proxy host is not found, so we fixup the error code.
         // For SOCKS proxies (mProxyTransparent == true), the socket
         // transport resolves the real host here, so there's no fixup
         // (see bug 226943).
@@ -3518,10 +3521,16 @@ nsSocketTransport::GetResetIPFamilyPrefe
 }
 
 NS_IMETHODIMP
 nsSocketTransport::GetEsniUsed(bool* aEsniUsed) {
   *aEsniUsed = mEsniUsed;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+nsSocketTransport::ResolvedByTRR(bool* aResolvedByTRR) {
+  *aResolvedByTRR = mResolvedByTRR;
+  return NS_OK;
+}
+
 }  // namespace net
 }  // namespace mozilla
--- a/netwerk/base/nsSocketTransport2.h
+++ b/netwerk/base/nsSocketTransport2.h
@@ -330,16 +330,17 @@ class nsSocketTransport final : public n
   nsCOMPtr<nsIDNSRecord> mDNSRecord;
 
   nsresult mDNSLookupStatus;
   PRIntervalTime mDNSARequestFinished;
   nsCOMPtr<nsICancelable> mDNSTxtRequest;
   nsCString mDNSRecordTxt;
   bool mEsniQueried;
   bool mEsniUsed;
+  bool mResolvedByTRR;
 
   // mNetAddr/mSelfAddr is valid from GetPeerAddr()/GetSelfAddr() once we have
   // reached STATE_TRANSFERRING. It must not change after that.
   void SetSocketName(PRFileDesc* fd);
   NetAddr mNetAddr;
   NetAddr mSelfAddr;  // getsockname()
   Atomic<bool, Relaxed> mNetAddrIsSet;
   Atomic<bool, Relaxed> mSelfAddrIsSet;
--- a/netwerk/protocol/http/TunnelUtils.cpp
+++ b/netwerk/protocol/http/TunnelUtils.cpp
@@ -1822,16 +1822,24 @@ SocketTransportShim::GetFirstRetryError(
 NS_IMETHODIMP
 SocketTransportShim::GetEsniUsed(bool* aEsniUsed) {
   if (mIsWebsocket) {
     LOG3(("WARNING: SocketTransportShim::GetEsniUsed %p", this));
   }
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+NS_IMETHODIMP
+SocketTransportShim::ResolvedByTRR(bool* aResolvedByTRR) {
+  if (mIsWebsocket) {
+    LOG3(("WARNING: SocketTransportShim::IsTRR %p", this));
+  }
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
 #define FWD_TS_PTR(fx, ts) \
   NS_IMETHODIMP            \
   SocketTransportShim::fx(ts* arg) { return mWrapped->fx(arg); }
 
 #define FWD_TS_ADDREF(fx, ts) \
   NS_IMETHODIMP               \
   SocketTransportShim::fx(ts** arg) { return mWrapped->fx(arg); }
 
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -8424,21 +8424,25 @@ nsHttpChannel::OnTransportStatus(nsITran
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread only");
   // cache the progress sink so we don't have to query for it each time.
   if (!mProgressSink) GetCallback(mProgressSink);
 
   if (status == NS_NET_STATUS_CONNECTED_TO ||
       status == NS_NET_STATUS_WAITING_FOR) {
     if (mTransaction) {
       mTransaction->GetNetworkAddresses(mSelfAddr, mPeerAddr);
+      mResolvedByTRR = mTransaction->ResolvedByTRR();
     } else {
       nsCOMPtr<nsISocketTransport> socketTransport = do_QueryInterface(trans);
       if (socketTransport) {
         socketTransport->GetSelfAddr(&mSelfAddr);
         socketTransport->GetPeerAddr(&mPeerAddr);
+        bool isTrr = false;
+        socketTransport->ResolvedByTRR(&isTrr);
+        mResolvedByTRR = isTrr;
       }
     }
   }
 
   // block socket status event after Cancel or OnStopRequest has been called.
   if (mProgressSink && NS_SUCCEEDED(mStatus) && mIsPending) {
     LOG(("sending progress%s notification [this=%p status=%" PRIx32
          " progress=%" PRId64 "/%" PRId64 "]\n",
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -717,16 +717,20 @@ class nsHttpChannel final : public HttpB
   // to the safe-browsing classifier rules, but the asynchronous cancellation
   // process hasn't finished yet.
   uint32_t mChannelClassifierCancellationPending : 1;
 
   // True only when we are between Resume and async fire of mCallOnResume.
   // Used to suspend any newly created pumps in mCallOnResume handler.
   uint32_t mAsyncResumePending : 1;
 
+  // If the request was performed to a TRR resolved IP address.
+  // Will be false if loaded from the cache.
+  uint32_t mResolvedByTRR : 1;
+
   // True only when we have checked whether this channel has been isolated for
   // anti-tracking purposes.
   uint32_t mHasBeenIsolatedChecked : 1;
   // True only when we have determined this channel should be isolated for
   // anti-tracking purposes.  Can never ben true unless mHasBeenIsolatedChecked
   // is true.
   uint32_t mIsIsolated : 1;
 
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -138,16 +138,17 @@ nsHttpTransaction::nsHttpTransaction()
       mResponseHeadTaken(false),
       mForTakeResponseTrailers(nullptr),
       mResponseTrailersTaken(false),
       mTopLevelOuterContentWindowId(0),
       mSubmittedRatePacing(false),
       mPassedRatePacing(false),
       mSynchronousRatePaceRequest(false),
       mClassOfService(0),
+      mResolvedByTRR(false),
       m0RTTInProgress(false),
       mDoNotTryEarlyData(false),
       mEarlyDataDisposition(EARLY_NONE),
       mFastOpenStatus(TFO_NOT_TRIED),
       mTrafficCategory(HttpTrafficCategory::eInvalid) {
   this->mSelfAddr.inet = {};
   this->mPeerAddr.inet = {};
   LOG(("Creating nsHttpTransaction @%p\n", this));
@@ -588,16 +589,17 @@ void nsHttpTransaction::OnTransportStatu
   if (status == NS_NET_STATUS_CONNECTED_TO ||
       status == NS_NET_STATUS_WAITING_FOR) {
     nsISocketTransport* socketTransport =
         mConnection ? mConnection->Transport() : nullptr;
     if (socketTransport) {
       MutexAutoLock lock(mLock);
       socketTransport->GetSelfAddr(&mSelfAddr);
       socketTransport->GetPeerAddr(&mPeerAddr);
+      socketTransport->ResolvedByTRR(&mResolvedByTRR);
     }
   }
 
   // If the timing is enabled, and we are not using a persistent connection
   // then the requestStart timestamp will be null, so we mark the timestamps
   // for domainLookupStart/End and connectStart/End
   // If we are using a persistent connection they will remain null,
   // and the correct value will be returned in Performance.
--- a/netwerk/protocol/http/nsHttpTransaction.h
+++ b/netwerk/protocol/http/nsHttpTransaction.h
@@ -458,20 +458,22 @@ class nsHttpTransaction final : public n
     mTransactionObserver = arg;
   }
 
  private:
   RefPtr<TransactionObserver> mTransactionObserver;
 
  public:
   void GetNetworkAddresses(NetAddr& self, NetAddr& peer);
+  bool ResolvedByTRR() { return mResolvedByTRR; }
 
  private:
   NetAddr mSelfAddr;
   NetAddr mPeerAddr;
+  bool mResolvedByTRR;
 
   bool m0RTTInProgress;
   bool mDoNotTryEarlyData;
   enum {
     EARLY_NONE,
     EARLY_SENT,
     EARLY_ACCEPTED,
     EARLY_425