Skip to content

Commit bfe94aa

Browse files
committed
quic: update quic impl to use latest ngtcp2/nghttp3
1 parent 5a56f4d commit bfe94aa

File tree

14 files changed

+218
-186
lines changed

14 files changed

+218
-186
lines changed

src/quic/application.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ BaseObjectPtr<Packet> Session::Application::CreateStreamDataPacket() {
151151
return Packet::Create(env(),
152152
session_->endpoint_.get(),
153153
session_->remote_address_,
154-
ngtcp2_conn_get_max_udp_payload_size(*session_),
154+
ngtcp2_conn_get_max_tx_udp_payload_size(*session_),
155155
"stream data");
156156
}
157157

@@ -296,7 +296,7 @@ ssize_t Session::Application::WriteVStream(PathStorage* path,
296296
&path->path,
297297
nullptr,
298298
buf,
299-
ngtcp2_conn_get_max_udp_payload_size(*session_),
299+
ngtcp2_conn_get_max_tx_udp_payload_size(*session_),
300300
ndatalen,
301301
flags,
302302
stream_data.id,

src/quic/bindingdata.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Endpoint;
2323
class Packet;
2424

2525
enum class Side {
26-
CLIENT = NGTCP2_CRYPTO_SIDE_CLIENT,
27-
SERVER = NGTCP2_CRYPTO_SIDE_SERVER,
26+
CLIENT,
27+
SERVER,
2828
};
2929

3030
enum class EndpointLabel {
@@ -119,7 +119,6 @@ constexpr size_t kMaxVectorCount = 16;
119119
V(alpn, "alpn") \
120120
V(application_options, "application") \
121121
V(bbr, "bbr") \
122-
V(bbr2, "bbr2") \
123122
V(ca, "ca") \
124123
V(certs, "certs") \
125124
V(cc_algorithm, "cc") \

src/quic/data.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ std::string TypeName(QuicError::Type type) {
126126
} // namespace
127127

128128
QuicError::QuicError(const std::string_view reason)
129-
: reason_(reason), ptr_(&error_) {}
129+
: reason_(reason), error_(), ptr_(&error_) {
130+
ngtcp2_ccerr_default(&error_);
131+
}
130132

131-
QuicError::QuicError(const ngtcp2_connection_close_error* ptr)
133+
QuicError::QuicError(const ngtcp2_ccerr* ptr)
132134
: reason_(reinterpret_cast<const char*>(ptr->reason), ptr->reasonlen),
133135
ptr_(ptr) {}
134136

135-
QuicError::QuicError(const ngtcp2_connection_close_error& error)
137+
QuicError::QuicError(const ngtcp2_ccerr& error)
136138
: reason_(reinterpret_cast<const char*>(error.reason), error.reasonlen),
137139
error_(error),
138140
ptr_(&error_) {}
@@ -175,11 +177,11 @@ const std::string_view QuicError::reason() const {
175177
return reason_;
176178
}
177179

178-
QuicError::operator const ngtcp2_connection_close_error&() const {
180+
QuicError::operator const ngtcp2_ccerr&() const {
179181
return *ptr_;
180182
}
181183

182-
QuicError::operator const ngtcp2_connection_close_error*() const {
184+
QuicError::operator const ngtcp2_ccerr*() const {
183185
return ptr_;
184186
}
185187

@@ -212,15 +214,15 @@ void QuicError::MemoryInfo(MemoryTracker* tracker) const {
212214
QuicError QuicError::ForTransport(error_code code,
213215
const std::string_view reason) {
214216
QuicError error(reason);
215-
ngtcp2_connection_close_error_set_transport_error(
217+
ngtcp2_ccerr_set_transport_error(
216218
&error.error_, code, error.reason_c_str(), reason.length());
217219
return error;
218220
}
219221

220222
QuicError QuicError::ForApplication(error_code code,
221223
const std::string_view reason) {
222224
QuicError error(reason);
223-
ngtcp2_connection_close_error_set_application_error(
225+
ngtcp2_ccerr_set_application_error(
224226
&error.error_, code, error.reason_c_str(), reason.length());
225227
return error;
226228
}
@@ -235,22 +237,20 @@ QuicError QuicError::ForIdleClose(const std::string_view reason) {
235237

236238
QuicError QuicError::ForNgtcp2Error(int code, const std::string_view reason) {
237239
QuicError error(reason);
238-
ngtcp2_connection_close_error_set_transport_error_liberr(
240+
ngtcp2_ccerr_set_liberr(
239241
&error.error_, code, error.reason_c_str(), reason.length());
240242
return error;
241243
}
242244

243245
QuicError QuicError::ForTlsAlert(int code, const std::string_view reason) {
244246
QuicError error(reason);
245-
ngtcp2_connection_close_error_set_transport_error_tls_alert(
247+
ngtcp2_ccerr_set_tls_alert(
246248
&error.error_, code, error.reason_c_str(), reason.length());
247249
return error;
248250
}
249251

250252
QuicError QuicError::FromConnectionClose(ngtcp2_conn* session) {
251-
QuicError error;
252-
ngtcp2_conn_get_connection_close_error(session, &error.error_);
253-
return error;
253+
return QuicError(ngtcp2_conn_get_ccerr(session));
254254
}
255255

256256
QuicError QuicError::TRANSPORT_NO_ERROR =

src/quic/data.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,28 @@ class QuicError final : public MemoryRetainer {
7171
static constexpr error_code QUIC_APP_NO_ERROR = 65280;
7272

7373
enum class Type {
74-
TRANSPORT = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT,
75-
APPLICATION = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION,
76-
VERSION_NEGOTIATION =
77-
NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_VERSION_NEGOTIATION,
78-
IDLE_CLOSE = NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT_IDLE_CLOSE,
74+
TRANSPORT = NGTCP2_CCERR_TYPE_TRANSPORT,
75+
APPLICATION = NGTCP2_CCERR_TYPE_APPLICATION,
76+
VERSION_NEGOTIATION = NGTCP2_CCERR_TYPE_VERSION_NEGOTIATION,
77+
IDLE_CLOSE = NGTCP2_CCERR_TYPE_IDLE_CLOSE,
7978
};
8079

8180
static constexpr error_code QUIC_ERROR_TYPE_TRANSPORT =
82-
NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_TRANSPORT;
81+
NGTCP2_CCERR_TYPE_TRANSPORT;
8382
static constexpr error_code QUIC_ERROR_TYPE_APPLICATION =
84-
NGTCP2_CONNECTION_CLOSE_ERROR_CODE_TYPE_APPLICATION;
83+
NGTCP2_CCERR_TYPE_APPLICATION;
8584

8685
explicit QuicError(const std::string_view reason = "");
87-
explicit QuicError(const ngtcp2_connection_close_error* ptr);
88-
explicit QuicError(const ngtcp2_connection_close_error& error);
86+
explicit QuicError(const ngtcp2_ccerr* ptr);
87+
explicit QuicError(const ngtcp2_ccerr& error);
8988

9089
Type type() const;
9190
error_code code() const;
9291
const std::string_view reason() const;
9392
uint64_t frame_type() const;
9493

95-
operator const ngtcp2_connection_close_error&() const;
96-
operator const ngtcp2_connection_close_error*() const;
94+
operator const ngtcp2_ccerr&() const;
95+
operator const ngtcp2_ccerr*() const;
9796

9897
// Returns false if the QuicError uses a no_error code with type
9998
// transport or application.
@@ -130,8 +129,8 @@ class QuicError final : public MemoryRetainer {
130129
const uint8_t* reason_c_str() const;
131130

132131
std::string reason_;
133-
ngtcp2_connection_close_error error_ = ngtcp2_connection_close_error();
134-
const ngtcp2_connection_close_error* ptr_ = nullptr;
132+
ngtcp2_ccerr error_;
133+
const ngtcp2_ccerr* ptr_ = nullptr;
135134
};
136135

137136
} // namespace quic

src/quic/endpoint.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ namespace quic {
7373
#define ENDPOINT_CC(V) \
7474
V(RENO, reno) \
7575
V(CUBIC, cubic) \
76-
V(BBR, bbr) \
77-
V(BBR2, bbr2)
76+
V(BBR, bbr)
7877

7978
struct Endpoint::State {
8079
#define V(_, name, type) type name;
@@ -427,11 +426,11 @@ int Endpoint::UDP::Bind(const Endpoint::Options& options) {
427426
}
428427

429428
void Endpoint::UDP::Ref() {
430-
if (!is_closed()) uv_ref(reinterpret_cast<uv_handle_t*>(&impl_->handle_));
429+
if (!is_closed_or_closing()) uv_ref(reinterpret_cast<uv_handle_t*>(&impl_->handle_));
431430
}
432431

433432
void Endpoint::UDP::Unref() {
434-
if (!is_closed()) uv_unref(reinterpret_cast<uv_handle_t*>(&impl_->handle_));
433+
if (!is_closed_or_closing()) uv_unref(reinterpret_cast<uv_handle_t*>(&impl_->handle_));
435434
}
436435

437436
int Endpoint::UDP::Start() {
@@ -476,7 +475,7 @@ Endpoint::UDP::operator bool() const {
476475
}
477476

478477
SocketAddress Endpoint::UDP::local_address() const {
479-
DCHECK(!is_closed() && is_bound());
478+
DCHECK(!is_closed_or_closing() && is_bound());
480479
return SocketAddress::FromSockName(impl_->handle_);
481480
}
482481

@@ -1012,7 +1011,7 @@ void Endpoint::Receive(const uv_buf_t& buf,
10121011

10131012
if (options_.validate_address) {
10141013
// If there is no token, generate and send one.
1015-
if (hd.token.len == 0) {
1014+
if (hd.tokenlen == 0) {
10161015
SendRetry(PathDescriptor{
10171016
version,
10181017
dcid,
@@ -1027,9 +1026,9 @@ void Endpoint::Receive(const uv_buf_t& buf,
10271026

10281027
// We have two kinds of tokens, each prefixed with a different magic
10291028
// byte.
1030-
switch (hd.token.base[0]) {
1029+
switch (hd.token[0]) {
10311030
case RetryToken::kTokenMagic: {
1032-
RetryToken token(hd.token.base, hd.token.len);
1031+
RetryToken token(hd.token, hd.tokenlen);
10331032
auto ocid = token.Validate(
10341033
version,
10351034
remote_address,
@@ -1055,7 +1054,7 @@ void Endpoint::Receive(const uv_buf_t& buf,
10551054
break;
10561055
}
10571056
case RegularToken::kTokenMagic: {
1058-
RegularToken token(hd.token.base, hd.token.len);
1057+
RegularToken token(hd.token, hd.tokenlen);
10591058
if (!token.Validate(
10601059
version,
10611060
remote_address,
@@ -1072,8 +1071,8 @@ void Endpoint::Receive(const uv_buf_t& buf,
10721071
// if a retry is sent.
10731072
return true;
10741073
}
1075-
hd.token.base = nullptr;
1076-
hd.token.len = 0;
1074+
hd.token = nullptr;
1075+
hd.tokenlen = 0;
10771076
break;
10781077
}
10791078
default: {
@@ -1093,7 +1092,7 @@ void Endpoint::Receive(const uv_buf_t& buf,
10931092
// so we don't have to do this dance again for this endpoint
10941093
// instance.
10951094
addrLRU_.Upsert(remote_address)->validated = true;
1096-
} else if (hd.token.len > 0) {
1095+
} else if (hd.tokenlen > 0) {
10971096
// If validation is turned off and there is a token, that's weird.
10981097
// The peer should only have a token if we sent it to them and we
10991098
// wouldn't have sent it unless validation was turned on. Let's

src/quic/endpoint.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Endpoint final : public AsyncWrap, public Packet::Listener {
3636
static constexpr auto QUIC_CC_ALGO_RENO = NGTCP2_CC_ALGO_RENO;
3737
static constexpr auto QUIC_CC_ALGO_CUBIC = NGTCP2_CC_ALGO_CUBIC;
3838
static constexpr auto QUIC_CC_ALGO_BBR = NGTCP2_CC_ALGO_BBR;
39-
static constexpr auto QUIC_CC_ALGO_BBR2 = NGTCP2_CC_ALGO_BBR2;
4039

4140
// Endpoint configuration options
4241
struct Options final : public MemoryRetainer {
@@ -131,10 +130,10 @@ class Endpoint final : public AsyncWrap, public Packet::Listener {
131130
#endif // DEBUG
132131

133132
// There are several common congestion control algorithms that ngtcp2 uses
134-
// to determine how it manages the flow control window: RENO, CUBIC, BBR,
135-
// and BBR2. The details of how each works is not relevant here. The choice
136-
// of which to use by default is arbitrary and we can choose whichever we'd
137-
// like. Additional performance profiling will be needed to determine which
133+
// to determine how it manages the flow control window: RENO, CUBIC, and BBR.
134+
// The details of how each works is not relevant here. The choice of which to
135+
// use by default is arbitrary and we can choose whichever we'd like.
136+
// Additional performance profiling will be needed to determine which
138137
// is the better of the two for our needs.
139138
ngtcp2_cc_algo cc_algorithm = NGTCP2_CC_ALGO_CUBIC;
140139

src/quic/preferredaddress.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ std::optional<const PreferredAddress::AddressInfo> get_address_info(
2828
if (!paddr.ipv4_present) return std::nullopt;
2929
PreferredAddress::AddressInfo address;
3030
address.family = FAMILY;
31-
address.port = paddr.ipv4_port;
31+
address.port = paddr.ipv4.sin_port;
3232
if (uv_inet_ntop(
33-
FAMILY, paddr.ipv4_addr, address.host, sizeof(address.host)) == 0) {
33+
FAMILY, &paddr.ipv4.sin_addr, address.host, sizeof(address.host)) == 0) {
3434
address.address = address.host;
3535
}
3636
return address;
3737
} else {
3838
if (!paddr.ipv6_present) return std::nullopt;
3939
PreferredAddress::AddressInfo address;
4040
address.family = FAMILY;
41-
address.port = paddr.ipv6_port;
41+
address.port = paddr.ipv6.sin6_port;
4242
if (uv_inet_ntop(
43-
FAMILY, paddr.ipv6_addr, address.host, sizeof(address.host)) == 0) {
43+
FAMILY, &paddr.ipv6.sin6_addr, address.host, sizeof(address.host)) == 0) {
4444
address.address = address.host;
4545
}
4646
return address;
@@ -50,20 +50,20 @@ std::optional<const PreferredAddress::AddressInfo> get_address_info(
5050
template <int FAMILY>
5151
void copy_to_transport_params(ngtcp2_transport_params* params,
5252
const sockaddr* addr) {
53-
params->preferred_address_present = true;
53+
params->preferred_addr_present = true;
5454
if constexpr (FAMILY == AF_INET) {
5555
const sockaddr_in* src = reinterpret_cast<const sockaddr_in*>(addr);
56-
params->preferred_address.ipv4_port = SocketAddress::GetPort(addr);
57-
memcpy(params->preferred_address.ipv4_addr,
56+
params->preferred_addr.ipv4.sin_port = SocketAddress::GetPort(addr);
57+
memcpy(&params->preferred_addr.ipv4.sin_addr,
5858
&src->sin_addr,
59-
sizeof(params->preferred_address.ipv4_addr));
59+
sizeof(params->preferred_addr.ipv4.sin_addr));
6060
} else {
6161
DCHECK_EQ(FAMILY, AF_INET6);
6262
const sockaddr_in6* src = reinterpret_cast<const sockaddr_in6*>(addr);
63-
params->preferred_address.ipv6_port = SocketAddress::GetPort(addr);
64-
memcpy(params->preferred_address.ipv6_addr,
63+
params->preferred_addr.ipv6.sin6_port = SocketAddress::GetPort(addr);
64+
memcpy(&params->preferred_addr.ipv6.sin6_addr,
6565
&src->sin6_addr,
66-
sizeof(params->preferred_address.ipv4_addr));
66+
sizeof(params->preferred_addr.ipv4.sin_addr));
6767
}
6868
UNREACHABLE();
6969
}

0 commit comments

Comments
 (0)