QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
| 5 | // The entity that handles framing writes for a Quic client or server. |
| 6 | // Each QuicSession will have a connection associated with it. |
| 7 | // |
| 8 | // On the server side, the Dispatcher handles the raw reads, and hands off |
| 9 | // packets via ProcessUdpPacket for framing and processing. |
| 10 | // |
| 11 | // On the client side, the Connection handles the raw reads, as well as the |
| 12 | // processing. |
| 13 | // |
| 14 | // Note: this class is not thread-safe. |
| 15 | |
| 16 | #ifndef QUICHE_QUIC_CORE_QUIC_CONNECTION_H_ |
| 17 | #define QUICHE_QUIC_CORE_QUIC_CONNECTION_H_ |
| 18 | |
| 19 | #include <cstddef> |
| 20 | #include <cstdint> |
| 21 | #include <list> |
| 22 | #include <map> |
| 23 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 24 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
vasilvv | 9a36d72 | 2020-10-02 16:51:38 -0700 | [diff] [blame] | 27 | #include "absl/strings/string_view.h" |
vasilvv | 7df418b | 2020-10-13 13:47:09 -0700 | [diff] [blame] | 28 | #include "absl/types/optional.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 29 | #include "quic/core/crypto/quic_decrypter.h" |
| 30 | #include "quic/core/crypto/quic_encrypter.h" |
| 31 | #include "quic/core/crypto/transport_parameters.h" |
| 32 | #include "quic/core/frames/quic_ack_frequency_frame.h" |
| 33 | #include "quic/core/frames/quic_max_streams_frame.h" |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 34 | #include "quic/core/frames/quic_new_connection_id_frame.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 35 | #include "quic/core/proto/cached_network_parameters_proto.h" |
| 36 | #include "quic/core/quic_alarm.h" |
| 37 | #include "quic/core/quic_alarm_factory.h" |
| 38 | #include "quic/core/quic_blocked_writer_interface.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 39 | #include "quic/core/quic_connection_id.h" |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 40 | #include "quic/core/quic_connection_id_manager.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 41 | #include "quic/core/quic_connection_stats.h" |
| 42 | #include "quic/core/quic_constants.h" |
| 43 | #include "quic/core/quic_framer.h" |
| 44 | #include "quic/core/quic_idle_network_detector.h" |
| 45 | #include "quic/core/quic_mtu_discovery.h" |
| 46 | #include "quic/core/quic_network_blackhole_detector.h" |
| 47 | #include "quic/core/quic_one_block_arena.h" |
| 48 | #include "quic/core/quic_packet_creator.h" |
| 49 | #include "quic/core/quic_packet_writer.h" |
| 50 | #include "quic/core/quic_packets.h" |
| 51 | #include "quic/core/quic_path_validator.h" |
| 52 | #include "quic/core/quic_sent_packet_manager.h" |
| 53 | #include "quic/core/quic_time.h" |
| 54 | #include "quic/core/quic_types.h" |
| 55 | #include "quic/core/uber_received_packet_manager.h" |
| 56 | #include "quic/platform/api/quic_containers.h" |
| 57 | #include "quic/platform/api/quic_export.h" |
renjietang | 7f1d9e1 | 2021-01-22 19:10:57 -0800 | [diff] [blame] | 58 | #include "quic/platform/api/quic_flags.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 59 | #include "quic/platform/api/quic_socket_address.h" |
bnc | 08fc2ae | 2021-04-27 14:57:51 -0700 | [diff] [blame] | 60 | #include "common/quiche_circular_deque.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 61 | |
| 62 | namespace quic { |
| 63 | |
| 64 | class QuicClock; |
| 65 | class QuicConfig; |
| 66 | class QuicConnection; |
| 67 | class QuicRandom; |
| 68 | |
| 69 | namespace test { |
| 70 | class QuicConnectionPeer; |
| 71 | } // namespace test |
| 72 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 73 | // Class that receives callbacks from the connection when frames are received |
| 74 | // and when other interesting events happen. |
| 75 | class QUIC_EXPORT_PRIVATE QuicConnectionVisitorInterface { |
| 76 | public: |
| 77 | virtual ~QuicConnectionVisitorInterface() {} |
| 78 | |
| 79 | // A simple visitor interface for dealing with a data frame. |
| 80 | virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; |
| 81 | |
| 82 | // Called when a CRYPTO frame containing handshake data is received. |
| 83 | virtual void OnCryptoFrame(const QuicCryptoFrame& frame) = 0; |
| 84 | |
| 85 | // The session should process the WINDOW_UPDATE frame, adjusting both stream |
| 86 | // and connection level flow control windows. |
| 87 | virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) = 0; |
| 88 | |
| 89 | // A BLOCKED frame indicates the peer is flow control blocked |
| 90 | // on a specified stream. |
| 91 | virtual void OnBlockedFrame(const QuicBlockedFrame& frame) = 0; |
| 92 | |
| 93 | // Called when the stream is reset by the peer. |
| 94 | virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0; |
| 95 | |
| 96 | // Called when the connection is going away according to the peer. |
| 97 | virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0; |
| 98 | |
| 99 | // Called when |message| has been received. |
vasilvv | 9a36d72 | 2020-10-02 16:51:38 -0700 | [diff] [blame] | 100 | virtual void OnMessageReceived(absl::string_view message) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 101 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 102 | // Called when a HANDSHAKE_DONE frame has been received. |
| 103 | virtual void OnHandshakeDoneReceived() = 0; |
| 104 | |
fayang | 133b868 | 2020-12-08 05:50:33 -0800 | [diff] [blame] | 105 | // Called when a NEW_TOKEN frame has been received. |
| 106 | virtual void OnNewTokenReceived(absl::string_view token) = 0; |
| 107 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 108 | // Called when a MAX_STREAMS frame has been received from the peer. |
| 109 | virtual bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 110 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 111 | // Called when a STREAMS_BLOCKED frame has been received from the peer. |
| 112 | virtual bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 113 | |
| 114 | // Called when the connection is closed either locally by the framer, or |
| 115 | // remotely by the peer. |
fkastenholz | 5d880a9 | 2019-06-21 09:01:56 -0700 | [diff] [blame] | 116 | virtual void OnConnectionClosed(const QuicConnectionCloseFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 117 | ConnectionCloseSource source) = 0; |
| 118 | |
| 119 | // Called when the connection failed to write because the socket was blocked. |
| 120 | virtual void OnWriteBlocked() = 0; |
| 121 | |
| 122 | // Called once a specific QUIC version is agreed by both endpoints. |
| 123 | virtual void OnSuccessfulVersionNegotiation( |
| 124 | const ParsedQuicVersion& version) = 0; |
| 125 | |
zhongyi | 83161e4 | 2019-08-19 09:06:25 -0700 | [diff] [blame] | 126 | // Called when a packet has been received by the connection, after being |
| 127 | // validated and parsed. Only called when the client receives a valid packet |
| 128 | // or the server receives a connectivity probing packet. |
| 129 | // |is_connectivity_probe| is true if the received packet is a connectivity |
| 130 | // probe. |
| 131 | virtual void OnPacketReceived(const QuicSocketAddress& self_address, |
| 132 | const QuicSocketAddress& peer_address, |
| 133 | bool is_connectivity_probe) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 134 | |
| 135 | // Called when a blocked socket becomes writable. |
| 136 | virtual void OnCanWrite() = 0; |
| 137 | |
QUICHE team | b834325 | 2019-04-29 13:58:01 -0700 | [diff] [blame] | 138 | // Called when the connection needs more data to probe for additional |
| 139 | // bandwidth. Returns true if data was sent, false otherwise. |
| 140 | virtual bool SendProbingData() = 0; |
| 141 | |
renjietang | 7f483b5 | 2020-05-20 14:30:47 -0700 | [diff] [blame] | 142 | // Called when stateless reset packet is received. Returns true if the |
| 143 | // connection needs to be closed. |
| 144 | virtual bool ValidateStatelessReset( |
| 145 | const quic::QuicSocketAddress& self_address, |
| 146 | const quic::QuicSocketAddress& peer_address) = 0; |
renjietang | 5b24589 | 2020-05-18 11:57:26 -0700 | [diff] [blame] | 147 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 148 | // Called when the connection experiences a change in congestion window. |
| 149 | virtual void OnCongestionWindowChange(QuicTime now) = 0; |
| 150 | |
| 151 | // Called when the connection receives a packet from a migrated client. |
| 152 | virtual void OnConnectionMigration(AddressChangeType type) = 0; |
| 153 | |
| 154 | // Called when the peer seems unreachable over the current path. |
| 155 | virtual void OnPathDegrading() = 0; |
| 156 | |
zhongyi | ef1d675 | 2020-06-11 16:19:28 -0700 | [diff] [blame] | 157 | // Called when forward progress made after path degrading. |
| 158 | virtual void OnForwardProgressMadeAfterPathDegrading() = 0; |
| 159 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 160 | // Called when the connection sends ack after |
| 161 | // max_consecutive_num_packets_with_no_retransmittable_frames_ consecutive not |
| 162 | // retransmittable packets sent. To instigate an ack from peer, a |
| 163 | // retransmittable frame needs to be added. |
| 164 | virtual void OnAckNeedsRetransmittableFrame() = 0; |
| 165 | |
haoyuewang | c921f8d | 2020-10-14 18:06:52 -0700 | [diff] [blame] | 166 | // Called when an AckFrequency frame need to be sent. |
| 167 | virtual void SendAckFrequency(const QuicAckFrequencyFrame& frame) = 0; |
| 168 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 169 | // Called to send a NEW_CONNECTION_ID frame. |
| 170 | virtual void SendNewConnectionId(const QuicNewConnectionIdFrame& frame) = 0; |
| 171 | |
| 172 | // Called to send a RETIRE_CONNECTION_ID frame. |
| 173 | virtual void SendRetireConnectionId(uint64_t sequence_number) = 0; |
| 174 | |
| 175 | // Called when server starts to use a server issued connection ID. |
| 176 | virtual void OnServerConnectionIdIssued( |
| 177 | const QuicConnectionId& server_connection_id) = 0; |
| 178 | |
| 179 | // Called when server stops to use a server issued connection ID. |
| 180 | virtual void OnServerConnectionIdRetired( |
| 181 | const QuicConnectionId& server_connection_id) = 0; |
| 182 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 183 | // Called to ask if the visitor wants to schedule write resumption as it both |
| 184 | // has pending data to write, and is able to write (e.g. based on flow control |
| 185 | // limits). |
| 186 | // Writes may be pending because they were write-blocked, congestion-throttled |
| 187 | // or yielded to other connections. |
| 188 | virtual bool WillingAndAbleToWrite() const = 0; |
| 189 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 190 | // Called to ask if the connection should be kept alive and prevented |
| 191 | // from timing out, for example if there are outstanding application |
| 192 | // transactions expecting a response. |
| 193 | virtual bool ShouldKeepConnectionAlive() const = 0; |
| 194 | |
fayang | a330b7c | 2020-09-10 08:15:39 -0700 | [diff] [blame] | 195 | // Called to retrieve streams information for logging purpose. |
| 196 | virtual std::string GetStreamsInfoForLogging() const = 0; |
| 197 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 198 | // Called when a self address change is observed. Returns true if self address |
| 199 | // change is allowed. |
| 200 | virtual bool AllowSelfAddressChange() const = 0; |
| 201 | |
fayang | c67c520 | 2020-01-22 07:43:15 -0800 | [diff] [blame] | 202 | // Called to get current handshake state. |
| 203 | virtual HandshakeState GetHandshakeState() const = 0; |
| 204 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 205 | // Called when a STOP_SENDING frame has been received. |
renjietang | eab918f | 2019-10-28 12:10:32 -0700 | [diff] [blame] | 206 | virtual void OnStopSendingFrame(const QuicStopSendingFrame& frame) = 0; |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 207 | |
| 208 | // Called when a packet of encryption |level| has been successfully decrypted. |
| 209 | virtual void OnPacketDecrypted(EncryptionLevel level) = 0; |
fayang | 2f2915d | 2020-01-24 06:47:15 -0800 | [diff] [blame] | 210 | |
| 211 | // Called when a 1RTT packet has been acknowledged. |
| 212 | virtual void OnOneRttPacketAcknowledged() = 0; |
fayang | 44ae4e9 | 2020-04-28 13:09:42 -0700 | [diff] [blame] | 213 | |
| 214 | // Called when a packet of ENCRYPTION_HANDSHAKE gets sent. |
| 215 | virtual void OnHandshakePacketSent() = 0; |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 216 | |
mattm | e57062e | 2020-10-19 11:32:43 -0700 | [diff] [blame] | 217 | // Called when a key update has occurred. |
| 218 | virtual void OnKeyUpdate(KeyUpdateReason reason) = 0; |
| 219 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 220 | // Called to generate a decrypter for the next key phase. Each call should |
| 221 | // generate the key for phase n+1. |
| 222 | virtual std::unique_ptr<QuicDecrypter> |
| 223 | AdvanceKeysAndCreateCurrentOneRttDecrypter() = 0; |
| 224 | |
| 225 | // Called to generate an encrypter for the same key phase of the last |
| 226 | // decrypter returned by AdvanceKeysAndCreateCurrentOneRttDecrypter(). |
| 227 | virtual std::unique_ptr<QuicEncrypter> CreateCurrentOneRttEncrypter() = 0; |
bnc | c03d2c2 | 2020-10-15 13:30:09 -0700 | [diff] [blame] | 228 | |
| 229 | // Called when connection is being closed right before a CONNECTION_CLOSE |
| 230 | // frame is serialized, but only on the server and only if forward secure |
| 231 | // encryption has already been established. |
| 232 | virtual void BeforeConnectionCloseSent() = 0; |
fayang | 133b868 | 2020-12-08 05:50:33 -0800 | [diff] [blame] | 233 | |
| 234 | // Called by the server to validate |token| in received INITIAL packets. |
| 235 | // Consider the client address gets validated (and therefore remove |
| 236 | // amplification factor) once the |token| gets successfully validated. |
| 237 | virtual bool ValidateToken(absl::string_view token) const = 0; |
danzh | edcc10d | 2020-12-21 14:47:15 -0800 | [diff] [blame] | 238 | |
| 239 | // Called by the server to send another token. |
| 240 | // Return false if the crypto stream fail to generate one. |
| 241 | virtual void MaybeSendAddressToken() = 0; |
haoyuewang | 1c1771f | 2021-03-15 15:01:53 -0700 | [diff] [blame] | 242 | |
| 243 | // Whether the server address is known to the connection. |
| 244 | virtual bool IsKnownServerAddress(const QuicSocketAddress& address) const = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | // Interface which gets callbacks from the QuicConnection at interesting |
| 248 | // points. Implementations must not mutate the state of the connection |
| 249 | // as a result of these callbacks. |
| 250 | class QUIC_EXPORT_PRIVATE QuicConnectionDebugVisitor |
| 251 | : public QuicSentPacketManager::DebugDelegate { |
| 252 | public: |
| 253 | ~QuicConnectionDebugVisitor() override {} |
| 254 | |
| 255 | // Called when a packet has been sent. |
wub | acc7c97 | 2020-09-14 16:16:32 -0700 | [diff] [blame] | 256 | virtual void OnPacketSent(QuicPacketNumber /*packet_number*/, |
| 257 | QuicPacketLength /*packet_length*/, |
| 258 | bool /*has_crypto_handshake*/, |
| 259 | TransmissionType /*transmission_type*/, |
| 260 | EncryptionLevel /*encryption_level*/, |
| 261 | const QuicFrames& /*retransmittable_frames*/, |
| 262 | const QuicFrames& /*nonretransmittable_frames*/, |
| 263 | QuicTime /*sent_time*/) {} |
| 264 | |
fayang | 6100ab7 | 2020-03-18 13:16:25 -0700 | [diff] [blame] | 265 | // Called when a coalesced packet has been sent. |
| 266 | virtual void OnCoalescedPacketSent( |
| 267 | const QuicCoalescedPacket& /*coalesced_packet*/, |
| 268 | size_t /*length*/) {} |
| 269 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 270 | // Called when a PING frame has been sent. |
| 271 | virtual void OnPingSent() {} |
| 272 | |
| 273 | // Called when a packet has been received, but before it is |
| 274 | // validated or parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 275 | virtual void OnPacketReceived(const QuicSocketAddress& /*self_address*/, |
| 276 | const QuicSocketAddress& /*peer_address*/, |
| 277 | const QuicEncryptedPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 278 | |
| 279 | // Called when the unauthenticated portion of the header has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 280 | virtual void OnUnauthenticatedHeader(const QuicPacketHeader& /*header*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 281 | |
| 282 | // Called when a packet is received with a connection id that does not |
| 283 | // match the ID of this connection. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 284 | virtual void OnIncorrectConnectionId(QuicConnectionId /*connection_id*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 285 | |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 286 | // Called when an undecryptable packet has been received. If |dropped| is |
| 287 | // true, the packet has been dropped. Otherwise, the packet will be queued and |
| 288 | // connection will attempt to process it later. |
| 289 | virtual void OnUndecryptablePacket(EncryptionLevel /*decryption_level*/, |
| 290 | bool /*dropped*/) {} |
| 291 | |
| 292 | // Called when attempting to process a previously undecryptable packet. |
| 293 | virtual void OnAttemptingToProcessUndecryptablePacket( |
| 294 | EncryptionLevel /*decryption_level*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 295 | |
| 296 | // Called when a duplicate packet has been received. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 297 | virtual void OnDuplicatePacket(QuicPacketNumber /*packet_number*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 298 | |
| 299 | // Called when the protocol version on the received packet doensn't match |
| 300 | // current protocol version of the connection. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 301 | virtual void OnProtocolVersionMismatch(ParsedQuicVersion /*version*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 302 | |
| 303 | // Called when the complete header of a packet has been parsed. |
fayang | 182ae36 | 2020-10-01 12:08:49 -0700 | [diff] [blame] | 304 | virtual void OnPacketHeader(const QuicPacketHeader& /*header*/, |
| 305 | QuicTime /*receive_time*/, |
| 306 | EncryptionLevel /*level*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 307 | |
| 308 | // Called when a StreamFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 309 | virtual void OnStreamFrame(const QuicStreamFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 310 | |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 311 | // Called when a CRYPTO frame containing handshake data is received. |
| 312 | virtual void OnCryptoFrame(const QuicCryptoFrame& /*frame*/) {} |
| 313 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 314 | // Called when a StopWaitingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 315 | virtual void OnStopWaitingFrame(const QuicStopWaitingFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | |
| 317 | // Called when a QuicPaddingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 318 | virtual void OnPaddingFrame(const QuicPaddingFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 319 | |
| 320 | // Called when a Ping has been parsed. |
fayang | d2bf0ba | 2020-08-14 07:57:56 -0700 | [diff] [blame] | 321 | virtual void OnPingFrame(const QuicPingFrame& /*frame*/, |
| 322 | QuicTime::Delta /*ping_received_delay*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 323 | |
| 324 | // Called when a GoAway has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 325 | virtual void OnGoAwayFrame(const QuicGoAwayFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 326 | |
| 327 | // Called when a RstStreamFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 328 | virtual void OnRstStreamFrame(const QuicRstStreamFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 329 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 330 | // Called when a ConnectionCloseFrame has been parsed. All forms |
| 331 | // of CONNECTION CLOSE are handled, Google QUIC, IETF QUIC |
| 332 | // CONNECTION CLOSE/Transport and IETF QUIC CONNECTION CLOSE/Application |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 333 | virtual void OnConnectionCloseFrame( |
| 334 | const QuicConnectionCloseFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 335 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 336 | // Called when a WindowUpdate has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 337 | virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& /*frame*/, |
| 338 | const QuicTime& /*receive_time*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 339 | |
| 340 | // Called when a BlockedFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 341 | virtual void OnBlockedFrame(const QuicBlockedFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 342 | |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 343 | // Called when a NewConnectionIdFrame has been parsed. |
| 344 | virtual void OnNewConnectionIdFrame( |
| 345 | const QuicNewConnectionIdFrame& /*frame*/) {} |
| 346 | |
| 347 | // Called when a RetireConnectionIdFrame has been parsed. |
| 348 | virtual void OnRetireConnectionIdFrame( |
| 349 | const QuicRetireConnectionIdFrame& /*frame*/) {} |
| 350 | |
| 351 | // Called when a NewTokenFrame has been parsed. |
| 352 | virtual void OnNewTokenFrame(const QuicNewTokenFrame& /*frame*/) {} |
| 353 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 354 | // Called when a MessageFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 355 | virtual void OnMessageFrame(const QuicMessageFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 356 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 357 | // Called when a HandshakeDoneFrame has been parsed. |
| 358 | virtual void OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& /*frame*/) {} |
| 359 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 360 | // Called when a public reset packet has been received. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 361 | virtual void OnPublicResetPacket(const QuicPublicResetPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 362 | |
| 363 | // Called when a version negotiation packet has been received. |
| 364 | virtual void OnVersionNegotiationPacket( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 365 | const QuicVersionNegotiationPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 366 | |
| 367 | // Called when the connection is closed. |
fkastenholz | ac11db0 | 2019-06-24 06:22:04 -0700 | [diff] [blame] | 368 | virtual void OnConnectionClosed(const QuicConnectionCloseFrame& /*frame*/, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 369 | ConnectionCloseSource /*source*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 370 | |
| 371 | // Called when the version negotiation is successful. |
| 372 | virtual void OnSuccessfulVersionNegotiation( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 373 | const ParsedQuicVersion& /*version*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 374 | |
| 375 | // Called when a CachedNetworkParameters is sent to the client. |
| 376 | virtual void OnSendConnectionState( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 377 | const CachedNetworkParameters& /*cached_network_params*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 378 | |
| 379 | // Called when a CachedNetworkParameters are received from the client. |
| 380 | virtual void OnReceiveConnectionState( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 381 | const CachedNetworkParameters& /*cached_network_params*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 382 | |
| 383 | // Called when the connection parameters are set from the supplied |
| 384 | // |config|. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 385 | virtual void OnSetFromConfig(const QuicConfig& /*config*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 386 | |
| 387 | // Called when RTT may have changed, including when an RTT is read from |
| 388 | // the config. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 389 | virtual void OnRttChanged(QuicTime::Delta /*rtt*/) const {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 390 | |
| 391 | // Called when a StopSendingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 392 | virtual void OnStopSendingFrame(const QuicStopSendingFrame& /*frame*/) {} |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 393 | |
| 394 | // Called when a PathChallengeFrame has been parsed. |
| 395 | virtual void OnPathChallengeFrame(const QuicPathChallengeFrame& /*frame*/) {} |
| 396 | |
| 397 | // Called when a PathResponseFrame has been parsed. |
| 398 | virtual void OnPathResponseFrame(const QuicPathResponseFrame& /*frame*/) {} |
renjietang | c705490 | 2019-09-25 13:13:52 -0700 | [diff] [blame] | 399 | |
| 400 | // Called when a StreamsBlockedFrame has been parsed. |
| 401 | virtual void OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& /*frame*/) { |
| 402 | } |
| 403 | |
| 404 | // Called when a MaxStreamsFrame has been parsed. |
| 405 | virtual void OnMaxStreamsFrame(const QuicMaxStreamsFrame& /*frame*/) {} |
fayang | 2cbfccf | 2019-11-14 14:02:15 -0800 | [diff] [blame] | 406 | |
fayang | 182ae36 | 2020-10-01 12:08:49 -0700 | [diff] [blame] | 407 | // Called when an AckFrequencyFrame has been parsed. |
| 408 | virtual void OnAckFrequencyFrame(const QuicAckFrequencyFrame& /*frame*/) {} |
| 409 | |
fayang | 2cbfccf | 2019-11-14 14:02:15 -0800 | [diff] [blame] | 410 | // Called when |count| packet numbers have been skipped. |
fayang | 08e1960 | 2020-07-09 13:08:35 -0700 | [diff] [blame] | 411 | virtual void OnNPacketNumbersSkipped(QuicPacketCount /*count*/, |
| 412 | QuicTime /*now*/) {} |
dschinazi | 631f160 | 2020-05-19 10:10:22 -0700 | [diff] [blame] | 413 | |
| 414 | // Called for QUIC+TLS versions when we send transport parameters. |
| 415 | virtual void OnTransportParametersSent( |
| 416 | const TransportParameters& /*transport_parameters*/) {} |
| 417 | |
| 418 | // Called for QUIC+TLS versions when we receive transport parameters. |
| 419 | virtual void OnTransportParametersReceived( |
| 420 | const TransportParameters& /*transport_parameters*/) {} |
renjietang | 8957c6e | 2020-08-12 16:08:21 -0700 | [diff] [blame] | 421 | |
| 422 | // Called for QUIC+TLS versions when we resume cached transport parameters for |
| 423 | // 0-RTT. |
| 424 | virtual void OnTransportParametersResumed( |
| 425 | const TransportParameters& /*transport_parameters*/) {} |
renjietang | 5c6834b | 2020-08-17 11:00:48 -0700 | [diff] [blame] | 426 | |
| 427 | // Called for QUIC+TLS versions when 0-RTT is rejected. |
renjietang | f71e806 | 2020-09-14 12:01:15 -0700 | [diff] [blame] | 428 | virtual void OnZeroRttRejected(int /*reject_reason*/) {} |
fayang | 2ac31ae | 2020-09-17 17:02:59 -0700 | [diff] [blame] | 429 | |
fayang | f2e0d90 | 2020-09-25 14:47:19 -0700 | [diff] [blame] | 430 | // Called for QUIC+TLS versions when 0-RTT packet gets acked. |
| 431 | virtual void OnZeroRttPacketAcked() {} |
| 432 | |
fayang | 2ac31ae | 2020-09-17 17:02:59 -0700 | [diff] [blame] | 433 | // Called on peer address change. |
| 434 | virtual void OnPeerAddressChange(AddressChangeType /*type*/, |
| 435 | QuicTime::Delta /*connection_time*/) {} |
danzh | d6cf8bd | 2021-03-03 15:45:08 -0800 | [diff] [blame] | 436 | |
| 437 | // Called after peer migration is validated. |
| 438 | virtual void OnPeerMigrationValidated(QuicTime::Delta /*connection_time*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | class QUIC_EXPORT_PRIVATE QuicConnectionHelperInterface { |
| 442 | public: |
| 443 | virtual ~QuicConnectionHelperInterface() {} |
| 444 | |
| 445 | // Returns a QuicClock to be used for all time related functions. |
| 446 | virtual const QuicClock* GetClock() const = 0; |
| 447 | |
| 448 | // Returns a QuicRandom to be used for all random number related functions. |
| 449 | virtual QuicRandom* GetRandomGenerator() = 0; |
| 450 | |
| 451 | // Returns a QuicBufferAllocator to be used for stream send buffers. |
| 452 | virtual QuicBufferAllocator* GetStreamSendBufferAllocator() = 0; |
| 453 | }; |
| 454 | |
| 455 | class QUIC_EXPORT_PRIVATE QuicConnection |
| 456 | : public QuicFramerVisitorInterface, |
| 457 | public QuicBlockedWriterInterface, |
fayang | cad1179 | 2019-09-16 13:11:44 -0700 | [diff] [blame] | 458 | public QuicPacketCreator::DelegateInterface, |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 459 | public QuicSentPacketManager::NetworkChangeVisitor, |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 460 | public QuicNetworkBlackholeDetector::Delegate, |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 461 | public QuicIdleNetworkDetector::Delegate, |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 462 | public QuicPathValidator::SendDelegate, |
| 463 | public QuicConnectionIdManagerVisitorInterface { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 464 | public: |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 465 | // Constructs a new QuicConnection for |connection_id| and |
| 466 | // |initial_peer_address| using |writer| to write packets. |owns_writer| |
| 467 | // specifies whether the connection takes ownership of |writer|. |helper| must |
| 468 | // outlive this connection. |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 469 | QuicConnection(QuicConnectionId server_connection_id, |
wub | 5df3663 | 2020-10-01 14:42:17 -0700 | [diff] [blame] | 470 | QuicSocketAddress initial_self_address, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 471 | QuicSocketAddress initial_peer_address, |
| 472 | QuicConnectionHelperInterface* helper, |
| 473 | QuicAlarmFactory* alarm_factory, |
| 474 | QuicPacketWriter* writer, |
| 475 | bool owns_writer, |
| 476 | Perspective perspective, |
| 477 | const ParsedQuicVersionVector& supported_versions); |
| 478 | QuicConnection(const QuicConnection&) = delete; |
| 479 | QuicConnection& operator=(const QuicConnection&) = delete; |
| 480 | ~QuicConnection() override; |
| 481 | |
| 482 | // Sets connection parameters from the supplied |config|. |
| 483 | void SetFromConfig(const QuicConfig& config); |
| 484 | |
wub | d09f1a6 | 2020-05-04 06:57:40 -0700 | [diff] [blame] | 485 | // Apply |connection_options| for this connection. Unlike SetFromConfig, this |
| 486 | // can happen at anytime in the life of a connection. |
| 487 | // Note there is no guarantee that all options can be applied. Components will |
| 488 | // only apply cherrypicked options that make sense at the time of the call. |
| 489 | void ApplyConnectionOptions(const QuicTagVector& connection_options); |
| 490 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 491 | // Called by the session when sending connection state to the client. |
| 492 | virtual void OnSendConnectionState( |
| 493 | const CachedNetworkParameters& cached_network_params); |
| 494 | |
| 495 | // Called by the session when receiving connection state from the client. |
| 496 | virtual void OnReceiveConnectionState( |
| 497 | const CachedNetworkParameters& cached_network_params); |
| 498 | |
| 499 | // Called by the Session when the client has provided CachedNetworkParameters. |
| 500 | virtual void ResumeConnectionState( |
| 501 | const CachedNetworkParameters& cached_network_params, |
| 502 | bool max_bandwidth_resumption); |
| 503 | |
| 504 | // Called by the Session when a max pacing rate for the connection is needed. |
| 505 | virtual void SetMaxPacingRate(QuicBandwidth max_pacing_rate); |
| 506 | |
| 507 | // Allows the client to adjust network parameters based on external |
| 508 | // information. |
QUICHE team | fdcfe3b | 2019-11-06 10:54:25 -0800 | [diff] [blame] | 509 | void AdjustNetworkParameters( |
| 510 | const SendAlgorithmInterface::NetworkParams& params); |
fayang | f1b99dc | 2019-05-14 06:29:18 -0700 | [diff] [blame] | 511 | void AdjustNetworkParameters(QuicBandwidth bandwidth, |
| 512 | QuicTime::Delta rtt, |
| 513 | bool allow_cwnd_to_decrease); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 514 | |
wub | 44e3305 | 2020-03-03 17:11:40 -0800 | [diff] [blame] | 515 | // Install a loss detection tuner. Must be called before OnConfigNegotiated. |
| 516 | void SetLossDetectionTuner( |
| 517 | std::unique_ptr<LossDetectionTunerInterface> tuner); |
| 518 | // Called by the session when session->is_configured() becomes true. |
| 519 | void OnConfigNegotiated(); |
| 520 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 521 | // Returns the max pacing rate for the connection. |
| 522 | virtual QuicBandwidth MaxPacingRate() const; |
| 523 | |
| 524 | // Sends crypto handshake messages of length |write_length| to the peer in as |
| 525 | // few packets as possible. Returns the number of bytes consumed from the |
| 526 | // data. |
| 527 | virtual size_t SendCryptoData(EncryptionLevel level, |
| 528 | size_t write_length, |
| 529 | QuicStreamOffset offset); |
| 530 | |
| 531 | // Send the data of length |write_length| to the peer in as few packets as |
| 532 | // possible. Returns the number of bytes consumed from data, and a boolean |
| 533 | // indicating if the fin bit was consumed. This does not indicate the data |
| 534 | // has been sent on the wire: it may have been turned into a packet and queued |
| 535 | // if the socket was unexpectedly blocked. |
| 536 | virtual QuicConsumedData SendStreamData(QuicStreamId id, |
| 537 | size_t write_length, |
| 538 | QuicStreamOffset offset, |
| 539 | StreamSendingState state); |
| 540 | |
| 541 | // Send |frame| to the peer. Returns true if frame is consumed, false |
| 542 | // otherwise. |
| 543 | virtual bool SendControlFrame(const QuicFrame& frame); |
| 544 | |
| 545 | // Called when stream |id| is reset because of |error|. |
| 546 | virtual void OnStreamReset(QuicStreamId id, QuicRstStreamErrorCode error); |
| 547 | |
| 548 | // Closes the connection. |
| 549 | // |connection_close_behavior| determines whether or not a connection close |
| 550 | // packet is sent to the peer. |
| 551 | virtual void CloseConnection( |
| 552 | QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 553 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 554 | ConnectionCloseBehavior connection_close_behavior); |
mattm | 55006b0 | 2021-01-14 15:09:54 -0800 | [diff] [blame] | 555 | // Closes the connection, specifying the wire error code |ietf_error| |
| 556 | // explicitly. |
| 557 | virtual void CloseConnection( |
| 558 | QuicErrorCode error, |
| 559 | QuicIetfTransportErrorCodes ietf_error, |
| 560 | const std::string& details, |
| 561 | ConnectionCloseBehavior connection_close_behavior); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 562 | |
wub | b104f0f | 2020-07-06 11:58:08 -0700 | [diff] [blame] | 563 | QuicConnectionStats& mutable_stats() { return stats_; } |
| 564 | |
dschinazi | 4933ced | 2020-10-20 09:51:12 -0700 | [diff] [blame] | 565 | int retransmittable_on_wire_ping_count() const { |
| 566 | return retransmittable_on_wire_ping_count_; |
| 567 | } |
| 568 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 569 | // Returns statistics tracked for this connection. |
| 570 | const QuicConnectionStats& GetStats(); |
| 571 | |
| 572 | // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from |
| 573 | // the peer. |
| 574 | // In a client, the packet may be "stray" and have a different connection ID |
| 575 | // than that of this connection. |
| 576 | virtual void ProcessUdpPacket(const QuicSocketAddress& self_address, |
| 577 | const QuicSocketAddress& peer_address, |
| 578 | const QuicReceivedPacket& packet); |
| 579 | |
| 580 | // QuicBlockedWriterInterface |
| 581 | // Called when the underlying connection becomes writable to allow queued |
| 582 | // writes to happen. |
| 583 | void OnBlockedWriterCanWrite() override; |
| 584 | |
| 585 | bool IsWriterBlocked() const override { |
| 586 | return writer_ != nullptr && writer_->IsWriteBlocked(); |
| 587 | } |
| 588 | |
| 589 | // Called when the caller thinks it's worth a try to write. |
fayang | c2638cc | 2021-04-05 14:45:40 -0700 | [diff] [blame] | 590 | // TODO(fayang): consider unifying this with QuicSession::OnCanWrite. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 591 | virtual void OnCanWrite(); |
| 592 | |
| 593 | // Called when an error occurs while attempting to write a packet to the |
| 594 | // network. |
| 595 | void OnWriteError(int error_code); |
| 596 | |
| 597 | // Whether |result| represents a MSG TOO BIG write error. |
| 598 | bool IsMsgTooBig(const WriteResult& result); |
| 599 | |
| 600 | // If the socket is not blocked, writes queued packets. |
| 601 | void WriteIfNotBlocked(); |
| 602 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 603 | // Set the packet writer. |
| 604 | void SetQuicPacketWriter(QuicPacketWriter* writer, bool owns_writer) { |
vasilvv | 5cef78e | 2021-01-30 11:11:14 -0800 | [diff] [blame] | 605 | QUICHE_DCHECK(writer != nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 606 | if (writer_ != nullptr && owns_writer_) { |
| 607 | delete writer_; |
| 608 | } |
| 609 | writer_ = writer; |
| 610 | owns_writer_ = owns_writer; |
| 611 | } |
| 612 | |
| 613 | // Set self address. |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 614 | void SetSelfAddress(QuicSocketAddress address) { |
| 615 | default_path_.self_address = address; |
| 616 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 617 | |
| 618 | // The version of the protocol this connection is using. |
| 619 | QuicTransportVersion transport_version() const { |
| 620 | return framer_.transport_version(); |
| 621 | } |
| 622 | |
| 623 | ParsedQuicVersion version() const { return framer_.version(); } |
| 624 | |
| 625 | // The versions of the protocol that this connection supports. |
| 626 | const ParsedQuicVersionVector& supported_versions() const { |
| 627 | return framer_.supported_versions(); |
| 628 | } |
| 629 | |
wub | f75c2c6 | 2020-02-05 06:34:09 -0800 | [diff] [blame] | 630 | // Mark version negotiated for this connection. Once called, the connection |
| 631 | // will ignore received version negotiation packets. |
| 632 | void SetVersionNegotiated() { |
| 633 | version_negotiated_ = true; |
| 634 | if (perspective_ == Perspective::IS_SERVER) { |
| 635 | framer_.InferPacketHeaderTypeFromVersion(); |
| 636 | } |
| 637 | } |
| 638 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 639 | // From QuicFramerVisitorInterface |
| 640 | void OnError(QuicFramer* framer) override; |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 641 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 642 | void OnPacket() override; |
| 643 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override; |
| 644 | void OnVersionNegotiationPacket( |
| 645 | const QuicVersionNegotiationPacket& packet) override; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 646 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 647 | QuicConnectionId new_connection_id, |
vasilvv | 9a36d72 | 2020-10-02 16:51:38 -0700 | [diff] [blame] | 648 | absl::string_view retry_token, |
| 649 | absl::string_view retry_integrity_tag, |
| 650 | absl::string_view retry_without_tag) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 651 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override; |
| 652 | bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
fayang | 93b4e4d | 2020-11-25 07:56:47 -0800 | [diff] [blame] | 653 | void OnDecryptedPacket(size_t length, EncryptionLevel level) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 654 | bool OnPacketHeader(const QuicPacketHeader& header) override; |
| 655 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override; |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 656 | void OnUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 657 | EncryptionLevel decryption_level, |
| 658 | bool has_decryption_key) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 659 | bool OnStreamFrame(const QuicStreamFrame& frame) override; |
| 660 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override; |
| 661 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 662 | QuicTime::Delta ack_delay_time) override; |
| 663 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override; |
| 664 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 665 | QuicTime timestamp) override; |
| 666 | bool OnAckFrameEnd(QuicPacketNumber start) override; |
| 667 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
| 668 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override; |
| 669 | bool OnPingFrame(const QuicPingFrame& frame) override; |
| 670 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
| 671 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 672 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override; |
| 673 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override; |
| 674 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override; |
| 675 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 676 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override; |
| 677 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 678 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 679 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 680 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override; |
| 681 | bool OnRetireConnectionIdFrame( |
| 682 | const QuicRetireConnectionIdFrame& frame) override; |
| 683 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override; |
| 684 | bool OnMessageFrame(const QuicMessageFrame& frame) override; |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 685 | bool OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& frame) override; |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 686 | bool OnAckFrequencyFrame(const QuicAckFrequencyFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 687 | void OnPacketComplete() override; |
bnc | 1ccd0bc | 2021-04-07 10:20:17 -0700 | [diff] [blame] | 688 | bool IsValidStatelessResetToken( |
| 689 | const StatelessResetToken& token) const override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 690 | void OnAuthenticatedIetfStatelessResetPacket( |
| 691 | const QuicIetfStatelessResetPacket& packet) override; |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 692 | void OnKeyUpdate(KeyUpdateReason reason) override; |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 693 | void OnDecryptedFirstPacketInKeyPhase() override; |
| 694 | std::unique_ptr<QuicDecrypter> AdvanceKeysAndCreateCurrentOneRttDecrypter() |
| 695 | override; |
| 696 | std::unique_ptr<QuicEncrypter> CreateCurrentOneRttEncrypter() override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 697 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 698 | // QuicPacketCreator::DelegateInterface |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 699 | bool ShouldGeneratePacket(HasRetransmittableData retransmittable, |
| 700 | IsHandshake handshake) override; |
| 701 | const QuicFrames MaybeBundleAckOpportunistically() override; |
wub | 50d4c71 | 2020-05-19 15:48:28 -0700 | [diff] [blame] | 702 | QuicPacketBuffer GetPacketBuffer() override; |
wub | 8a5dafa | 2020-05-13 12:30:17 -0700 | [diff] [blame] | 703 | void OnSerializedPacket(SerializedPacket packet) override; |
ianswett | b023c7b | 2019-05-06 12:38:10 -0700 | [diff] [blame] | 704 | void OnUnrecoverableError(QuicErrorCode error, |
fkastenholz | 85f1890 | 2019-05-28 12:47:00 -0700 | [diff] [blame] | 705 | const std::string& error_details) override; |
fayang | 1504296 | 2020-07-01 12:14:29 -0700 | [diff] [blame] | 706 | SerializedPacketFate GetSerializedPacketFate( |
| 707 | bool is_mtu_discovery, |
| 708 | EncryptionLevel encryption_level) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 709 | |
| 710 | // QuicSentPacketManager::NetworkChangeVisitor |
| 711 | void OnCongestionChange() override; |
| 712 | void OnPathMtuIncreased(QuicPacketLength packet_size) override; |
| 713 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 714 | // QuicNetworkBlackholeDetector::Delegate |
| 715 | void OnPathDegradingDetected() override; |
| 716 | void OnBlackholeDetected() override; |
wub | 8add68a | 2020-07-27 12:07:38 -0700 | [diff] [blame] | 717 | void OnPathMtuReductionDetected() override; |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 718 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 719 | // QuicIdleNetworkDetector::Delegate |
| 720 | void OnHandshakeTimeout() override; |
| 721 | void OnIdleNetworkDetected() override; |
| 722 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 723 | // QuicConnectionIdManagerVisitorInterface |
| 724 | void OnPeerIssuedConnectionIdRetired() override; |
| 725 | bool SendNewConnectionId(const QuicNewConnectionIdFrame& frame) override; |
| 726 | void OnNewConnectionIdIssued(const QuicConnectionId& connection_id) override; |
| 727 | void OnSelfIssuedConnectionIdRetired( |
| 728 | const QuicConnectionId& connection_id) override; |
| 729 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 730 | // Please note, this is not a const function. For logging purpose, please use |
| 731 | // ack_frame(). |
| 732 | const QuicFrame GetUpdatedAckFrame(); |
| 733 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 734 | // Called to send a new connection ID to client if the # of connection ID has |
| 735 | // not exceeded the active connection ID limits. |
| 736 | void MaybeSendConnectionIdToClient(); |
| 737 | |
fayang | bd79392 | 2019-08-26 14:19:24 -0700 | [diff] [blame] | 738 | // Called when the handshake completes. On the client side, handshake |
| 739 | // completes on receipt of SHLO. On the server side, handshake completes when |
| 740 | // SHLO gets ACKed (or a forward secure packet gets decrypted successfully). |
| 741 | // TODO(fayang): Add a guard that this only gets called once. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 742 | void OnHandshakeComplete(); |
| 743 | |
| 744 | // Accessors |
| 745 | void set_visitor(QuicConnectionVisitorInterface* visitor) { |
| 746 | visitor_ = visitor; |
| 747 | } |
| 748 | void set_debug_visitor(QuicConnectionDebugVisitor* debug_visitor) { |
| 749 | debug_visitor_ = debug_visitor; |
| 750 | sent_packet_manager_.SetDebugDelegate(debug_visitor); |
| 751 | } |
| 752 | // Used in Chromium, but not internally. |
| 753 | // Must only be called before ping_alarm_ is set. |
| 754 | void set_ping_timeout(QuicTime::Delta ping_timeout) { |
vasilvv | 5cef78e | 2021-01-30 11:11:14 -0800 | [diff] [blame] | 755 | QUICHE_DCHECK(!ping_alarm_->IsSet()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 756 | ping_timeout_ = ping_timeout; |
| 757 | } |
zhongyi | cdf8b1b | 2019-10-22 12:03:10 -0700 | [diff] [blame] | 758 | const QuicTime::Delta ping_timeout() const { return ping_timeout_; } |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 759 | // Sets an initial timeout for the ping alarm when there is no retransmittable |
| 760 | // data in flight, allowing for a more aggressive ping alarm in that case. |
| 761 | void set_initial_retransmittable_on_wire_timeout( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 762 | QuicTime::Delta retransmittable_on_wire_timeout) { |
vasilvv | 5cef78e | 2021-01-30 11:11:14 -0800 | [diff] [blame] | 763 | QUICHE_DCHECK(!ping_alarm_->IsSet()); |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 764 | initial_retransmittable_on_wire_timeout_ = retransmittable_on_wire_timeout; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 765 | } |
zhongyi | cdf8b1b | 2019-10-22 12:03:10 -0700 | [diff] [blame] | 766 | const QuicTime::Delta initial_retransmittable_on_wire_timeout() const { |
| 767 | return initial_retransmittable_on_wire_timeout_; |
| 768 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 769 | // Used in Chromium, but not internally. |
| 770 | void set_creator_debug_delegate(QuicPacketCreator::DebugDelegate* visitor) { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 771 | packet_creator_.set_debug_delegate(visitor); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 772 | } |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 773 | const QuicSocketAddress& self_address() const { |
| 774 | return default_path_.self_address; |
| 775 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 776 | const QuicSocketAddress& peer_address() const { return direct_peer_address_; } |
| 777 | const QuicSocketAddress& effective_peer_address() const { |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 778 | return default_path_.peer_address; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 779 | } |
haoyuewang | 16ef03b | 2021-06-30 07:59:53 -0700 | [diff] [blame] | 780 | const QuicConnectionId& connection_id() const { |
| 781 | return default_path_.server_connection_id; |
| 782 | } |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 783 | const QuicConnectionId& client_connection_id() const { |
haoyuewang | 16ef03b | 2021-06-30 07:59:53 -0700 | [diff] [blame] | 784 | return default_path_.client_connection_id; |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 785 | } |
| 786 | void set_client_connection_id(QuicConnectionId client_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 787 | const QuicClock* clock() const { return clock_; } |
| 788 | QuicRandom* random_generator() const { return random_generator_; } |
| 789 | QuicByteCount max_packet_length() const; |
| 790 | void SetMaxPacketLength(QuicByteCount length); |
| 791 | |
| 792 | size_t mtu_probe_count() const { return mtu_probe_count_; } |
| 793 | |
| 794 | bool connected() const { return connected_; } |
| 795 | |
| 796 | // Must only be called on client connections. |
| 797 | const ParsedQuicVersionVector& server_supported_versions() const { |
vasilvv | 5cef78e | 2021-01-30 11:11:14 -0800 | [diff] [blame] | 798 | QUICHE_DCHECK_EQ(Perspective::IS_CLIENT, perspective_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 799 | return server_supported_versions_; |
| 800 | } |
| 801 | |
ianswett | fc16a2b | 2020-05-18 16:05:49 -0700 | [diff] [blame] | 802 | bool HasQueuedPackets() const { return !buffered_packets_.empty(); } |
| 803 | // Testing only. TODO(ianswett): Use a peer instead. |
fayang | e62e63c | 2019-12-04 07:16:25 -0800 | [diff] [blame] | 804 | size_t NumQueuedPackets() const { return buffered_packets_.size(); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 805 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 806 | // Returns true if the connection has queued packets or frames. |
| 807 | bool HasQueuedData() const; |
| 808 | |
| 809 | // Sets the handshake and idle state connection timeouts. |
| 810 | void SetNetworkTimeouts(QuicTime::Delta handshake_timeout, |
| 811 | QuicTime::Delta idle_timeout); |
| 812 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 813 | // Called when the ping alarm fires. Causes a ping frame to be sent only |
| 814 | // if the retransmission alarm is not running. |
| 815 | void OnPingTimeout(); |
| 816 | |
| 817 | // Sets up a packet with an QuicAckFrame and sends it out. |
| 818 | void SendAck(); |
| 819 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 820 | // Called when an RTO fires. Resets the retransmission alarm if there are |
| 821 | // remaining unacked packets. |
| 822 | void OnRetransmissionTimeout(); |
| 823 | |
renjietang | b2b8ff2 | 2020-07-07 16:18:54 -0700 | [diff] [blame] | 824 | // Mark all sent 0-RTT encrypted packets for retransmission. Called when new |
| 825 | // 0-RTT or 1-RTT key is available in gQUIC, or when 0-RTT is rejected in IETF |
renjietang | f71e806 | 2020-09-14 12:01:15 -0700 | [diff] [blame] | 826 | // QUIC. |reject_reason| is used in TLS-QUIC to log why 0-RTT was rejected. |
| 827 | void MarkZeroRttPacketsForRetransmission(int reject_reason); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 828 | |
| 829 | // Calls |sent_packet_manager_|'s NeuterUnencryptedPackets. Used when the |
| 830 | // connection becomes forward secure and hasn't received acks for all packets. |
| 831 | void NeuterUnencryptedPackets(); |
| 832 | |
| 833 | // Changes the encrypter used for level |level| to |encrypter|. |
| 834 | void SetEncrypter(EncryptionLevel level, |
| 835 | std::unique_ptr<QuicEncrypter> encrypter); |
| 836 | |
fayang | b296fb8 | 2020-02-11 08:14:28 -0800 | [diff] [blame] | 837 | // Called to remove encrypter of encryption |level|. |
| 838 | void RemoveEncrypter(EncryptionLevel level); |
| 839 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 840 | // SetNonceForPublicHeader sets the nonce that will be transmitted in the |
| 841 | // header of each packet encrypted at the initial encryption level decrypted. |
| 842 | // This should only be called on the server side. |
| 843 | void SetDiversificationNonce(const DiversificationNonce& nonce); |
| 844 | |
| 845 | // SetDefaultEncryptionLevel sets the encryption level that will be applied |
| 846 | // to new packets. |
| 847 | void SetDefaultEncryptionLevel(EncryptionLevel level); |
| 848 | |
| 849 | // SetDecrypter sets the primary decrypter, replacing any that already exists. |
vasilvv | 5cef78e | 2021-01-30 11:11:14 -0800 | [diff] [blame] | 850 | // If an alternative decrypter is in place then the function QUICHE_DCHECKs. |
| 851 | // This is intended for cases where one knows that future packets will be |
| 852 | // using the new decrypter and the previous decrypter is now obsolete. |level| |
| 853 | // indicates the encryption level of the new decrypter. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 854 | void SetDecrypter(EncryptionLevel level, |
| 855 | std::unique_ptr<QuicDecrypter> decrypter); |
| 856 | |
| 857 | // SetAlternativeDecrypter sets a decrypter that may be used to decrypt |
| 858 | // future packets. |level| indicates the encryption level of the decrypter. If |
| 859 | // |latch_once_used| is true, then the first time that the decrypter is |
| 860 | // successful it will replace the primary decrypter. Otherwise both |
| 861 | // decrypters will remain active and the primary decrypter will be the one |
| 862 | // last used. |
| 863 | void SetAlternativeDecrypter(EncryptionLevel level, |
| 864 | std::unique_ptr<QuicDecrypter> decrypter, |
| 865 | bool latch_once_used); |
| 866 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 867 | void InstallDecrypter(EncryptionLevel level, |
| 868 | std::unique_ptr<QuicDecrypter> decrypter); |
| 869 | void RemoveDecrypter(EncryptionLevel level); |
| 870 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 871 | // Discard keys for the previous key phase. |
| 872 | void DiscardPreviousOneRttKeys(); |
| 873 | |
| 874 | // Returns true if it is currently allowed to initiate a key update. |
| 875 | bool IsKeyUpdateAllowed() const; |
| 876 | |
mattm | 948d689 | 2020-10-22 17:24:11 -0700 | [diff] [blame] | 877 | // Returns true if packets have been sent in the current 1-RTT key phase but |
| 878 | // none of these packets have been acked. |
| 879 | bool HaveSentPacketsInCurrentKeyPhaseButNoneAcked() const; |
| 880 | |
mattm | d061ef1 | 2020-10-23 11:21:31 -0700 | [diff] [blame] | 881 | // Returns the count of packets received that appeared to attempt a key |
| 882 | // update but failed decryption that have been received since the last |
| 883 | // successfully decrypted packet. |
| 884 | QuicPacketCount PotentialPeerKeyUpdateAttemptCount() const; |
| 885 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 886 | // Increment the key phase. It is a bug to call this when IsKeyUpdateAllowed() |
| 887 | // is false. Returns false on error. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 888 | bool InitiateKeyUpdate(KeyUpdateReason reason); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 889 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 890 | const QuicDecrypter* decrypter() const; |
| 891 | const QuicDecrypter* alternative_decrypter() const; |
| 892 | |
| 893 | Perspective perspective() const { return perspective_; } |
| 894 | |
| 895 | // Allow easy overriding of truncated connection IDs. |
| 896 | void set_can_truncate_connection_ids(bool can) { |
| 897 | can_truncate_connection_ids_ = can; |
| 898 | } |
| 899 | |
| 900 | // Returns the underlying sent packet manager. |
| 901 | const QuicSentPacketManager& sent_packet_manager() const { |
| 902 | return sent_packet_manager_; |
| 903 | } |
| 904 | |
| 905 | // Returns the underlying sent packet manager. |
| 906 | QuicSentPacketManager& sent_packet_manager() { return sent_packet_manager_; } |
| 907 | |
ianswett | 309987e | 2019-08-02 13:16:26 -0700 | [diff] [blame] | 908 | UberReceivedPacketManager& received_packet_manager() { |
| 909 | return uber_received_packet_manager_; |
| 910 | } |
| 911 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 912 | bool CanWrite(HasRetransmittableData retransmittable); |
| 913 | |
| 914 | // When the flusher is out of scope, only the outermost flusher will cause a |
| 915 | // flush of the connection and set the retransmission alarm if there is one |
| 916 | // pending. In addition, this flusher can be configured to ensure that an ACK |
| 917 | // frame is included in the first packet created, if there's new ack |
| 918 | // information to be sent. |
| 919 | class QUIC_EXPORT_PRIVATE ScopedPacketFlusher { |
| 920 | public: |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 921 | explicit ScopedPacketFlusher(QuicConnection* connection); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 922 | ~ScopedPacketFlusher(); |
| 923 | |
| 924 | private: |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 925 | QuicConnection* connection_; |
| 926 | // If true, when this flusher goes out of scope, flush connection and set |
| 927 | // retransmission alarm if there is one pending. |
| 928 | bool flush_and_set_pending_retransmission_alarm_on_delete_; |
fayang | d868245 | 2020-09-28 09:09:29 -0700 | [diff] [blame] | 929 | // Latched connection's handshake_packet_sent_ on creation of this flusher. |
| 930 | const bool handshake_packet_sent_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 931 | }; |
| 932 | |
fayang | ec14d2b | 2020-10-02 12:00:05 -0700 | [diff] [blame] | 933 | class QUIC_EXPORT_PRIVATE ScopedEncryptionLevelContext { |
| 934 | public: |
| 935 | ScopedEncryptionLevelContext(QuicConnection* connection, |
| 936 | EncryptionLevel level); |
| 937 | ~ScopedEncryptionLevelContext(); |
| 938 | |
| 939 | private: |
| 940 | QuicConnection* connection_; |
| 941 | // Latched current write encryption level on creation of this context. |
| 942 | EncryptionLevel latched_encryption_level_; |
| 943 | }; |
| 944 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 945 | QuicPacketWriter* writer() { return writer_; } |
| 946 | const QuicPacketWriter* writer() const { return writer_; } |
| 947 | |
| 948 | // Sends an MTU discovery packet of size |target_mtu|. If the packet is |
| 949 | // acknowledged by the peer, the maximum packet size will be increased to |
| 950 | // |target_mtu|. |
| 951 | void SendMtuDiscoveryPacket(QuicByteCount target_mtu); |
| 952 | |
| 953 | // Sends a connectivity probing packet to |peer_address| with |
| 954 | // |probing_writer|. If |probing_writer| is nullptr, will use default |
| 955 | // packet writer to write the packet. Returns true if subsequent packets can |
| 956 | // be written to the probing writer. If connection is V99, a padded IETF QUIC |
| 957 | // PATH_CHALLENGE packet is transmitted; if not V99, a Google QUIC padded PING |
| 958 | // packet is transmitted. |
| 959 | virtual bool SendConnectivityProbingPacket( |
| 960 | QuicPacketWriter* probing_writer, |
| 961 | const QuicSocketAddress& peer_address); |
| 962 | |
| 963 | // Sends response to a connectivity probe. Sends either a Padded Ping |
| 964 | // or an IETF PATH_RESPONSE based on the version of the connection. |
| 965 | // Is the counterpart to SendConnectivityProbingPacket(). |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 966 | // TODO(danzh): remove this method after deprecating |
| 967 | // --gfe2_reloadable_flag_quic_send_path_response. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 968 | virtual void SendConnectivityProbingResponsePacket( |
| 969 | const QuicSocketAddress& peer_address); |
| 970 | |
wub | 610f7ce | 2020-08-14 14:19:02 -0700 | [diff] [blame] | 971 | // Disable MTU discovery on this connection. |
| 972 | void DisableMtuDiscovery(); |
| 973 | |
wub | 173916e | 2019-11-27 14:36:24 -0800 | [diff] [blame] | 974 | // Sends an MTU discovery packet and updates the MTU discovery alarm. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 975 | void DiscoverMtu(); |
| 976 | |
| 977 | // Sets the session notifier on the SentPacketManager. |
| 978 | void SetSessionNotifier(SessionNotifierInterface* session_notifier); |
| 979 | |
| 980 | // Set data producer in framer. |
| 981 | void SetDataProducer(QuicStreamFrameDataProducer* data_producer); |
| 982 | |
| 983 | // Set transmission type of next sending packets. |
| 984 | void SetTransmissionType(TransmissionType type); |
| 985 | |
| 986 | // Tries to send |message| and returns the message status. |
QUICHE team | 350e9e6 | 2019-11-19 13:16:24 -0800 | [diff] [blame] | 987 | // If |flush| is false, this will return a MESSAGE_STATUS_BLOCKED |
| 988 | // when the connection is deemed unwritable. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 989 | virtual MessageStatus SendMessage(QuicMessageId message_id, |
vasilvv | 2c82ff7 | 2021-07-14 09:58:38 -0700 | [diff] [blame] | 990 | absl::Span<QuicMemSlice> message, |
QUICHE team | 350e9e6 | 2019-11-19 13:16:24 -0800 | [diff] [blame] | 991 | bool flush); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 992 | |
| 993 | // Returns the largest payload that will fit into a single MESSAGE frame. |
ianswett | b239f86 | 2019-04-05 09:15:06 -0700 | [diff] [blame] | 994 | // Because overhead can vary during a connection, this method should be |
| 995 | // checked for every message. |
| 996 | QuicPacketLength GetCurrentLargestMessagePayload() const; |
| 997 | // Returns the largest payload that will fit into a single MESSAGE frame at |
| 998 | // any point during the connection. This assumes the version and |
| 999 | // connection ID lengths do not change. |
| 1000 | QuicPacketLength GetGuaranteedLargestMessagePayload() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1001 | |
haoyuewang | cb7960c | 2020-11-23 16:40:53 -0800 | [diff] [blame] | 1002 | void SetUnackedMapInitialCapacity(); |
| 1003 | |
haoyuewang | e0acd51 | 2020-11-05 09:18:36 -0800 | [diff] [blame] | 1004 | virtual int GetUnackedMapInitialCapacity() const { |
| 1005 | return kDefaultUnackedPacketsInitialCapacity; |
| 1006 | } |
| 1007 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1008 | // Returns the id of the cipher last used for decrypting packets. |
| 1009 | uint32_t cipher_id() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1010 | |
| 1011 | std::vector<std::unique_ptr<QuicEncryptedPacket>>* termination_packets() { |
| 1012 | return termination_packets_.get(); |
| 1013 | } |
| 1014 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1015 | bool ack_frame_updated() const; |
| 1016 | |
| 1017 | QuicConnectionHelperInterface* helper() { return helper_; } |
wub | b104f0f | 2020-07-06 11:58:08 -0700 | [diff] [blame] | 1018 | const QuicConnectionHelperInterface* helper() const { return helper_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1019 | QuicAlarmFactory* alarm_factory() { return alarm_factory_; } |
| 1020 | |
vasilvv | 9a36d72 | 2020-10-02 16:51:38 -0700 | [diff] [blame] | 1021 | absl::string_view GetCurrentPacket(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1022 | |
| 1023 | const QuicFramer& framer() const { return framer_; } |
| 1024 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 1025 | const QuicPacketCreator& packet_creator() const { return packet_creator_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1026 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1027 | EncryptionLevel encryption_level() const { return encryption_level_; } |
| 1028 | EncryptionLevel last_decrypted_level() const { |
| 1029 | return last_decrypted_packet_level_; |
| 1030 | } |
| 1031 | |
| 1032 | const QuicSocketAddress& last_packet_source_address() const { |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 1033 | return last_received_packet_info_.source_address; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | bool fill_up_link_during_probing() const { |
| 1037 | return fill_up_link_during_probing_; |
| 1038 | } |
| 1039 | void set_fill_up_link_during_probing(bool new_value) { |
| 1040 | fill_up_link_during_probing_ = new_value; |
| 1041 | } |
| 1042 | |
| 1043 | // This setting may be changed during the crypto handshake in order to |
| 1044 | // enable/disable padding of different packets in the crypto handshake. |
| 1045 | // |
| 1046 | // This setting should never be set to false in public facing endpoints. It |
| 1047 | // can only be set to false if there is some other mechanism of preventing |
| 1048 | // amplification attacks, such as ICE (plus its a non-standard quic). |
nharper | 3907ac2 | 2019-09-25 15:32:28 -0700 | [diff] [blame] | 1049 | void set_fully_pad_crypto_handshake_packets(bool new_value) { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 1050 | packet_creator_.set_fully_pad_crypto_handshake_packets(new_value); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | bool fully_pad_during_crypto_handshake() const { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 1054 | return packet_creator_.fully_pad_crypto_handshake_packets(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | size_t min_received_before_ack_decimation() const; |
| 1058 | void set_min_received_before_ack_decimation(size_t new_value); |
| 1059 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1060 | // If |defer| is true, configures the connection to defer sending packets in |
| 1061 | // response to an ACK to the SendAlarm. If |defer| is false, packets may be |
| 1062 | // sent immediately after receiving an ACK. |
| 1063 | void set_defer_send_in_response_to_packets(bool defer) { |
| 1064 | defer_send_in_response_to_packets_ = defer; |
| 1065 | } |
| 1066 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1067 | // Sets the current per-packet options for the connection. The QuicConnection |
| 1068 | // does not take ownership of |options|; |options| must live for as long as |
| 1069 | // the QuicConnection is in use. |
| 1070 | void set_per_packet_options(PerPacketOptions* options) { |
| 1071 | per_packet_options_ = options; |
| 1072 | } |
| 1073 | |
| 1074 | bool IsPathDegrading() const { return is_path_degrading_; } |
| 1075 | |
| 1076 | // Attempts to process any queued undecryptable packets. |
| 1077 | void MaybeProcessUndecryptablePackets(); |
| 1078 | |
| 1079 | // Queue a coalesced packet. |
| 1080 | void QueueCoalescedPacket(const QuicEncryptedPacket& packet); |
| 1081 | |
fayang | c2638cc | 2021-04-05 14:45:40 -0700 | [diff] [blame] | 1082 | // Process previously queued coalesced packets. Returns true if any coalesced |
| 1083 | // packets have been successfully processed. |
| 1084 | bool MaybeProcessCoalescedPackets(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1085 | |
| 1086 | enum PacketContent : uint8_t { |
| 1087 | NO_FRAMES_RECEIVED, |
| 1088 | // TODO(fkastenholz): Change name when we get rid of padded ping/ |
| 1089 | // pre-version-99. |
| 1090 | // Also PATH CHALLENGE and PATH RESPONSE. |
| 1091 | FIRST_FRAME_IS_PING, |
| 1092 | SECOND_FRAME_IS_PADDING, |
| 1093 | NOT_PADDED_PING, // Set if the packet is not {PING, PADDING}. |
| 1094 | }; |
| 1095 | |
fayang | fa3b1d6 | 2019-11-18 08:02:13 -0800 | [diff] [blame] | 1096 | // Whether the handshake completes from this connection's perspective. |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 1097 | bool IsHandshakeComplete() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1098 | |
fayang | 5014e92 | 2020-01-22 12:28:11 -0800 | [diff] [blame] | 1099 | // Whether peer completes handshake. Only used with TLS handshake. |
| 1100 | bool IsHandshakeConfirmed() const; |
| 1101 | |
QUICHE team | 1f3de24 | 2019-03-20 07:24:48 -0700 | [diff] [blame] | 1102 | // Returns the largest received packet number sent by peer. |
| 1103 | QuicPacketNumber GetLargestReceivedPacket() const; |
| 1104 | |
dschinazi | 187683d | 2020-05-27 17:34:51 -0400 | [diff] [blame] | 1105 | // Sets the original destination connection ID on the connection. |
| 1106 | // This is called by QuicDispatcher when it has replaced the connection ID. |
| 1107 | void SetOriginalDestinationConnectionId( |
| 1108 | const QuicConnectionId& original_destination_connection_id); |
QUICHE team | c65d1d1 | 2019-03-19 20:58:04 -0700 | [diff] [blame] | 1109 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 1110 | // Returns the original destination connection ID used for this connection. |
| 1111 | QuicConnectionId GetOriginalDestinationConnectionId(); |
| 1112 | |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 1113 | // Called when ACK alarm goes off. Sends ACKs of those packet number spaces |
| 1114 | // which have expired ACK timeout. Only used when this connection supports |
| 1115 | // multiple packet number spaces. |
| 1116 | void SendAllPendingAcks(); |
| 1117 | |
| 1118 | // Returns true if this connection supports multiple packet number spaces. |
| 1119 | bool SupportsMultiplePacketNumberSpaces() const; |
| 1120 | |
fayang | 21ffb71 | 2019-05-16 08:39:26 -0700 | [diff] [blame] | 1121 | // For logging purpose. |
| 1122 | const QuicAckFrame& ack_frame() const; |
| 1123 | |
dschinazi | 5c03085 | 2019-07-11 15:45:53 -0700 | [diff] [blame] | 1124 | // Install encrypter and decrypter for ENCRYPTION_INITIAL using |
| 1125 | // |connection_id| as the first client-sent destination connection ID, |
| 1126 | // or the one sent after an IETF Retry. |
| 1127 | void InstallInitialCrypters(QuicConnectionId connection_id); |
| 1128 | |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 1129 | // Called when version is considered negotiated. |
| 1130 | void OnSuccessfulVersionNegotiation(); |
| 1131 | |
zhongyi | 2da16be | 2020-06-17 11:05:23 -0700 | [diff] [blame] | 1132 | // Called when self migration succeeds after probing. |
danzh | db84462 | 2021-02-18 10:23:05 -0800 | [diff] [blame] | 1133 | void OnSuccessfulMigration(bool is_port_change); |
zhongyi | 2da16be | 2020-06-17 11:05:23 -0700 | [diff] [blame] | 1134 | |
dschinazi | 631f160 | 2020-05-19 10:10:22 -0700 | [diff] [blame] | 1135 | // Called for QUIC+TLS versions when we send transport parameters. |
| 1136 | void OnTransportParametersSent( |
| 1137 | const TransportParameters& transport_parameters) const; |
| 1138 | |
| 1139 | // Called for QUIC+TLS versions when we receive transport parameters. |
| 1140 | void OnTransportParametersReceived( |
| 1141 | const TransportParameters& transport_parameters) const; |
| 1142 | |
renjietang | 8957c6e | 2020-08-12 16:08:21 -0700 | [diff] [blame] | 1143 | // Called for QUIC+TLS versions when we resume cached transport parameters for |
| 1144 | // 0-RTT. |
| 1145 | void OnTransportParametersResumed( |
| 1146 | const TransportParameters& transport_parameters) const; |
| 1147 | |
fayang | 9adfb53 | 2020-06-04 06:58:45 -0700 | [diff] [blame] | 1148 | // Returns true if ack_alarm_ is set. |
| 1149 | bool HasPendingAcks() const; |
| 1150 | |
wub | be634b7 | 2020-06-16 08:41:26 -0700 | [diff] [blame] | 1151 | void OnUserAgentIdKnown() { sent_packet_manager_.OnUserAgentIdKnown(); } |
| 1152 | |
dschinazi | 6458eb3 | 2020-06-23 12:38:41 -0700 | [diff] [blame] | 1153 | // Enables Legacy Version Encapsulation using |server_name| as SNI. |
| 1154 | // Can only be set if this is a client connection. |
| 1155 | void EnableLegacyVersionEncapsulation(const std::string& server_name); |
| 1156 | |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1157 | bool send_path_response() const { return send_path_response_; } |
| 1158 | |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1159 | bool use_path_validator() const { return use_path_validator_; } |
| 1160 | |
fayang | 001c828 | 2020-07-29 12:39:29 -0700 | [diff] [blame] | 1161 | // If now is close to idle timeout, returns true and sends a connectivity |
| 1162 | // probing packet to test the connection for liveness. Otherwise, returns |
| 1163 | // false. |
| 1164 | bool MaybeTestLiveness(); |
| 1165 | |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1166 | // QuicPathValidator::SendDelegate |
danzh | e919b00 | 2020-10-14 14:44:46 -0700 | [diff] [blame] | 1167 | // Send PATH_CHALLENGE using the given path information. If |writer| is the |
| 1168 | // default writer, PATH_CHALLENGE can be bundled with other frames, and the |
| 1169 | // containing packet can be buffered if the writer is blocked. Otherwise, |
| 1170 | // PATH_CHALLENGE will be written in an individual packet and it will be |
| 1171 | // dropped if write fails. |data_buffer| will be populated with the payload |
| 1172 | // for future validation. |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1173 | // Return false if the connection is closed thus the caller will not continue |
| 1174 | // the validation, otherwise return true. |
| 1175 | bool SendPathChallenge(const QuicPathFrameBuffer& data_buffer, |
danzh | e919b00 | 2020-10-14 14:44:46 -0700 | [diff] [blame] | 1176 | const QuicSocketAddress& self_address, |
| 1177 | const QuicSocketAddress& peer_address, |
danzh | 8037466 | 2020-12-21 15:56:17 -0800 | [diff] [blame] | 1178 | const QuicSocketAddress& effective_peer_address, |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1179 | QuicPacketWriter* writer) override; |
| 1180 | // If |writer| is the default writer and |peer_address| is the same as |
| 1181 | // peer_address(), return the PTO of this connection. Otherwise, return 3 * |
| 1182 | // kInitialRtt. |
| 1183 | QuicTime GetRetryTimeout(const QuicSocketAddress& peer_address_to_use, |
| 1184 | QuicPacketWriter* writer_to_use) const override; |
| 1185 | |
| 1186 | // Start vaildating the path defined by |context| asynchronously and call the |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1187 | // |result_delegate| after validation finishes. If the connection is |
| 1188 | // validating another path, cancel and fail that validation before starting |
| 1189 | // this one. |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1190 | void ValidatePath( |
| 1191 | std::unique_ptr<QuicPathValidationContext> context, |
| 1192 | std::unique_ptr<QuicPathValidator::ResultDelegate> result_delegate); |
danzh | e919b00 | 2020-10-14 14:44:46 -0700 | [diff] [blame] | 1193 | |
haoyuewang | 2d2fdd1 | 2020-09-16 11:26:56 -0700 | [diff] [blame] | 1194 | bool can_receive_ack_frequency_frame() const { |
| 1195 | return can_receive_ack_frequency_frame_; |
| 1196 | } |
| 1197 | |
| 1198 | void set_can_receive_ack_frequency_frame() { |
| 1199 | can_receive_ack_frequency_frame_ = true; |
| 1200 | } |
| 1201 | |
wub | 28ecbba | 2020-10-16 16:13:47 -0700 | [diff] [blame] | 1202 | bool is_processing_packet() const { return framer_.is_processing_packet(); } |
| 1203 | |
fayang | 5100e29 | 2020-10-30 14:37:44 -0700 | [diff] [blame] | 1204 | bool use_encryption_level_context() const { |
| 1205 | return use_encryption_level_context_; |
| 1206 | } |
| 1207 | |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1208 | bool HasPendingPathValidation() const; |
| 1209 | |
renjietang | 4afe9ca | 2020-12-15 10:52:08 -0800 | [diff] [blame] | 1210 | QuicPathValidationContext* GetPathValidationContext() const; |
| 1211 | |
| 1212 | void CancelPathValidation(); |
| 1213 | |
haoyuewang | dc60baf | 2021-04-19 14:03:14 -0700 | [diff] [blame] | 1214 | // Returns true if the migration succeeds, otherwise returns false (e.g., no |
| 1215 | // available CIDs, connection disconnected, etc). |
| 1216 | bool MigratePath(const QuicSocketAddress& self_address, |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 1217 | const QuicSocketAddress& peer_address, |
| 1218 | QuicPacketWriter* writer, |
| 1219 | bool owns_writer); |
| 1220 | |
haoyuewang | dc60baf | 2021-04-19 14:03:14 -0700 | [diff] [blame] | 1221 | // Called to clear the alternative_path_ when path validation failed on the |
| 1222 | // client side. |
| 1223 | void OnPathValidationFailureAtClient(); |
| 1224 | |
fayang | 133b868 | 2020-12-08 05:50:33 -0800 | [diff] [blame] | 1225 | void SetSourceAddressTokenToSend(absl::string_view token); |
| 1226 | |
wub | a9b70f0 | 2020-12-09 12:49:27 -0800 | [diff] [blame] | 1227 | void SendPing() { |
| 1228 | SendPingAtLevel(use_encryption_level_context_ |
| 1229 | ? framer().GetEncryptionLevelToSendApplicationData() |
| 1230 | : encryption_level_); |
| 1231 | } |
| 1232 | |
haoyuewang | 2d355fe | 2021-01-05 16:42:50 -0800 | [diff] [blame] | 1233 | virtual std::vector<QuicConnectionId> GetActiveServerConnectionIds() const; |
| 1234 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1235 | bool validate_client_address() const { return validate_client_addresses_; } |
| 1236 | |
haoyuewang | b9142bc | 2021-04-13 06:28:22 -0700 | [diff] [blame] | 1237 | bool support_multiple_connection_ids() const { |
| 1238 | return support_multiple_connection_ids_; |
| 1239 | } |
| 1240 | |
haoyuewang | dc60baf | 2021-04-19 14:03:14 -0700 | [diff] [blame] | 1241 | bool connection_migration_use_new_cid() const { |
| 1242 | return connection_migration_use_new_cid_; |
| 1243 | } |
| 1244 | |
haoyuewang | ffae80c | 2021-04-29 12:33:56 -0400 | [diff] [blame] | 1245 | bool count_bytes_on_alternative_path_separately() const { |
| 1246 | return count_bytes_on_alternative_path_separately_; |
| 1247 | } |
| 1248 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 1249 | // Instantiates connection ID manager. |
| 1250 | void CreateConnectionIdManager(); |
| 1251 | |
fayang | c2638cc | 2021-04-05 14:45:40 -0700 | [diff] [blame] | 1252 | bool donot_write_mid_packet_processing() const { |
| 1253 | return donot_write_mid_packet_processing_; |
| 1254 | } |
| 1255 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1256 | protected: |
| 1257 | // Calls cancel() on all the alarms owned by this connection. |
| 1258 | void CancelAllAlarms(); |
| 1259 | |
| 1260 | // Send a packet to the peer, and takes ownership of the packet if the packet |
| 1261 | // cannot be written immediately. |
wub | 8a5dafa | 2020-05-13 12:30:17 -0700 | [diff] [blame] | 1262 | virtual void SendOrQueuePacket(SerializedPacket packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1263 | |
| 1264 | // Called after a packet is received from a new effective peer address and is |
| 1265 | // decrypted. Starts validation of effective peer's address change. Calls |
| 1266 | // OnConnectionMigration as soon as the address changed. |
| 1267 | void StartEffectivePeerMigration(AddressChangeType type); |
| 1268 | |
| 1269 | // Called when a effective peer address migration is validated. |
| 1270 | virtual void OnEffectivePeerMigrationValidated(); |
| 1271 | |
| 1272 | // Get the effective peer address from the packet being processed. For proxied |
| 1273 | // connections, effective peer address is the address of the endpoint behind |
| 1274 | // the proxy. For non-proxied connections, effective peer address is the same |
| 1275 | // as peer address. |
| 1276 | // |
| 1277 | // Notes for implementations in subclasses: |
| 1278 | // - If the connection is not proxied, the overridden method should use the |
| 1279 | // base implementation: |
| 1280 | // |
| 1281 | // return QuicConnection::GetEffectivePeerAddressFromCurrentPacket(); |
| 1282 | // |
| 1283 | // - If the connection is proxied, the overridden method may return either of |
| 1284 | // the following: |
| 1285 | // a) The address of the endpoint behind the proxy. The address is used to |
| 1286 | // drive effective peer migration. |
| 1287 | // b) An uninitialized address, meaning the effective peer address does not |
| 1288 | // change. |
| 1289 | virtual QuicSocketAddress GetEffectivePeerAddressFromCurrentPacket() const; |
| 1290 | |
| 1291 | // Selects and updates the version of the protocol being used by selecting a |
| 1292 | // version from |available_versions| which is also supported. Returns true if |
| 1293 | // such a version exists, false otherwise. |
| 1294 | bool SelectMutualVersion(const ParsedQuicVersionVector& available_versions); |
| 1295 | |
| 1296 | // Returns the current per-packet options for the connection. |
| 1297 | PerPacketOptions* per_packet_options() { return per_packet_options_; } |
| 1298 | |
| 1299 | AddressChangeType active_effective_peer_migration_type() const { |
| 1300 | return active_effective_peer_migration_type_; |
| 1301 | } |
| 1302 | |
ianswett | dc1e7ab | 2019-05-03 16:10:44 -0700 | [diff] [blame] | 1303 | // Sends a connection close packet to the peer and includes an ACK if the ACK |
| 1304 | // is not empty, the |error| is not PACKET_WRITE_ERROR, and it fits. |
mattm | 55006b0 | 2021-01-14 15:09:54 -0800 | [diff] [blame] | 1305 | // |ietf_error| may optionally be be used to directly specify the wire |
| 1306 | // error code. Otherwise if |ietf_error| is NO_IETF_QUIC_ERROR, the |
| 1307 | // QuicErrorCodeToTransportErrorCode mapping of |error| will be used. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1308 | virtual void SendConnectionClosePacket(QuicErrorCode error, |
mattm | 55006b0 | 2021-01-14 15:09:54 -0800 | [diff] [blame] | 1309 | QuicIetfTransportErrorCodes ietf_error, |
ianswett | dc1e7ab | 2019-05-03 16:10:44 -0700 | [diff] [blame] | 1310 | const std::string& details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1311 | |
| 1312 | // Returns true if the packet should be discarded and not sent. |
fayang | 1504296 | 2020-07-01 12:14:29 -0700 | [diff] [blame] | 1313 | virtual bool ShouldDiscardPacket(EncryptionLevel encryption_level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1314 | |
| 1315 | // Retransmits packets continuously until blocked by the congestion control. |
| 1316 | // If there are no packets to retransmit, does not do anything. |
| 1317 | void SendProbingRetransmissions(); |
| 1318 | |
| 1319 | // Decides whether to send probing retransmissions, and does so if required. |
| 1320 | void MaybeSendProbingRetransmissions(); |
| 1321 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1322 | // Notify various components(Session etc.) that this connection has been |
| 1323 | // migrated. |
danzh | ab0c7a3 | 2021-01-19 15:20:17 -0800 | [diff] [blame] | 1324 | virtual void OnConnectionMigration(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1325 | |
| 1326 | // Return whether the packet being processed is a connectivity probing. |
| 1327 | // A packet is a connectivity probing if it is a padded ping packet with self |
| 1328 | // and/or peer address changes. |
| 1329 | bool IsCurrentPacketConnectivityProbing() const; |
| 1330 | |
| 1331 | // Return true iff the writer is blocked, if blocked, call |
| 1332 | // visitor_->OnWriteBlocked() to add the connection into the write blocked |
| 1333 | // list. |
| 1334 | bool HandleWriteBlocked(); |
| 1335 | |
fayang | 93b4e4d | 2020-11-25 07:56:47 -0800 | [diff] [blame] | 1336 | // Whether connection enforces anti-amplification limit. |
| 1337 | bool EnforceAntiAmplificationLimit() const; |
| 1338 | |
| 1339 | void AddBytesReceivedBeforeAddressValidation(size_t length) { |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 1340 | default_path_.bytes_received_before_address_validation += length; |
fayang | 93b4e4d | 2020-11-25 07:56:47 -0800 | [diff] [blame] | 1341 | } |
| 1342 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1343 | private: |
| 1344 | friend class test::QuicConnectionPeer; |
| 1345 | |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1346 | struct QUIC_EXPORT_PRIVATE PendingPathChallenge { |
| 1347 | QuicPathFrameBuffer received_path_challenge; |
| 1348 | QuicSocketAddress peer_address; |
| 1349 | }; |
| 1350 | |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 1351 | struct QUIC_EXPORT_PRIVATE PathState { |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1352 | PathState() = default; |
| 1353 | |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 1354 | PathState(const QuicSocketAddress& alternative_self_address, |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1355 | const QuicSocketAddress& alternative_peer_address, |
| 1356 | const QuicConnectionId& client_connection_id, |
| 1357 | const QuicConnectionId& server_connection_id, |
| 1358 | bool stateless_reset_token_received, |
| 1359 | StatelessResetToken stateless_reset_token) |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1360 | : self_address(alternative_self_address), |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1361 | peer_address(alternative_peer_address), |
| 1362 | client_connection_id(client_connection_id), |
| 1363 | server_connection_id(server_connection_id), |
| 1364 | stateless_reset_token(stateless_reset_token), |
| 1365 | stateless_reset_token_received(stateless_reset_token_received) {} |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1366 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1367 | PathState(PathState&& other); |
| 1368 | |
| 1369 | PathState& operator=(PathState&& other); |
| 1370 | |
danzh | 3b63070 | 2021-01-12 14:15:23 -0800 | [diff] [blame] | 1371 | // Reset all the members. |
| 1372 | void Clear(); |
| 1373 | |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1374 | QuicSocketAddress self_address; |
| 1375 | // The actual peer address behind the proxy if there is any. |
| 1376 | QuicSocketAddress peer_address; |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1377 | QuicConnectionId client_connection_id; |
| 1378 | QuicConnectionId server_connection_id; |
| 1379 | StatelessResetToken stateless_reset_token; |
| 1380 | bool stateless_reset_token_received = false; |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 1381 | // True if the peer address has been validated. Address is considered |
| 1382 | // validated when 1) an address token of the peer address is received and |
| 1383 | // validated, or 2) a HANDSHAKE packet has been successfully processed on |
| 1384 | // this path, or 3) a path validation on this path has succeeded. |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1385 | bool validated = false; |
| 1386 | // Used by the sever to apply anti-amplification limit after this path |
| 1387 | // becomes the default path if |peer_address| hasn't been validated. |
danzh | 046212e | 2021-01-26 11:44:09 -0800 | [diff] [blame] | 1388 | QuicByteCount bytes_received_before_address_validation = 0; |
| 1389 | QuicByteCount bytes_sent_before_address_validation = 0; |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1390 | // Points to the send algorithm on the old default path while connection is |
| 1391 | // validating migrated peer address. Nullptr otherwise. |
| 1392 | std::unique_ptr<SendAlgorithmInterface> send_algorithm; |
| 1393 | absl::optional<RttStats> rtt_stats; |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1394 | }; |
| 1395 | |
renjietang | 58b3af3 | 2020-11-11 15:48:58 -0800 | [diff] [blame] | 1396 | using QueuedPacketList = std::list<SerializedPacket>; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1397 | |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1398 | // BufferedPacket stores necessary information (encrypted buffer and self/peer |
| 1399 | // addresses) of those packets which are serialized but failed to send because |
| 1400 | // socket is blocked. From unacked packet map and send algorithm's |
| 1401 | // perspective, buffered packets are treated as sent. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 1402 | struct QUIC_EXPORT_PRIVATE BufferedPacket { |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1403 | BufferedPacket(const SerializedPacket& packet, |
| 1404 | const QuicSocketAddress& self_address, |
| 1405 | const QuicSocketAddress& peer_address); |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 1406 | BufferedPacket(char* encrypted_buffer, |
| 1407 | QuicPacketLength encrypted_length, |
| 1408 | const QuicSocketAddress& self_address, |
| 1409 | const QuicSocketAddress& peer_address); |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1410 | BufferedPacket(const BufferedPacket& other) = delete; |
| 1411 | BufferedPacket(const BufferedPacket&& other) = delete; |
| 1412 | |
| 1413 | ~BufferedPacket(); |
| 1414 | |
| 1415 | // encrypted_buffer is owned by buffered packet. |
vasilvv | 9a36d72 | 2020-10-02 16:51:38 -0700 | [diff] [blame] | 1416 | absl::string_view encrypted_buffer; |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1417 | // Self and peer addresses when the packet is serialized. |
| 1418 | const QuicSocketAddress self_address; |
| 1419 | const QuicSocketAddress peer_address; |
| 1420 | }; |
| 1421 | |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 1422 | // ReceivedPacketInfo comprises the received packet information, which can be |
| 1423 | // retrieved before the packet gets successfully decrypted. |
| 1424 | struct QUIC_EXPORT_PRIVATE ReceivedPacketInfo { |
| 1425 | explicit ReceivedPacketInfo(QuicTime receipt_time) |
| 1426 | : received_bytes_counted(false), receipt_time(receipt_time) {} |
| 1427 | ReceivedPacketInfo(const QuicSocketAddress& destination_address, |
| 1428 | const QuicSocketAddress& source_address, |
| 1429 | QuicTime receipt_time) |
| 1430 | : received_bytes_counted(false), |
| 1431 | destination_address(destination_address), |
| 1432 | source_address(source_address), |
| 1433 | receipt_time(receipt_time) {} |
| 1434 | |
| 1435 | bool received_bytes_counted; |
| 1436 | QuicSocketAddress destination_address; |
| 1437 | QuicSocketAddress source_address; |
| 1438 | QuicTime receipt_time; |
| 1439 | }; |
| 1440 | |
fayang | f7bc0ad | 2021-05-27 05:15:25 -0700 | [diff] [blame] | 1441 | // UndecrytablePacket comprises a undecryptable packet and related |
| 1442 | // information. |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1443 | struct QUIC_EXPORT_PRIVATE UndecryptablePacket { |
| 1444 | UndecryptablePacket(const QuicEncryptedPacket& packet, |
fayang | f7bc0ad | 2021-05-27 05:15:25 -0700 | [diff] [blame] | 1445 | EncryptionLevel encryption_level, |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 1446 | const ReceivedPacketInfo& packet_info) |
fayang | f7bc0ad | 2021-05-27 05:15:25 -0700 | [diff] [blame] | 1447 | : packet(packet.Clone()), |
| 1448 | encryption_level(encryption_level), |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 1449 | packet_info(packet_info) {} |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1450 | |
| 1451 | std::unique_ptr<QuicEncryptedPacket> packet; |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1452 | EncryptionLevel encryption_level; |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 1453 | ReceivedPacketInfo packet_info; |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1454 | }; |
| 1455 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1456 | // Handles the reverse path validation result depending on connection state: |
| 1457 | // whether the connection is validating a migrated peer address or is |
| 1458 | // validating an alternative path. |
| 1459 | class ReversePathValidationResultDelegate |
| 1460 | : public QuicPathValidator::ResultDelegate { |
| 1461 | public: |
| 1462 | ReversePathValidationResultDelegate( |
| 1463 | QuicConnection* connection, |
| 1464 | const QuicSocketAddress& direct_peer_address); |
| 1465 | |
| 1466 | void OnPathValidationSuccess( |
| 1467 | std::unique_ptr<QuicPathValidationContext> context) override; |
| 1468 | |
| 1469 | void OnPathValidationFailure( |
| 1470 | std::unique_ptr<QuicPathValidationContext> context) override; |
| 1471 | |
| 1472 | private: |
| 1473 | QuicConnection* connection_; |
| 1474 | QuicSocketAddress original_direct_peer_address_; |
| 1475 | }; |
| 1476 | |
fayang | 4b5b4e6 | 2021-04-14 06:16:42 -0700 | [diff] [blame] | 1477 | // A class which sets and clears in_on_retransmission_time_out_ when entering |
| 1478 | // and exiting OnRetransmissionTimeout, respectively. |
| 1479 | class QUIC_EXPORT_PRIVATE ScopedRetransmissionTimeoutIndicator { |
| 1480 | public: |
| 1481 | // |connection| must outlive this indicator. |
| 1482 | explicit ScopedRetransmissionTimeoutIndicator(QuicConnection* connection); |
| 1483 | |
| 1484 | ~ScopedRetransmissionTimeoutIndicator(); |
| 1485 | |
| 1486 | private: |
| 1487 | QuicConnection* connection_; // Not owned. |
| 1488 | }; |
| 1489 | |
haoyuewang | be217f5 | 2021-06-04 09:15:24 -0700 | [diff] [blame] | 1490 | // If peer uses non-empty connection ID, discards any buffered packets on path |
| 1491 | // change in IETF QUIC. |
| 1492 | void MaybeClearQueuedPacketsOnPathChange(); |
| 1493 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1494 | // Notifies the visitor of the close and marks the connection as disconnected. |
fkastenholz | 85f1890 | 2019-05-28 12:47:00 -0700 | [diff] [blame] | 1495 | // Does not send a connection close frame to the peer. It should only be |
| 1496 | // called by CloseConnection or OnConnectionCloseFrame, OnPublicResetPacket, |
| 1497 | // and OnAuthenticatedIetfStatelessResetPacket. |
mattm | 55006b0 | 2021-01-14 15:09:54 -0800 | [diff] [blame] | 1498 | // |ietf_error| may optionally be be used to directly specify the wire |
| 1499 | // error code. Otherwise if |ietf_error| is NO_IETF_QUIC_ERROR, the |
| 1500 | // QuicErrorCodeToTransportErrorCode mapping of |error| will be used. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1501 | void TearDownLocalConnectionState(QuicErrorCode error, |
mattm | 55006b0 | 2021-01-14 15:09:54 -0800 | [diff] [blame] | 1502 | QuicIetfTransportErrorCodes ietf_error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1503 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1504 | ConnectionCloseSource source); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 1505 | void TearDownLocalConnectionState(const QuicConnectionCloseFrame& frame, |
| 1506 | ConnectionCloseSource source); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1507 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 1508 | // Replace server connection ID on the client side from retry packet or |
| 1509 | // initial packets with a different source connection ID. |
| 1510 | void ReplaceInitialServerConnectionId( |
| 1511 | const QuicConnectionId& new_server_connection_id); |
| 1512 | |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1513 | // Given the server_connection_id find if there is already a corresponding |
haoyuewang | 23d20ac | 2021-04-29 10:55:34 -0400 | [diff] [blame] | 1514 | // client connection ID used on default/alternative path. If not, find if |
| 1515 | // there is an unused connection ID. |
| 1516 | void FindMatchingOrNewClientConnectionIdOrToken( |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1517 | const PathState& default_path, |
| 1518 | const PathState& alternative_path, |
| 1519 | const QuicConnectionId& server_connection_id, |
| 1520 | QuicConnectionId* client_connection_id, |
| 1521 | bool* stateless_reset_token_received, |
haoyuewang | 23d20ac | 2021-04-29 10:55:34 -0400 | [diff] [blame] | 1522 | StatelessResetToken* stateless_reset_token); |
| 1523 | |
| 1524 | // Returns true and sets connection IDs if (self_address, peer_address) |
| 1525 | // corresponds to either the default path or alternative path. Returns false |
| 1526 | // otherwise. |
| 1527 | bool FindOnPathConnectionIds(const QuicSocketAddress& self_address, |
| 1528 | const QuicSocketAddress& peer_address, |
| 1529 | QuicConnectionId* client_connection_id, |
| 1530 | QuicConnectionId* server_connection_id) const; |
| 1531 | |
| 1532 | // Set default_path_ to the new_path_state and update the connection IDs in |
| 1533 | // packet creator accordingly. |
| 1534 | void SetDefaultPathState(PathState new_path_state); |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 1535 | |
haoyuewang | ae8f91f | 2021-04-28 14:58:13 -0400 | [diff] [blame] | 1536 | // Returns true if header contains valid server connection ID. |
| 1537 | bool ValidateServerConnectionId(const QuicPacketHeader& header) const; |
| 1538 | |
haoyuewang | dc60baf | 2021-04-19 14:03:14 -0700 | [diff] [blame] | 1539 | // Update the connection IDs when client migrates with/without validation. |
| 1540 | // Returns false if required connection ID is not available. |
| 1541 | bool UpdateConnectionIdsOnClientMigration( |
| 1542 | const QuicSocketAddress& self_address, |
| 1543 | const QuicSocketAddress& peer_address); |
| 1544 | |
| 1545 | // Retire active peer issued connection IDs after they are no longer used on |
| 1546 | // any path. |
| 1547 | void RetirePeerIssuedConnectionIdsNoLongerOnPath(); |
| 1548 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1549 | // Writes the given packet to socket, encrypted with packet's |
| 1550 | // encryption_level. Returns true on successful write, and false if the writer |
| 1551 | // was blocked and the write needs to be tried again. Notifies the |
| 1552 | // SentPacketManager when the write is successful and sets |
| 1553 | // retransmittable frames to nullptr. |
| 1554 | // Saves the connection close packet for later transmission, even if the |
| 1555 | // writer is write blocked. |
| 1556 | bool WritePacket(SerializedPacket* packet); |
| 1557 | |
mattm | d074485 | 2020-10-16 14:42:01 -0700 | [diff] [blame] | 1558 | // Enforce AEAD Confidentiality limits by iniating key update or closing |
| 1559 | // connection if too many packets have been encrypted with the current key. |
| 1560 | // Returns true if the connection was closed. Should not be called for |
| 1561 | // termination packets. |
| 1562 | bool MaybeHandleAeadConfidentialityLimits(const SerializedPacket& packet); |
| 1563 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1564 | // Flush packets buffered in the writer, if any. |
| 1565 | void FlushPackets(); |
| 1566 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1567 | // Make sure a stop waiting we got from our peer is sane. |
| 1568 | // Returns nullptr if the frame is valid or an error string if it was invalid. |
| 1569 | const char* ValidateStopWaitingFrame( |
| 1570 | const QuicStopWaitingFrame& stop_waiting); |
| 1571 | |
| 1572 | // Sends a version negotiation packet to the peer. |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1573 | void SendVersionNegotiationPacket(bool ietf_quic, bool has_length_prefix); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1574 | |
| 1575 | // Clears any accumulated frames from the last received packet. |
| 1576 | void ClearLastFrames(); |
| 1577 | |
| 1578 | // Deletes and clears any queued packets. |
| 1579 | void ClearQueuedPackets(); |
| 1580 | |
| 1581 | // Closes the connection if the sent packet manager is tracking too many |
| 1582 | // outstanding packets. |
| 1583 | void CloseIfTooManyOutstandingSentPackets(); |
| 1584 | |
| 1585 | // Writes as many queued packets as possible. The connection must not be |
| 1586 | // blocked when this is called. |
| 1587 | void WriteQueuedPackets(); |
| 1588 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1589 | // Queues |packet| in the hopes that it can be decrypted in the |
| 1590 | // future, when a new key is installed. |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1591 | void QueueUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 1592 | EncryptionLevel decryption_level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1593 | |
| 1594 | // Sends any packets which are a response to the last packet, including both |
| 1595 | // acks and pending writes if an ack opened the congestion window. |
| 1596 | void MaybeSendInResponseToPacket(); |
| 1597 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1598 | // Gets the least unacked packet number, which is the next packet number to be |
| 1599 | // sent if there are no outstanding packets. |
| 1600 | QuicPacketNumber GetLeastUnacked() const; |
| 1601 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1602 | // Sets the ping alarm to the appropriate value, if any. |
| 1603 | void SetPingAlarm(); |
| 1604 | |
| 1605 | // Sets the retransmission alarm based on SentPacketManager. |
| 1606 | void SetRetransmissionAlarm(); |
| 1607 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1608 | // Sets the MTU discovery alarm if necessary. |
| 1609 | // |sent_packet_number| is the recently sent packet number. |
| 1610 | void MaybeSetMtuAlarm(QuicPacketNumber sent_packet_number); |
| 1611 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1612 | HasRetransmittableData IsRetransmittable(const SerializedPacket& packet); |
fayang | 8bff33c | 2020-08-06 07:37:22 -0700 | [diff] [blame] | 1613 | bool IsTerminationPacket(const SerializedPacket& packet, |
| 1614 | QuicErrorCode* error_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1615 | |
| 1616 | // Set the size of the packet we are targeting while doing path MTU discovery. |
| 1617 | void SetMtuDiscoveryTarget(QuicByteCount target); |
| 1618 | |
| 1619 | // Returns |suggested_max_packet_size| clamped to any limits set by the |
| 1620 | // underlying writer, connection, or protocol. |
| 1621 | QuicByteCount GetLimitedMaxPacketSize( |
| 1622 | QuicByteCount suggested_max_packet_size); |
| 1623 | |
| 1624 | // Do any work which logically would be done in OnPacket but can not be |
| 1625 | // safely done until the packet is validated. Returns true if packet can be |
| 1626 | // handled, false otherwise. |
| 1627 | bool ProcessValidatedPacket(const QuicPacketHeader& header); |
| 1628 | |
QUICHE team | d791e2c | 2019-03-15 10:28:21 -0700 | [diff] [blame] | 1629 | // Returns true if received |packet_number| can be processed. Please note, |
| 1630 | // this is called after packet got decrypted successfully. |
| 1631 | bool ValidateReceivedPacketNumber(QuicPacketNumber packet_number); |
| 1632 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1633 | // Consider receiving crypto frame on non crypto stream as memory corruption. |
| 1634 | bool MaybeConsiderAsMemoryCorruption(const QuicStreamFrame& frame); |
| 1635 | |
| 1636 | // Check if the connection has no outstanding data to send and notify |
| 1637 | // congestion controller if it is the case. |
| 1638 | void CheckIfApplicationLimited(); |
| 1639 | |
| 1640 | // Sets |current_packet_content_| to |type| if applicable. And |
| 1641 | // starts effective peer migration if current packet is confirmed not a |
| 1642 | // connectivity probe and |current_effective_peer_migration_type_| indicates |
| 1643 | // effective peer address change. |
renjietang | 7f1d9e1 | 2021-01-22 19:10:57 -0800 | [diff] [blame] | 1644 | // Returns true if connection is still alive. |
| 1645 | ABSL_MUST_USE_RESULT bool UpdatePacketContent(QuicFrameType type); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1646 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1647 | // Called when last received ack frame has been processed. |
| 1648 | // |send_stop_waiting| indicates whether a stop waiting needs to be sent. |
| 1649 | // |acked_new_packet| is true if a previously-unacked packet was acked. |
| 1650 | void PostProcessAfterAckFrame(bool send_stop_waiting, bool acked_new_packet); |
| 1651 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1652 | // Updates the release time into the future. |
| 1653 | void UpdateReleaseTimeIntoFuture(); |
| 1654 | |
| 1655 | // Sends generic path probe packet to the peer. If we are not IETF QUIC, will |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1656 | // always send a padded ping, regardless of whether this is a request or not. |
| 1657 | // TODO(danzh): remove |is_response| after deprecating |
| 1658 | // --gfe2_reloadable_flag_quic_send_path_response. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1659 | bool SendGenericPathProbePacket(QuicPacketWriter* probing_writer, |
| 1660 | const QuicSocketAddress& peer_address, |
| 1661 | bool is_response); |
| 1662 | |
| 1663 | // Called when an ACK is about to send. Resets ACK related internal states, |
| 1664 | // e.g., cancels ack_alarm_, resets |
| 1665 | // num_retransmittable_packets_received_since_last_ack_sent_ etc. |
| 1666 | void ResetAckStates(); |
| 1667 | |
ianswett | 6083a10 | 2020-02-09 12:04:04 -0800 | [diff] [blame] | 1668 | // Returns true if the ACK frame should be bundled with ACK-eliciting frame. |
| 1669 | bool ShouldBundleRetransmittableFrameWithAck() const; |
| 1670 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 1671 | void PopulateStopWaitingFrame(QuicStopWaitingFrame* stop_waiting); |
| 1672 | |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 1673 | // Enables multiple packet number spaces support based on handshake protocol |
| 1674 | // and flags. |
| 1675 | void MaybeEnableMultiplePacketNumberSpacesSupport(); |
| 1676 | |
fayang | 9f430a5 | 2020-05-08 07:28:33 -0700 | [diff] [blame] | 1677 | // Called to update ACK timeout when an retransmittable frame has been parsed. |
| 1678 | void MaybeUpdateAckTimeout(); |
| 1679 | |
fayang | fe963c5 | 2020-07-16 06:56:09 -0700 | [diff] [blame] | 1680 | // Tries to fill coalesced packet with data of higher packet space. |
| 1681 | void MaybeCoalescePacketOfHigherSpace(); |
| 1682 | |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 1683 | // Serialize and send coalesced_packet. Returns false if serialization fails |
| 1684 | // or the write causes errors, otherwise, returns true. |
| 1685 | bool FlushCoalescedPacket(); |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1686 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1687 | // Returns the encryption level the connection close packet should be sent at, |
| 1688 | // which is the highest encryption level that peer can guarantee to process. |
| 1689 | EncryptionLevel GetConnectionCloseEncryptionLevel() const; |
| 1690 | |
QUICHE team | 76e1c62 | 2019-03-19 14:36:39 -0700 | [diff] [blame] | 1691 | // Called after an ACK frame is successfully processed to update largest |
| 1692 | // received packet number which contains an ACK frame. |
| 1693 | void SetLargestReceivedPacketWithAck(QuicPacketNumber new_value); |
| 1694 | |
fayang | 656cbb5 | 2020-06-09 13:29:35 -0700 | [diff] [blame] | 1695 | // Called when new packets have been acknowledged or old keys have been |
| 1696 | // discarded. |
| 1697 | void OnForwardProgressMade(); |
| 1698 | |
QUICHE team | 76e1c62 | 2019-03-19 14:36:39 -0700 | [diff] [blame] | 1699 | // Returns largest received packet number which contains an ACK frame. |
| 1700 | QuicPacketNumber GetLargestReceivedPacketWithAck() const; |
| 1701 | |
| 1702 | // Returns the largest packet number that has been sent. |
| 1703 | QuicPacketNumber GetLargestSentPacket() const; |
| 1704 | |
| 1705 | // Returns the largest sent packet number that has been ACKed by peer. |
| 1706 | QuicPacketNumber GetLargestAckedPacket() const; |
| 1707 | |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 1708 | // Whether connection is limited by amplification factor. |
| 1709 | bool LimitedByAmplificationFactor() const; |
| 1710 | |
wub | ed245d2 | 2020-05-07 10:46:00 -0700 | [diff] [blame] | 1711 | // Called before sending a packet to get packet send time and to set the |
| 1712 | // release time delay in |per_packet_options_|. Return the time when the |
| 1713 | // packet is scheduled to be released(a.k.a send time), which is NOW + delay. |
| 1714 | // Returns Now() and does not update release time delay if |
| 1715 | // |supports_release_time_| is false. |
| 1716 | QuicTime CalculatePacketSentTime(); |
| 1717 | |
wub | 8add68a | 2020-07-27 12:07:38 -0700 | [diff] [blame] | 1718 | // If we have a previously validate MTU value, e.g. due to a write error, |
| 1719 | // revert to it and disable MTU discovery. |
| 1720 | // Return true iff we reverted to a previously validate MTU. |
| 1721 | bool MaybeRevertToPreviousMtu(); |
| 1722 | |
| 1723 | QuicTime GetPathMtuReductionDeadline() const; |
wub | 748e20b | 2020-03-20 14:33:59 -0700 | [diff] [blame] | 1724 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 1725 | // Returns path degrading deadline. QuicTime::Zero() means no path degrading |
| 1726 | // detection is needed. |
| 1727 | QuicTime GetPathDegradingDeadline() const; |
| 1728 | |
| 1729 | // Returns true if path degrading should be detected. |
| 1730 | bool ShouldDetectPathDegrading() const; |
| 1731 | |
| 1732 | // Returns network blackhole deadline. QuicTime::Zero() means no blackhole |
| 1733 | // detection is needed. |
| 1734 | QuicTime GetNetworkBlackholeDeadline() const; |
| 1735 | |
| 1736 | // Returns true if network blackhole should be detected. |
| 1737 | bool ShouldDetectBlackhole() const; |
| 1738 | |
fayang | 1d49cfb | 2020-10-22 08:19:46 -0700 | [diff] [blame] | 1739 | // Returns retransmission deadline. |
| 1740 | QuicTime GetRetransmissionDeadline() const; |
| 1741 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 1742 | // Validate connection IDs used during the handshake. Closes the connection |
| 1743 | // on validation failure. |
| 1744 | bool ValidateConfigConnectionIds(const QuicConfig& config); |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 1745 | |
fayang | 5c2c7b5 | 2020-07-09 13:47:16 -0400 | [diff] [blame] | 1746 | // Called when ACK alarm goes off. Try to bundle crypto data with ACKs. |
| 1747 | void MaybeBundleCryptoDataWithAcks(); |
fayang | 7d4b017 | 2020-06-18 14:05:45 -0700 | [diff] [blame] | 1748 | |
fayang | 750b54f | 2020-06-18 06:26:54 -0700 | [diff] [blame] | 1749 | // Returns true if an undecryptable packet of |decryption_level| should be |
| 1750 | // buffered (such that connection can try to decrypt it later). |
| 1751 | bool ShouldEnqueueUnDecryptablePacket(EncryptionLevel decryption_level, |
| 1752 | bool has_decryption_key) const; |
| 1753 | |
fayang | 06574dc | 2020-06-18 13:58:09 -0700 | [diff] [blame] | 1754 | // Returns string which contains undecryptable packets information. |
| 1755 | std::string UndecryptablePacketsInfo() const; |
| 1756 | |
dschinazi | 6458eb3 | 2020-06-23 12:38:41 -0700 | [diff] [blame] | 1757 | // Sets the max packet length on the packet creator if needed. |
| 1758 | void MaybeUpdatePacketCreatorMaxPacketLengthAndPadding(); |
| 1759 | |
| 1760 | // Sets internal state to enable or disable Legacy Version Encapsulation. |
| 1761 | void MaybeActivateLegacyVersionEncapsulation(); |
| 1762 | void MaybeDisactivateLegacyVersionEncapsulation(); |
| 1763 | |
danzh | b7abebb | 2020-08-04 11:06:17 -0700 | [diff] [blame] | 1764 | // For Google Quic, if the current packet is connectivity probing packet, call |
| 1765 | // session OnPacketReceived() which eventually sends connectivity probing |
| 1766 | // response on server side. And no-op on client side. And for both Google Quic |
| 1767 | // and IETF Quic, start migration if the current packet is a non-probing |
| 1768 | // packet. |
| 1769 | // TODO(danzh) rename to MaybeRespondToPeerMigration() when Google Quic is |
| 1770 | // deprecated. |
| 1771 | void MaybeRespondToConnectivityProbingOrMigration(); |
| 1772 | |
danzh | 623f6ef | 2020-08-25 16:44:37 -0700 | [diff] [blame] | 1773 | // Called in IETF QUIC. Start peer migration if a non-probing frame is |
| 1774 | // received and the current packet number is largest received so far. |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1775 | void MaybeStartIetfPeerMigration(); |
danzh | 623f6ef | 2020-08-25 16:44:37 -0700 | [diff] [blame] | 1776 | |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1777 | // Send PATH_RESPONSE to the given peer address. |
| 1778 | bool SendPathResponse(const QuicPathFrameBuffer& data_buffer, |
haoyuewang | 23d20ac | 2021-04-29 10:55:34 -0400 | [diff] [blame] | 1779 | const QuicSocketAddress& peer_address_to_send, |
| 1780 | const QuicSocketAddress& effective_peer_address); |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1781 | |
| 1782 | // Update both connection's and packet creator's peer address. |
| 1783 | void UpdatePeerAddress(QuicSocketAddress peer_address); |
| 1784 | |
fayang | ec14d2b | 2020-10-02 12:00:05 -0700 | [diff] [blame] | 1785 | // Send PING at encryption level. |
| 1786 | void SendPingAtLevel(EncryptionLevel level); |
| 1787 | |
danzh | e919b00 | 2020-10-14 14:44:46 -0700 | [diff] [blame] | 1788 | // Write the given packet with |self_address| and |peer_address| using |
| 1789 | // |writer|. |
| 1790 | bool WritePacketUsingWriter(std::unique_ptr<SerializedPacket> packet, |
| 1791 | QuicPacketWriter* writer, |
| 1792 | const QuicSocketAddress& self_address, |
| 1793 | const QuicSocketAddress& peer_address, |
| 1794 | bool measure_rtt); |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1795 | |
danzh | a4b519c | 2021-02-05 12:10:55 -0800 | [diff] [blame] | 1796 | // Increment bytes sent/received on the alternative path if the current packet |
| 1797 | // is sent/received on that path. |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1798 | void MaybeUpdateBytesSentToAlternativeAddress( |
| 1799 | const QuicSocketAddress& peer_address, |
| 1800 | QuicByteCount sent_packet_size); |
| 1801 | void MaybeUpdateBytesReceivedFromAlternativeAddress( |
| 1802 | QuicByteCount received_packet_size); |
| 1803 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1804 | // TODO(danzh) pass in PathState of the incoming packet or the packet sent |
| 1805 | // once PathState is used in packet creator. Return true if the given self |
| 1806 | // address and peer address is the same as the self address and peer address |
| 1807 | // of the default path. |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1808 | bool IsDefaultPath(const QuicSocketAddress& self_address, |
| 1809 | const QuicSocketAddress& peer_address) const; |
| 1810 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1811 | // Return true if the |self_address| and |peer_address| is the same as the |
danzh | a4b519c | 2021-02-05 12:10:55 -0800 | [diff] [blame] | 1812 | // self address and peer address of the alternative path. |
| 1813 | bool IsAlternativePath(const QuicSocketAddress& self_address, |
| 1814 | const QuicSocketAddress& peer_address) const; |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 1815 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 1816 | // Restore connection default path and congestion control state to the last |
| 1817 | // validated path and its state. Called after fail to validate peer address |
| 1818 | // upon detecting a peer migration. |
| 1819 | void RestoreToLastValidatedPath( |
| 1820 | QuicSocketAddress original_direct_peer_address); |
| 1821 | |
| 1822 | // Return true if the current incoming packet is from a peer address that is |
| 1823 | // validated. |
| 1824 | bool IsReceivedPeerAddressValidated() const; |
| 1825 | |
| 1826 | // Called after receiving PATH_CHALLENGE. Update packet content and |
| 1827 | // alternative path state if the current packet is from a non-default path. |
| 1828 | // Return true if framer should continue processing the packet. |
| 1829 | bool OnPathChallengeFrameInternal(const QuicPathChallengeFrame& frame); |
| 1830 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 1831 | virtual std::unique_ptr<QuicSelfIssuedConnectionIdManager> |
| 1832 | MakeSelfIssuedConnectionIdManager(); |
| 1833 | |
danzh | a1c0815 | 2021-03-15 10:29:40 -0700 | [diff] [blame] | 1834 | // Called on peer IP change or restoring to previous address to reset |
| 1835 | // congestion window, RTT stats, retransmission timer, etc. Only used in IETF |
| 1836 | // QUIC. |
| 1837 | std::unique_ptr<SendAlgorithmInterface> OnPeerIpAddressChanged(); |
| 1838 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 1839 | // Process NewConnectionIdFrame either sent from peer or synsthesized from |
| 1840 | // preferred_address transport parameter. |
| 1841 | bool OnNewConnectionIdFrameInner(const QuicNewConnectionIdFrame& frame); |
| 1842 | |
haoyuewang | b9142bc | 2021-04-13 06:28:22 -0700 | [diff] [blame] | 1843 | // Called to patch missing client connection ID on default/alternative paths |
| 1844 | // when a new client connection ID is received. |
| 1845 | void OnClientConnectionIdAvailable(); |
| 1846 | |
fayang | f9866cc | 2021-06-25 16:10:18 -0700 | [diff] [blame] | 1847 | // Returns true if connection needs to set retransmission alarm after a packet |
| 1848 | // gets sent. |
| 1849 | bool ShouldSetRetransmissionAlarmOnPacketSent(bool in_flight, |
| 1850 | EncryptionLevel level) const; |
| 1851 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1852 | QuicFramer framer_; |
| 1853 | |
| 1854 | // Contents received in the current packet, especially used to identify |
| 1855 | // whether the current packet is a padded PING packet. |
| 1856 | PacketContent current_packet_content_; |
| 1857 | // Set to true as soon as the packet currently being processed has been |
| 1858 | // detected as a connectivity probing. |
| 1859 | // Always false outside the context of ProcessUdpPacket(). |
| 1860 | bool is_current_packet_connectivity_probing_; |
| 1861 | |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1862 | bool has_path_challenge_in_current_packet_; |
| 1863 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1864 | // Caches the current effective peer migration type if a effective peer |
| 1865 | // migration might be initiated. As soon as the current packet is confirmed |
| 1866 | // not a connectivity probe, effective peer migration will start. |
| 1867 | AddressChangeType current_effective_peer_migration_type_; |
| 1868 | QuicConnectionHelperInterface* helper_; // Not owned. |
| 1869 | QuicAlarmFactory* alarm_factory_; // Not owned. |
| 1870 | PerPacketOptions* per_packet_options_; // Not owned. |
| 1871 | QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. |
| 1872 | bool owns_writer_; |
| 1873 | // Encryption level for new packets. Should only be changed via |
| 1874 | // SetDefaultEncryptionLevel(). |
| 1875 | EncryptionLevel encryption_level_; |
| 1876 | const QuicClock* clock_; |
| 1877 | QuicRandom* random_generator_; |
| 1878 | |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1879 | // On the server, the connection ID is set when receiving the first packet. |
| 1880 | // This variable ensures we only set it this way once. |
| 1881 | bool client_connection_id_is_set_; |
dschinazi | f31282b | 2021-03-03 11:33:48 -0800 | [diff] [blame] | 1882 | |
| 1883 | // Whether we've already replaced our server connection ID due to receiving an |
| 1884 | // INITIAL packet with a different source connection ID. Only used on client. |
| 1885 | bool server_connection_id_replaced_by_initial_ = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1886 | // Address on the last successfully processed packet received from the |
| 1887 | // direct peer. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1888 | |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 1889 | // Other than initialization, do not modify it directly, use |
| 1890 | // UpdatePeerAddress() instead. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1891 | QuicSocketAddress direct_peer_address_; |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 1892 | // The default path on which the endpoint sends non-probing packets. |
| 1893 | // The send algorithm and RTT stats of this path are stored in |
| 1894 | // |sent_packet_manager_| instead of in this object. |
| 1895 | PathState default_path_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1896 | |
| 1897 | // Records change type when the effective peer initiates migration to a new |
| 1898 | // address. Reset to NO_CHANGE after effective peer migration is validated. |
| 1899 | AddressChangeType active_effective_peer_migration_type_; |
| 1900 | |
| 1901 | // Records highest sent packet number when effective peer migration is |
| 1902 | // started. |
| 1903 | QuicPacketNumber highest_packet_sent_before_effective_peer_migration_; |
| 1904 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 1905 | // True if Key Update is supported on this connection. |
| 1906 | bool support_key_update_for_connection_; |
| 1907 | |
| 1908 | // Tracks the lowest packet sent in the current key phase. Will be |
| 1909 | // uninitialized before the first one-RTT packet has been sent or after a |
| 1910 | // key update but before the first packet has been sent. |
| 1911 | QuicPacketNumber lowest_packet_sent_in_current_key_phase_; |
| 1912 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1913 | // True if the last packet has gotten far enough in the framer to be |
| 1914 | // decrypted. |
| 1915 | bool last_packet_decrypted_; |
| 1916 | QuicByteCount last_size_; // Size of the last received packet. |
| 1917 | // TODO(rch): remove this when b/27221014 is fixed. |
| 1918 | const char* current_packet_data_; // UDP payload of packet currently being |
| 1919 | // parsed or nullptr. |
| 1920 | EncryptionLevel last_decrypted_packet_level_; |
| 1921 | QuicPacketHeader last_header_; |
| 1922 | bool should_last_packet_instigate_acks_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1923 | |
| 1924 | // Track some peer state so we can do less bookkeeping |
| 1925 | // Largest sequence sent by the peer which had an ack frame (latest ack info). |
QUICHE team | 76e1c62 | 2019-03-19 14:36:39 -0700 | [diff] [blame] | 1926 | // Do not read or write directly, use GetLargestReceivedPacketWithAck() and |
| 1927 | // SetLargestReceivedPacketWithAck() instead. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1928 | QuicPacketNumber largest_seen_packet_with_ack_; |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 1929 | // Largest packet number sent by the peer which had an ACK frame per packet |
| 1930 | // number space. Only used when this connection supports multiple packet |
| 1931 | // number spaces. |
| 1932 | QuicPacketNumber largest_seen_packets_with_ack_[NUM_PACKET_NUMBER_SPACES]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1933 | |
| 1934 | // Largest packet number sent by the peer which had a stop waiting frame. |
| 1935 | QuicPacketNumber largest_seen_packet_with_stop_waiting_; |
| 1936 | |
| 1937 | // Collection of packets which were received before encryption was |
| 1938 | // established, but which could not be decrypted. We buffer these on |
| 1939 | // the assumption that they could not be processed because they were |
| 1940 | // sent with the INITIAL encryption and the CHLO message was lost. |
fayang | a5c3383 | 2020-09-15 09:16:48 -0700 | [diff] [blame] | 1941 | std::deque<UndecryptablePacket> undecryptable_packets_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1942 | |
| 1943 | // Collection of coalesced packets which were received while processing |
| 1944 | // the current packet. |
bnc | 08fc2ae | 2021-04-27 14:57:51 -0700 | [diff] [blame] | 1945 | quiche::QuicheCircularDeque<std::unique_ptr<QuicEncryptedPacket>> |
wub | a750aab | 2020-02-10 06:43:15 -0800 | [diff] [blame] | 1946 | received_coalesced_packets_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1947 | |
| 1948 | // Maximum number of undecryptable packets the connection will store. |
| 1949 | size_t max_undecryptable_packets_; |
| 1950 | |
| 1951 | // Maximum number of tracked packets. |
| 1952 | QuicPacketCount max_tracked_packets_; |
| 1953 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1954 | // Contains the connection close packets if the connection has been closed. |
| 1955 | std::unique_ptr<std::vector<std::unique_ptr<QuicEncryptedPacket>>> |
| 1956 | termination_packets_; |
| 1957 | |
| 1958 | // Determines whether or not a connection close packet is sent to the peer |
dschinazi | 9a6194e | 2020-04-30 16:21:09 -0700 | [diff] [blame] | 1959 | // after idle timeout due to lack of network activity. During the handshake, |
| 1960 | // a connection close packet is sent, but not after. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1961 | ConnectionCloseBehavior idle_timeout_connection_close_behavior_; |
| 1962 | |
fayang | ddd3e9d | 2020-06-03 11:00:19 -0700 | [diff] [blame] | 1963 | // When > 0, close the QUIC connection after this number of RTOs. |
| 1964 | size_t num_rtos_for_blackhole_detection_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1965 | |
wub | 5ea41ef | 2020-10-16 13:31:19 -0700 | [diff] [blame] | 1966 | // Statistics for this session. |
| 1967 | QuicConnectionStats stats_; |
| 1968 | |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 1969 | UberReceivedPacketManager uber_received_packet_manager_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1970 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1971 | // Indicates how many consecutive times an ack has arrived which indicates |
| 1972 | // the peer needs to stop waiting for some packets. |
dschinazi | 5c1d7d8 | 2020-07-29 16:42:50 -0700 | [diff] [blame] | 1973 | // TODO(fayang): remove this when deprecating Q043. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1974 | int stop_waiting_count_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1975 | |
| 1976 | // Indicates the retransmission alarm needs to be set. |
| 1977 | bool pending_retransmission_alarm_; |
| 1978 | |
| 1979 | // If true, defer sending data in response to received packets to the |
| 1980 | // SendAlarm. |
| 1981 | bool defer_send_in_response_to_packets_; |
| 1982 | |
| 1983 | // The timeout for PING. |
| 1984 | QuicTime::Delta ping_timeout_; |
| 1985 | |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 1986 | // Initial timeout for how long the wire can have no retransmittable packets. |
| 1987 | QuicTime::Delta initial_retransmittable_on_wire_timeout_; |
| 1988 | |
| 1989 | // Indicates how many retransmittable-on-wire pings have been emitted without |
| 1990 | // receiving any new data in between. |
| 1991 | int consecutive_retransmittable_on_wire_ping_count_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1992 | |
dschinazi | 4933ced | 2020-10-20 09:51:12 -0700 | [diff] [blame] | 1993 | // Indicates how many retransmittable-on-wire pings have been emitted. |
| 1994 | int retransmittable_on_wire_ping_count_; |
| 1995 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1996 | // Arena to store class implementations within the QuicConnection. |
| 1997 | QuicConnectionArena arena_; |
| 1998 | |
| 1999 | // An alarm that fires when an ACK should be sent to the peer. |
| 2000 | QuicArenaScopedPtr<QuicAlarm> ack_alarm_; |
| 2001 | // An alarm that fires when a packet needs to be retransmitted. |
| 2002 | QuicArenaScopedPtr<QuicAlarm> retransmission_alarm_; |
| 2003 | // An alarm that is scheduled when the SentPacketManager requires a delay |
| 2004 | // before sending packets and fires when the packet may be sent. |
| 2005 | QuicArenaScopedPtr<QuicAlarm> send_alarm_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2006 | // An alarm that fires when a ping should be sent. |
| 2007 | QuicArenaScopedPtr<QuicAlarm> ping_alarm_; |
| 2008 | // An alarm that fires when an MTU probe should be sent. |
| 2009 | QuicArenaScopedPtr<QuicAlarm> mtu_discovery_alarm_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2010 | // An alarm that fires to process undecryptable packets when new decyrption |
| 2011 | // keys are available. |
| 2012 | QuicArenaScopedPtr<QuicAlarm> process_undecryptable_packets_alarm_; |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 2013 | // An alarm that fires to discard keys for the previous key phase some time |
| 2014 | // after a key update has completed. |
| 2015 | QuicArenaScopedPtr<QuicAlarm> discard_previous_one_rtt_keys_alarm_; |
mattm | ad5eb5d | 2020-12-03 16:12:15 -0800 | [diff] [blame] | 2016 | // An alarm that fires to discard 0-RTT decryption keys some time after the |
| 2017 | // first 1-RTT packet has been decrypted. Only used on server connections with |
| 2018 | // TLS handshaker. |
| 2019 | QuicArenaScopedPtr<QuicAlarm> discard_zero_rtt_decryption_keys_alarm_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2020 | // Neither visitor is owned by this class. |
| 2021 | QuicConnectionVisitorInterface* visitor_; |
| 2022 | QuicConnectionDebugVisitor* debug_visitor_; |
| 2023 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 2024 | QuicPacketCreator packet_creator_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2025 | |
fayang | aee86fb | 2021-06-02 12:06:08 -0700 | [diff] [blame] | 2026 | // Information about the last received QUIC packet, which may not have been |
| 2027 | // successfully decrypted and processed. |
| 2028 | ReceivedPacketInfo last_received_packet_info_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2029 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2030 | // Sent packet manager which tracks the status of packets sent by this |
| 2031 | // connection and contains the send and receive algorithms to determine when |
| 2032 | // to send packets. |
| 2033 | QuicSentPacketManager sent_packet_manager_; |
| 2034 | |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 2035 | // Indicates whether connection version has been negotiated. |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 2036 | // Always true for server connections. |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 2037 | bool version_negotiated_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2038 | |
| 2039 | // Tracks if the connection was created by the server or the client. |
| 2040 | Perspective perspective_; |
| 2041 | |
| 2042 | // True by default. False if we've received or sent an explicit connection |
| 2043 | // close. |
| 2044 | bool connected_; |
| 2045 | |
haoyuewang | 1063e45 | 2021-04-28 10:44:33 -0700 | [diff] [blame] | 2046 | // Destination connection ID of the last received packet. If this ID is the |
| 2047 | // original server connection ID chosen by client and server replaces it with |
| 2048 | // a different ID, last_packet_destination_connection_id_ is set to the |
| 2049 | // replacement connection ID on the server side. |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 2050 | QuicConnectionId last_packet_destination_connection_id_; |
| 2051 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2052 | // Set to false if the connection should not send truncated connection IDs to |
| 2053 | // the peer, even if the peer supports it. |
| 2054 | bool can_truncate_connection_ids_; |
| 2055 | |
| 2056 | // If non-empty this contains the set of versions received in a |
| 2057 | // version negotiation packet. |
| 2058 | ParsedQuicVersionVector server_supported_versions_; |
| 2059 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2060 | // The number of MTU probes already sent. |
| 2061 | size_t mtu_probe_count_; |
| 2062 | |
wub | ecb643f | 2020-03-19 08:58:46 -0700 | [diff] [blame] | 2063 | // The value of |long_term_mtu_| prior to the last successful MTU increase. |
| 2064 | // 0 means either |
| 2065 | // - MTU discovery has never been enabled, or |
| 2066 | // - MTU discovery has been enabled, but the connection got a packet write |
| 2067 | // error with a new (successfully probed) MTU, so it reverted |
wub | 748e20b | 2020-03-20 14:33:59 -0700 | [diff] [blame] | 2068 | // |long_term_mtu_| to the value before the last increase. |
wub | ecb643f | 2020-03-19 08:58:46 -0700 | [diff] [blame] | 2069 | QuicPacketLength previous_validated_mtu_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2070 | // The value of the MTU regularly used by the connection. This is different |
| 2071 | // from the value returned by max_packet_size(), as max_packet_size() returns |
| 2072 | // the value of the MTU as currently used by the serializer, so if |
| 2073 | // serialization of an MTU probe is in progress, those two values will be |
| 2074 | // different. |
| 2075 | QuicByteCount long_term_mtu_; |
| 2076 | |
dschinazi | 4ad1f46 | 2020-01-16 11:56:52 -0800 | [diff] [blame] | 2077 | // The maximum UDP payload size that our peer has advertised support for. |
| 2078 | // Defaults to kDefaultMaxPacketSizeTransportParam until received from peer. |
| 2079 | QuicByteCount peer_max_packet_size_; |
| 2080 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2081 | // The size of the largest packet received from peer. |
| 2082 | QuicByteCount largest_received_packet_size_; |
| 2083 | |
| 2084 | // Indicates whether a write error is encountered currently. This is used to |
| 2085 | // avoid infinite write errors. |
| 2086 | bool write_error_occurred_; |
| 2087 | |
| 2088 | // Indicates not to send or process stop waiting frames. |
| 2089 | bool no_stop_waiting_frames_; |
| 2090 | |
| 2091 | // Consecutive number of sent packets which have no retransmittable frames. |
| 2092 | size_t consecutive_num_packets_with_no_retransmittable_frames_; |
| 2093 | |
| 2094 | // After this many packets sent without retransmittable frames, an artificial |
| 2095 | // retransmittable frame(a WINDOW_UPDATE) will be created to solicit an ack |
| 2096 | // from the peer. Default to kMaxConsecutiveNonRetransmittablePackets. |
| 2097 | size_t max_consecutive_num_packets_with_no_retransmittable_frames_; |
| 2098 | |
ianswett | 6083a10 | 2020-02-09 12:04:04 -0800 | [diff] [blame] | 2099 | // If true, bundle an ack-eliciting frame with an ACK if the PTO or RTO alarm |
| 2100 | // have previously fired. |
| 2101 | bool bundle_retransmittable_with_pto_ack_; |
| 2102 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2103 | // If true, the connection will fill up the pipe with extra data whenever the |
| 2104 | // congestion controller needs it in order to make a bandwidth estimate. This |
| 2105 | // is useful if the application pesistently underutilizes the link, but still |
| 2106 | // relies on having a reasonable bandwidth estimate from the connection, e.g. |
| 2107 | // for real time applications. |
| 2108 | bool fill_up_link_during_probing_; |
| 2109 | |
| 2110 | // If true, the probing retransmission will not be started again. This is |
| 2111 | // used to safeguard against an accidental tail recursion in probing |
| 2112 | // retransmission code. |
| 2113 | bool probing_retransmission_pending_; |
| 2114 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2115 | // Id of latest sent control frame. 0 if no control frame has been sent. |
| 2116 | QuicControlFrameId last_control_frame_id_; |
| 2117 | |
| 2118 | // True if the peer is unreachable on the current path. |
| 2119 | bool is_path_degrading_; |
| 2120 | |
| 2121 | // True if an ack frame is being processed. |
| 2122 | bool processing_ack_frame_; |
| 2123 | |
| 2124 | // True if the writer supports release timestamp. |
| 2125 | bool supports_release_time_; |
| 2126 | |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 2127 | std::unique_ptr<QuicPeerIssuedConnectionIdManager> peer_issued_cid_manager_; |
| 2128 | std::unique_ptr<QuicSelfIssuedConnectionIdManager> self_issued_cid_manager_; |
| 2129 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2130 | // Time this connection can release packets into the future. |
| 2131 | QuicTime::Delta release_time_into_future_; |
| 2132 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2133 | // Payload of most recently transmitted IETF QUIC connectivity |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2134 | // probe packet (the PATH_CHALLENGE payload). This implementation transmits |
| 2135 | // only one PATH_CHALLENGE per connectivity probe, so only one |
| 2136 | // QuicPathFrameBuffer is needed. |
| 2137 | std::unique_ptr<QuicPathFrameBuffer> transmitted_connectivity_probe_payload_; |
| 2138 | |
| 2139 | // Payloads that were received in the most recent probe. This needs to be a |
| 2140 | // Deque because the peer might no be using this implementation, and others |
| 2141 | // might send a packet with more than one PATH_CHALLENGE, so all need to be |
| 2142 | // saved and responded to. |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 2143 | // TODO(danzh) deprecate this field when deprecating |
| 2144 | // --quic_send_path_response. |
bnc | 08fc2ae | 2021-04-27 14:57:51 -0700 | [diff] [blame] | 2145 | quiche::QuicheCircularDeque<QuicPathFrameBuffer> |
| 2146 | received_path_challenge_payloads_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2147 | |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 2148 | // Buffer outstanding PATH_CHALLENGEs if socket write is blocked, future |
| 2149 | // OnCanWrite will attempt to respond with PATH_RESPONSEs using the retained |
| 2150 | // payload and peer addresses. |
fayang | a1ffa16 | 2021-04-13 05:43:02 -0700 | [diff] [blame] | 2151 | // TODO(fayang): remove this when deprecating quic_drop_unsent_path_response. |
bnc | 08fc2ae | 2021-04-27 14:57:51 -0700 | [diff] [blame] | 2152 | quiche::QuicheCircularDeque<PendingPathChallenge> |
| 2153 | pending_path_challenge_payloads_; |
danzh | 8a27a1a | 2020-09-02 10:26:28 -0700 | [diff] [blame] | 2154 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 2155 | // When we receive a RETRY packet or some INITIAL packets, we replace |
| 2156 | // |server_connection_id_| with the value from that packet and save off the |
| 2157 | // original value of |server_connection_id_| into |
| 2158 | // |original_destination_connection_id_| for validation. |
vasilvv | 7df418b | 2020-10-13 13:47:09 -0700 | [diff] [blame] | 2159 | absl::optional<QuicConnectionId> original_destination_connection_id_; |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 2160 | |
haoyuewang | 1063e45 | 2021-04-28 10:44:33 -0700 | [diff] [blame] | 2161 | // The connection ID that replaces original_destination_connection_id_. |
| 2162 | QuicConnectionId original_destination_connection_id_replacement_; |
| 2163 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 2164 | // After we receive a RETRY packet, |retry_source_connection_id_| contains |
| 2165 | // the source connection ID from that packet. |
vasilvv | 7df418b | 2020-10-13 13:47:09 -0700 | [diff] [blame] | 2166 | absl::optional<QuicConnectionId> retry_source_connection_id_; |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 2167 | |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 2168 | // Used to store content of packets which cannot be sent because of write |
| 2169 | // blocked. Packets' encrypted buffers are copied and owned by |
| 2170 | // buffered_packets_. From unacked_packet_map (and congestion control)'s |
fayang | e62e63c | 2019-12-04 07:16:25 -0800 | [diff] [blame] | 2171 | // perspective, those packets are considered sent. |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 2172 | std::list<BufferedPacket> buffered_packets_; |
| 2173 | |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 2174 | // Used to coalesce packets of different encryption level into the same UDP |
| 2175 | // datagram. Connection stops trying to coalesce packets if a forward secure |
| 2176 | // packet gets acknowledged. |
| 2177 | QuicCoalescedPacket coalesced_packet_; |
| 2178 | |
wub | f76cf2a | 2019-10-11 18:49:07 -0700 | [diff] [blame] | 2179 | QuicConnectionMtuDiscoverer mtu_discoverer_; |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 2180 | |
| 2181 | QuicNetworkBlackholeDetector blackhole_detector_; |
| 2182 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 2183 | QuicIdleNetworkDetector idle_network_detector_; |
| 2184 | |
fayang | f78b693 | 2020-06-08 08:36:45 -0700 | [diff] [blame] | 2185 | bool blackhole_detection_disabled_ = false; |
| 2186 | |
fayang | aa4f3f2 | 2020-06-05 16:22:00 -0700 | [diff] [blame] | 2187 | const bool default_enable_5rto_blackhole_detection_ = |
fayang | 656cbb5 | 2020-06-09 13:29:35 -0700 | [diff] [blame] | 2188 | GetQuicReloadableFlag(quic_default_enable_5rto_blackhole_detection2); |
dschinazi | 6458eb3 | 2020-06-23 12:38:41 -0700 | [diff] [blame] | 2189 | |
| 2190 | // Whether the Legacy Version Encapsulation feature is enabled. |
| 2191 | bool legacy_version_encapsulation_enabled_ = false; |
| 2192 | // Whether we are in the middle of sending a packet using Legacy Version |
| 2193 | // Encapsulation. |
| 2194 | bool legacy_version_encapsulation_in_progress_ = false; |
| 2195 | // SNI to send when using Legacy Version Encapsulation. |
| 2196 | std::string legacy_version_encapsulation_sni_; |
fayang | fe963c5 | 2020-07-16 06:56:09 -0700 | [diff] [blame] | 2197 | // True if next packet is intended to consume remaining space in the |
| 2198 | // coalescer. |
| 2199 | bool fill_coalesced_packet_ = false; |
fayang | 84305ed | 2020-08-24 13:00:40 -0700 | [diff] [blame] | 2200 | |
| 2201 | size_t anti_amplification_factor_ = |
| 2202 | GetQuicFlag(FLAGS_quic_anti_amplification_factor); |
danzh | 623f6ef | 2020-08-25 16:44:37 -0700 | [diff] [blame] | 2203 | |
danzh | a685322 | 2021-05-07 08:06:03 -0700 | [diff] [blame] | 2204 | // latch --gfe2_reloadable_flag_quic_send_path_response. |
| 2205 | bool send_path_response_ = GetQuicReloadableFlag(quic_send_path_response2); |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 2206 | |
| 2207 | bool use_path_validator_ = |
| 2208 | send_path_response_ && |
| 2209 | GetQuicReloadableFlag(quic_pass_path_response_to_validator); |
| 2210 | |
haoyuewang | 2d2fdd1 | 2020-09-16 11:26:56 -0700 | [diff] [blame] | 2211 | // True if AckFrequencyFrame is supported. |
| 2212 | bool can_receive_ack_frequency_frame_ = false; |
fayang | 9a74ee9 | 2020-09-23 15:49:11 -0700 | [diff] [blame] | 2213 | |
fayang | daeb819 | 2020-09-24 09:28:59 -0700 | [diff] [blame] | 2214 | // Indicate whether coalescing is done. |
| 2215 | bool coalescing_done_ = false; |
| 2216 | |
fayang | d868245 | 2020-09-28 09:09:29 -0700 | [diff] [blame] | 2217 | // Indicate whether any ENCRYPTION_HANDSHAKE packet has been sent. |
| 2218 | bool handshake_packet_sent_ = false; |
| 2219 | |
haoyuewang | 24d8d70 | 2020-10-19 08:05:01 -0700 | [diff] [blame] | 2220 | // Indicate whether to send an AckFrequencyFrame upon handshake completion. |
| 2221 | // The AckFrequencyFrame sent will updates client's max_ack_delay, which if |
| 2222 | // chosen properly can reduce the CPU and bandwidth usage for ACK frames. |
| 2223 | bool send_ack_frequency_on_handshake_completion_ = false; |
| 2224 | |
haoyuewang | c921f8d | 2020-10-14 18:06:52 -0700 | [diff] [blame] | 2225 | // Indicate whether AckFrequency frame has been sent. |
| 2226 | bool ack_frequency_sent_ = false; |
| 2227 | |
mattm | ad5eb5d | 2020-12-03 16:12:15 -0800 | [diff] [blame] | 2228 | // True if a 0-RTT decrypter was or is installed at some point in the |
| 2229 | // connection's lifetime. |
| 2230 | bool had_zero_rtt_decrypter_ = false; |
| 2231 | |
| 2232 | // True after the first 1-RTT packet has successfully decrypted. |
| 2233 | bool have_decrypted_first_one_rtt_packet_ = false; |
| 2234 | |
fayang | 4b5b4e6 | 2021-04-14 06:16:42 -0700 | [diff] [blame] | 2235 | // True if we are currently processing OnRetransmissionTimeout. |
| 2236 | bool in_on_retransmission_time_out_ = false; |
| 2237 | |
fayang | 5100e29 | 2020-10-30 14:37:44 -0700 | [diff] [blame] | 2238 | const bool use_encryption_level_context_; |
danzh | e6211dc | 2020-11-19 09:19:00 -0800 | [diff] [blame] | 2239 | |
| 2240 | QuicPathValidator path_validator_; |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 2241 | |
danzh | a4b519c | 2021-02-05 12:10:55 -0800 | [diff] [blame] | 2242 | // Stores information of a path which maybe used as default path in the |
| 2243 | // future. On the client side, it gets created when the client starts |
| 2244 | // validating a new path and gets cleared once it becomes the default path or |
| 2245 | // the path validation fails or replaced by a newer path of interest. On the |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 2246 | // server side, alternative_path gets created when server: 1) receives |
| 2247 | // PATH_CHALLENGE on non-default path, or 2) switches to a not yet validated |
| 2248 | // default path such that it needs to store the previous validated default |
| 2249 | // path. |
| 2250 | // Note that if alternative_path_ stores a validated path information (case |
| 2251 | // 2), do not override it on receiving PATH_CHALLENGE (case 1). |
danzh | 37b722e | 2021-02-17 11:09:08 -0800 | [diff] [blame] | 2252 | PathState alternative_path_; |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 2253 | |
renjietang | 5c9a9ce | 2021-01-19 15:48:57 -0800 | [diff] [blame] | 2254 | // This field is used to debug b/177312785. |
| 2255 | QuicFrameType most_recent_frame_type_; |
| 2256 | |
danzh | 046212e | 2021-01-26 11:44:09 -0800 | [diff] [blame] | 2257 | bool count_bytes_on_alternative_path_separately_ = |
danzh | 9cb85b7 | 2020-12-30 07:17:09 -0800 | [diff] [blame] | 2258 | GetQuicReloadableFlag(quic_count_bytes_on_alternative_path_seperately); |
renjietang | 7f1d9e1 | 2021-01-22 19:10:57 -0800 | [diff] [blame] | 2259 | |
danzh | a25ed9d | 2021-02-19 12:40:26 -0800 | [diff] [blame] | 2260 | // If true, upon seeing a new client address, validate the client address. |
danzh | f0bc77d | 2021-03-25 15:08:48 -0700 | [diff] [blame] | 2261 | bool validate_client_addresses_ = false; |
haoyuewang | e3c51d9 | 2021-03-08 07:35:03 -0800 | [diff] [blame] | 2262 | |
| 2263 | bool support_multiple_connection_ids_ = false; |
fayang | c2638cc | 2021-04-05 14:45:40 -0700 | [diff] [blame] | 2264 | |
| 2265 | const bool donot_write_mid_packet_processing_ = |
| 2266 | GetQuicReloadableFlag(quic_donot_write_mid_packet_processing); |
haoyuewang | 5c49d3e | 2021-04-08 07:33:33 -0700 | [diff] [blame] | 2267 | |
haoyuewang | 53cbf3f | 2021-04-13 12:52:11 -0700 | [diff] [blame] | 2268 | // Indicates whether we should proactively validate peer address on a |
| 2269 | // PATH_CHALLENGE received. |
| 2270 | bool should_proactively_validate_peer_address_on_path_challenge_ = false; |
| 2271 | |
haoyuewang | dc60baf | 2021-04-19 14:03:14 -0700 | [diff] [blame] | 2272 | // Enable this via reloadable flag once this feature is complete. |
| 2273 | bool connection_migration_use_new_cid_ = false; |
| 2274 | |
haoyuewang | 53cbf3f | 2021-04-13 12:52:11 -0700 | [diff] [blame] | 2275 | const bool group_path_response_and_challenge_sending_closer_ = |
| 2276 | GetQuicReloadableFlag( |
| 2277 | quic_group_path_response_and_challenge_sending_closer); |
| 2278 | |
fayang | f7bc0ad | 2021-05-27 05:15:25 -0700 | [diff] [blame] | 2279 | const bool reset_per_packet_state_for_undecryptable_packets_ = |
| 2280 | GetQuicReloadableFlag( |
| 2281 | quic_reset_per_packet_state_for_undecryptable_packets); |
fayang | fb75f7e | 2021-07-14 12:38:18 -0700 | [diff] [blame] | 2282 | |
| 2283 | const bool add_missing_update_ack_timeout_ = |
| 2284 | GetQuicReloadableFlag(quic_add_missing_update_ack_timeout); |
haoyuewang | 095051f | 2021-07-16 12:11:35 -0700 | [diff] [blame] | 2285 | |
| 2286 | const bool ack_cid_frames_ = GetQuicReloadableFlag(quic_ack_cid_frames); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2287 | }; |
| 2288 | |
| 2289 | } // namespace quic |
| 2290 | |
| 2291 | #endif // QUICHE_QUIC_CORE_QUIC_CONNECTION_H_ |