@fails-components/webtransport 0.3.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/lib/client.js +81 -40
  2. package/lib/dom.ts +7 -5
  3. package/lib/http2/browser/browser.js +168 -0
  4. package/lib/http2/browser/browserparser.js +248 -0
  5. package/lib/http2/flowcontroller.js +371 -0
  6. package/lib/http2/node/capsuleparser.js +291 -0
  7. package/lib/http2/node/client.js +239 -0
  8. package/lib/http2/node/index.js +2 -0
  9. package/lib/http2/node/server.js +499 -0
  10. package/lib/http2/node/websocketparser.js +829 -0
  11. package/lib/http2/parserbase.js +139 -0
  12. package/lib/http2/parserbasehttp2.js +128 -0
  13. package/lib/http2/session.js +225 -0
  14. package/lib/http2/stream.js +354 -0
  15. package/lib/http2/websocketcommon.js +1 -0
  16. package/lib/{index.js → index.browser.js} +6 -10
  17. package/lib/index.node.js +27 -0
  18. package/lib/server.js +252 -69
  19. package/lib/session.js +31 -68
  20. package/lib/stream.js +103 -179
  21. package/lib/types.ts +174 -87
  22. package/lib/utils.js +2 -1
  23. package/lib/webstreams.browser.js +6 -0
  24. package/lib/webstreams.js +7 -0
  25. package/lib/webtransport.browser.js +284 -0
  26. package/lib/webtransport.node.js +137 -0
  27. package/lib/{webtransport.js → webtransportbase.js} +47 -41
  28. package/old_test/test.js +31 -29
  29. package/old_test/testsuite.js +1 -1
  30. package/package.json +18 -17
  31. package/readme.md +94 -30
  32. package/test/bidirectional-streams.spec.js +51 -9
  33. package/test/datagrams.spec.js +8 -2
  34. package/test/fixtures/known-bytes.js +29 -0
  35. package/test/fixtures/read-stream.js +1 -1
  36. package/test/fixtures/reader-value.js +1 -1
  37. package/test/fixtures/server.js +24 -10
  38. package/test/fixtures/webtransport.browser.js +20 -2
  39. package/test/fixtures/webtransport.js +1 -1
  40. package/test/index.js +33 -6
  41. package/test/pw-no-https-errors.json +5 -0
  42. package/test/session.spec.js +71 -52
  43. package/test/unidirectional-streams.spec.js +20 -4
  44. package/CMakeLists.txt +0 -991
  45. package/LICENSE.chromium +0 -27
  46. package/LICENSE.envoy +0 -207
  47. package/build.js +0 -313
  48. package/dist/lib/client.d.ts +0 -78
  49. package/dist/lib/client.d.ts.map +0 -1
  50. package/dist/lib/dom.d.ts +0 -87
  51. package/dist/lib/dom.d.ts.map +0 -1
  52. package/dist/lib/error.d.ts +0 -8
  53. package/dist/lib/error.d.ts.map +0 -1
  54. package/dist/lib/event-loop.d.ts +0 -33
  55. package/dist/lib/event-loop.d.ts.map +0 -1
  56. package/dist/lib/index.d.ts +0 -79
  57. package/dist/lib/index.d.ts.map +0 -1
  58. package/dist/lib/native.d.ts +0 -2
  59. package/dist/lib/native.d.ts.map +0 -1
  60. package/dist/lib/server.d.ts +0 -92
  61. package/dist/lib/server.d.ts.map +0 -1
  62. package/dist/lib/session.d.ts +0 -298
  63. package/dist/lib/session.d.ts.map +0 -1
  64. package/dist/lib/stream.d.ts +0 -135
  65. package/dist/lib/stream.d.ts.map +0 -1
  66. package/dist/lib/transport.d.ts +0 -34
  67. package/dist/lib/transport.d.ts.map +0 -1
  68. package/dist/lib/types.d.ts +0 -212
  69. package/dist/lib/types.d.ts.map +0 -1
  70. package/dist/lib/utils.d.ts +0 -11
  71. package/dist/lib/utils.d.ts.map +0 -1
  72. package/dist/lib/webtransport.d.ts +0 -47
  73. package/dist/lib/webtransport.d.ts.map +0 -1
  74. package/dist/test/bidirectional-streams.spec.d.ts +0 -5
  75. package/dist/test/bidirectional-streams.spec.d.ts.map +0 -1
  76. package/dist/test/datagrams.spec.d.ts +0 -5
  77. package/dist/test/datagrams.spec.d.ts.map +0 -1
  78. package/dist/test/event-loop.node.d.ts +0 -2
  79. package/dist/test/event-loop.node.d.ts.map +0 -1
  80. package/dist/test/fixtures/certificate.d.ts +0 -21
  81. package/dist/test/fixtures/certificate.d.ts.map +0 -1
  82. package/dist/test/fixtures/chai.d.ts +0 -2
  83. package/dist/test/fixtures/chai.d.ts.map +0 -1
  84. package/dist/test/fixtures/known-bytes.d.ts +0 -6
  85. package/dist/test/fixtures/known-bytes.d.ts.map +0 -1
  86. package/dist/test/fixtures/p-timeout.d.ts +0 -8
  87. package/dist/test/fixtures/p-timeout.d.ts.map +0 -1
  88. package/dist/test/fixtures/read-cert-hash.d.ts +0 -6
  89. package/dist/test/fixtures/read-cert-hash.d.ts.map +0 -1
  90. package/dist/test/fixtures/read-stream.d.ts +0 -19
  91. package/dist/test/fixtures/read-stream.d.ts.map +0 -1
  92. package/dist/test/fixtures/reader-value.d.ts +0 -22
  93. package/dist/test/fixtures/reader-value.d.ts.map +0 -1
  94. package/dist/test/fixtures/server.d.ts +0 -5
  95. package/dist/test/fixtures/server.d.ts.map +0 -1
  96. package/dist/test/fixtures/webtransport.browser.d.ts +0 -3
  97. package/dist/test/fixtures/webtransport.browser.d.ts.map +0 -1
  98. package/dist/test/fixtures/webtransport.d.ts +0 -3
  99. package/dist/test/fixtures/webtransport.d.ts.map +0 -1
  100. package/dist/test/fixtures/write-stream.d.ts +0 -10
  101. package/dist/test/fixtures/write-stream.d.ts.map +0 -1
  102. package/dist/test/index.d.ts +0 -2
  103. package/dist/test/index.d.ts.map +0 -1
  104. package/dist/test/session.spec.d.ts +0 -5
  105. package/dist/test/session.spec.d.ts.map +0 -1
  106. package/dist/test/unidirectional-streams.spec.d.ts +0 -2
  107. package/dist/test/unidirectional-streams.spec.d.ts.map +0 -1
  108. package/failslogolicensereadme.txt +0 -4
  109. package/lib/event-loop.js +0 -88
  110. package/lib/native.js +0 -28
  111. package/lib/transport.js +0 -82
  112. package/platform/icufix/fakedata.cpp +0 -8
  113. package/platform/quiche/quic/core/io/socket_win.inc +0 -3
  114. package/platform/quiche_platform_impl/quiche_bug_tracker_impl.h +0 -7
  115. package/platform/quiche_platform_impl/quiche_client_stats_impl.h +0 -7
  116. package/platform/quiche_platform_impl/quiche_command_line_flags_impl.h +0 -7
  117. package/platform/quiche_platform_impl/quiche_containers_impl.h +0 -7
  118. package/platform/quiche_platform_impl/quiche_event_loop_impl.h +0 -7
  119. package/platform/quiche_platform_impl/quiche_export_impl.h +0 -6
  120. package/platform/quiche_platform_impl/quiche_flag_utils_impl.h +0 -11
  121. package/platform/quiche_platform_impl/quiche_flags_impl.h +0 -8
  122. package/platform/quiche_platform_impl/quiche_iovec_impl.h +0 -10
  123. package/platform/quiche_platform_impl/quiche_logging_impl.h +0 -21
  124. package/platform/quiche_platform_impl/quiche_mem_slice_impl.h +0 -2
  125. package/platform/quiche_platform_impl/quiche_mutex_impl.h +0 -8
  126. package/platform/quiche_platform_impl/quiche_prefetch_impl.h +0 -11
  127. package/platform/quiche_platform_impl/quiche_reference_counted_impl.h +0 -16
  128. package/platform/quiche_platform_impl/quiche_server_stats_impl.h +0 -7
  129. package/platform/quiche_platform_impl/quiche_stack_trace_impl.h +0 -12
  130. package/platform/quiche_platform_impl/quiche_stream_buffer_allocator_impl.h +0 -8
  131. package/platform/quiche_platform_impl/quiche_testvalue_impl.h +0 -1
  132. package/platform/quiche_platform_impl/quiche_thread_local_impl.h +0 -6
  133. package/platform/quiche_platform_impl/quiche_time_utils_impl.h +0 -13
  134. package/platform/quiche_platform_impl/quiche_udp_socket_platform_impl.h +0 -39
  135. package/src/http3backendresponse.cc +0 -36
  136. package/src/http3backendresponse.h +0 -109
  137. package/src/http3client.cc +0 -1529
  138. package/src/http3client.h +0 -557
  139. package/src/http3clientsession.cc +0 -65
  140. package/src/http3clientsession.h +0 -60
  141. package/src/http3clientstream.cc +0 -52
  142. package/src/http3clientstream.h +0 -42
  143. package/src/http3dispatcher.cc +0 -62
  144. package/src/http3dispatcher.h +0 -57
  145. package/src/http3eventloop.cc +0 -1107
  146. package/src/http3eventloop.h +0 -316
  147. package/src/http3server.cc +0 -514
  148. package/src/http3server.h +0 -151
  149. package/src/http3serverbackend.cc +0 -105
  150. package/src/http3serverbackend.h +0 -98
  151. package/src/http3serversession.cc +0 -123
  152. package/src/http3serversession.h +0 -95
  153. package/src/http3serverstream.cc +0 -463
  154. package/src/http3serverstream.h +0 -114
  155. package/src/http3sessioncache.cc +0 -85
  156. package/src/http3sessioncache.h +0 -59
  157. package/src/http3wtsessionvisitor.cc +0 -46
  158. package/src/http3wtsessionvisitor.h +0 -397
  159. package/src/http3wtstreamvisitor.cc +0 -155
  160. package/src/http3wtstreamvisitor.h +0 -404
  161. package/test/event-loop.node.js +0 -24
  162. package/tsconfig.json +0 -39
package/src/http3client.h DELETED
@@ -1,557 +0,0 @@
1
- // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
2
- // Use of this source code is governed by a BSD-style license that can be
3
- // found in the LICENSE file.
4
-
5
- // portions taken from libquiche, original copyright, see LICENSE.chromium
6
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
7
- // Use of this source code is governed by a BSD-style license that can be
8
- // found in the LICENSE file.
9
-
10
- #ifndef WT_HTTP3_CLIENT_H
11
- #define WT_HTTP3_CLIENT_H
12
-
13
- #include <napi.h>
14
-
15
- #include <cstdint>
16
- #include <memory>
17
- #include <string>
18
- #include <queue>
19
-
20
- #include "src/http3eventloop.h"
21
- #include "absl/base/attributes.h"
22
- #include "absl/strings/string_view.h"
23
- #include "quiche/quic/core/crypto/crypto_handshake.h"
24
- #include "quiche/quic/core/http/quic_client_push_promise_index.h"
25
- #include "quiche/quic/core/http/quic_spdy_client_session.h"
26
- #include "quiche/quic/core/http/quic_spdy_client_stream.h"
27
- #include "quiche/quic/core/quic_config.h"
28
- #include "quiche/quic/core/quic_packet_reader.h"
29
- #include "quiche/quic/platform/api/quic_socket_address.h"
30
- #include "quiche/quic/core/proto/cached_network_parameters_proto.h"
31
- #include "quiche/quic/core/deterministic_connection_id_generator.h"
32
- #include "quiche/quic/core/quic_framer.h"
33
- #include "quiche/quic/core/quic_packet_creator.h"
34
- #include "quiche/quic/core/quic_packets.h"
35
- #include "quiche/common/quiche_linked_hash_map.h"
36
- #include "quiche/quic/core/crypto/web_transport_fingerprint_proof_verifier.h"
37
-
38
- namespace quic
39
- {
40
-
41
- class ProofVerifier;
42
- class QuicServerId;
43
- class SessionCache;
44
- class QuicPacketWriterWrapper;
45
- class Http3EventLoop;
46
- class Http3Client;
47
-
48
- class Http3ClientJS : public Napi::ObjectWrap<Http3ClientJS>,
49
- public LifetimeHelper
50
- {
51
- public:
52
- Http3ClientJS(const Napi::CallbackInfo &info);
53
-
54
- // js stuff
55
-
56
- void openWTSession(const Napi::CallbackInfo &info);
57
- void closeClient(const Napi::CallbackInfo &info);
58
-
59
- static void InitExports(Napi::Env env, Napi::Object exports)
60
- {
61
- Napi::Function tplcl =
62
- ObjectWrap<Http3ClientJS>::DefineClass(env, "Http3WebTransportClient",
63
- {
64
- Napi::InstanceWrap<Http3ClientJS>::InstanceMethod<&Http3ClientJS::openWTSession>("openWTSession",
65
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
66
- Napi::InstanceWrap<Http3ClientJS>::InstanceMethod<&Http3ClientJS::closeClient>("closeClient",
67
- static_cast<napi_property_attributes>(napi_writable | napi_configurable)),
68
-
69
- });
70
- exports.Set("Http3WebTransportClient", tplcl);
71
- }
72
-
73
- void doUnref() override
74
- {
75
- Unref();
76
- }
77
-
78
- Http3Client *getObj()
79
- {
80
- return client_.get();
81
- }
82
-
83
- protected:
84
- std::unique_ptr<Http3Client> client_;
85
- };
86
-
87
- class Http3Client : public QuicSpdyStream::Visitor,
88
- public QuicSocketEventListener,
89
- public QuicClientPushPromiseIndex::Delegate,
90
- public ProcessPacketInterface
91
- {
92
- friend class Http3ClientJS;
93
-
94
- public:
95
- Http3Client(Http3EventLoop *eventloop, QuicSocketAddress server_address,
96
- const std::string &server_hostname,
97
- int local_port,
98
- std::unique_ptr<ProofVerifier> proof_verifier,
99
- std::unique_ptr<SessionCache> session_cache,
100
- std::unique_ptr<QuicConnectionHelperInterface> helper);
101
-
102
- ~Http3Client() override;
103
-
104
- // From OnRegistration
105
-
106
- void OnSocketEvent(QuicEventLoop *event_loop, QuicUdpSocketFd fd,
107
- QuicSocketEventMask events) override;
108
-
109
- // From ProcessPacketInterface. This will be called for each received
110
- // packet.
111
- void ProcessPacket(const QuicSocketAddress &self_address,
112
- const QuicSocketAddress &peer_address,
113
- const QuicReceivedPacket &packet) override;
114
-
115
- // Sets the |user_agent_id| of the |client_|.
116
- void SetUserAgentID(const std::string &user_agent_id);
117
-
118
- // Wraps data in a quic packet and sends it.
119
- // ssize_t SendData(const std::string &data, bool last_data);
120
- /*
121
- // As above, but |delegate| will be notified when |data| is ACKed.
122
- ssize_t SendData(
123
- const std::string& data, bool last_data,
124
- quiche::QuicheReferenceCountedPointer<QuicAckListenerInterface>
125
- ack_listener);
126
- */
127
-
128
- // Clears any outstanding state and sends a simple GET of 'uri' to the
129
- // server. Returns 0 if the request failed and no bytes were written.
130
- void SendRequest(const std::string &uri);
131
- // Send a request R and a RST_FRAME which resets R, in the same packet.
132
- void SendRequestAndRstTogether(const std::string &uri);
133
-
134
- // Sends a request containing |headers| and |body| and returns the number of
135
- // bytes sent (the size of the serialized request headers and body).
136
- void SendMessageAsync(const spdy::Http2HeaderBlock &headers,
137
- absl::string_view body);
138
- // Sends a request containing |headers| and |body| with the fin bit set to
139
- // |fin| and returns the number of bytes sent (the size of the serialized
140
- // request headers and body).
141
- void SendMessageAsync(const spdy::Http2HeaderBlock &headers,
142
- absl::string_view body, bool fin);
143
-
144
- void SendConnectivityProbing();
145
- void Connect();
146
-
147
- // A spdy session has to call CryptoConnect on top of the regular
148
- // initialization.
149
- void InitializeSession();
150
-
151
- // Start the crypto handshake. This can be done in place of the synchronous
152
- // Connect(), but callers are responsible for making sure the crypto handshake
153
- // completes.
154
- void StartConnect();
155
-
156
- void ResetConnection();
157
- void Disconnect();
158
-
159
- // Returns true if the crypto handshake has yet to establish encryption.
160
- // Returns false if encryption is active (even if the server hasn't confirmed
161
- // the handshake) or if the connection has been closed.
162
- bool EncryptionBeingEstablished();
163
-
164
- QuicSocketAddress local_address() const;
165
- void ClearPerRequestState();
166
- // ssize_t Send(absl::string_view data);
167
- bool connected() const;
168
- bool buffer_body() const;
169
- void set_buffer_body(bool buffer_body);
170
-
171
- // Getters for stream state. Please note, these getters are divided into two
172
- // groups. 1) returns state which only get updated once a complete response
173
- // is received. 2) returns state of the oldest active stream which have
174
- // received partial response (if any).
175
- // Group 1.
176
- const spdy::Http2HeaderBlock &response_trailers() const;
177
- bool response_complete() const;
178
- int64_t response_body_size() const;
179
- const std::string &response_body() const;
180
- // Group 2.
181
- bool response_headers_complete() const;
182
- const spdy::Http2HeaderBlock *response_headers() const;
183
- int64_t response_size() const;
184
- size_t bytes_read() const;
185
- size_t bytes_written() const;
186
-
187
- // If the client has at least one UDP socket, return the latest created one.
188
- // Otherwise, return -1.
189
- int GetLatestFD() const;
190
-
191
- bool CreateUDPSocketAndBind(QuicSocketAddress server_address,
192
- QuicIpAddress bind_to_address,
193
- int bind_to_port);
194
- void CleanUpAllUDPSockets();
195
- // If |fd| is an open UDP socket, unregister and close it. Otherwise, do
196
- // nothing.
197
- void CleanUpUDPSocket(int fd);
198
-
199
- QuicSocketAddress GetLatestClientAddress() const;
200
-
201
- // Migrate local address to <|new_host|, a random port>.
202
- // Return whether the migration succeeded.
203
- bool MigrateSocket(const QuicIpAddress &new_host);
204
- // Migrate local address to <|new_host|, |port|>.
205
- // Return whether the migration succeeded.
206
- bool MigrateSocketWithSpecifiedPort(const QuicIpAddress &new_host, int port);
207
- QuicIpAddress bind_to_address() const;
208
- void set_bind_to_address(QuicIpAddress address);
209
- const QuicSocketAddress &address() const;
210
-
211
- // Returns a newly created QuicSpdyClientStream to callback
212
- void CreateClientStream(std::function<void(QuicSpdyClientStream *)> finish);
213
-
214
- // From QuicSpdyStream::Visitor
215
- void OnClose(QuicSpdyStream *stream) override;
216
-
217
- // QuicSpdyClientBase::Reponselistener
218
- void OnCompleteResponse(
219
- QuicStreamId id, const spdy::Http2HeaderBlock &response_headers,
220
- const absl::string_view &response_body);
221
-
222
- // From QuicClientPushPromiseIndex::Delegate
223
- bool CheckVary(const spdy::Http2HeaderBlock &client_request,
224
- const spdy::Http2HeaderBlock &promise_request,
225
- const spdy::Http2HeaderBlock &promise_response) override;
226
- void OnRendezvousResult(QuicSpdyStream *) override;
227
-
228
- // Returns nullptr if the maximum number of streams have already been created.
229
- // QuicSpdyClientStream *GetOrCreateStream();
230
- // async replacement
231
- void RunOnStreamMaybeCreateStream(std::function<void(QuicSpdyClientStream *)> finish);
232
-
233
- // Calls GetOrCreateStream(), sends the request on the stream, and
234
- // stores the request in case it needs to be resent. If |headers| is
235
- // null, only the body will be sent on the stream.
236
- void GetOrCreateStreamAndSendRequest(
237
- const spdy::Http2HeaderBlock *headers, absl::string_view body, bool fin);
238
-
239
- QuicRstStreamErrorCode stream_error() { return stream_error_; }
240
- QuicErrorCode connection_error() const;
241
-
242
- // Get the server config map. Server config must exist.
243
- const QuicTagValueMap &GetServerConfig();
244
-
245
- void set_auto_reconnect(bool reconnect) { auto_reconnect_ = reconnect; }
246
-
247
- void set_priority(QuicStreamPriority priority) { priority_ = priority; }
248
-
249
- void WaitForWriteToFlush();
250
-
251
- size_t num_requests() const { return num_requests_; }
252
-
253
- size_t num_responses() const { return num_responses_; }
254
-
255
- void set_server_address(const QuicSocketAddress &server_address)
256
- {
257
- server_address_ = server_address;
258
- }
259
-
260
- // Explicitly set the SNI value for this client, overriding the default
261
- // behavior which extracts the SNI value from the request URL.
262
- void OverrideSni(const std::string &sni)
263
- {
264
- override_sni_set_ = true;
265
- override_sni_ = sni;
266
- }
267
-
268
- void Initialize();
269
-
270
- // Given |uri|, populates the fields in |headers| for a simple GET
271
- // request. If |uri| is a relative URL, the QuicServerId will be
272
- // use to specify the authority.
273
- bool PopulateHeaderBlockFromUrl(const std::string &uri,
274
- spdy::Http2HeaderBlock *headers);
275
-
276
- QuicSpdyClientStream *latest_created_stream()
277
- {
278
- return latest_created_stream_;
279
- }
280
-
281
- Http3ClientJS *getJS() { return js_; };
282
-
283
- protected:
284
- Http3Client();
285
- Http3Client(const Http3Client &) = delete;
286
- Http3Client(const Http3Client &&) = delete;
287
- Http3Client &operator=(const Http3Client &) = delete;
288
- Http3Client &operator=(const Http3Client &&) = delete;
289
-
290
- // Subclasses may need to explicitly clear the session on destruction
291
- // if they create it with objects that will be destroyed before this is.
292
- // You probably want to call this if you override CreateQuicSpdyClientSession.
293
- void ResetSession() { session_.reset(); }
294
-
295
- void ClearDataToResend();
296
-
297
- private:
298
- class Http3ClientDataToResend
299
- {
300
- public:
301
- Http3ClientDataToResend(
302
- std::unique_ptr<spdy::Http2HeaderBlock> headers, absl::string_view body,
303
- bool fin, Http3Client *client);
304
-
305
- ~Http3ClientDataToResend();
306
-
307
- void Resend();
308
-
309
- protected:
310
- std::unique_ptr<spdy::Http2HeaderBlock> headers_;
311
- absl::string_view body_;
312
- bool fin_;
313
- Http3Client *client_;
314
- };
315
-
316
- // PerStreamState of a stream is updated when it is closed.
317
- struct PerStreamState
318
- {
319
- PerStreamState(const PerStreamState &other);
320
- PerStreamState(QuicRstStreamErrorCode stream_error, bool response_complete,
321
- bool response_headers_complete,
322
- const spdy::Http2HeaderBlock &response_headers,
323
- const absl::string_view response,
324
- const spdy::Http2HeaderBlock &response_trailers,
325
- uint64_t bytes_read, uint64_t bytes_written,
326
- int64_t response_body_size);
327
- ~PerStreamState();
328
-
329
- QuicRstStreamErrorCode stream_error;
330
- bool response_complete;
331
- bool response_headers_complete;
332
- spdy::Http2HeaderBlock response_headers;
333
- std::string response;
334
- spdy::Http2HeaderBlock response_trailers;
335
- uint64_t bytes_read;
336
- uint64_t bytes_written;
337
- int64_t response_body_size;
338
- };
339
-
340
- // Index of pending promised streams. Must outlive |session_|.
341
- QuicClientPushPromiseIndex push_promise_index_;
342
-
343
- // Returns true and set |version| if client can reconnect with a different
344
- // version.
345
- bool CanReconnectWithDifferentVersion(ParsedQuicVersion *version) const;
346
-
347
- std::unique_ptr<QuicPacketWriter> CreateWriterForNewNetwork(
348
- const QuicIpAddress &new_host, int port);
349
-
350
- // Returns true if the corresponding of this client has active requests.
351
- bool HasActiveRequests();
352
-
353
- ConnectionIdGeneratorInterface &connection_id_generator();
354
-
355
- // Actually clean up |fd|.
356
- void CleanUpUDPSocketImpl(QuicUdpSocketFd fd);
357
-
358
- bool clientInitialize();
359
-
360
- bool HaveActiveStream();
361
-
362
- bool handleConnecting();
363
-
364
- bool checkSession();
365
-
366
- // Read oldest received response and remove it from closed_stream_states_.
367
- // void ReadNextResponse();
368
-
369
- // Clear open_streams_, closed_stream_states_ and reset
370
- // latest_created_stream_.
371
- void ClearPerConnectionState();
372
-
373
- // Update latest_created_stream_, add |stream| to open_streams_ and starts
374
- // tracking its state.
375
- void SetLatestCreatedStream(QuicSpdyClientStream *stream);
376
-
377
- void openWTSessionInt(absl::string_view path);
378
-
379
- bool closeClientInt();
380
-
381
- void setJS(Http3ClientJS *js) { js_ = js; };
382
- Http3ClientJS *js_;
383
-
384
- QuicSpdyClientStream *latest_created_stream_;
385
- std::map<QuicStreamId, QuicSpdyClientStream *> open_streams_;
386
- // Received responses of closed streams.
387
- quiche::QuicheLinkedHashMap<QuicStreamId, PerStreamState>
388
- closed_stream_states_;
389
-
390
- // Map mapping created UDP sockets to their addresses. By using linked hash
391
- // map, the order of socket creation can be recorded.
392
- quiche::QuicheLinkedHashMap<int, QuicSocketAddress> fd_address_map_;
393
-
394
- QuicRstStreamErrorCode stream_error_;
395
-
396
- bool response_complete_;
397
- bool response_headers_complete_;
398
- mutable spdy::Http2HeaderBlock response_headers_;
399
-
400
- // Parsed response trailers (if present), copied from the stream in OnClose.
401
- spdy::Http2HeaderBlock response_trailers_;
402
-
403
- QuicStreamPriority priority_;
404
- std::string response_;
405
- // bytes_read_ and bytes_written_ are updated only when stream_ is released;
406
- // prefer bytes_read() and bytes_written() member functions.
407
- uint64_t bytes_read_;
408
- uint64_t bytes_written_;
409
- // The number of HTTP body bytes received.
410
- int64_t response_body_size_;
411
- // True if we tried to connect already since the last call to Disconnect().
412
- bool connect_attempted_;
413
- // The client will auto-connect exactly once before sending data. If
414
- // something causes a connection reset, it will not automatically reconnect
415
- // unless auto_reconnect_ is true.
416
- bool auto_reconnect_;
417
- // Should we buffer the response body? Defaults to true.
418
- bool buffer_body_;
419
- // For async push promise rendezvous, validation may fail in which
420
- // case the request should be retried.
421
- std::unique_ptr<Http3ClientDataToResend> push_promise_data_to_resend_;
422
-
423
- // Keeps track of any data that must be resent upon a subsequent successful
424
- // connection, in case the client receives a stateless reject.
425
- std::vector<std::unique_ptr<Http3ClientDataToResend>> data_to_resend_on_connect_;
426
-
427
- // Number of requests/responses this client has sent/received.
428
- size_t num_requests_;
429
- size_t num_responses_;
430
-
431
- // If set, this value is used for the connection SNI, overriding the usual
432
- // logic which extracts the SNI from the request URL.
433
- bool override_sni_set_ = false;
434
- std::string override_sni_;
435
-
436
- // from QuicClient
437
-
438
- // |server_id_| is a tuple (hostname, port, is_https) of the server.
439
- QuicServerId server_id_;
440
-
441
- // Tracks if the client is initialized to connect.
442
- bool initialized_;
443
-
444
- // Address of the server.
445
- QuicSocketAddress server_address_;
446
-
447
- // If initialized, the address to bind to.
448
- QuicIpAddress bind_to_address_;
449
-
450
- // Local port to bind to. Initialize to 0.
451
- int local_port_;
452
-
453
- // config_ and crypto_config_ contain configuration and cached state about
454
- // servers.
455
- QuicConfig config_;
456
- QuicCryptoClientConfig crypto_config_;
457
-
458
- // Helper to be used by created connections. Must outlive |session_|.
459
- std::unique_ptr<QuicConnectionHelperInterface> helper_;
460
-
461
- // Alarm factory to be used by created connections. Must outlive |session_|.
462
- std::unique_ptr<QuicAlarmFactory> alarm_factory_;
463
-
464
- // Writer used to actually send packets to the wire. Must outlive |session_|.
465
- std::unique_ptr<QuicPacketWriter> writer_;
466
-
467
- // Session which manages streams.
468
- std::unique_ptr<QuicSpdyClientSession> session_;
469
-
470
- // This vector contains QUIC versions which we currently support.
471
- // This should be ordered such that the highest supported version is the first
472
- // element, with subsequent elements in descending order (versions can be
473
- // skipped as necessary). We will always pick supported_versions_[0] as the
474
- // initial version to use.
475
- ParsedQuicVersionVector supported_versions_;
476
-
477
- // The initial value of maximum packet size of the connection. If set to
478
- // zero, the default is used.
479
- QuicByteCount initial_max_packet_length_;
480
-
481
- // The number of hellos sent during the current/latest connection.
482
- int num_sent_client_hellos_;
483
-
484
- // Used to store any errors that occurred with the overall connection (as
485
- // opposed to that associated with the last session object).
486
- QuicErrorCode connection_error_;
487
-
488
- // True when the client is attempting to connect. Set to false between a call
489
- // to Disconnect() and the subsequent call to StartConnect(). When
490
- // connected_or_attempting_connect_ is false, the session object corresponds
491
- // to the previous client-level connection.
492
- bool connected_or_attempting_connect_;
493
-
494
- // The debug visitor set on the connection right after it is constructed.
495
- // Not owned, must be valid for the lifetime of the QuicClientBase instance.
496
- QuicConnectionDebugVisitor *connection_debug_visitor_;
497
-
498
- // GenerateNewConnectionId creates a random connection ID of this length.
499
- // Defaults to 8.
500
- uint8_t server_connection_id_length_;
501
-
502
- // GetClientConnectionId creates a random connection ID of this length.
503
- // Defaults to 0.
504
- uint8_t client_connection_id_length_;
505
-
506
- // Stores validated paths.
507
- std::vector<std::unique_ptr<QuicPathValidationContext>> validated_paths_;
508
-
509
- // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
510
- // because the socket would otherwise overflow.
511
- bool overflow_supported_;
512
-
513
- // If overflow_supported_ is true, this will be the number of packets dropped
514
- // during the lifetime of the server.
515
- QuicPacketCount packets_dropped_;
516
-
517
- // If not zero, used to set client's max inbound header size before session
518
- // initialize.
519
- size_t max_inbound_header_list_size_ = 0;
520
-
521
- // If true, store the latest response code, headers, and body.
522
- bool store_response_;
523
- // HTTP response code from most recent response.
524
- int latest_response_code_;
525
- // HTTP/2 headers from most recent response.
526
- std::string latest_response_headers_;
527
- // preliminary 100 Continue HTTP/2 headers from most recent response, if any.
528
- std::string preliminary_response_headers_;
529
- // HTTP/2 headers from most recent response.
530
- spdy::Http2HeaderBlock latest_response_header_block_;
531
- // Body of most recent response.
532
- std::string latest_response_body_;
533
- // HTTP/2 trailers from most recent response.
534
- std::string latest_response_trailers_;
535
-
536
- int max_reads_per_loop_;
537
-
538
- // Point to a QuicPacketReader object on the heap. The reader allocates more
539
- // space than allowed on the stack.
540
- std::unique_ptr<QuicPacketReader> packet_reader_;
541
-
542
- DeterministicConnectionIdGenerator connection_id_generator_{
543
- kQuicDefaultConnectionIdLength};
544
-
545
- Http3EventLoop *eventloop_;
546
- // connection workflow
547
- bool wait_for_encryption_;
548
- bool connection_in_progress_;
549
- uint32_t num_attempts_connect_;
550
- bool webtransport_server_support_inform_;
551
-
552
- std::queue<std::function<void(QuicSpdyClientStream *)>> finish_stream_open_;
553
- };
554
-
555
- } // namespace quic
556
-
557
- #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_TEST_CLIENT_H_
@@ -1,65 +0,0 @@
1
- // modifications
2
- // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
3
- // Use of this source code is governed by a BSD-style license that can be
4
- // found in the LICENSE file.
5
-
6
- // original copyright, see LICENSE.chromium
7
- // Copyright (c) 2018 The Chromium Authors. All rights reserved.
8
- // Use of this source code is governed by a BSD-style license that can be
9
- // found in the LICENSE file.
10
-
11
- #include "src/http3clientsession.h"
12
-
13
- #include <utility>
14
-
15
- namespace quic
16
- {
17
-
18
- Http3ClientSession::Http3ClientSession(
19
- const QuicConfig &config, const ParsedQuicVersionVector &supported_versions,
20
- QuicConnection *connection, const QuicServerId &server_id,
21
- QuicCryptoClientConfig *crypto_config,
22
- QuicClientPushPromiseIndex *push_promise_index, bool drop_response_body)
23
- : Http3ClientSession(config, supported_versions, connection, server_id,
24
- crypto_config, push_promise_index,
25
- drop_response_body,
26
- /*enable_web_transport=*/false)
27
- {
28
- }
29
-
30
- Http3ClientSession::Http3ClientSession(
31
- const QuicConfig &config, const ParsedQuicVersionVector &supported_versions,
32
- QuicConnection *connection, const QuicServerId &server_id,
33
- QuicCryptoClientConfig *crypto_config,
34
- QuicClientPushPromiseIndex *push_promise_index, bool drop_response_body,
35
- bool enable_web_transport)
36
- : QuicSpdyClientSession(config, supported_versions, connection, server_id,
37
- crypto_config, push_promise_index),
38
- drop_response_body_(drop_response_body),
39
- enable_web_transport_(enable_web_transport) {}
40
-
41
- std::unique_ptr<QuicSpdyClientStream>
42
- Http3ClientSession::CreateClientStream()
43
- {
44
- auto stream = std::make_unique<Http3ClientStream>(
45
- GetNextOutgoingBidirectionalStreamId(), this, BIDIRECTIONAL,
46
- drop_response_body_);
47
- stream->set_on_interim_headers(on_interim_headers_);
48
- return stream;
49
- }
50
-
51
- WebTransportHttp3VersionSet Http3ClientSession::LocallySupportedWebTransportVersions()
52
- const
53
- {
54
- return enable_web_transport_
55
- ? kDefaultSupportedWebTransportVersions
56
- : WebTransportHttp3VersionSet();
57
- }
58
-
59
- HttpDatagramSupport Http3ClientSession::LocalHttpDatagramSupport()
60
- {
61
- return enable_web_transport_ ? HttpDatagramSupport::kRfcAndDraft04
62
- : HttpDatagramSupport::kNone;
63
- }
64
-
65
- } // namespace quic
@@ -1,60 +0,0 @@
1
- // modifications
2
- // Copyright (c) 2022 Marten Richter or other contributers (see commit). All rights reserved.
3
- // Use of this source code is governed by a BSD-style license that can be
4
- // found in the LICENSE file.
5
-
6
- // original copyright, see LICENSE.chromium
7
- // Copyright (c) 2018 The Chromium Authors. All rights reserved.
8
- // Use of this source code is governed by a BSD-style license that can be
9
- // found in the LICENSE file.
10
-
11
- #ifndef HTTP3_CLIENT_SESSION_H
12
- #define HTTP3_CLIENT_SESSION_H
13
-
14
- #include <functional>
15
- #include <utility>
16
-
17
- #include "quiche/quic/core/http/quic_spdy_client_session.h"
18
- #include "src/http3clientstream.h"
19
-
20
- namespace quic
21
- {
22
-
23
- class Http3ClientSession : public QuicSpdyClientSession
24
- {
25
- public:
26
- Http3ClientSession(const QuicConfig &config,
27
- const ParsedQuicVersionVector &supported_versions,
28
- QuicConnection *connection,
29
- const QuicServerId &server_id,
30
- QuicCryptoClientConfig *crypto_config,
31
- QuicClientPushPromiseIndex *push_promise_index,
32
- bool drop_response_body);
33
- Http3ClientSession(const QuicConfig &config,
34
- const ParsedQuicVersionVector &supported_versions,
35
- QuicConnection *connection,
36
- const QuicServerId &server_id,
37
- QuicCryptoClientConfig *crypto_config,
38
- QuicClientPushPromiseIndex *push_promise_index,
39
- bool drop_response_body, bool enable_web_transport);
40
-
41
- std::unique_ptr<QuicSpdyClientStream> CreateClientStream() override;
42
- WebTransportHttp3VersionSet LocallySupportedWebTransportVersions()
43
- const override;
44
- HttpDatagramSupport LocalHttpDatagramSupport() override;
45
-
46
- void set_on_interim_headers(
47
- std::function<void(const spdy::Http2HeaderBlock &)> on_interim_headers)
48
- {
49
- on_interim_headers_ = std::move(on_interim_headers);
50
- }
51
-
52
- private:
53
- std::function<void(const spdy::Http2HeaderBlock &)> on_interim_headers_;
54
- const bool drop_response_body_;
55
- const bool enable_web_transport_;
56
- };
57
-
58
- } // namespace quic
59
-
60
- #endif // QUICHE_QUIC_TOOLS_QUIC_SIMPLE_CLIENT_SESSION_H_