Skip to content

Commit 1ae7f4b

Browse files
committed
quic: add scaffolding for http3 internals
1 parent 2057b2b commit 1ae7f4b

16 files changed

+1079
-154
lines changed

node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@
354354
'src/quic/cid.cc',
355355
'src/quic/data.cc',
356356
'src/quic/endpoint.cc',
357+
'src/quic/http3.cc',
357358
'src/quic/logstream.cc',
358359
'src/quic/packet.cc',
359360
'src/quic/preferredaddress.cc',
@@ -368,6 +369,7 @@
368369
'src/quic/cid.h',
369370
'src/quic/data.h',
370371
'src/quic/endpoint.h',
372+
'src/quic/http3.h',
371373
'src/quic/logstream.h',
372374
'src/quic/packet.h',
373375
'src/quic/preferredaddress.h',

src/quic/application.cc

+36-33
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC
22

33
#include "application.h"
4-
#include <debug_utils-inl.h>
54
#include <async_wrap-inl.h>
5+
#include <debug_utils-inl.h>
66
#include <node_bob.h>
77
#include <node_sockaddr-inl.h>
88
#include <uv.h>
99
#include <v8.h>
1010
#include "defs.h"
1111
#include "endpoint.h"
12+
#include "http3.h"
1213
#include "packet.h"
1314
#include "session.h"
1415

@@ -23,33 +24,20 @@ using v8::Value;
2324

2425
namespace quic {
2526

26-
struct Session::Application::StreamData final {
27-
// The actual number of vectors in the struct, up to kMaxVectorCount.
28-
size_t count = 0;
29-
size_t remaining = 0;
30-
// The stream identifier. If this is a negative value then no stream is
31-
// identified.
32-
int64_t id = -1;
33-
int fin = 0;
34-
ngtcp2_vec data[kMaxVectorCount]{};
35-
ngtcp2_vec* buf = data;
36-
BaseObjectPtr<Stream> stream;
37-
};
38-
3927
// ============================================================================
4028
// Session::Application_Options
4129
const Session::Application_Options Session::Application_Options::kDefault = {};
4230

4331
Session::Application_Options::operator const nghttp3_settings() const {
4432
// In theory, Application_Options might contain options for more than just
4533
// HTTP/3. Here we extract only the properties that are relevant to HTTP/3.
46-
return nghttp3_settings {
47-
max_field_section_size,
48-
qpack_max_dtable_capacity,
49-
qpack_encoder_max_dtable_capacity,
50-
qpack_blocked_streams,
51-
enable_connect_protocol,
52-
enable_datagrams,
34+
return nghttp3_settings{
35+
max_field_section_size,
36+
qpack_max_dtable_capacity,
37+
qpack_encoder_max_dtable_capacity,
38+
qpack_blocked_streams,
39+
enable_connect_protocol,
40+
enable_datagrams,
5341
};
5442
}
5543

@@ -59,13 +47,14 @@ std::string Session::Application_Options::ToString() const {
5947
std::string res("{");
6048
res += prefix + "max header pairs: " + std::to_string(max_header_pairs);
6149
res += prefix + "max header length: " + std::to_string(max_header_length);
62-
res += prefix + "max field section size: " +
63-
std::to_string(max_field_section_size);
50+
res += prefix +
51+
"max field section size: " + std::to_string(max_field_section_size);
6452
res += prefix + "qpack max dtable capacity: " +
6553
std::to_string(qpack_max_dtable_capacity);
6654
res += prefix + "qpack encoder max dtable capacity: " +
6755
std::to_string(qpack_encoder_max_dtable_capacity);
68-
res += prefix + "qpack blocked streams: " + std::to_string(qpack_blocked_streams);
56+
res += prefix +
57+
"qpack blocked streams: " + std::to_string(qpack_blocked_streams);
6958
res += prefix + "enable connect protocol: " +
7059
(enable_connect_protocol ? std::string("yes") : std::string("no"));
7160
res += prefix + "enable datagrams: " +
@@ -118,7 +107,10 @@ bool Session::Application::Start() {
118107

119108
void Session::Application::AcknowledgeStreamData(Stream* stream,
120109
size_t datalen) {
121-
Debug(session_, "Application acknowledging stream %" PRIi64 " data: %zu", stream->id(), datalen);
110+
Debug(session_,
111+
"Application acknowledging stream %" PRIi64 " data: %zu",
112+
stream->id(),
113+
datalen);
122114
DCHECK_NOT_NULL(stream);
123115
stream->Acknowledge(datalen);
124116
}
@@ -184,7 +176,8 @@ Session::Application::ExtractSessionTicketAppData(
184176
void Session::Application::SetStreamPriority(const Stream& stream,
185177
StreamPriority priority,
186178
StreamPriorityFlags flags) {
187-
Debug(session_, "Application setting stream %" PRIi64 " priority", stream.id());
179+
Debug(
180+
session_, "Application setting stream %" PRIi64 " priority", stream.id());
188181
// By default do nothing.
189182
}
190183

@@ -201,20 +194,29 @@ BaseObjectPtr<Packet> Session::Application::CreateStreamDataPacket() {
201194
}
202195

203196
void Session::Application::StreamClose(Stream* stream, QuicError error) {
204-
Debug(session_, "Application closing stream %" PRIi64 " with error %s", stream->id(), error);
197+
Debug(session_,
198+
"Application closing stream %" PRIi64 " with error %s",
199+
stream->id(),
200+
error);
205201
stream->Destroy(error);
206202
}
207203

208204
void Session::Application::StreamStopSending(Stream* stream, QuicError error) {
209-
Debug(session_, "Application stopping sending on stream %" PRIi64 " with error %s", stream->id(), error);
205+
Debug(session_,
206+
"Application stopping sending on stream %" PRIi64 " with error %s",
207+
stream->id(),
208+
error);
210209
DCHECK_NOT_NULL(stream);
211210
stream->ReceiveStopSending(error);
212211
}
213212

214213
void Session::Application::StreamReset(Stream* stream,
215214
uint64_t final_size,
216215
QuicError error) {
217-
Debug(session_, "Application resetting stream %" PRIi64 " with error %s", stream->id(), error);
216+
Debug(session_,
217+
"Application resetting stream %" PRIi64 " with error %s",
218+
stream->id(),
219+
error);
218220
stream->ReceiveStreamReset(final_size, error);
219221
}
220222

@@ -498,13 +500,14 @@ class DefaultApplication final : public Session::Application {
498500
};
499501

500502
std::unique_ptr<Session::Application> Session::select_application() {
501-
// if (config.options.crypto_options.alpn == NGHTTP3_ALPN_H3)
502-
// return std::make_unique<Http3>(session,
503-
// config.options.application_options);
504-
505503
// In the future, we may end up supporting additional QUIC protocols. As they
506504
// are added, extend the cases here to create and return them.
507505

506+
if (config_.options.tls_options.alpn == NGHTTP3_ALPN_H3) {
507+
Debug(this, "Selecting HTTP/3 application");
508+
return createHttp3Application(this, config_.options.application_options);
509+
}
510+
508511
Debug(this, "Selecting default application");
509512
return std::make_unique<DefaultApplication>(
510513
this, config_.options.application_options);

src/quic/application.h

+16
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class Session::Application : public MemoryRetainer {
118118
protected:
119119
inline Environment* env() const { return session_->env(); }
120120
inline Session& session() { return *session_; }
121+
inline const Session& session() const { return *session_; }
121122

122123
BaseObjectPtr<Packet> CreateStreamDataPacket();
123124

@@ -137,6 +138,21 @@ class Session::Application : public MemoryRetainer {
137138
Session* session_;
138139
};
139140

141+
struct Session::Application::StreamData final {
142+
// The actual number of vectors in the struct, up to kMaxVectorCount.
143+
size_t count = 0;
144+
size_t remaining = 0;
145+
// The stream identifier. If this is a negative value then no stream is
146+
// identified.
147+
int64_t id = -1;
148+
int fin = 0;
149+
ngtcp2_vec data[kMaxVectorCount]{};
150+
ngtcp2_vec* buf = data;
151+
BaseObjectPtr<Stream> stream;
152+
153+
inline operator nghttp3_vec() const { return {data[0].base, data[0].len}; }
154+
};
155+
140156
} // namespace quic
141157
} // namespace node
142158

src/quic/defs.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace quic {
1313
#define NGTCP2_ERR(V) (V != NGTCP2_SUCCESS)
1414
#define NGTCP2_OK(V) (V == NGTCP2_SUCCESS)
1515

16-
#define IF_QUIC_DEBUG(env) \
16+
#define IF_QUIC_DEBUG(env) \
1717
if (UNLIKELY(env->enabled_debug_list()->enabled(DebugCategory::QUIC)))
1818

1919
template <typename Opt, std::string Opt::*member>
@@ -169,6 +169,7 @@ class DebugIndentScope {
169169
res += "}";
170170
return res;
171171
}
172+
172173
private:
173174
static int indent_;
174175
};

0 commit comments

Comments
 (0)