File: HttpConnectionUDP.h

package info (click to toggle)
firefox 147.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,320 kB
  • sloc: cpp: 7,607,359; javascript: 6,533,295; ansic: 3,775,223; python: 1,415,500; xml: 634,561; asm: 438,949; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (160 lines) | stat: -rw-r--r-- 5,258 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef HttpConnectionUDP_h__
#define HttpConnectionUDP_h__

#include "HttpConnectionBase.h"
#include "nsHttpConnectionInfo.h"
#include "nsHttpResponseHead.h"
#include "nsAHttpTransaction.h"
#include "nsCOMPtr.h"
#include "nsProxyRelease.h"
#include "prinrval.h"
#include "mozilla/Mutex.h"
#include "ARefBase.h"
#include "TimingStruct.h"
#include "HttpTrafficAnalyzer.h"

#include "nsIAsyncInputStream.h"
#include "nsIAsyncOutputStream.h"
#include "nsISupportsPriority.h"
#include "nsIInterfaceRequestor.h"
#include "nsITimer.h"
#include "Http3Session.h"

class nsIDNSRecord;
class nsISocketTransport;
class nsITLSSocketControl;

namespace mozilla {
namespace net {

class nsHttpHandler;
class ASpdySession;

// 1dcc863e-db90-4652-a1fe-13fea0b54e46
#define HTTPCONNECTIONUDP_IID \
  {0xb97d2036, 0xb441, 0x48be, {0xb3, 0x1e, 0x25, 0x3e, 0xe8, 0x32, 0xdd, 0x67}}

//-----------------------------------------------------------------------------
// HttpConnectionUDP - represents a connection to a HTTP3 server
//
// NOTE: this objects lives on the socket thread only.  it should not be
// accessed from any other thread.
//-----------------------------------------------------------------------------

class HttpConnectionUDP final : public HttpConnectionBase,
                                public nsIUDPSocketSyncListener,
                                public nsIInterfaceRequestor {
 private:
  virtual ~HttpConnectionUDP();

 public:
  NS_INLINE_DECL_STATIC_IID(HTTPCONNECTIONUDP_IID)
  NS_DECL_HTTPCONNECTIONBASE
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIUDPSOCKETSYNCLISTENER
  NS_DECL_NSIINTERFACEREQUESTOR

  HttpConnectionUDP();

  [[nodiscard]] nsresult Init(nsHttpConnectionInfo* info,
                              nsIDNSRecord* dnsRecord, nsresult status,
                              nsIInterfaceRequestor* callbacks, uint32_t caps);
  [[nodiscard]] nsresult InitWithSocket(nsHttpConnectionInfo* info,
                                        nsIUDPSocket* aSocket,
                                        NetAddr aPeerAddr,
                                        nsIInterfaceRequestor* callbacks,
                                        uint32_t caps);

  friend class HttpConnectionUDPForceIO;

  [[nodiscard]] static nsresult ReadFromStream(nsIInputStream*, void*,
                                               const char*, uint32_t, uint32_t,
                                               uint32_t*);

  bool UsingHttp3() override { return true; }

  void OnQuicTimeoutExpired();

  int64_t BytesWritten() override;

  nsresult GetSelfAddr(NetAddr* addr) override;
  nsresult GetPeerAddr(NetAddr* addr) override;
  bool ResolvedByTRR() override;
  nsIRequest::TRRMode EffectiveTRRMode() override;
  TRRSkippedReason TRRSkipReason() override;
  bool GetEchConfigUsed() override { return false; }

  void NotifyDataRead();
  void NotifyDataWrite();

  Http3Stats GetStats();

  void ResetTransaction(nsHttpTransaction* aHttpTransaction);

  void HandleTunnelResponse(nsHttpTransaction* aHttpTransaction,
                            uint16_t responseStatus, bool* reset);

  nsresult CreateTunnelStream(nsAHttpTransaction* httpTransaction,
                              HttpConnectionBase** aHttpConnection,
                              bool aIsExtendedCONNECT = false) override;

  void OnConnected();

 private:
  nsresult InitCommon(nsIUDPSocket* aSocket, const NetAddr& aPeerAddr,
                      nsIInterfaceRequestor* callbacks, uint32_t caps,
                      bool isInTunnel);
  [[nodiscard]] nsresult OnTransactionDone(nsresult reason);
  nsresult RecvData();
  nsresult SendData();
  already_AddRefed<nsIInputStream> CreateProxyConnectStream(
      nsAHttpTransaction* trans);

 private:
  RefPtr<nsHttpHandler> mHttpHandler;  // keep gHttpHandler alive

  RefPtr<nsIAsyncInputStream> mInputOverflow;

  bool mConnectedTransport = false;
  bool mDontReuse = false;
  bool mIsReused = false;
  bool mLastTransactionExpectedNoContent = false;
  bool mConnected = false;

  int32_t mPriority = nsISupportsPriority::PRIORITY_NORMAL;

 private:
  // For ForceSend()
  static void ForceSendIO(nsITimer* aTimer, void* aClosure);
  [[nodiscard]] nsresult MaybeForceSendIO();
  bool mForceSendPending = false;
  nsCOMPtr<nsITimer> mForceSendTimer;

  PRIntervalTime mLastRequestBytesSentTime = 0;
  nsCOMPtr<nsIUDPSocket> mSocket;

  nsCOMPtr<nsINetAddr> mSelfAddr;
  nsCOMPtr<nsINetAddr> mPeerAddr;
  bool mResolvedByTRR = false;
  nsIRequest::TRRMode mEffectiveTRRMode = nsIRequest::TRR_DEFAULT_MODE;
  TRRSkippedReason mTRRSkipReason = nsITRRSkipReason::TRR_UNSET;

 private:
  // Http3
  RefPtr<Http3Session> mHttp3Session;
  nsCString mAlpnToken;
  bool mIsInTunnel = false;
  bool mProxyConnectSucceeded = false;
  nsTArray<RefPtr<nsHttpTransaction>> mQueuedHttpConnectTransaction;
  nsTArray<RefPtr<nsHttpTransaction>> mQueuedConnectUdpTransaction;
};

}  // namespace net
}  // namespace mozilla

#endif  // HttpConnectionUDP_h__