tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ASpdySession.h (4352B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_net_ASpdySession_h
      8 #define mozilla_net_ASpdySession_h
      9 
     10 #include "nsAHttpTransaction.h"
     11 #include "prinrval.h"
     12 #include "nsHttp.h"
     13 #include "nsString.h"
     14 
     15 class nsISocketTransport;
     16 
     17 namespace mozilla {
     18 namespace net {
     19 
     20 class nsHttpConnection;
     21 class WebTransportSessionBase;
     22 
     23 class ASpdySession : public nsAHttpTransaction {
     24 public:
     25  ASpdySession() = default;
     26  virtual ~ASpdySession() = default;
     27 
     28  [[nodiscard]] virtual bool AddStream(nsAHttpTransaction*, int32_t,
     29                                       nsIInterfaceRequestor*) = 0;
     30  virtual bool CanReuse() = 0;
     31  virtual bool RoomForMoreStreams() = 0;
     32  virtual PRIntervalTime IdleTime() = 0;
     33  virtual uint32_t ReadTimeoutTick(PRIntervalTime now) = 0;
     34  virtual void DontReuse() = 0;
     35  virtual enum SpdyVersion SpdyVersion() = 0;
     36 
     37  static ASpdySession* NewSpdySession(net::SpdyVersion version,
     38                                      nsISocketTransport*, bool);
     39 
     40  virtual bool TestJoinConnection(const nsACString& hostname, int32_t port) = 0;
     41  virtual bool JoinConnection(const nsACString& hostname, int32_t port) = 0;
     42 
     43  virtual void PrintDiagnostics(nsCString& log) = 0;
     44 
     45  bool ResponseTimeoutEnabled() const final { return true; }
     46 
     47  virtual void SendPing() = 0;
     48 
     49  const static uint32_t kSendingChunkSize = 16000;
     50  const static uint32_t kTCPSendBufferSize = 131072;
     51  const static uint32_t kInitialPushAllowance = 131072;  // match default pref
     52 
     53  // This is roughly the amount of data a suspended channel will have to
     54  // buffer before h2 flow control kicks in.
     55  const static uint32_t kInitialRwin = 12 * 1024 * 1024;  // 12MB
     56 
     57  const static uint32_t kDefaultMaxConcurrent = 100;
     58 
     59  // soft errors are errors that terminate a stream without terminating the
     60  // connection. In general non-network errors are stream errors as well
     61  // as network specific items like cancels.
     62  static bool SoftStreamError(nsresult code) {
     63    if (NS_SUCCEEDED(code) || code == NS_BASE_STREAM_WOULD_BLOCK) {
     64      return false;
     65    }
     66 
     67    // this could go either way, but because there are network instances of
     68    // it being a hard error we should consider it hard.
     69    if (code == NS_ERROR_FAILURE || code == NS_ERROR_OUT_OF_MEMORY) {
     70      return false;
     71    }
     72 
     73    if (NS_ERROR_GET_MODULE(code) != NS_ERROR_MODULE_NETWORK) {
     74      return true;
     75    }
     76 
     77    // these are network specific soft errors
     78    return (code == NS_BASE_STREAM_CLOSED || code == NS_BINDING_FAILED ||
     79            code == NS_BINDING_ABORTED || code == NS_BINDING_REDIRECTED ||
     80            code == NS_ERROR_INVALID_CONTENT_ENCODING ||
     81            code == NS_BINDING_RETARGETED ||
     82            code == NS_ERROR_CORRUPTED_CONTENT ||
     83            code == NS_ERROR_NET_TIMEOUT_EXTERNAL);
     84  }
     85 
     86  virtual void SetCleanShutdown(bool) = 0;
     87  virtual ExtendedCONNECTSupport GetExtendedCONNECTSupport() = 0;
     88 
     89  virtual Result<already_AddRefed<mozilla::net::nsHttpConnection>, nsresult>
     90  CreateTunnelStream(nsAHttpTransaction* aHttpTransaction,
     91                     nsIInterfaceRequestor* aCallbacks, PRIntervalTime aRtt,
     92                     bool aIsExtendedCONNECT = false) = 0;
     93 
     94  virtual WebTransportSessionBase* GetWebTransportSession(
     95      nsAHttpTransaction* aTransaction) = 0;
     96 };
     97 
     98 using ALPNCallback = bool (*)(nsITLSSocketControl*);
     99 
    100 // this is essentially a single instantiation as a member of nsHttpHandler.
    101 // It could be all static except using static ctors of XPCOM objects is a
    102 // bad idea.
    103 class SpdyInformation {
    104 public:
    105  SpdyInformation();
    106  ~SpdyInformation() = default;
    107 
    108  SpdyVersion Version;      // telemetry enum e.g. SPDY_VERSION_31
    109  nsCString VersionString;  // npn string e.g. "spdy/3.1"
    110 
    111  // the ALPNCallback function allows the protocol stack to decide whether or
    112  // not to offer a particular protocol based on the known TLS information
    113  // that we will offer in the client hello (such as version). There has
    114  // not been a Server Hello received yet, so not much else can be considered.
    115  ALPNCallback ALPNCallbacks;
    116 };
    117 
    118 }  // namespace net
    119 }  // namespace mozilla
    120 
    121 #endif  // mozilla_net_ASpdySession_h