tor-browser

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

HttpConnectionMgrShell.h (10713B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef HttpConnectionMgrShell_h__
      6 #define HttpConnectionMgrShell_h__
      7 
      8 #include "nsISupports.h"
      9 
     10 class nsIEventTarget;
     11 class nsIHttpUpgradeListener;
     12 class nsIInterfaceRequestor;
     13 
     14 namespace mozilla::net {
     15 
     16 class ARefBase;
     17 class EventTokenBucket;
     18 class HttpTransactionShell;
     19 class nsHttpConnectionInfo;
     20 class HttpConnectionBase;
     21 class nsHttpConnectionMgr;
     22 class HttpConnectionMgrParent;
     23 class SpeculativeTransaction;
     24 class ClassOfService;
     25 
     26 //----------------------------------------------------------------------------
     27 // Abstract base class for HTTP connection manager in chrome process
     28 //----------------------------------------------------------------------------
     29 
     30 // f5379ff9-2758-4bec-9992-2351c258aed6
     31 #define HTTPCONNECTIONMGRSHELL_IID \
     32  {0xf5379ff9, 0x2758, 0x4bec, {0x99, 0x92, 0x23, 0x51, 0xc2, 0x58, 0xae, 0xd6}}
     33 
     34 class HttpConnectionMgrShell : public nsISupports {
     35 public:
     36  NS_INLINE_DECL_STATIC_IID(HTTPCONNECTIONMGRSHELL_IID)
     37 
     38  enum nsParamName : uint32_t {
     39    MAX_URGENT_START_Q,
     40    MAX_CONNECTIONS,
     41    MAX_PERSISTENT_CONNECTIONS_PER_HOST,
     42    MAX_PERSISTENT_CONNECTIONS_PER_PROXY,
     43    MAX_REQUEST_DELAY,
     44    THROTTLING_ENABLED,
     45    THROTTLING_SUSPEND_FOR,
     46    THROTTLING_RESUME_FOR,
     47    THROTTLING_READ_LIMIT,
     48    THROTTLING_READ_INTERVAL,
     49    THROTTLING_HOLD_TIME,
     50    THROTTLING_MAX_TIME,
     51    PROXY_BE_CONSERVATIVE
     52  };
     53 
     54  [[nodiscard]] virtual nsresult Init(
     55      uint16_t maxUrgentExcessiveConns, uint16_t maxConnections,
     56      uint16_t maxPersistentConnectionsPerHost,
     57      uint16_t maxPersistentConnectionsPerProxy, uint16_t maxRequestDelay,
     58      bool throttleEnabled, uint32_t throttleSuspendFor,
     59      uint32_t throttleResumeFor, uint32_t throttleHoldTime,
     60      uint32_t throttleMaxTime, bool beConservativeForProxy) = 0;
     61 
     62  [[nodiscard]] virtual nsresult Shutdown() = 0;
     63 
     64  // called from main thread to post a new request token bucket
     65  // to the socket thread
     66  [[nodiscard]] virtual nsresult UpdateRequestTokenBucket(
     67      EventTokenBucket* aBucket) = 0;
     68 
     69  // Close all idle persistent connections and prevent any active connections
     70  // from being reused.
     71  [[nodiscard]] virtual nsresult DoShiftReloadConnectionCleanup() = 0;
     72 
     73  // Like DoShiftReloadConnectionCleanup() above, but also resets CI specific
     74  // information such as Happy Eyeballs history.
     75  [[nodiscard]] virtual nsresult DoShiftReloadConnectionCleanupWithConnInfo(
     76      nsHttpConnectionInfo*) = 0;
     77 
     78  // called to force the connection manager to prune its list of idle
     79  // connections.
     80  [[nodiscard]] virtual nsresult PruneDeadConnections() = 0;
     81 
     82  // this cancels all outstanding transactions but does not shut down the mgr
     83  virtual void AbortAndCloseAllConnections(int32_t, ARefBase*) = 0;
     84 
     85  // called to update a parameter after the connection manager has already
     86  // been initialized.
     87  [[nodiscard]] virtual nsresult UpdateParam(nsParamName name,
     88                                             uint16_t value) = 0;
     89 
     90  // Causes a large amount of connection diagnostic information to be
     91  // printed to the javascript console
     92  virtual void PrintDiagnostics() = 0;
     93 
     94  virtual nsresult UpdateCurrentBrowserId(uint64_t aId) = 0;
     95 
     96  // adds a transaction to the list of managed transactions.
     97  [[nodiscard]] virtual nsresult AddTransaction(HttpTransactionShell*,
     98                                                int32_t priority) = 0;
     99 
    100  // Add a new transaction with a sticky connection from |transWithStickyConn|.
    101  [[nodiscard]] virtual nsresult AddTransactionWithStickyConn(
    102      HttpTransactionShell* trans, int32_t priority,
    103      HttpTransactionShell* transWithStickyConn) = 0;
    104 
    105  // called to reschedule the given transaction.  it must already have been
    106  // added to the connection manager via AddTransaction.
    107  [[nodiscard]] virtual nsresult RescheduleTransaction(HttpTransactionShell*,
    108                                                       int32_t priority) = 0;
    109 
    110  void virtual UpdateClassOfServiceOnTransaction(
    111      HttpTransactionShell*, const ClassOfService& classOfService) = 0;
    112 
    113  // cancels a transaction w/ the given reason.
    114  [[nodiscard]] virtual nsresult CancelTransaction(HttpTransactionShell*,
    115                                                   nsresult reason) = 0;
    116 
    117  // called when a connection is done processing a transaction.  if the
    118  // connection can be reused then it will be added to the idle list, else
    119  // it will be closed.
    120  [[nodiscard]] virtual nsresult ReclaimConnection(
    121      HttpConnectionBase* conn) = 0;
    122 
    123  // called to force the transaction queue to be processed once more, giving
    124  // preference to the specified connection.
    125  [[nodiscard]] virtual nsresult ProcessPendingQ(nsHttpConnectionInfo*) = 0;
    126 
    127  // Try and process all pending transactions
    128  [[nodiscard]] virtual nsresult ProcessPendingQ() = 0;
    129 
    130  // called to get a reference to the socket transport service.  the socket
    131  // transport service is not available when the connection manager is down.
    132  [[nodiscard]] virtual nsresult GetSocketThreadTarget(nsIEventTarget**) = 0;
    133 
    134  // called to indicate a transaction for the connectionInfo is likely coming
    135  // soon. The connection manager may use this information to start a TCP
    136  // and/or SSL level handshake for that resource immediately so that it is
    137  // ready when the transaction is submitted. No obligation is taken on by the
    138  // connection manager, nor is the submitter obligated to actually submit a
    139  // real transaction for this connectionInfo.
    140  [[nodiscard]] virtual nsresult SpeculativeConnect(
    141      nsHttpConnectionInfo*, nsIInterfaceRequestor*, uint32_t caps = 0,
    142      SpeculativeTransaction* = nullptr, bool aFetchHTTPSRR = false) = 0;
    143 
    144  // "VerifyTraffic" means marking connections now, and then check again in
    145  // N seconds to see if there's been any traffic and if not, kill
    146  // that connection.
    147  [[nodiscard]] virtual nsresult VerifyTraffic() = 0;
    148 
    149  virtual void ExcludeHttp2(const nsHttpConnectionInfo* ci) = 0;
    150  virtual void ExcludeHttp3(const nsHttpConnectionInfo* ci) = 0;
    151 
    152  // clears the connection history mCT
    153  [[nodiscard]] virtual nsresult ClearConnectionHistory() = 0;
    154 
    155  // called by the main thread to execute the taketransport() logic on the
    156  // socket thread after a 101 response has been received and the socket
    157  // needs to be transferred to an expectant upgrade listener such as
    158  // websockets.
    159  // @param aTrans: a transaction that contains a sticky connection. We'll
    160  //                take the transport of this connection.
    161  [[nodiscard]] virtual nsresult CompleteUpgrade(
    162      HttpTransactionShell* aTrans,
    163      nsIHttpUpgradeListener* aUpgradeListener) = 0;
    164 
    165  virtual nsHttpConnectionMgr* AsHttpConnectionMgr() = 0;
    166  virtual HttpConnectionMgrParent* AsHttpConnectionMgrParent() = 0;
    167 };
    168 
    169 #define NS_DECL_HTTPCONNECTIONMGRSHELL                                         \
    170  virtual nsresult Init(                                                       \
    171      uint16_t maxUrgentExcessiveConns, uint16_t maxConnections,               \
    172      uint16_t maxPersistentConnectionsPerHost,                                \
    173      uint16_t maxPersistentConnectionsPerProxy, uint16_t maxRequestDelay,     \
    174      bool throttleEnabled, uint32_t throttleSuspendFor,                       \
    175      uint32_t throttleResumeFor, uint32_t throttleHoldTime,                   \
    176      uint32_t throttleMaxTime, bool beConservativeForProxy) override;         \
    177  virtual nsresult Shutdown() override;                                        \
    178  virtual nsresult UpdateRequestTokenBucket(EventTokenBucket* aBucket)         \
    179      override;                                                                \
    180  virtual nsresult DoShiftReloadConnectionCleanup() override;                  \
    181  virtual nsresult DoShiftReloadConnectionCleanupWithConnInfo(                 \
    182      nsHttpConnectionInfo*) override;                                         \
    183  virtual nsresult PruneDeadConnections() override;                            \
    184  virtual void AbortAndCloseAllConnections(int32_t, ARefBase*) override;       \
    185  virtual nsresult UpdateParam(nsParamName name, uint16_t value) override;     \
    186  virtual void PrintDiagnostics() override;                                    \
    187  virtual nsresult UpdateCurrentBrowserId(uint64_t aId) override;              \
    188  virtual nsresult AddTransaction(HttpTransactionShell*, int32_t priority)     \
    189      override;                                                                \
    190  virtual nsresult AddTransactionWithStickyConn(                               \
    191      HttpTransactionShell* trans, int32_t priority,                           \
    192      HttpTransactionShell* transWithStickyConn) override;                     \
    193  virtual nsresult RescheduleTransaction(HttpTransactionShell*,                \
    194                                         int32_t priority) override;           \
    195  void virtual UpdateClassOfServiceOnTransaction(                              \
    196      HttpTransactionShell*, const ClassOfService& classOfService) override;   \
    197  virtual nsresult CancelTransaction(HttpTransactionShell*, nsresult reason)   \
    198      override;                                                                \
    199  virtual nsresult ReclaimConnection(HttpConnectionBase* conn) override;       \
    200  virtual nsresult ProcessPendingQ(nsHttpConnectionInfo*) override;            \
    201  virtual nsresult ProcessPendingQ() override;                                 \
    202  virtual nsresult GetSocketThreadTarget(nsIEventTarget**) override;           \
    203  virtual nsresult SpeculativeConnect(                                         \
    204      nsHttpConnectionInfo*, nsIInterfaceRequestor*, uint32_t caps = 0,        \
    205      SpeculativeTransaction* = nullptr, bool aFetchHTTPSRR = false) override; \
    206  virtual nsresult VerifyTraffic() override;                                   \
    207  virtual void ExcludeHttp2(const nsHttpConnectionInfo* ci) override;          \
    208  virtual void ExcludeHttp3(const nsHttpConnectionInfo* ci) override;          \
    209  virtual nsresult ClearConnectionHistory() override;                          \
    210  virtual nsresult CompleteUpgrade(HttpTransactionShell* aTrans,               \
    211                                   nsIHttpUpgradeListener* aUpgradeListener)   \
    212      override;                                                                \
    213  nsHttpConnectionMgr* AsHttpConnectionMgr() override;                         \
    214  HttpConnectionMgrParent* AsHttpConnectionMgrParent() override;
    215 
    216 }  // namespace mozilla::net
    217 
    218 #endif  // HttpConnectionMgrShell_h__