QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. 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 | |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 5 | #include "quic/core/quic_config.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6 | |
| 7 | #include <algorithm> |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 8 | #include <cstring> |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 9 | #include <limits> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 10 | #include <string> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 11 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
vasilvv | 8f9591b | 2020-10-26 17:01:14 -0700 | [diff] [blame] | 13 | #include "absl/base/attributes.h" |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 14 | #include "absl/strings/string_view.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 15 | #include "quic/core/crypto/crypto_handshake_message.h" |
| 16 | #include "quic/core/crypto/crypto_protocol.h" |
| 17 | #include "quic/core/quic_connection_id.h" |
| 18 | #include "quic/core/quic_constants.h" |
| 19 | #include "quic/core/quic_socket_address_coder.h" |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 20 | #include "quic/core/quic_types.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 21 | #include "quic/core/quic_utils.h" |
| 22 | #include "quic/platform/api/quic_bug_tracker.h" |
| 23 | #include "quic/platform/api/quic_flag_utils.h" |
| 24 | #include "quic/platform/api/quic_flags.h" |
| 25 | #include "quic/platform/api/quic_logging.h" |
| 26 | #include "quic/platform/api/quic_socket_address.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | |
| 28 | namespace quic { |
| 29 | |
| 30 | // Reads the value corresponding to |name_| from |msg| into |out|. If the |
| 31 | // |name_| is absent in |msg| and |presence| is set to OPTIONAL |out| is set |
| 32 | // to |default_value|. |
| 33 | QuicErrorCode ReadUint32(const CryptoHandshakeMessage& msg, |
| 34 | QuicTag tag, |
| 35 | QuicConfigPresence presence, |
| 36 | uint32_t default_value, |
| 37 | uint32_t* out, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 38 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 39 | QUICHE_DCHECK(error_details != nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | QuicErrorCode error = msg.GetUint32(tag, out); |
| 41 | switch (error) { |
| 42 | case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 43 | if (presence == PRESENCE_REQUIRED) { |
| 44 | *error_details = "Missing " + QuicTagToString(tag); |
| 45 | break; |
| 46 | } |
| 47 | error = QUIC_NO_ERROR; |
| 48 | *out = default_value; |
| 49 | break; |
| 50 | case QUIC_NO_ERROR: |
| 51 | break; |
| 52 | default: |
| 53 | *error_details = "Bad " + QuicTagToString(tag); |
| 54 | break; |
| 55 | } |
| 56 | return error; |
| 57 | } |
| 58 | |
| 59 | QuicConfigValue::QuicConfigValue(QuicTag tag, QuicConfigPresence presence) |
| 60 | : tag_(tag), presence_(presence) {} |
| 61 | QuicConfigValue::~QuicConfigValue() {} |
| 62 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | QuicFixedUint32::QuicFixedUint32(QuicTag tag, QuicConfigPresence presence) |
| 64 | : QuicConfigValue(tag, presence), |
| 65 | has_send_value_(false), |
| 66 | has_receive_value_(false) {} |
| 67 | QuicFixedUint32::~QuicFixedUint32() {} |
| 68 | |
| 69 | bool QuicFixedUint32::HasSendValue() const { |
| 70 | return has_send_value_; |
| 71 | } |
| 72 | |
| 73 | uint32_t QuicFixedUint32::GetSendValue() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 74 | QUIC_BUG_IF(quic_bug_12743_1, !has_send_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | << "No send value to get for tag:" << QuicTagToString(tag_); |
| 76 | return send_value_; |
| 77 | } |
| 78 | |
| 79 | void QuicFixedUint32::SetSendValue(uint32_t value) { |
| 80 | has_send_value_ = true; |
| 81 | send_value_ = value; |
| 82 | } |
| 83 | |
| 84 | bool QuicFixedUint32::HasReceivedValue() const { |
| 85 | return has_receive_value_; |
| 86 | } |
| 87 | |
| 88 | uint32_t QuicFixedUint32::GetReceivedValue() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 89 | QUIC_BUG_IF(quic_bug_12743_2, !has_receive_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 90 | << "No receive value to get for tag:" << QuicTagToString(tag_); |
| 91 | return receive_value_; |
| 92 | } |
| 93 | |
| 94 | void QuicFixedUint32::SetReceivedValue(uint32_t value) { |
| 95 | has_receive_value_ = true; |
| 96 | receive_value_ = value; |
| 97 | } |
| 98 | |
| 99 | void QuicFixedUint32::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 100 | if (tag_ == 0) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 101 | QUIC_BUG(quic_bug_12743_3) |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 102 | << "This parameter does not support writing to CryptoHandshakeMessage"; |
| 103 | return; |
| 104 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 105 | if (has_send_value_) { |
| 106 | out->SetValue(tag_, send_value_); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | QuicErrorCode QuicFixedUint32::ProcessPeerHello( |
| 111 | const CryptoHandshakeMessage& peer_hello, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 112 | HelloType /*hello_type*/, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 113 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 114 | QUICHE_DCHECK(error_details != nullptr); |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 115 | if (tag_ == 0) { |
| 116 | *error_details = |
| 117 | "This parameter does not support reading from CryptoHandshakeMessage"; |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 118 | QUIC_BUG(quic_bug_10575_1) << *error_details; |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 119 | return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
| 120 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value_); |
| 122 | switch (error) { |
| 123 | case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 124 | if (presence_ == PRESENCE_OPTIONAL) { |
| 125 | return QUIC_NO_ERROR; |
| 126 | } |
| 127 | *error_details = "Missing " + QuicTagToString(tag_); |
| 128 | break; |
| 129 | case QUIC_NO_ERROR: |
| 130 | has_receive_value_ = true; |
| 131 | break; |
| 132 | default: |
| 133 | *error_details = "Bad " + QuicTagToString(tag_); |
| 134 | break; |
| 135 | } |
| 136 | return error; |
| 137 | } |
| 138 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 139 | QuicFixedUint62::QuicFixedUint62(QuicTag name, QuicConfigPresence presence) |
| 140 | : QuicConfigValue(name, presence), |
| 141 | has_send_value_(false), |
| 142 | has_receive_value_(false) {} |
| 143 | |
| 144 | QuicFixedUint62::~QuicFixedUint62() {} |
| 145 | |
| 146 | bool QuicFixedUint62::HasSendValue() const { |
| 147 | return has_send_value_; |
| 148 | } |
| 149 | |
| 150 | uint64_t QuicFixedUint62::GetSendValue() const { |
| 151 | if (!has_send_value_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 152 | QUIC_BUG(quic_bug_10575_2) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 153 | << "No send value to get for tag:" << QuicTagToString(tag_); |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | return send_value_; |
| 157 | } |
| 158 | |
| 159 | void QuicFixedUint62::SetSendValue(uint64_t value) { |
| 160 | if (value > kVarInt62MaxValue) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 161 | QUIC_BUG(quic_bug_10575_3) << "QuicFixedUint62 invalid value " << value; |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 162 | value = kVarInt62MaxValue; |
| 163 | } |
| 164 | has_send_value_ = true; |
| 165 | send_value_ = value; |
| 166 | } |
| 167 | |
| 168 | bool QuicFixedUint62::HasReceivedValue() const { |
| 169 | return has_receive_value_; |
| 170 | } |
| 171 | |
| 172 | uint64_t QuicFixedUint62::GetReceivedValue() const { |
| 173 | if (!has_receive_value_) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 174 | QUIC_BUG(quic_bug_10575_4) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 175 | << "No receive value to get for tag:" << QuicTagToString(tag_); |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | return receive_value_; |
| 179 | } |
| 180 | |
| 181 | void QuicFixedUint62::SetReceivedValue(uint64_t value) { |
| 182 | has_receive_value_ = true; |
| 183 | receive_value_ = value; |
| 184 | } |
| 185 | |
| 186 | void QuicFixedUint62::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
| 187 | if (!has_send_value_) { |
| 188 | return; |
| 189 | } |
| 190 | uint32_t send_value32; |
| 191 | if (send_value_ > std::numeric_limits<uint32_t>::max()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 192 | QUIC_BUG(quic_bug_10575_5) << "Attempting to send " << send_value_ |
| 193 | << " for tag:" << QuicTagToString(tag_); |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 194 | send_value32 = std::numeric_limits<uint32_t>::max(); |
| 195 | } else { |
| 196 | send_value32 = static_cast<uint32_t>(send_value_); |
| 197 | } |
| 198 | out->SetValue(tag_, send_value32); |
| 199 | } |
| 200 | |
| 201 | QuicErrorCode QuicFixedUint62::ProcessPeerHello( |
| 202 | const CryptoHandshakeMessage& peer_hello, |
| 203 | HelloType /*hello_type*/, |
| 204 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 205 | QUICHE_DCHECK(error_details != nullptr); |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 206 | uint32_t receive_value32; |
| 207 | QuicErrorCode error = peer_hello.GetUint32(tag_, &receive_value32); |
| 208 | // GetUint32 is guaranteed to always initialize receive_value32. |
| 209 | receive_value_ = receive_value32; |
| 210 | switch (error) { |
| 211 | case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 212 | if (presence_ == PRESENCE_OPTIONAL) { |
| 213 | return QUIC_NO_ERROR; |
| 214 | } |
| 215 | *error_details = "Missing " + QuicTagToString(tag_); |
| 216 | break; |
| 217 | case QUIC_NO_ERROR: |
| 218 | has_receive_value_ = true; |
| 219 | break; |
| 220 | default: |
| 221 | *error_details = "Bad " + QuicTagToString(tag_); |
| 222 | break; |
| 223 | } |
| 224 | return error; |
| 225 | } |
| 226 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 227 | QuicFixedStatelessResetToken::QuicFixedStatelessResetToken( |
| 228 | QuicTag tag, |
| 229 | QuicConfigPresence presence) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 230 | : QuicConfigValue(tag, presence), |
| 231 | has_send_value_(false), |
| 232 | has_receive_value_(false) {} |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 233 | QuicFixedStatelessResetToken::~QuicFixedStatelessResetToken() {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 234 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 235 | bool QuicFixedStatelessResetToken::HasSendValue() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 236 | return has_send_value_; |
| 237 | } |
| 238 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 239 | const StatelessResetToken& QuicFixedStatelessResetToken::GetSendValue() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 240 | QUIC_BUG_IF(quic_bug_12743_4, !has_send_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 241 | << "No send value to get for tag:" << QuicTagToString(tag_); |
| 242 | return send_value_; |
| 243 | } |
| 244 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 245 | void QuicFixedStatelessResetToken::SetSendValue( |
| 246 | const StatelessResetToken& value) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 247 | has_send_value_ = true; |
| 248 | send_value_ = value; |
| 249 | } |
| 250 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 251 | bool QuicFixedStatelessResetToken::HasReceivedValue() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 252 | return has_receive_value_; |
| 253 | } |
| 254 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 255 | const StatelessResetToken& QuicFixedStatelessResetToken::GetReceivedValue() |
| 256 | const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 257 | QUIC_BUG_IF(quic_bug_12743_5, !has_receive_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 258 | << "No receive value to get for tag:" << QuicTagToString(tag_); |
| 259 | return receive_value_; |
| 260 | } |
| 261 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 262 | void QuicFixedStatelessResetToken::SetReceivedValue( |
| 263 | const StatelessResetToken& value) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 264 | has_receive_value_ = true; |
| 265 | receive_value_ = value; |
| 266 | } |
| 267 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 268 | void QuicFixedStatelessResetToken::ToHandshakeMessage( |
| 269 | CryptoHandshakeMessage* out) const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 270 | if (has_send_value_) { |
| 271 | out->SetValue(tag_, send_value_); |
| 272 | } |
| 273 | } |
| 274 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 275 | QuicErrorCode QuicFixedStatelessResetToken::ProcessPeerHello( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 276 | const CryptoHandshakeMessage& peer_hello, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 277 | HelloType /*hello_type*/, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 278 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 279 | QUICHE_DCHECK(error_details != nullptr); |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 280 | QuicErrorCode error = |
| 281 | peer_hello.GetStatelessResetToken(tag_, &receive_value_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 282 | switch (error) { |
| 283 | case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 284 | if (presence_ == PRESENCE_OPTIONAL) { |
| 285 | return QUIC_NO_ERROR; |
| 286 | } |
| 287 | *error_details = "Missing " + QuicTagToString(tag_); |
| 288 | break; |
| 289 | case QUIC_NO_ERROR: |
| 290 | has_receive_value_ = true; |
| 291 | break; |
| 292 | default: |
| 293 | *error_details = "Bad " + QuicTagToString(tag_); |
| 294 | break; |
| 295 | } |
| 296 | return error; |
| 297 | } |
| 298 | |
| 299 | QuicFixedTagVector::QuicFixedTagVector(QuicTag name, |
| 300 | QuicConfigPresence presence) |
| 301 | : QuicConfigValue(name, presence), |
| 302 | has_send_values_(false), |
| 303 | has_receive_values_(false) {} |
| 304 | |
| 305 | QuicFixedTagVector::QuicFixedTagVector(const QuicFixedTagVector& other) = |
| 306 | default; |
| 307 | |
| 308 | QuicFixedTagVector::~QuicFixedTagVector() {} |
| 309 | |
| 310 | bool QuicFixedTagVector::HasSendValues() const { |
| 311 | return has_send_values_; |
| 312 | } |
| 313 | |
wub | bde76c3 | 2020-04-23 11:33:13 -0700 | [diff] [blame] | 314 | const QuicTagVector& QuicFixedTagVector::GetSendValues() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 315 | QUIC_BUG_IF(quic_bug_12743_6, !has_send_values_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | << "No send values to get for tag:" << QuicTagToString(tag_); |
| 317 | return send_values_; |
| 318 | } |
| 319 | |
| 320 | void QuicFixedTagVector::SetSendValues(const QuicTagVector& values) { |
| 321 | has_send_values_ = true; |
| 322 | send_values_ = values; |
| 323 | } |
| 324 | |
| 325 | bool QuicFixedTagVector::HasReceivedValues() const { |
| 326 | return has_receive_values_; |
| 327 | } |
| 328 | |
wub | bde76c3 | 2020-04-23 11:33:13 -0700 | [diff] [blame] | 329 | const QuicTagVector& QuicFixedTagVector::GetReceivedValues() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 330 | QUIC_BUG_IF(quic_bug_12743_7, !has_receive_values_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 331 | << "No receive value to get for tag:" << QuicTagToString(tag_); |
| 332 | return receive_values_; |
| 333 | } |
| 334 | |
| 335 | void QuicFixedTagVector::SetReceivedValues(const QuicTagVector& values) { |
| 336 | has_receive_values_ = true; |
| 337 | receive_values_ = values; |
| 338 | } |
| 339 | |
| 340 | void QuicFixedTagVector::ToHandshakeMessage(CryptoHandshakeMessage* out) const { |
| 341 | if (has_send_values_) { |
| 342 | out->SetVector(tag_, send_values_); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | QuicErrorCode QuicFixedTagVector::ProcessPeerHello( |
| 347 | const CryptoHandshakeMessage& peer_hello, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 348 | HelloType /*hello_type*/, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 349 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 350 | QUICHE_DCHECK(error_details != nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 351 | QuicTagVector values; |
| 352 | QuicErrorCode error = peer_hello.GetTaglist(tag_, &values); |
| 353 | switch (error) { |
| 354 | case QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND: |
| 355 | if (presence_ == PRESENCE_OPTIONAL) { |
| 356 | return QUIC_NO_ERROR; |
| 357 | } |
| 358 | *error_details = "Missing " + QuicTagToString(tag_); |
| 359 | break; |
| 360 | case QUIC_NO_ERROR: |
| 361 | QUIC_DVLOG(1) << "Received Connection Option tags from receiver."; |
| 362 | has_receive_values_ = true; |
| 363 | receive_values_.insert(receive_values_.end(), values.begin(), |
| 364 | values.end()); |
| 365 | break; |
| 366 | default: |
| 367 | *error_details = "Bad " + QuicTagToString(tag_); |
| 368 | break; |
| 369 | } |
| 370 | return error; |
| 371 | } |
| 372 | |
| 373 | QuicFixedSocketAddress::QuicFixedSocketAddress(QuicTag tag, |
| 374 | QuicConfigPresence presence) |
| 375 | : QuicConfigValue(tag, presence), |
| 376 | has_send_value_(false), |
| 377 | has_receive_value_(false) {} |
| 378 | |
| 379 | QuicFixedSocketAddress::~QuicFixedSocketAddress() {} |
| 380 | |
| 381 | bool QuicFixedSocketAddress::HasSendValue() const { |
| 382 | return has_send_value_; |
| 383 | } |
| 384 | |
| 385 | const QuicSocketAddress& QuicFixedSocketAddress::GetSendValue() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 386 | QUIC_BUG_IF(quic_bug_12743_8, !has_send_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 387 | << "No send value to get for tag:" << QuicTagToString(tag_); |
| 388 | return send_value_; |
| 389 | } |
| 390 | |
| 391 | void QuicFixedSocketAddress::SetSendValue(const QuicSocketAddress& value) { |
| 392 | has_send_value_ = true; |
| 393 | send_value_ = value; |
| 394 | } |
| 395 | |
| 396 | bool QuicFixedSocketAddress::HasReceivedValue() const { |
| 397 | return has_receive_value_; |
| 398 | } |
| 399 | |
| 400 | const QuicSocketAddress& QuicFixedSocketAddress::GetReceivedValue() const { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 401 | QUIC_BUG_IF(quic_bug_12743_9, !has_receive_value_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 402 | << "No receive value to get for tag:" << QuicTagToString(tag_); |
| 403 | return receive_value_; |
| 404 | } |
| 405 | |
| 406 | void QuicFixedSocketAddress::SetReceivedValue(const QuicSocketAddress& value) { |
| 407 | has_receive_value_ = true; |
| 408 | receive_value_ = value; |
| 409 | } |
| 410 | |
| 411 | void QuicFixedSocketAddress::ToHandshakeMessage( |
| 412 | CryptoHandshakeMessage* out) const { |
| 413 | if (has_send_value_) { |
| 414 | QuicSocketAddressCoder address_coder(send_value_); |
| 415 | out->SetStringPiece(tag_, address_coder.Encode()); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | QuicErrorCode QuicFixedSocketAddress::ProcessPeerHello( |
| 420 | const CryptoHandshakeMessage& peer_hello, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 421 | HelloType /*hello_type*/, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 422 | std::string* error_details) { |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 423 | absl::string_view address; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 424 | if (!peer_hello.GetStringPiece(tag_, &address)) { |
| 425 | if (presence_ == PRESENCE_REQUIRED) { |
| 426 | *error_details = "Missing " + QuicTagToString(tag_); |
| 427 | return QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND; |
| 428 | } |
| 429 | } else { |
| 430 | QuicSocketAddressCoder address_coder; |
| 431 | if (address_coder.Decode(address.data(), address.length())) { |
| 432 | SetReceivedValue( |
| 433 | QuicSocketAddress(address_coder.ip(), address_coder.port())); |
| 434 | } |
| 435 | } |
| 436 | return QUIC_NO_ERROR; |
| 437 | } |
| 438 | |
| 439 | QuicConfig::QuicConfig() |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 440 | : negotiated_(false), |
| 441 | max_time_before_crypto_handshake_(QuicTime::Delta::Zero()), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 442 | max_idle_time_before_crypto_handshake_(QuicTime::Delta::Zero()), |
| 443 | max_undecryptable_packets_(0), |
| 444 | connection_options_(kCOPT, PRESENCE_OPTIONAL), |
| 445 | client_connection_options_(kCLOP, PRESENCE_OPTIONAL), |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 446 | max_idle_timeout_to_send_(QuicTime::Delta::Infinite()), |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 447 | max_bidirectional_streams_(kMIBS, PRESENCE_REQUIRED), |
| 448 | max_unidirectional_streams_(kMIUS, PRESENCE_OPTIONAL), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 449 | bytes_for_connection_id_(kTCID, PRESENCE_OPTIONAL), |
| 450 | initial_round_trip_time_us_(kIRTT, PRESENCE_OPTIONAL), |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 451 | initial_max_stream_data_bytes_incoming_bidirectional_(0, |
| 452 | PRESENCE_OPTIONAL), |
| 453 | initial_max_stream_data_bytes_outgoing_bidirectional_(0, |
| 454 | PRESENCE_OPTIONAL), |
| 455 | initial_max_stream_data_bytes_unidirectional_(0, PRESENCE_OPTIONAL), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 456 | initial_stream_flow_control_window_bytes_(kSFCW, PRESENCE_OPTIONAL), |
| 457 | initial_session_flow_control_window_bytes_(kCFCW, PRESENCE_OPTIONAL), |
| 458 | connection_migration_disabled_(kNCMR, PRESENCE_OPTIONAL), |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 459 | key_update_supported_remotely_(false), |
| 460 | key_update_supported_locally_(false), |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 461 | alternate_server_address_ipv6_(kASAD, PRESENCE_OPTIONAL), |
| 462 | alternate_server_address_ipv4_(kASAD, PRESENCE_OPTIONAL), |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 463 | stateless_reset_token_(kSRST, PRESENCE_OPTIONAL), |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 464 | max_ack_delay_ms_(kMAD, PRESENCE_OPTIONAL), |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 465 | min_ack_delay_ms_(0, PRESENCE_OPTIONAL), |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 466 | ack_delay_exponent_(kADE, PRESENCE_OPTIONAL), |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 467 | max_udp_payload_size_(0, PRESENCE_OPTIONAL), |
dschinazi | 4673023 | 2020-05-07 10:01:21 -0700 | [diff] [blame] | 468 | max_datagram_frame_size_(0, PRESENCE_OPTIONAL), |
| 469 | active_connection_id_limit_(0, PRESENCE_OPTIONAL) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 470 | SetDefaults(); |
| 471 | } |
| 472 | |
| 473 | QuicConfig::QuicConfig(const QuicConfig& other) = default; |
| 474 | |
| 475 | QuicConfig::~QuicConfig() {} |
| 476 | |
| 477 | bool QuicConfig::SetInitialReceivedConnectionOptions( |
| 478 | const QuicTagVector& tags) { |
| 479 | if (HasReceivedConnectionOptions()) { |
| 480 | // If we have already received connection options (via handshake or due to |
| 481 | // a previous call), don't re-initialize. |
| 482 | return false; |
| 483 | } |
| 484 | connection_options_.SetReceivedValues(tags); |
| 485 | return true; |
| 486 | } |
| 487 | |
| 488 | void QuicConfig::SetConnectionOptionsToSend( |
| 489 | const QuicTagVector& connection_options) { |
| 490 | connection_options_.SetSendValues(connection_options); |
| 491 | } |
| 492 | |
| 493 | bool QuicConfig::HasReceivedConnectionOptions() const { |
| 494 | return connection_options_.HasReceivedValues(); |
| 495 | } |
| 496 | |
wub | bde76c3 | 2020-04-23 11:33:13 -0700 | [diff] [blame] | 497 | const QuicTagVector& QuicConfig::ReceivedConnectionOptions() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 498 | return connection_options_.GetReceivedValues(); |
| 499 | } |
| 500 | |
| 501 | bool QuicConfig::HasSendConnectionOptions() const { |
| 502 | return connection_options_.HasSendValues(); |
| 503 | } |
| 504 | |
wub | bde76c3 | 2020-04-23 11:33:13 -0700 | [diff] [blame] | 505 | const QuicTagVector& QuicConfig::SendConnectionOptions() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 506 | return connection_options_.GetSendValues(); |
| 507 | } |
| 508 | |
| 509 | bool QuicConfig::HasClientSentConnectionOption(QuicTag tag, |
| 510 | Perspective perspective) const { |
| 511 | if (perspective == Perspective::IS_SERVER) { |
| 512 | if (HasReceivedConnectionOptions() && |
| 513 | ContainsQuicTag(ReceivedConnectionOptions(), tag)) { |
| 514 | return true; |
| 515 | } |
| 516 | } else if (HasSendConnectionOptions() && |
| 517 | ContainsQuicTag(SendConnectionOptions(), tag)) { |
| 518 | return true; |
| 519 | } |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | void QuicConfig::SetClientConnectionOptions( |
| 524 | const QuicTagVector& client_connection_options) { |
| 525 | client_connection_options_.SetSendValues(client_connection_options); |
| 526 | } |
| 527 | |
| 528 | bool QuicConfig::HasClientRequestedIndependentOption( |
| 529 | QuicTag tag, |
| 530 | Perspective perspective) const { |
| 531 | if (perspective == Perspective::IS_SERVER) { |
| 532 | return (HasReceivedConnectionOptions() && |
| 533 | ContainsQuicTag(ReceivedConnectionOptions(), tag)); |
| 534 | } |
| 535 | |
| 536 | return (client_connection_options_.HasSendValues() && |
| 537 | ContainsQuicTag(client_connection_options_.GetSendValues(), tag)); |
| 538 | } |
| 539 | |
wub | d09f1a6 | 2020-05-04 06:57:40 -0700 | [diff] [blame] | 540 | const QuicTagVector& QuicConfig::ClientRequestedIndependentOptions( |
| 541 | Perspective perspective) const { |
| 542 | static const QuicTagVector* no_options = new QuicTagVector; |
| 543 | if (perspective == Perspective::IS_SERVER) { |
| 544 | return HasReceivedConnectionOptions() ? ReceivedConnectionOptions() |
| 545 | : *no_options; |
| 546 | } |
| 547 | |
| 548 | return client_connection_options_.HasSendValues() |
| 549 | ? client_connection_options_.GetSendValues() |
| 550 | : *no_options; |
| 551 | } |
| 552 | |
dschinazi | be284d1 | 2020-04-30 17:42:16 -0700 | [diff] [blame] | 553 | void QuicConfig::SetIdleNetworkTimeout(QuicTime::Delta idle_network_timeout) { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 554 | if (idle_network_timeout.ToMicroseconds() <= 0) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 555 | QUIC_BUG(quic_bug_10575_6) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 556 | << "Invalid idle network timeout " << idle_network_timeout; |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 557 | return; |
| 558 | } |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 559 | max_idle_timeout_to_send_ = idle_network_timeout; |
dschinazi | be284d1 | 2020-04-30 17:42:16 -0700 | [diff] [blame] | 560 | } |
| 561 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 562 | QuicTime::Delta QuicConfig::IdleNetworkTimeout() const { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 563 | // TODO(b/152032210) add a QUIC_BUG to ensure that is not called before we've |
| 564 | // received the peer's values. This is true in production code but not in all |
| 565 | // of our tests that use a fake QuicConfig. |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 566 | if (!received_max_idle_timeout_.has_value()) { |
| 567 | return max_idle_timeout_to_send_; |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 568 | } |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 569 | return received_max_idle_timeout_.value(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 570 | } |
| 571 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 572 | void QuicConfig::SetMaxBidirectionalStreamsToSend(uint32_t max_streams) { |
| 573 | max_bidirectional_streams_.SetSendValue(max_streams); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 574 | } |
| 575 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 576 | uint32_t QuicConfig::GetMaxBidirectionalStreamsToSend() const { |
| 577 | return max_bidirectional_streams_.GetSendValue(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 578 | } |
| 579 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 580 | bool QuicConfig::HasReceivedMaxBidirectionalStreams() const { |
| 581 | return max_bidirectional_streams_.HasReceivedValue(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 582 | } |
| 583 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 584 | uint32_t QuicConfig::ReceivedMaxBidirectionalStreams() const { |
| 585 | return max_bidirectional_streams_.GetReceivedValue(); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 586 | } |
| 587 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 588 | void QuicConfig::SetMaxUnidirectionalStreamsToSend(uint32_t max_streams) { |
| 589 | max_unidirectional_streams_.SetSendValue(max_streams); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 590 | } |
| 591 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 592 | uint32_t QuicConfig::GetMaxUnidirectionalStreamsToSend() const { |
| 593 | return max_unidirectional_streams_.GetSendValue(); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 594 | } |
| 595 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 596 | bool QuicConfig::HasReceivedMaxUnidirectionalStreams() const { |
| 597 | return max_unidirectional_streams_.HasReceivedValue(); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 598 | } |
| 599 | |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 600 | uint32_t QuicConfig::ReceivedMaxUnidirectionalStreams() const { |
| 601 | return max_unidirectional_streams_.GetReceivedValue(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 602 | } |
| 603 | |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 604 | void QuicConfig::SetMaxAckDelayToSendMs(uint32_t max_ack_delay_ms) { |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 605 | max_ack_delay_ms_.SetSendValue(max_ack_delay_ms); |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 606 | } |
| 607 | |
dschinazi | f67b5c5 | 2020-05-18 15:18:14 -0700 | [diff] [blame] | 608 | uint32_t QuicConfig::GetMaxAckDelayToSendMs() const { |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 609 | return max_ack_delay_ms_.GetSendValue(); |
| 610 | } |
| 611 | |
| 612 | bool QuicConfig::HasReceivedMaxAckDelayMs() const { |
| 613 | return max_ack_delay_ms_.HasReceivedValue(); |
| 614 | } |
| 615 | |
| 616 | uint32_t QuicConfig::ReceivedMaxAckDelayMs() const { |
| 617 | return max_ack_delay_ms_.GetReceivedValue(); |
| 618 | } |
| 619 | |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 620 | void QuicConfig::SetMinAckDelayMs(uint32_t min_ack_delay_ms) { |
| 621 | min_ack_delay_ms_.SetSendValue(min_ack_delay_ms); |
| 622 | } |
| 623 | |
| 624 | uint32_t QuicConfig::GetMinAckDelayToSendMs() const { |
| 625 | return min_ack_delay_ms_.GetSendValue(); |
| 626 | } |
| 627 | |
| 628 | bool QuicConfig::HasReceivedMinAckDelayMs() const { |
| 629 | return min_ack_delay_ms_.HasReceivedValue(); |
| 630 | } |
| 631 | |
| 632 | uint32_t QuicConfig::ReceivedMinAckDelayMs() const { |
| 633 | return min_ack_delay_ms_.GetReceivedValue(); |
| 634 | } |
| 635 | |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 636 | void QuicConfig::SetAckDelayExponentToSend(uint32_t exponent) { |
| 637 | ack_delay_exponent_.SetSendValue(exponent); |
| 638 | } |
| 639 | |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 640 | uint32_t QuicConfig::GetAckDelayExponentToSend() const { |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 641 | return ack_delay_exponent_.GetSendValue(); |
| 642 | } |
| 643 | |
| 644 | bool QuicConfig::HasReceivedAckDelayExponent() const { |
| 645 | return ack_delay_exponent_.HasReceivedValue(); |
| 646 | } |
| 647 | |
| 648 | uint32_t QuicConfig::ReceivedAckDelayExponent() const { |
| 649 | return ack_delay_exponent_.GetReceivedValue(); |
| 650 | } |
| 651 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 652 | void QuicConfig::SetMaxPacketSizeToSend(uint64_t max_udp_payload_size) { |
| 653 | max_udp_payload_size_.SetSendValue(max_udp_payload_size); |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 654 | } |
| 655 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 656 | uint64_t QuicConfig::GetMaxPacketSizeToSend() const { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 657 | return max_udp_payload_size_.GetSendValue(); |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | bool QuicConfig::HasReceivedMaxPacketSize() const { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 661 | return max_udp_payload_size_.HasReceivedValue(); |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 662 | } |
| 663 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 664 | uint64_t QuicConfig::ReceivedMaxPacketSize() const { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 665 | return max_udp_payload_size_.GetReceivedValue(); |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 666 | } |
| 667 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 668 | void QuicConfig::SetMaxDatagramFrameSizeToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 669 | uint64_t max_datagram_frame_size) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 670 | max_datagram_frame_size_.SetSendValue(max_datagram_frame_size); |
| 671 | } |
| 672 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 673 | uint64_t QuicConfig::GetMaxDatagramFrameSizeToSend() const { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 674 | return max_datagram_frame_size_.GetSendValue(); |
| 675 | } |
| 676 | |
| 677 | bool QuicConfig::HasReceivedMaxDatagramFrameSize() const { |
| 678 | return max_datagram_frame_size_.HasReceivedValue(); |
| 679 | } |
| 680 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 681 | uint64_t QuicConfig::ReceivedMaxDatagramFrameSize() const { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 682 | return max_datagram_frame_size_.GetReceivedValue(); |
| 683 | } |
| 684 | |
dschinazi | 4673023 | 2020-05-07 10:01:21 -0700 | [diff] [blame] | 685 | void QuicConfig::SetActiveConnectionIdLimitToSend( |
| 686 | uint64_t active_connection_id_limit) { |
| 687 | active_connection_id_limit_.SetSendValue(active_connection_id_limit); |
| 688 | } |
| 689 | |
| 690 | uint64_t QuicConfig::GetActiveConnectionIdLimitToSend() const { |
| 691 | return active_connection_id_limit_.GetSendValue(); |
| 692 | } |
| 693 | |
| 694 | bool QuicConfig::HasReceivedActiveConnectionIdLimit() const { |
| 695 | return active_connection_id_limit_.HasReceivedValue(); |
| 696 | } |
| 697 | |
| 698 | uint64_t QuicConfig::ReceivedActiveConnectionIdLimit() const { |
| 699 | return active_connection_id_limit_.GetReceivedValue(); |
| 700 | } |
| 701 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 702 | bool QuicConfig::HasSetBytesForConnectionIdToSend() const { |
| 703 | return bytes_for_connection_id_.HasSendValue(); |
| 704 | } |
| 705 | |
| 706 | void QuicConfig::SetBytesForConnectionIdToSend(uint32_t bytes) { |
| 707 | bytes_for_connection_id_.SetSendValue(bytes); |
| 708 | } |
| 709 | |
| 710 | bool QuicConfig::HasReceivedBytesForConnectionId() const { |
| 711 | return bytes_for_connection_id_.HasReceivedValue(); |
| 712 | } |
| 713 | |
| 714 | uint32_t QuicConfig::ReceivedBytesForConnectionId() const { |
| 715 | return bytes_for_connection_id_.GetReceivedValue(); |
| 716 | } |
| 717 | |
dschinazi | 7e51f6b | 2020-05-13 17:36:44 -0700 | [diff] [blame] | 718 | void QuicConfig::SetInitialRoundTripTimeUsToSend(uint64_t rtt) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 719 | initial_round_trip_time_us_.SetSendValue(rtt); |
| 720 | } |
| 721 | |
| 722 | bool QuicConfig::HasReceivedInitialRoundTripTimeUs() const { |
| 723 | return initial_round_trip_time_us_.HasReceivedValue(); |
| 724 | } |
| 725 | |
dschinazi | 7e51f6b | 2020-05-13 17:36:44 -0700 | [diff] [blame] | 726 | uint64_t QuicConfig::ReceivedInitialRoundTripTimeUs() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 727 | return initial_round_trip_time_us_.GetReceivedValue(); |
| 728 | } |
| 729 | |
| 730 | bool QuicConfig::HasInitialRoundTripTimeUsToSend() const { |
| 731 | return initial_round_trip_time_us_.HasSendValue(); |
| 732 | } |
| 733 | |
dschinazi | 7e51f6b | 2020-05-13 17:36:44 -0700 | [diff] [blame] | 734 | uint64_t QuicConfig::GetInitialRoundTripTimeUsToSend() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 735 | return initial_round_trip_time_us_.GetSendValue(); |
| 736 | } |
| 737 | |
| 738 | void QuicConfig::SetInitialStreamFlowControlWindowToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 739 | uint64_t window_bytes) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 740 | if (window_bytes < kMinimumFlowControlSendWindow) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 741 | QUIC_BUG(quic_bug_10575_7) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 742 | << "Initial stream flow control receive window (" << window_bytes |
| 743 | << ") cannot be set lower than minimum (" |
| 744 | << kMinimumFlowControlSendWindow << ")."; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 745 | window_bytes = kMinimumFlowControlSendWindow; |
| 746 | } |
| 747 | initial_stream_flow_control_window_bytes_.SetSendValue(window_bytes); |
| 748 | } |
| 749 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 750 | uint64_t QuicConfig::GetInitialStreamFlowControlWindowToSend() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 751 | return initial_stream_flow_control_window_bytes_.GetSendValue(); |
| 752 | } |
| 753 | |
| 754 | bool QuicConfig::HasReceivedInitialStreamFlowControlWindowBytes() const { |
| 755 | return initial_stream_flow_control_window_bytes_.HasReceivedValue(); |
| 756 | } |
| 757 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 758 | uint64_t QuicConfig::ReceivedInitialStreamFlowControlWindowBytes() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 759 | return initial_stream_flow_control_window_bytes_.GetReceivedValue(); |
| 760 | } |
| 761 | |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 762 | void QuicConfig::SetInitialMaxStreamDataBytesIncomingBidirectionalToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 763 | uint64_t window_bytes) { |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 764 | initial_max_stream_data_bytes_incoming_bidirectional_.SetSendValue( |
| 765 | window_bytes); |
| 766 | } |
| 767 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 768 | uint64_t QuicConfig::GetInitialMaxStreamDataBytesIncomingBidirectionalToSend() |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 769 | const { |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 770 | if (initial_max_stream_data_bytes_incoming_bidirectional_.HasSendValue()) { |
| 771 | return initial_max_stream_data_bytes_incoming_bidirectional_.GetSendValue(); |
| 772 | } |
| 773 | return initial_stream_flow_control_window_bytes_.GetSendValue(); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | bool QuicConfig::HasReceivedInitialMaxStreamDataBytesIncomingBidirectional() |
| 777 | const { |
| 778 | return initial_max_stream_data_bytes_incoming_bidirectional_ |
| 779 | .HasReceivedValue(); |
| 780 | } |
| 781 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 782 | uint64_t QuicConfig::ReceivedInitialMaxStreamDataBytesIncomingBidirectional() |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 783 | const { |
| 784 | return initial_max_stream_data_bytes_incoming_bidirectional_ |
| 785 | .GetReceivedValue(); |
| 786 | } |
| 787 | |
| 788 | void QuicConfig::SetInitialMaxStreamDataBytesOutgoingBidirectionalToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 789 | uint64_t window_bytes) { |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 790 | initial_max_stream_data_bytes_outgoing_bidirectional_.SetSendValue( |
| 791 | window_bytes); |
| 792 | } |
| 793 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 794 | uint64_t QuicConfig::GetInitialMaxStreamDataBytesOutgoingBidirectionalToSend() |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 795 | const { |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 796 | if (initial_max_stream_data_bytes_outgoing_bidirectional_.HasSendValue()) { |
| 797 | return initial_max_stream_data_bytes_outgoing_bidirectional_.GetSendValue(); |
| 798 | } |
| 799 | return initial_stream_flow_control_window_bytes_.GetSendValue(); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | bool QuicConfig::HasReceivedInitialMaxStreamDataBytesOutgoingBidirectional() |
| 803 | const { |
| 804 | return initial_max_stream_data_bytes_outgoing_bidirectional_ |
| 805 | .HasReceivedValue(); |
| 806 | } |
| 807 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 808 | uint64_t QuicConfig::ReceivedInitialMaxStreamDataBytesOutgoingBidirectional() |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 809 | const { |
| 810 | return initial_max_stream_data_bytes_outgoing_bidirectional_ |
| 811 | .GetReceivedValue(); |
| 812 | } |
| 813 | |
| 814 | void QuicConfig::SetInitialMaxStreamDataBytesUnidirectionalToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 815 | uint64_t window_bytes) { |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 816 | initial_max_stream_data_bytes_unidirectional_.SetSendValue(window_bytes); |
| 817 | } |
| 818 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 819 | uint64_t QuicConfig::GetInitialMaxStreamDataBytesUnidirectionalToSend() const { |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 820 | if (initial_max_stream_data_bytes_unidirectional_.HasSendValue()) { |
| 821 | return initial_max_stream_data_bytes_unidirectional_.GetSendValue(); |
| 822 | } |
| 823 | return initial_stream_flow_control_window_bytes_.GetSendValue(); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | bool QuicConfig::HasReceivedInitialMaxStreamDataBytesUnidirectional() const { |
| 827 | return initial_max_stream_data_bytes_unidirectional_.HasReceivedValue(); |
| 828 | } |
| 829 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 830 | uint64_t QuicConfig::ReceivedInitialMaxStreamDataBytesUnidirectional() const { |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 831 | return initial_max_stream_data_bytes_unidirectional_.GetReceivedValue(); |
| 832 | } |
| 833 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 834 | void QuicConfig::SetInitialSessionFlowControlWindowToSend( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 835 | uint64_t window_bytes) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 836 | if (window_bytes < kMinimumFlowControlSendWindow) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 837 | QUIC_BUG(quic_bug_10575_8) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 838 | << "Initial session flow control receive window (" << window_bytes |
| 839 | << ") cannot be set lower than default (" |
| 840 | << kMinimumFlowControlSendWindow << ")."; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 841 | window_bytes = kMinimumFlowControlSendWindow; |
| 842 | } |
| 843 | initial_session_flow_control_window_bytes_.SetSendValue(window_bytes); |
| 844 | } |
| 845 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 846 | uint64_t QuicConfig::GetInitialSessionFlowControlWindowToSend() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 847 | return initial_session_flow_control_window_bytes_.GetSendValue(); |
| 848 | } |
| 849 | |
| 850 | bool QuicConfig::HasReceivedInitialSessionFlowControlWindowBytes() const { |
| 851 | return initial_session_flow_control_window_bytes_.HasReceivedValue(); |
| 852 | } |
| 853 | |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 854 | uint64_t QuicConfig::ReceivedInitialSessionFlowControlWindowBytes() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 855 | return initial_session_flow_control_window_bytes_.GetReceivedValue(); |
| 856 | } |
| 857 | |
| 858 | void QuicConfig::SetDisableConnectionMigration() { |
| 859 | connection_migration_disabled_.SetSendValue(1); |
| 860 | } |
| 861 | |
| 862 | bool QuicConfig::DisableConnectionMigration() const { |
| 863 | return connection_migration_disabled_.HasReceivedValue(); |
| 864 | } |
| 865 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 866 | void QuicConfig::SetKeyUpdateSupportedLocally() { |
| 867 | key_update_supported_locally_ = true; |
| 868 | } |
| 869 | |
| 870 | bool QuicConfig::KeyUpdateSupportedForConnection() const { |
mattm | f7f203a | 2020-10-23 12:19:32 -0700 | [diff] [blame] | 871 | return KeyUpdateSupportedRemotely() && KeyUpdateSupportedLocally(); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | bool QuicConfig::KeyUpdateSupportedLocally() const { |
| 875 | return key_update_supported_locally_; |
| 876 | } |
| 877 | |
mattm | f7f203a | 2020-10-23 12:19:32 -0700 | [diff] [blame] | 878 | bool QuicConfig::KeyUpdateSupportedRemotely() const { |
| 879 | return key_update_supported_remotely_; |
| 880 | } |
| 881 | |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 882 | void QuicConfig::SetIPv6AlternateServerAddressToSend( |
| 883 | const QuicSocketAddress& alternate_server_address_ipv6) { |
| 884 | if (!alternate_server_address_ipv6.host().IsIPv6()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 885 | QUIC_BUG(quic_bug_10575_9) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 886 | << "Cannot use SetIPv6AlternateServerAddressToSend with " |
| 887 | << alternate_server_address_ipv6; |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 888 | return; |
| 889 | } |
| 890 | alternate_server_address_ipv6_.SetSendValue(alternate_server_address_ipv6); |
| 891 | } |
| 892 | |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 893 | void QuicConfig::SetIPv6AlternateServerAddressToSend( |
| 894 | const QuicSocketAddress& alternate_server_address_ipv6, |
| 895 | const QuicConnectionId& connection_id, |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 896 | const StatelessResetToken& stateless_reset_token) { |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 897 | if (!alternate_server_address_ipv6.host().IsIPv6()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 898 | QUIC_BUG(quic_bug_10575_10) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 899 | << "Cannot use SetIPv6AlternateServerAddressToSend with " |
| 900 | << alternate_server_address_ipv6; |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 901 | return; |
| 902 | } |
| 903 | alternate_server_address_ipv6_.SetSendValue(alternate_server_address_ipv6); |
| 904 | preferred_address_connection_id_and_token_ = |
| 905 | std::make_pair(connection_id, stateless_reset_token); |
| 906 | } |
| 907 | |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 908 | bool QuicConfig::HasReceivedIPv6AlternateServerAddress() const { |
| 909 | return alternate_server_address_ipv6_.HasReceivedValue(); |
| 910 | } |
| 911 | |
| 912 | const QuicSocketAddress& QuicConfig::ReceivedIPv6AlternateServerAddress() |
| 913 | const { |
| 914 | return alternate_server_address_ipv6_.GetReceivedValue(); |
| 915 | } |
| 916 | |
| 917 | void QuicConfig::SetIPv4AlternateServerAddressToSend( |
| 918 | const QuicSocketAddress& alternate_server_address_ipv4) { |
| 919 | if (!alternate_server_address_ipv4.host().IsIPv4()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 920 | QUIC_BUG(quic_bug_10575_11) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 921 | << "Cannot use SetIPv4AlternateServerAddressToSend with " |
| 922 | << alternate_server_address_ipv4; |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | alternate_server_address_ipv4_.SetSendValue(alternate_server_address_ipv4); |
| 926 | } |
| 927 | |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 928 | void QuicConfig::SetIPv4AlternateServerAddressToSend( |
| 929 | const QuicSocketAddress& alternate_server_address_ipv4, |
| 930 | const QuicConnectionId& connection_id, |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 931 | const StatelessResetToken& stateless_reset_token) { |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 932 | if (!alternate_server_address_ipv4.host().IsIPv4()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 933 | QUIC_BUG(quic_bug_10575_12) |
QUICHE team | 5c9cddc | 2021-03-09 15:52:30 -0800 | [diff] [blame] | 934 | << "Cannot use SetIPv4AlternateServerAddressToSend with " |
| 935 | << alternate_server_address_ipv4; |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | alternate_server_address_ipv4_.SetSendValue(alternate_server_address_ipv4); |
| 939 | preferred_address_connection_id_and_token_ = |
| 940 | std::make_pair(connection_id, stateless_reset_token); |
| 941 | } |
| 942 | |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 943 | bool QuicConfig::HasReceivedIPv4AlternateServerAddress() const { |
| 944 | return alternate_server_address_ipv4_.HasReceivedValue(); |
| 945 | } |
| 946 | |
| 947 | const QuicSocketAddress& QuicConfig::ReceivedIPv4AlternateServerAddress() |
| 948 | const { |
| 949 | return alternate_server_address_ipv4_.GetReceivedValue(); |
| 950 | } |
| 951 | |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 952 | bool QuicConfig::HasReceivedPreferredAddressConnectionIdAndToken() const { |
| 953 | return (HasReceivedIPv6AlternateServerAddress() || |
| 954 | HasReceivedIPv4AlternateServerAddress()) && |
| 955 | preferred_address_connection_id_and_token_.has_value(); |
| 956 | } |
| 957 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 958 | const std::pair<QuicConnectionId, StatelessResetToken>& |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 959 | QuicConfig::ReceivedPreferredAddressConnectionIdAndToken() const { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 960 | QUICHE_DCHECK(HasReceivedPreferredAddressConnectionIdAndToken()); |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 961 | return *preferred_address_connection_id_and_token_; |
| 962 | } |
| 963 | |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 964 | void QuicConfig::SetOriginalConnectionIdToSend( |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 965 | const QuicConnectionId& original_destination_connection_id) { |
| 966 | original_destination_connection_id_to_send_ = |
| 967 | original_destination_connection_id; |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | bool QuicConfig::HasReceivedOriginalConnectionId() const { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 971 | return received_original_destination_connection_id_.has_value(); |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | QuicConnectionId QuicConfig::ReceivedOriginalConnectionId() const { |
| 975 | if (!HasReceivedOriginalConnectionId()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 976 | QUIC_BUG(quic_bug_10575_13) << "No received original connection ID"; |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 977 | return EmptyQuicConnectionId(); |
| 978 | } |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 979 | return received_original_destination_connection_id_.value(); |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 980 | } |
| 981 | |
dschinazi | d7beb60 | 2020-05-28 16:47:21 -0700 | [diff] [blame] | 982 | void QuicConfig::SetInitialSourceConnectionIdToSend( |
| 983 | const QuicConnectionId& initial_source_connection_id) { |
| 984 | initial_source_connection_id_to_send_ = initial_source_connection_id; |
| 985 | } |
| 986 | |
| 987 | bool QuicConfig::HasReceivedInitialSourceConnectionId() const { |
| 988 | return received_initial_source_connection_id_.has_value(); |
| 989 | } |
| 990 | |
| 991 | QuicConnectionId QuicConfig::ReceivedInitialSourceConnectionId() const { |
| 992 | if (!HasReceivedInitialSourceConnectionId()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 993 | QUIC_BUG(quic_bug_10575_14) << "No received initial source connection ID"; |
dschinazi | d7beb60 | 2020-05-28 16:47:21 -0700 | [diff] [blame] | 994 | return EmptyQuicConnectionId(); |
| 995 | } |
| 996 | return received_initial_source_connection_id_.value(); |
| 997 | } |
| 998 | |
| 999 | void QuicConfig::SetRetrySourceConnectionIdToSend( |
| 1000 | const QuicConnectionId& retry_source_connection_id) { |
| 1001 | retry_source_connection_id_to_send_ = retry_source_connection_id; |
| 1002 | } |
| 1003 | |
| 1004 | bool QuicConfig::HasReceivedRetrySourceConnectionId() const { |
| 1005 | return received_retry_source_connection_id_.has_value(); |
| 1006 | } |
| 1007 | |
| 1008 | QuicConnectionId QuicConfig::ReceivedRetrySourceConnectionId() const { |
| 1009 | if (!HasReceivedRetrySourceConnectionId()) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 1010 | QUIC_BUG(quic_bug_10575_15) << "No received retry source connection ID"; |
dschinazi | d7beb60 | 2020-05-28 16:47:21 -0700 | [diff] [blame] | 1011 | return EmptyQuicConnectionId(); |
| 1012 | } |
| 1013 | return received_retry_source_connection_id_.value(); |
| 1014 | } |
| 1015 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1016 | void QuicConfig::SetStatelessResetTokenToSend( |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 1017 | const StatelessResetToken& stateless_reset_token) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1018 | stateless_reset_token_.SetSendValue(stateless_reset_token); |
| 1019 | } |
| 1020 | |
| 1021 | bool QuicConfig::HasReceivedStatelessResetToken() const { |
| 1022 | return stateless_reset_token_.HasReceivedValue(); |
| 1023 | } |
| 1024 | |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 1025 | const StatelessResetToken& QuicConfig::ReceivedStatelessResetToken() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1026 | return stateless_reset_token_.GetReceivedValue(); |
| 1027 | } |
| 1028 | |
| 1029 | bool QuicConfig::negotiated() const { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1030 | return negotiated_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | void QuicConfig::SetCreateSessionTagIndicators(QuicTagVector tags) { |
| 1034 | create_session_tag_indicators_ = std::move(tags); |
| 1035 | } |
| 1036 | |
| 1037 | const QuicTagVector& QuicConfig::create_session_tag_indicators() const { |
| 1038 | return create_session_tag_indicators_; |
| 1039 | } |
| 1040 | |
| 1041 | void QuicConfig::SetDefaults() { |
dschinazi | 027366e | 2020-05-01 14:31:19 -0700 | [diff] [blame] | 1042 | SetIdleNetworkTimeout(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs)); |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1043 | SetMaxBidirectionalStreamsToSend(kDefaultMaxStreamsPerConnection); |
| 1044 | SetMaxUnidirectionalStreamsToSend(kDefaultMaxStreamsPerConnection); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1045 | max_time_before_crypto_handshake_ = |
| 1046 | QuicTime::Delta::FromSeconds(kMaxTimeForCryptoHandshakeSecs); |
| 1047 | max_idle_time_before_crypto_handshake_ = |
| 1048 | QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs); |
| 1049 | max_undecryptable_packets_ = kDefaultMaxUndecryptablePackets; |
| 1050 | |
| 1051 | SetInitialStreamFlowControlWindowToSend(kMinimumFlowControlSendWindow); |
| 1052 | SetInitialSessionFlowControlWindowToSend(kMinimumFlowControlSendWindow); |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 1053 | SetMaxAckDelayToSendMs(kDefaultDelayedAckTimeMs); |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 1054 | SetAckDelayExponentToSend(kDefaultAckDelayExponent); |
dschinazi | 5888113 | 2019-11-11 11:34:02 -0800 | [diff] [blame] | 1055 | SetMaxPacketSizeToSend(kMaxIncomingPacketSize); |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 1056 | SetMaxDatagramFrameSizeToSend(kMaxAcceptedDatagramFrameSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1057 | } |
| 1058 | |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 1059 | void QuicConfig::ToHandshakeMessage( |
| 1060 | CryptoHandshakeMessage* out, |
| 1061 | QuicTransportVersion transport_version) const { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1062 | // Idle timeout has custom rules that are different from other values. |
| 1063 | // We configure ourselves with the minumum value between the one sent and |
| 1064 | // the one received. Additionally, when QUIC_CRYPTO is used, the server |
| 1065 | // MUST send an idle timeout no greater than the idle timeout it received |
| 1066 | // from the client. We therefore send the received value if it is lower. |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1067 | QuicFixedUint32 max_idle_timeout_seconds(kICSL, PRESENCE_REQUIRED); |
| 1068 | uint32_t max_idle_timeout_to_send_seconds = |
| 1069 | max_idle_timeout_to_send_.ToSeconds(); |
| 1070 | if (received_max_idle_timeout_.has_value() && |
| 1071 | received_max_idle_timeout_->ToSeconds() < |
| 1072 | max_idle_timeout_to_send_seconds) { |
| 1073 | max_idle_timeout_to_send_seconds = received_max_idle_timeout_->ToSeconds(); |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1074 | } |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1075 | max_idle_timeout_seconds.SetSendValue(max_idle_timeout_to_send_seconds); |
| 1076 | max_idle_timeout_seconds.ToHandshakeMessage(out); |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1077 | |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 1078 | // Do not need a version check here, max...bi... will encode |
| 1079 | // as "MIDS" -- the max initial dynamic streams tag -- if |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 1080 | // doing some version other than IETF QUIC. |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1081 | max_bidirectional_streams_.ToHandshakeMessage(out); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 1082 | if (VersionHasIetfQuicFrames(transport_version)) { |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1083 | max_unidirectional_streams_.ToHandshakeMessage(out); |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 1084 | ack_delay_exponent_.ToHandshakeMessage(out); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 1085 | } |
dschinazi | 74d2c0a | 2020-08-10 12:08:54 -0700 | [diff] [blame] | 1086 | if (max_ack_delay_ms_.GetSendValue() != kDefaultDelayedAckTimeMs) { |
| 1087 | // Only send max ack delay if it is using a non-default value, because |
| 1088 | // the default value is used by QuicSentPacketManager if it is not |
| 1089 | // sent during the handshake, and we want to save bytes. |
dschinazi | 46d05bc | 2020-06-17 19:17:54 -0700 | [diff] [blame] | 1090 | max_ack_delay_ms_.ToHandshakeMessage(out); |
| 1091 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1092 | bytes_for_connection_id_.ToHandshakeMessage(out); |
| 1093 | initial_round_trip_time_us_.ToHandshakeMessage(out); |
| 1094 | initial_stream_flow_control_window_bytes_.ToHandshakeMessage(out); |
| 1095 | initial_session_flow_control_window_bytes_.ToHandshakeMessage(out); |
| 1096 | connection_migration_disabled_.ToHandshakeMessage(out); |
| 1097 | connection_options_.ToHandshakeMessage(out); |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 1098 | if (alternate_server_address_ipv6_.HasSendValue()) { |
| 1099 | alternate_server_address_ipv6_.ToHandshakeMessage(out); |
| 1100 | } else { |
| 1101 | alternate_server_address_ipv4_.ToHandshakeMessage(out); |
| 1102 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1103 | stateless_reset_token_.ToHandshakeMessage(out); |
| 1104 | } |
| 1105 | |
| 1106 | QuicErrorCode QuicConfig::ProcessPeerHello( |
| 1107 | const CryptoHandshakeMessage& peer_hello, |
| 1108 | HelloType hello_type, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1109 | std::string* error_details) { |
vasilvv | f803516 | 2021-02-01 14:49:14 -0800 | [diff] [blame] | 1110 | QUICHE_DCHECK(error_details != nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1111 | |
| 1112 | QuicErrorCode error = QUIC_NO_ERROR; |
| 1113 | if (error == QUIC_NO_ERROR) { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1114 | // Idle timeout has custom rules that are different from other values. |
| 1115 | // We configure ourselves with the minumum value between the one sent and |
| 1116 | // the one received. Additionally, when QUIC_CRYPTO is used, the server |
| 1117 | // MUST send an idle timeout no greater than the idle timeout it received |
| 1118 | // from the client. |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1119 | QuicFixedUint32 max_idle_timeout_seconds(kICSL, PRESENCE_REQUIRED); |
| 1120 | error = max_idle_timeout_seconds.ProcessPeerHello(peer_hello, hello_type, |
| 1121 | error_details); |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1122 | if (error == QUIC_NO_ERROR) { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1123 | if (max_idle_timeout_seconds.GetReceivedValue() > |
| 1124 | max_idle_timeout_to_send_.ToSeconds()) { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1125 | // The received value is higher than ours, ignore it if from the client |
| 1126 | // and raise an error if from the server. |
| 1127 | if (hello_type == SERVER) { |
| 1128 | error = QUIC_INVALID_NEGOTIATED_VALUE; |
| 1129 | *error_details = |
| 1130 | "Invalid value received for " + QuicTagToString(kICSL); |
| 1131 | } |
| 1132 | } else { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1133 | received_max_idle_timeout_ = QuicTime::Delta::FromSeconds( |
| 1134 | max_idle_timeout_seconds.GetReceivedValue()); |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1135 | } |
| 1136 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1137 | } |
| 1138 | if (error == QUIC_NO_ERROR) { |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1139 | error = max_bidirectional_streams_.ProcessPeerHello(peer_hello, hello_type, |
| 1140 | error_details); |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 1141 | } |
| 1142 | if (error == QUIC_NO_ERROR) { |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1143 | error = max_unidirectional_streams_.ProcessPeerHello(peer_hello, hello_type, |
| 1144 | error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1145 | } |
| 1146 | if (error == QUIC_NO_ERROR) { |
| 1147 | error = bytes_for_connection_id_.ProcessPeerHello(peer_hello, hello_type, |
| 1148 | error_details); |
| 1149 | } |
| 1150 | if (error == QUIC_NO_ERROR) { |
| 1151 | error = initial_round_trip_time_us_.ProcessPeerHello(peer_hello, hello_type, |
| 1152 | error_details); |
| 1153 | } |
| 1154 | if (error == QUIC_NO_ERROR) { |
| 1155 | error = initial_stream_flow_control_window_bytes_.ProcessPeerHello( |
| 1156 | peer_hello, hello_type, error_details); |
| 1157 | } |
| 1158 | if (error == QUIC_NO_ERROR) { |
| 1159 | error = initial_session_flow_control_window_bytes_.ProcessPeerHello( |
| 1160 | peer_hello, hello_type, error_details); |
| 1161 | } |
| 1162 | if (error == QUIC_NO_ERROR) { |
| 1163 | error = connection_migration_disabled_.ProcessPeerHello( |
| 1164 | peer_hello, hello_type, error_details); |
| 1165 | } |
| 1166 | if (error == QUIC_NO_ERROR) { |
| 1167 | error = connection_options_.ProcessPeerHello(peer_hello, hello_type, |
| 1168 | error_details); |
| 1169 | } |
| 1170 | if (error == QUIC_NO_ERROR) { |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 1171 | QuicFixedSocketAddress alternate_server_address(kASAD, PRESENCE_OPTIONAL); |
| 1172 | error = alternate_server_address.ProcessPeerHello(peer_hello, hello_type, |
| 1173 | error_details); |
| 1174 | if (error == QUIC_NO_ERROR && alternate_server_address.HasReceivedValue()) { |
| 1175 | const QuicSocketAddress& received_address = |
| 1176 | alternate_server_address.GetReceivedValue(); |
| 1177 | if (received_address.host().IsIPv6()) { |
| 1178 | alternate_server_address_ipv6_.SetReceivedValue(received_address); |
| 1179 | } else if (received_address.host().IsIPv4()) { |
| 1180 | alternate_server_address_ipv4_.SetReceivedValue(received_address); |
| 1181 | } |
| 1182 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1183 | } |
| 1184 | if (error == QUIC_NO_ERROR) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1185 | error = stateless_reset_token_.ProcessPeerHello(peer_hello, hello_type, |
| 1186 | error_details); |
| 1187 | } |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 1188 | |
dschinazi | 40975ad | 2020-06-17 18:18:01 -0700 | [diff] [blame] | 1189 | if (error == QUIC_NO_ERROR) { |
fkastenholz | 4c7303c | 2019-07-29 08:17:07 -0700 | [diff] [blame] | 1190 | error = max_ack_delay_ms_.ProcessPeerHello(peer_hello, hello_type, |
| 1191 | error_details); |
| 1192 | } |
fkastenholz | 4dc4ba3 | 2019-07-30 09:55:25 -0700 | [diff] [blame] | 1193 | if (error == QUIC_NO_ERROR) { |
| 1194 | error = ack_delay_exponent_.ProcessPeerHello(peer_hello, hello_type, |
| 1195 | error_details); |
| 1196 | } |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1197 | if (error == QUIC_NO_ERROR) { |
| 1198 | negotiated_ = true; |
| 1199 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1200 | return error; |
| 1201 | } |
| 1202 | |
| 1203 | bool QuicConfig::FillTransportParameters(TransportParameters* params) const { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1204 | if (original_destination_connection_id_to_send_.has_value()) { |
| 1205 | params->original_destination_connection_id = |
| 1206 | original_destination_connection_id_to_send_.value(); |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1209 | params->max_idle_timeout_ms.set_value( |
| 1210 | max_idle_timeout_to_send_.ToMilliseconds()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1211 | |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1212 | if (stateless_reset_token_.HasSendValue()) { |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 1213 | StatelessResetToken stateless_reset_token = |
| 1214 | stateless_reset_token_.GetSendValue(); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1215 | params->stateless_reset_token.assign( |
| 1216 | reinterpret_cast<const char*>(&stateless_reset_token), |
| 1217 | reinterpret_cast<const char*>(&stateless_reset_token) + |
| 1218 | sizeof(stateless_reset_token)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1219 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1220 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1221 | params->max_udp_payload_size.set_value(GetMaxPacketSizeToSend()); |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 1222 | params->max_datagram_frame_size.set_value(GetMaxDatagramFrameSizeToSend()); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1223 | params->initial_max_data.set_value( |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 1224 | GetInitialSessionFlowControlWindowToSend()); |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 1225 | // The max stream data bidirectional transport parameters can be either local |
| 1226 | // or remote. A stream is local iff it is initiated by the endpoint that sent |
| 1227 | // the transport parameter (see the Transport Parameter Definitions section of |
| 1228 | // draft-ietf-quic-transport). In this function we are sending transport |
| 1229 | // parameters, so a local stream is one we initiated, which means an outgoing |
| 1230 | // stream. |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1231 | params->initial_max_stream_data_bidi_local.set_value( |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 1232 | GetInitialMaxStreamDataBytesOutgoingBidirectionalToSend()); |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 1233 | params->initial_max_stream_data_bidi_remote.set_value( |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 1234 | GetInitialMaxStreamDataBytesIncomingBidirectionalToSend()); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1235 | params->initial_max_stream_data_uni.set_value( |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 1236 | GetInitialMaxStreamDataBytesUnidirectionalToSend()); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1237 | params->initial_max_streams_bidi.set_value( |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1238 | GetMaxBidirectionalStreamsToSend()); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1239 | params->initial_max_streams_uni.set_value( |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1240 | GetMaxUnidirectionalStreamsToSend()); |
dschinazi | 40975ad | 2020-06-17 18:18:01 -0700 | [diff] [blame] | 1241 | params->max_ack_delay.set_value(GetMaxAckDelayToSendMs()); |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 1242 | if (min_ack_delay_ms_.HasSendValue()) { |
| 1243 | params->min_ack_delay_us.set_value(min_ack_delay_ms_.GetSendValue() * |
| 1244 | kNumMicrosPerMilli); |
| 1245 | } |
dschinazi | 90165ee | 2019-10-15 15:11:41 -0700 | [diff] [blame] | 1246 | params->ack_delay_exponent.set_value(GetAckDelayExponentToSend()); |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1247 | params->disable_active_migration = |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1248 | connection_migration_disabled_.HasSendValue() && |
| 1249 | connection_migration_disabled_.GetSendValue() != 0; |
| 1250 | |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 1251 | if (alternate_server_address_ipv6_.HasSendValue() || |
| 1252 | alternate_server_address_ipv4_.HasSendValue()) { |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1253 | TransportParameters::PreferredAddress preferred_address; |
dschinazi | faa70a7 | 2020-04-30 16:56:51 -0700 | [diff] [blame] | 1254 | if (alternate_server_address_ipv6_.HasSendValue()) { |
| 1255 | preferred_address.ipv6_socket_address = |
| 1256 | alternate_server_address_ipv6_.GetSendValue(); |
| 1257 | } |
| 1258 | if (alternate_server_address_ipv4_.HasSendValue()) { |
| 1259 | preferred_address.ipv4_socket_address = |
| 1260 | alternate_server_address_ipv4_.GetSendValue(); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1261 | } |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 1262 | if (preferred_address_connection_id_and_token_) { |
| 1263 | preferred_address.connection_id = |
| 1264 | preferred_address_connection_id_and_token_->first; |
| 1265 | auto* begin = reinterpret_cast<const char*>( |
| 1266 | &preferred_address_connection_id_and_token_->second); |
| 1267 | auto* end = |
| 1268 | begin + sizeof(preferred_address_connection_id_and_token_->second); |
| 1269 | preferred_address.stateless_reset_token.assign(begin, end); |
| 1270 | } |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1271 | params->preferred_address = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 1272 | std::make_unique<TransportParameters::PreferredAddress>( |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1273 | preferred_address); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1274 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1275 | |
dschinazi | 4673023 | 2020-05-07 10:01:21 -0700 | [diff] [blame] | 1276 | if (active_connection_id_limit_.HasSendValue()) { |
| 1277 | params->active_connection_id_limit.set_value( |
| 1278 | active_connection_id_limit_.GetSendValue()); |
| 1279 | } |
| 1280 | |
dschinazi | d7beb60 | 2020-05-28 16:47:21 -0700 | [diff] [blame] | 1281 | if (initial_source_connection_id_to_send_.has_value()) { |
| 1282 | params->initial_source_connection_id = |
| 1283 | initial_source_connection_id_to_send_.value(); |
| 1284 | } |
| 1285 | |
| 1286 | if (retry_source_connection_id_to_send_.has_value()) { |
| 1287 | params->retry_source_connection_id = |
| 1288 | retry_source_connection_id_to_send_.value(); |
| 1289 | } |
| 1290 | |
dschinazi | 83c586a | 2020-07-07 11:50:45 -0700 | [diff] [blame] | 1291 | if (initial_round_trip_time_us_.HasSendValue()) { |
| 1292 | params->initial_round_trip_time_us.set_value( |
| 1293 | initial_round_trip_time_us_.GetSendValue()); |
| 1294 | } |
| 1295 | if (connection_options_.HasSendValues() && |
| 1296 | !connection_options_.GetSendValues().empty()) { |
| 1297 | params->google_connection_options = connection_options_.GetSendValues(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1298 | } |
dschinazi | 7e51f6b | 2020-05-13 17:36:44 -0700 | [diff] [blame] | 1299 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 1300 | if (!KeyUpdateSupportedLocally()) { |
| 1301 | params->key_update_not_yet_supported = true; |
| 1302 | } |
dschinazi | d73dc1f | 2020-08-12 15:10:04 -0700 | [diff] [blame] | 1303 | |
vasilvv | a2ef301 | 2019-09-12 18:32:14 -0700 | [diff] [blame] | 1304 | params->custom_parameters = custom_transport_parameters_to_send_; |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1305 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1306 | return true; |
| 1307 | } |
| 1308 | |
| 1309 | QuicErrorCode QuicConfig::ProcessTransportParameters( |
| 1310 | const TransportParameters& params, |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1311 | bool is_resumption, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1312 | std::string* error_details) { |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1313 | if (!is_resumption && params.original_destination_connection_id.has_value()) { |
| 1314 | received_original_destination_connection_id_ = |
| 1315 | params.original_destination_connection_id.value(); |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1318 | if (params.max_idle_timeout_ms.value() > 0 && |
| 1319 | params.max_idle_timeout_ms.value() < |
| 1320 | static_cast<uint64_t>(max_idle_timeout_to_send_.ToMilliseconds())) { |
dschinazi | f7c6a91 | 2020-05-05 11:39:53 -0700 | [diff] [blame] | 1321 | // An idle timeout of zero indicates it is disabled. |
| 1322 | // We also ignore values higher than ours which will cause us to use the |
| 1323 | // smallest value between ours and our peer's. |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1324 | received_max_idle_timeout_ = |
| 1325 | QuicTime::Delta::FromMilliseconds(params.max_idle_timeout_ms.value()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1326 | } |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1327 | |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1328 | if (!is_resumption && !params.stateless_reset_token.empty()) { |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 1329 | StatelessResetToken stateless_reset_token; |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1330 | if (params.stateless_reset_token.size() != sizeof(stateless_reset_token)) { |
QUICHE team | d6d05e5 | 2021-03-16 14:22:01 -0700 | [diff] [blame] | 1331 | QUIC_BUG(quic_bug_10575_16) << "Bad stateless reset token length " |
| 1332 | << params.stateless_reset_token.size(); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1333 | *error_details = "Bad stateless reset token length"; |
| 1334 | return QUIC_INTERNAL_ERROR; |
| 1335 | } |
| 1336 | memcpy(&stateless_reset_token, params.stateless_reset_token.data(), |
| 1337 | params.stateless_reset_token.size()); |
| 1338 | stateless_reset_token_.SetReceivedValue(stateless_reset_token); |
| 1339 | } |
| 1340 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1341 | if (params.max_udp_payload_size.IsValid()) { |
| 1342 | max_udp_payload_size_.SetReceivedValue(params.max_udp_payload_size.value()); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 1345 | if (params.max_datagram_frame_size.IsValid()) { |
| 1346 | max_datagram_frame_size_.SetReceivedValue( |
| 1347 | params.max_datagram_frame_size.value()); |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 1348 | } |
| 1349 | |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1350 | initial_session_flow_control_window_bytes_.SetReceivedValue( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 1351 | params.initial_max_data.value()); |
| 1352 | |
| 1353 | // IETF QUIC specifies stream IDs and stream counts as 62-bit integers but |
| 1354 | // our implementation uses uint32_t to represent them to save memory. |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1355 | max_bidirectional_streams_.SetReceivedValue( |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1356 | std::min<uint64_t>(params.initial_max_streams_bidi.value(), |
| 1357 | std::numeric_limits<uint32_t>::max())); |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 1358 | max_unidirectional_streams_.SetReceivedValue( |
fkastenholz | d3a1de9 | 2019-05-15 07:00:07 -0700 | [diff] [blame] | 1359 | std::min<uint64_t>(params.initial_max_streams_uni.value(), |
| 1360 | std::numeric_limits<uint32_t>::max())); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1361 | |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 1362 | // The max stream data bidirectional transport parameters can be either local |
| 1363 | // or remote. A stream is local iff it is initiated by the endpoint that sent |
| 1364 | // the transport parameter (see the Transport Parameter Definitions section of |
| 1365 | // draft-ietf-quic-transport). However in this function we are processing |
| 1366 | // received transport parameters, so a local stream is one initiated by our |
| 1367 | // peer, which means an incoming stream. |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 1368 | initial_max_stream_data_bytes_incoming_bidirectional_.SetReceivedValue( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 1369 | params.initial_max_stream_data_bidi_local.value()); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 1370 | initial_max_stream_data_bytes_outgoing_bidirectional_.SetReceivedValue( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 1371 | params.initial_max_stream_data_bidi_remote.value()); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 1372 | initial_max_stream_data_bytes_unidirectional_.SetReceivedValue( |
dschinazi | f1e7b42 | 2020-04-30 12:21:28 -0700 | [diff] [blame] | 1373 | params.initial_max_stream_data_uni.value()); |
rch | b045185 | 2019-09-11 21:17:01 -0700 | [diff] [blame] | 1374 | |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1375 | if (!is_resumption) { |
dschinazi | 40975ad | 2020-06-17 18:18:01 -0700 | [diff] [blame] | 1376 | max_ack_delay_ms_.SetReceivedValue(params.max_ack_delay.value()); |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1377 | if (params.ack_delay_exponent.IsValid()) { |
| 1378 | ack_delay_exponent_.SetReceivedValue(params.ack_delay_exponent.value()); |
| 1379 | } |
| 1380 | if (params.preferred_address != nullptr) { |
| 1381 | if (params.preferred_address->ipv6_socket_address.port() != 0) { |
| 1382 | alternate_server_address_ipv6_.SetReceivedValue( |
| 1383 | params.preferred_address->ipv6_socket_address); |
| 1384 | } |
| 1385 | if (params.preferred_address->ipv4_socket_address.port() != 0) { |
| 1386 | alternate_server_address_ipv4_.SetReceivedValue( |
| 1387 | params.preferred_address->ipv4_socket_address); |
| 1388 | } |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 1389 | // TODO(haoyuewang) Treat 0 length connection ID sent in preferred_address |
| 1390 | // as a connection error of type TRANSPORT_PARAMETER_ERROR when server |
| 1391 | // fully supports it. |
| 1392 | if (!params.preferred_address->connection_id.IsEmpty()) { |
| 1393 | preferred_address_connection_id_and_token_ = std::make_pair( |
| 1394 | params.preferred_address->connection_id, |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 1395 | *reinterpret_cast<const StatelessResetToken*>( |
haoyuewang | 2a6cbc5 | 2021-01-13 06:49:02 -0800 | [diff] [blame] | 1396 | ¶ms.preferred_address->stateless_reset_token.front())); |
| 1397 | } |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1398 | } |
haoyuewang | 042cc3f | 2020-11-30 11:50:09 -0800 | [diff] [blame] | 1399 | if (params.min_ack_delay_us.value() != 0) { |
| 1400 | if (params.min_ack_delay_us.value() > |
| 1401 | params.max_ack_delay.value() * kNumMicrosPerMilli) { |
| 1402 | *error_details = "MinAckDelay is greater than MaxAckDelay."; |
| 1403 | return IETF_QUIC_PROTOCOL_VIOLATION; |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 1404 | } |
haoyuewang | 042cc3f | 2020-11-30 11:50:09 -0800 | [diff] [blame] | 1405 | min_ack_delay_ms_.SetReceivedValue(params.min_ack_delay_us.value() / |
| 1406 | kNumMicrosPerMilli); |
haoyuewang | 7cffa54 | 2020-07-15 17:12:27 -0700 | [diff] [blame] | 1407 | } |
dschinazi | 8067d55 | 2019-11-13 19:44:00 -0800 | [diff] [blame] | 1408 | } |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1409 | |
dschinazi | 5a29bd5 | 2020-05-21 19:37:32 -0700 | [diff] [blame] | 1410 | if (params.disable_active_migration) { |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1411 | connection_migration_disabled_.SetReceivedValue(1u); |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1412 | } |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 1413 | if (!is_resumption && !params.key_update_not_yet_supported) { |
| 1414 | key_update_supported_remotely_ = true; |
| 1415 | } |
dschinazi | 52127d7 | 2019-04-17 15:12:38 -0700 | [diff] [blame] | 1416 | |
dschinazi | 4673023 | 2020-05-07 10:01:21 -0700 | [diff] [blame] | 1417 | active_connection_id_limit_.SetReceivedValue( |
| 1418 | params.active_connection_id_limit.value()); |
| 1419 | |
dschinazi | d7beb60 | 2020-05-28 16:47:21 -0700 | [diff] [blame] | 1420 | if (!is_resumption) { |
| 1421 | if (params.initial_source_connection_id.has_value()) { |
| 1422 | received_initial_source_connection_id_ = |
| 1423 | params.initial_source_connection_id.value(); |
| 1424 | } |
| 1425 | if (params.retry_source_connection_id.has_value()) { |
| 1426 | received_retry_source_connection_id_ = |
| 1427 | params.retry_source_connection_id.value(); |
| 1428 | } |
| 1429 | } |
| 1430 | |
dschinazi | 83c586a | 2020-07-07 11:50:45 -0700 | [diff] [blame] | 1431 | if (params.initial_round_trip_time_us.value() > 0) { |
dschinazi | 83c586a | 2020-07-07 11:50:45 -0700 | [diff] [blame] | 1432 | initial_round_trip_time_us_.SetReceivedValue( |
| 1433 | params.initial_round_trip_time_us.value()); |
| 1434 | } |
| 1435 | if (params.google_connection_options.has_value()) { |
dschinazi | 83c586a | 2020-07-07 11:50:45 -0700 | [diff] [blame] | 1436 | connection_options_.SetReceivedValues( |
| 1437 | params.google_connection_options.value()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1438 | } |
| 1439 | |
vasilvv | a2ef301 | 2019-09-12 18:32:14 -0700 | [diff] [blame] | 1440 | received_custom_transport_parameters_ = params.custom_parameters; |
| 1441 | |
renjietang | c31106b | 2020-05-06 10:44:17 -0700 | [diff] [blame] | 1442 | if (!is_resumption) { |
| 1443 | negotiated_ = true; |
| 1444 | } |
dschinazi | 6464c4a | 2019-09-11 16:25:01 -0700 | [diff] [blame] | 1445 | *error_details = ""; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1446 | return QUIC_NO_ERROR; |
| 1447 | } |
| 1448 | |
| 1449 | } // namespace quic |