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 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 28 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
dschinazi | 631f160 | 2020-05-19 10:10:22 -0700 | [diff] [blame] | 29 | #include "net/third_party/quiche/src/quic/core/crypto/transport_parameters.h" |
renjietang | c705490 | 2019-09-25 13:13:52 -0700 | [diff] [blame] | 30 | #include "net/third_party/quiche/src/quic/core/frames/quic_max_streams_frame.h" |
dschinazi | 56fb53e | 2019-06-21 15:30:04 -0700 | [diff] [blame] | 31 | #include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters_proto.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | #include "net/third_party/quiche/src/quic/core/quic_alarm.h" |
| 33 | #include "net/third_party/quiche/src/quic/core/quic_alarm_factory.h" |
| 34 | #include "net/third_party/quiche/src/quic/core/quic_blocked_writer_interface.h" |
danzh | bf4836c | 2020-02-11 20:29:15 -0800 | [diff] [blame] | 35 | #include "net/third_party/quiche/src/quic/core/quic_circular_deque.h" |
QUICHE team | c65d1d1 | 2019-03-19 20:58:04 -0700 | [diff] [blame] | 36 | #include "net/third_party/quiche/src/quic/core/quic_connection_id.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | #include "net/third_party/quiche/src/quic/core/quic_connection_stats.h" |
| 38 | #include "net/third_party/quiche/src/quic/core/quic_framer.h" |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 39 | #include "net/third_party/quiche/src/quic/core/quic_idle_network_detector.h" |
wub | f76cf2a | 2019-10-11 18:49:07 -0700 | [diff] [blame] | 40 | #include "net/third_party/quiche/src/quic/core/quic_mtu_discovery.h" |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 41 | #include "net/third_party/quiche/src/quic/core/quic_network_blackhole_detector.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 42 | #include "net/third_party/quiche/src/quic/core/quic_one_block_arena.h" |
| 43 | #include "net/third_party/quiche/src/quic/core/quic_packet_creator.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 44 | #include "net/third_party/quiche/src/quic/core/quic_packet_writer.h" |
| 45 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | #include "net/third_party/quiche/src/quic/core/quic_sent_packet_manager.h" |
| 47 | #include "net/third_party/quiche/src/quic/core/quic_time.h" |
| 48 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 49 | #include "net/third_party/quiche/src/quic/core/uber_received_packet_manager.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | #include "net/third_party/quiche/src/quic/platform/api/quic_containers.h" |
| 51 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 52 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 53 | #include "net/third_party/quiche/src/common/platform/api/quiche_optional.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 54 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
| 55 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 56 | |
| 57 | namespace quic { |
| 58 | |
| 59 | class QuicClock; |
| 60 | class QuicConfig; |
| 61 | class QuicConnection; |
| 62 | class QuicRandom; |
| 63 | |
| 64 | namespace test { |
| 65 | class QuicConnectionPeer; |
| 66 | } // namespace test |
| 67 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | // Class that receives callbacks from the connection when frames are received |
| 69 | // and when other interesting events happen. |
| 70 | class QUIC_EXPORT_PRIVATE QuicConnectionVisitorInterface { |
| 71 | public: |
| 72 | virtual ~QuicConnectionVisitorInterface() {} |
| 73 | |
| 74 | // A simple visitor interface for dealing with a data frame. |
| 75 | virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; |
| 76 | |
| 77 | // Called when a CRYPTO frame containing handshake data is received. |
| 78 | virtual void OnCryptoFrame(const QuicCryptoFrame& frame) = 0; |
| 79 | |
| 80 | // The session should process the WINDOW_UPDATE frame, adjusting both stream |
| 81 | // and connection level flow control windows. |
| 82 | virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) = 0; |
| 83 | |
| 84 | // A BLOCKED frame indicates the peer is flow control blocked |
| 85 | // on a specified stream. |
| 86 | virtual void OnBlockedFrame(const QuicBlockedFrame& frame) = 0; |
| 87 | |
| 88 | // Called when the stream is reset by the peer. |
| 89 | virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0; |
| 90 | |
| 91 | // Called when the connection is going away according to the peer. |
| 92 | virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0; |
| 93 | |
| 94 | // Called when |message| has been received. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 95 | virtual void OnMessageReceived(quiche::QuicheStringPiece message) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 97 | // Called when a HANDSHAKE_DONE frame has been received. |
| 98 | virtual void OnHandshakeDoneReceived() = 0; |
| 99 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 100 | // Called when a MAX_STREAMS frame has been received from the peer. |
| 101 | virtual bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 103 | // Called when a STREAMS_BLOCKED frame has been received from the peer. |
| 104 | virtual bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 105 | |
| 106 | // Called when the connection is closed either locally by the framer, or |
| 107 | // remotely by the peer. |
fkastenholz | 5d880a9 | 2019-06-21 09:01:56 -0700 | [diff] [blame] | 108 | virtual void OnConnectionClosed(const QuicConnectionCloseFrame& frame, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 109 | ConnectionCloseSource source) = 0; |
| 110 | |
| 111 | // Called when the connection failed to write because the socket was blocked. |
| 112 | virtual void OnWriteBlocked() = 0; |
| 113 | |
| 114 | // Called once a specific QUIC version is agreed by both endpoints. |
| 115 | virtual void OnSuccessfulVersionNegotiation( |
| 116 | const ParsedQuicVersion& version) = 0; |
| 117 | |
zhongyi | 83161e4 | 2019-08-19 09:06:25 -0700 | [diff] [blame] | 118 | // Called when a packet has been received by the connection, after being |
| 119 | // validated and parsed. Only called when the client receives a valid packet |
| 120 | // or the server receives a connectivity probing packet. |
| 121 | // |is_connectivity_probe| is true if the received packet is a connectivity |
| 122 | // probe. |
| 123 | virtual void OnPacketReceived(const QuicSocketAddress& self_address, |
| 124 | const QuicSocketAddress& peer_address, |
| 125 | bool is_connectivity_probe) = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 126 | |
| 127 | // Called when a blocked socket becomes writable. |
| 128 | virtual void OnCanWrite() = 0; |
| 129 | |
QUICHE team | b834325 | 2019-04-29 13:58:01 -0700 | [diff] [blame] | 130 | // Called when the connection needs more data to probe for additional |
| 131 | // bandwidth. Returns true if data was sent, false otherwise. |
| 132 | virtual bool SendProbingData() = 0; |
| 133 | |
renjietang | 7f483b5 | 2020-05-20 14:30:47 -0700 | [diff] [blame] | 134 | // Called when stateless reset packet is received. Returns true if the |
| 135 | // connection needs to be closed. |
| 136 | virtual bool ValidateStatelessReset( |
| 137 | const quic::QuicSocketAddress& self_address, |
| 138 | const quic::QuicSocketAddress& peer_address) = 0; |
renjietang | 5b24589 | 2020-05-18 11:57:26 -0700 | [diff] [blame] | 139 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 140 | // Called when the connection experiences a change in congestion window. |
| 141 | virtual void OnCongestionWindowChange(QuicTime now) = 0; |
| 142 | |
| 143 | // Called when the connection receives a packet from a migrated client. |
| 144 | virtual void OnConnectionMigration(AddressChangeType type) = 0; |
| 145 | |
| 146 | // Called when the peer seems unreachable over the current path. |
| 147 | virtual void OnPathDegrading() = 0; |
| 148 | |
zhongyi | ef1d675 | 2020-06-11 16:19:28 -0700 | [diff] [blame] | 149 | // Called when forward progress made after path degrading. |
| 150 | virtual void OnForwardProgressMadeAfterPathDegrading() = 0; |
| 151 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 152 | // Called when the connection sends ack after |
| 153 | // max_consecutive_num_packets_with_no_retransmittable_frames_ consecutive not |
| 154 | // retransmittable packets sent. To instigate an ack from peer, a |
| 155 | // retransmittable frame needs to be added. |
| 156 | virtual void OnAckNeedsRetransmittableFrame() = 0; |
| 157 | |
| 158 | // Called when a ping needs to be sent. |
| 159 | virtual void SendPing() = 0; |
| 160 | |
| 161 | // Called to ask if the visitor wants to schedule write resumption as it both |
| 162 | // has pending data to write, and is able to write (e.g. based on flow control |
| 163 | // limits). |
| 164 | // Writes may be pending because they were write-blocked, congestion-throttled |
| 165 | // or yielded to other connections. |
| 166 | virtual bool WillingAndAbleToWrite() const = 0; |
| 167 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 168 | // Called to ask if the connection should be kept alive and prevented |
| 169 | // from timing out, for example if there are outstanding application |
| 170 | // transactions expecting a response. |
| 171 | virtual bool ShouldKeepConnectionAlive() const = 0; |
| 172 | |
| 173 | // Called when a self address change is observed. Returns true if self address |
| 174 | // change is allowed. |
| 175 | virtual bool AllowSelfAddressChange() const = 0; |
| 176 | |
fayang | c67c520 | 2020-01-22 07:43:15 -0800 | [diff] [blame] | 177 | // Called to get current handshake state. |
| 178 | virtual HandshakeState GetHandshakeState() const = 0; |
| 179 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 180 | // Called when a STOP_SENDING frame has been received. |
renjietang | eab918f | 2019-10-28 12:10:32 -0700 | [diff] [blame] | 181 | virtual void OnStopSendingFrame(const QuicStopSendingFrame& frame) = 0; |
fayang | d58736d | 2019-11-27 13:35:31 -0800 | [diff] [blame] | 182 | |
| 183 | // Called when a packet of encryption |level| has been successfully decrypted. |
| 184 | virtual void OnPacketDecrypted(EncryptionLevel level) = 0; |
fayang | 2f2915d | 2020-01-24 06:47:15 -0800 | [diff] [blame] | 185 | |
| 186 | // Called when a 1RTT packet has been acknowledged. |
| 187 | virtual void OnOneRttPacketAcknowledged() = 0; |
fayang | 44ae4e9 | 2020-04-28 13:09:42 -0700 | [diff] [blame] | 188 | |
| 189 | // Called when a packet of ENCRYPTION_HANDSHAKE gets sent. |
| 190 | virtual void OnHandshakePacketSent() = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | // Interface which gets callbacks from the QuicConnection at interesting |
| 194 | // points. Implementations must not mutate the state of the connection |
| 195 | // as a result of these callbacks. |
| 196 | class QUIC_EXPORT_PRIVATE QuicConnectionDebugVisitor |
| 197 | : public QuicSentPacketManager::DebugDelegate { |
| 198 | public: |
| 199 | ~QuicConnectionDebugVisitor() override {} |
| 200 | |
| 201 | // Called when a packet has been sent. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 202 | virtual void OnPacketSent(const SerializedPacket& /*serialized_packet*/, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 203 | TransmissionType /*transmission_type*/, |
| 204 | QuicTime /*sent_time*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 205 | |
fayang | 6100ab7 | 2020-03-18 13:16:25 -0700 | [diff] [blame] | 206 | // Called when a coalesced packet has been sent. |
| 207 | virtual void OnCoalescedPacketSent( |
| 208 | const QuicCoalescedPacket& /*coalesced_packet*/, |
| 209 | size_t /*length*/) {} |
| 210 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 211 | // Called when a PING frame has been sent. |
| 212 | virtual void OnPingSent() {} |
| 213 | |
| 214 | // Called when a packet has been received, but before it is |
| 215 | // validated or parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 216 | virtual void OnPacketReceived(const QuicSocketAddress& /*self_address*/, |
| 217 | const QuicSocketAddress& /*peer_address*/, |
| 218 | const QuicEncryptedPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 219 | |
| 220 | // Called when the unauthenticated portion of the header has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 221 | virtual void OnUnauthenticatedHeader(const QuicPacketHeader& /*header*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 222 | |
| 223 | // Called when a packet is received with a connection id that does not |
| 224 | // match the ID of this connection. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 225 | virtual void OnIncorrectConnectionId(QuicConnectionId /*connection_id*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 226 | |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 227 | // Called when an undecryptable packet has been received. If |dropped| is |
| 228 | // true, the packet has been dropped. Otherwise, the packet will be queued and |
| 229 | // connection will attempt to process it later. |
| 230 | virtual void OnUndecryptablePacket(EncryptionLevel /*decryption_level*/, |
| 231 | bool /*dropped*/) {} |
| 232 | |
| 233 | // Called when attempting to process a previously undecryptable packet. |
| 234 | virtual void OnAttemptingToProcessUndecryptablePacket( |
| 235 | EncryptionLevel /*decryption_level*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 236 | |
| 237 | // Called when a duplicate packet has been received. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 238 | virtual void OnDuplicatePacket(QuicPacketNumber /*packet_number*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 239 | |
| 240 | // Called when the protocol version on the received packet doensn't match |
| 241 | // current protocol version of the connection. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 242 | virtual void OnProtocolVersionMismatch(ParsedQuicVersion /*version*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 243 | |
| 244 | // Called when the complete header of a packet has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 245 | virtual void OnPacketHeader(const QuicPacketHeader& /*header*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 246 | |
| 247 | // Called when a StreamFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 248 | virtual void OnStreamFrame(const QuicStreamFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 249 | |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 250 | // Called when a CRYPTO frame containing handshake data is received. |
| 251 | virtual void OnCryptoFrame(const QuicCryptoFrame& /*frame*/) {} |
| 252 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 253 | // Called when a StopWaitingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 254 | virtual void OnStopWaitingFrame(const QuicStopWaitingFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 255 | |
| 256 | // Called when a QuicPaddingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 257 | virtual void OnPaddingFrame(const QuicPaddingFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 258 | |
| 259 | // Called when a Ping has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 260 | virtual void OnPingFrame(const QuicPingFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 261 | |
| 262 | // Called when a GoAway has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 263 | virtual void OnGoAwayFrame(const QuicGoAwayFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 264 | |
| 265 | // Called when a RstStreamFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 266 | virtual void OnRstStreamFrame(const QuicRstStreamFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 267 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 268 | // Called when a ConnectionCloseFrame has been parsed. All forms |
| 269 | // of CONNECTION CLOSE are handled, Google QUIC, IETF QUIC |
| 270 | // CONNECTION CLOSE/Transport and IETF QUIC CONNECTION CLOSE/Application |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 271 | virtual void OnConnectionCloseFrame( |
| 272 | const QuicConnectionCloseFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 273 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 274 | // Called when a WindowUpdate has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 275 | virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& /*frame*/, |
| 276 | const QuicTime& /*receive_time*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 277 | |
| 278 | // Called when a BlockedFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 279 | virtual void OnBlockedFrame(const QuicBlockedFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 280 | |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 281 | // Called when a NewConnectionIdFrame has been parsed. |
| 282 | virtual void OnNewConnectionIdFrame( |
| 283 | const QuicNewConnectionIdFrame& /*frame*/) {} |
| 284 | |
| 285 | // Called when a RetireConnectionIdFrame has been parsed. |
| 286 | virtual void OnRetireConnectionIdFrame( |
| 287 | const QuicRetireConnectionIdFrame& /*frame*/) {} |
| 288 | |
| 289 | // Called when a NewTokenFrame has been parsed. |
| 290 | virtual void OnNewTokenFrame(const QuicNewTokenFrame& /*frame*/) {} |
| 291 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 292 | // Called when a MessageFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 293 | virtual void OnMessageFrame(const QuicMessageFrame& /*frame*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 294 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 295 | // Called when a HandshakeDoneFrame has been parsed. |
| 296 | virtual void OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& /*frame*/) {} |
| 297 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 298 | // Called when a public reset packet has been received. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 299 | virtual void OnPublicResetPacket(const QuicPublicResetPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | |
| 301 | // Called when a version negotiation packet has been received. |
| 302 | virtual void OnVersionNegotiationPacket( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 303 | const QuicVersionNegotiationPacket& /*packet*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 304 | |
| 305 | // Called when the connection is closed. |
fkastenholz | ac11db0 | 2019-06-24 06:22:04 -0700 | [diff] [blame] | 306 | virtual void OnConnectionClosed(const QuicConnectionCloseFrame& /*frame*/, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 307 | ConnectionCloseSource /*source*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 308 | |
| 309 | // Called when the version negotiation is successful. |
| 310 | virtual void OnSuccessfulVersionNegotiation( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 311 | const ParsedQuicVersion& /*version*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 312 | |
| 313 | // Called when a CachedNetworkParameters is sent to the client. |
| 314 | virtual void OnSendConnectionState( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 315 | const CachedNetworkParameters& /*cached_network_params*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | |
| 317 | // Called when a CachedNetworkParameters are received from the client. |
| 318 | virtual void OnReceiveConnectionState( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 319 | const CachedNetworkParameters& /*cached_network_params*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 320 | |
| 321 | // Called when the connection parameters are set from the supplied |
| 322 | // |config|. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 323 | virtual void OnSetFromConfig(const QuicConfig& /*config*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 324 | |
| 325 | // Called when RTT may have changed, including when an RTT is read from |
| 326 | // the config. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 327 | virtual void OnRttChanged(QuicTime::Delta /*rtt*/) const {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 328 | |
| 329 | // Called when a StopSendingFrame has been parsed. |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 330 | virtual void OnStopSendingFrame(const QuicStopSendingFrame& /*frame*/) {} |
rch | b7e6e64 | 2019-09-03 21:57:05 -0700 | [diff] [blame] | 331 | |
| 332 | // Called when a PathChallengeFrame has been parsed. |
| 333 | virtual void OnPathChallengeFrame(const QuicPathChallengeFrame& /*frame*/) {} |
| 334 | |
| 335 | // Called when a PathResponseFrame has been parsed. |
| 336 | virtual void OnPathResponseFrame(const QuicPathResponseFrame& /*frame*/) {} |
renjietang | c705490 | 2019-09-25 13:13:52 -0700 | [diff] [blame] | 337 | |
| 338 | // Called when a StreamsBlockedFrame has been parsed. |
| 339 | virtual void OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& /*frame*/) { |
| 340 | } |
| 341 | |
| 342 | // Called when a MaxStreamsFrame has been parsed. |
| 343 | virtual void OnMaxStreamsFrame(const QuicMaxStreamsFrame& /*frame*/) {} |
fayang | 2cbfccf | 2019-11-14 14:02:15 -0800 | [diff] [blame] | 344 | |
| 345 | // Called when |count| packet numbers have been skipped. |
| 346 | virtual void OnNPacketNumbersSkipped(QuicPacketCount /*count*/) {} |
dschinazi | 631f160 | 2020-05-19 10:10:22 -0700 | [diff] [blame] | 347 | |
| 348 | // Called for QUIC+TLS versions when we send transport parameters. |
| 349 | virtual void OnTransportParametersSent( |
| 350 | const TransportParameters& /*transport_parameters*/) {} |
| 351 | |
| 352 | // Called for QUIC+TLS versions when we receive transport parameters. |
| 353 | virtual void OnTransportParametersReceived( |
| 354 | const TransportParameters& /*transport_parameters*/) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | class QUIC_EXPORT_PRIVATE QuicConnectionHelperInterface { |
| 358 | public: |
| 359 | virtual ~QuicConnectionHelperInterface() {} |
| 360 | |
| 361 | // Returns a QuicClock to be used for all time related functions. |
| 362 | virtual const QuicClock* GetClock() const = 0; |
| 363 | |
| 364 | // Returns a QuicRandom to be used for all random number related functions. |
| 365 | virtual QuicRandom* GetRandomGenerator() = 0; |
| 366 | |
| 367 | // Returns a QuicBufferAllocator to be used for stream send buffers. |
| 368 | virtual QuicBufferAllocator* GetStreamSendBufferAllocator() = 0; |
| 369 | }; |
| 370 | |
| 371 | class QUIC_EXPORT_PRIVATE QuicConnection |
| 372 | : public QuicFramerVisitorInterface, |
| 373 | public QuicBlockedWriterInterface, |
fayang | cad1179 | 2019-09-16 13:11:44 -0700 | [diff] [blame] | 374 | public QuicPacketCreator::DelegateInterface, |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 375 | public QuicSentPacketManager::NetworkChangeVisitor, |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 376 | public QuicNetworkBlackholeDetector::Delegate, |
| 377 | public QuicIdleNetworkDetector::Delegate { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 378 | public: |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 379 | // Constructs a new QuicConnection for |connection_id| and |
| 380 | // |initial_peer_address| using |writer| to write packets. |owns_writer| |
| 381 | // specifies whether the connection takes ownership of |writer|. |helper| must |
| 382 | // outlive this connection. |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 383 | QuicConnection(QuicConnectionId server_connection_id, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 384 | QuicSocketAddress initial_peer_address, |
| 385 | QuicConnectionHelperInterface* helper, |
| 386 | QuicAlarmFactory* alarm_factory, |
| 387 | QuicPacketWriter* writer, |
| 388 | bool owns_writer, |
| 389 | Perspective perspective, |
| 390 | const ParsedQuicVersionVector& supported_versions); |
| 391 | QuicConnection(const QuicConnection&) = delete; |
| 392 | QuicConnection& operator=(const QuicConnection&) = delete; |
| 393 | ~QuicConnection() override; |
| 394 | |
| 395 | // Sets connection parameters from the supplied |config|. |
| 396 | void SetFromConfig(const QuicConfig& config); |
| 397 | |
wub | d09f1a6 | 2020-05-04 06:57:40 -0700 | [diff] [blame] | 398 | // Apply |connection_options| for this connection. Unlike SetFromConfig, this |
| 399 | // can happen at anytime in the life of a connection. |
| 400 | // Note there is no guarantee that all options can be applied. Components will |
| 401 | // only apply cherrypicked options that make sense at the time of the call. |
| 402 | void ApplyConnectionOptions(const QuicTagVector& connection_options); |
| 403 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 404 | // Called by the session when sending connection state to the client. |
| 405 | virtual void OnSendConnectionState( |
| 406 | const CachedNetworkParameters& cached_network_params); |
| 407 | |
| 408 | // Called by the session when receiving connection state from the client. |
| 409 | virtual void OnReceiveConnectionState( |
| 410 | const CachedNetworkParameters& cached_network_params); |
| 411 | |
| 412 | // Called by the Session when the client has provided CachedNetworkParameters. |
| 413 | virtual void ResumeConnectionState( |
| 414 | const CachedNetworkParameters& cached_network_params, |
| 415 | bool max_bandwidth_resumption); |
| 416 | |
| 417 | // Called by the Session when a max pacing rate for the connection is needed. |
| 418 | virtual void SetMaxPacingRate(QuicBandwidth max_pacing_rate); |
| 419 | |
| 420 | // Allows the client to adjust network parameters based on external |
| 421 | // information. |
QUICHE team | fdcfe3b | 2019-11-06 10:54:25 -0800 | [diff] [blame] | 422 | void AdjustNetworkParameters( |
| 423 | const SendAlgorithmInterface::NetworkParams& params); |
fayang | f1b99dc | 2019-05-14 06:29:18 -0700 | [diff] [blame] | 424 | void AdjustNetworkParameters(QuicBandwidth bandwidth, |
| 425 | QuicTime::Delta rtt, |
| 426 | bool allow_cwnd_to_decrease); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 427 | |
wub | 44e3305 | 2020-03-03 17:11:40 -0800 | [diff] [blame] | 428 | // Install a loss detection tuner. Must be called before OnConfigNegotiated. |
| 429 | void SetLossDetectionTuner( |
| 430 | std::unique_ptr<LossDetectionTunerInterface> tuner); |
| 431 | // Called by the session when session->is_configured() becomes true. |
| 432 | void OnConfigNegotiated(); |
| 433 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 434 | // Returns the max pacing rate for the connection. |
| 435 | virtual QuicBandwidth MaxPacingRate() const; |
| 436 | |
| 437 | // Sends crypto handshake messages of length |write_length| to the peer in as |
| 438 | // few packets as possible. Returns the number of bytes consumed from the |
| 439 | // data. |
| 440 | virtual size_t SendCryptoData(EncryptionLevel level, |
| 441 | size_t write_length, |
| 442 | QuicStreamOffset offset); |
| 443 | |
| 444 | // Send the data of length |write_length| to the peer in as few packets as |
| 445 | // possible. Returns the number of bytes consumed from data, and a boolean |
| 446 | // indicating if the fin bit was consumed. This does not indicate the data |
| 447 | // has been sent on the wire: it may have been turned into a packet and queued |
| 448 | // if the socket was unexpectedly blocked. |
| 449 | virtual QuicConsumedData SendStreamData(QuicStreamId id, |
| 450 | size_t write_length, |
| 451 | QuicStreamOffset offset, |
| 452 | StreamSendingState state); |
| 453 | |
| 454 | // Send |frame| to the peer. Returns true if frame is consumed, false |
| 455 | // otherwise. |
| 456 | virtual bool SendControlFrame(const QuicFrame& frame); |
| 457 | |
| 458 | // Called when stream |id| is reset because of |error|. |
| 459 | virtual void OnStreamReset(QuicStreamId id, QuicRstStreamErrorCode error); |
| 460 | |
| 461 | // Closes the connection. |
| 462 | // |connection_close_behavior| determines whether or not a connection close |
| 463 | // packet is sent to the peer. |
| 464 | virtual void CloseConnection( |
| 465 | QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 466 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 467 | ConnectionCloseBehavior connection_close_behavior); |
| 468 | |
| 469 | // Returns statistics tracked for this connection. |
| 470 | const QuicConnectionStats& GetStats(); |
| 471 | |
| 472 | // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from |
| 473 | // the peer. |
| 474 | // In a client, the packet may be "stray" and have a different connection ID |
| 475 | // than that of this connection. |
| 476 | virtual void ProcessUdpPacket(const QuicSocketAddress& self_address, |
| 477 | const QuicSocketAddress& peer_address, |
| 478 | const QuicReceivedPacket& packet); |
| 479 | |
| 480 | // QuicBlockedWriterInterface |
| 481 | // Called when the underlying connection becomes writable to allow queued |
| 482 | // writes to happen. |
| 483 | void OnBlockedWriterCanWrite() override; |
| 484 | |
| 485 | bool IsWriterBlocked() const override { |
| 486 | return writer_ != nullptr && writer_->IsWriteBlocked(); |
| 487 | } |
| 488 | |
| 489 | // Called when the caller thinks it's worth a try to write. |
| 490 | virtual void OnCanWrite(); |
| 491 | |
| 492 | // Called when an error occurs while attempting to write a packet to the |
| 493 | // network. |
| 494 | void OnWriteError(int error_code); |
| 495 | |
| 496 | // Whether |result| represents a MSG TOO BIG write error. |
| 497 | bool IsMsgTooBig(const WriteResult& result); |
| 498 | |
| 499 | // If the socket is not blocked, writes queued packets. |
| 500 | void WriteIfNotBlocked(); |
| 501 | |
| 502 | // If the socket is not blocked, writes queued packets and bundles any pending |
| 503 | // ACKs. |
| 504 | void WriteAndBundleAcksIfNotBlocked(); |
| 505 | |
| 506 | // Set the packet writer. |
| 507 | void SetQuicPacketWriter(QuicPacketWriter* writer, bool owns_writer) { |
| 508 | DCHECK(writer != nullptr); |
| 509 | if (writer_ != nullptr && owns_writer_) { |
| 510 | delete writer_; |
| 511 | } |
| 512 | writer_ = writer; |
| 513 | owns_writer_ = owns_writer; |
| 514 | } |
| 515 | |
| 516 | // Set self address. |
| 517 | void SetSelfAddress(QuicSocketAddress address) { self_address_ = address; } |
| 518 | |
| 519 | // The version of the protocol this connection is using. |
| 520 | QuicTransportVersion transport_version() const { |
| 521 | return framer_.transport_version(); |
| 522 | } |
| 523 | |
| 524 | ParsedQuicVersion version() const { return framer_.version(); } |
| 525 | |
| 526 | // The versions of the protocol that this connection supports. |
| 527 | const ParsedQuicVersionVector& supported_versions() const { |
| 528 | return framer_.supported_versions(); |
| 529 | } |
| 530 | |
wub | f75c2c6 | 2020-02-05 06:34:09 -0800 | [diff] [blame] | 531 | // Mark version negotiated for this connection. Once called, the connection |
| 532 | // will ignore received version negotiation packets. |
| 533 | void SetVersionNegotiated() { |
| 534 | version_negotiated_ = true; |
| 535 | if (perspective_ == Perspective::IS_SERVER) { |
| 536 | framer_.InferPacketHeaderTypeFromVersion(); |
| 537 | } |
| 538 | } |
| 539 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 540 | // From QuicFramerVisitorInterface |
| 541 | void OnError(QuicFramer* framer) override; |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 542 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 543 | void OnPacket() override; |
| 544 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override; |
| 545 | void OnVersionNegotiationPacket( |
| 546 | const QuicVersionNegotiationPacket& packet) override; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 547 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 548 | QuicConnectionId new_connection_id, |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 549 | quiche::QuicheStringPiece retry_token, |
| 550 | quiche::QuicheStringPiece retry_integrity_tag, |
| 551 | quiche::QuicheStringPiece retry_without_tag) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 552 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override; |
| 553 | bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
| 554 | void OnDecryptedPacket(EncryptionLevel level) override; |
| 555 | bool OnPacketHeader(const QuicPacketHeader& header) override; |
| 556 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override; |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 557 | void OnUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 558 | EncryptionLevel decryption_level, |
| 559 | bool has_decryption_key) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 560 | bool OnStreamFrame(const QuicStreamFrame& frame) override; |
| 561 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override; |
| 562 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 563 | QuicTime::Delta ack_delay_time) override; |
| 564 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override; |
| 565 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 566 | QuicTime timestamp) override; |
| 567 | bool OnAckFrameEnd(QuicPacketNumber start) override; |
| 568 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
| 569 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override; |
| 570 | bool OnPingFrame(const QuicPingFrame& frame) override; |
| 571 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
| 572 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 573 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override; |
| 574 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override; |
| 575 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override; |
| 576 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 577 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override; |
| 578 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 579 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 580 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 581 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override; |
| 582 | bool OnRetireConnectionIdFrame( |
| 583 | const QuicRetireConnectionIdFrame& frame) override; |
| 584 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override; |
| 585 | bool OnMessageFrame(const QuicMessageFrame& frame) override; |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 586 | bool OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& frame) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 587 | void OnPacketComplete() override; |
| 588 | bool IsValidStatelessResetToken(QuicUint128 token) const override; |
| 589 | void OnAuthenticatedIetfStatelessResetPacket( |
| 590 | const QuicIetfStatelessResetPacket& packet) override; |
| 591 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 592 | // QuicPacketCreator::DelegateInterface |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 593 | bool ShouldGeneratePacket(HasRetransmittableData retransmittable, |
| 594 | IsHandshake handshake) override; |
| 595 | const QuicFrames MaybeBundleAckOpportunistically() override; |
wub | 50d4c71 | 2020-05-19 15:48:28 -0700 | [diff] [blame] | 596 | QuicPacketBuffer GetPacketBuffer() override; |
wub | 8a5dafa | 2020-05-13 12:30:17 -0700 | [diff] [blame] | 597 | void OnSerializedPacket(SerializedPacket packet) override; |
ianswett | b023c7b | 2019-05-06 12:38:10 -0700 | [diff] [blame] | 598 | void OnUnrecoverableError(QuicErrorCode error, |
fkastenholz | 85f1890 | 2019-05-28 12:47:00 -0700 | [diff] [blame] | 599 | const std::string& error_details) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 600 | |
| 601 | // QuicSentPacketManager::NetworkChangeVisitor |
| 602 | void OnCongestionChange() override; |
| 603 | void OnPathMtuIncreased(QuicPacketLength packet_size) override; |
| 604 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 605 | // QuicNetworkBlackholeDetector::Delegate |
| 606 | void OnPathDegradingDetected() override; |
| 607 | void OnBlackholeDetected() override; |
| 608 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 609 | // QuicIdleNetworkDetector::Delegate |
| 610 | void OnHandshakeTimeout() override; |
| 611 | void OnIdleNetworkDetected() override; |
| 612 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 613 | // Please note, this is not a const function. For logging purpose, please use |
| 614 | // ack_frame(). |
| 615 | const QuicFrame GetUpdatedAckFrame(); |
| 616 | |
fayang | bd79392 | 2019-08-26 14:19:24 -0700 | [diff] [blame] | 617 | // Called when the handshake completes. On the client side, handshake |
| 618 | // completes on receipt of SHLO. On the server side, handshake completes when |
| 619 | // SHLO gets ACKed (or a forward secure packet gets decrypted successfully). |
| 620 | // TODO(fayang): Add a guard that this only gets called once. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 621 | void OnHandshakeComplete(); |
| 622 | |
| 623 | // Accessors |
| 624 | void set_visitor(QuicConnectionVisitorInterface* visitor) { |
| 625 | visitor_ = visitor; |
| 626 | } |
| 627 | void set_debug_visitor(QuicConnectionDebugVisitor* debug_visitor) { |
| 628 | debug_visitor_ = debug_visitor; |
| 629 | sent_packet_manager_.SetDebugDelegate(debug_visitor); |
| 630 | } |
| 631 | // Used in Chromium, but not internally. |
| 632 | // Must only be called before ping_alarm_ is set. |
| 633 | void set_ping_timeout(QuicTime::Delta ping_timeout) { |
| 634 | DCHECK(!ping_alarm_->IsSet()); |
| 635 | ping_timeout_ = ping_timeout; |
| 636 | } |
zhongyi | cdf8b1b | 2019-10-22 12:03:10 -0700 | [diff] [blame] | 637 | const QuicTime::Delta ping_timeout() const { return ping_timeout_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 638 | // Used in Chromium, but not internally. |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 639 | // Sets an initial timeout for the ping alarm when there is no retransmittable |
| 640 | // data in flight, allowing for a more aggressive ping alarm in that case. |
| 641 | void set_initial_retransmittable_on_wire_timeout( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 642 | QuicTime::Delta retransmittable_on_wire_timeout) { |
| 643 | DCHECK(!ping_alarm_->IsSet()); |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 644 | initial_retransmittable_on_wire_timeout_ = retransmittable_on_wire_timeout; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 645 | } |
zhongyi | cdf8b1b | 2019-10-22 12:03:10 -0700 | [diff] [blame] | 646 | const QuicTime::Delta initial_retransmittable_on_wire_timeout() const { |
| 647 | return initial_retransmittable_on_wire_timeout_; |
| 648 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 649 | // Used in Chromium, but not internally. |
| 650 | void set_creator_debug_delegate(QuicPacketCreator::DebugDelegate* visitor) { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 651 | packet_creator_.set_debug_delegate(visitor); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 652 | } |
| 653 | const QuicSocketAddress& self_address() const { return self_address_; } |
| 654 | const QuicSocketAddress& peer_address() const { return direct_peer_address_; } |
| 655 | const QuicSocketAddress& effective_peer_address() const { |
| 656 | return effective_peer_address_; |
| 657 | } |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 658 | QuicConnectionId connection_id() const { return server_connection_id_; } |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 659 | QuicConnectionId client_connection_id() const { |
| 660 | return client_connection_id_; |
| 661 | } |
| 662 | void set_client_connection_id(QuicConnectionId client_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 663 | const QuicClock* clock() const { return clock_; } |
| 664 | QuicRandom* random_generator() const { return random_generator_; } |
| 665 | QuicByteCount max_packet_length() const; |
| 666 | void SetMaxPacketLength(QuicByteCount length); |
| 667 | |
| 668 | size_t mtu_probe_count() const { return mtu_probe_count_; } |
| 669 | |
| 670 | bool connected() const { return connected_; } |
| 671 | |
| 672 | // Must only be called on client connections. |
| 673 | const ParsedQuicVersionVector& server_supported_versions() const { |
| 674 | DCHECK_EQ(Perspective::IS_CLIENT, perspective_); |
| 675 | return server_supported_versions_; |
| 676 | } |
| 677 | |
ianswett | fc16a2b | 2020-05-18 16:05:49 -0700 | [diff] [blame] | 678 | bool HasQueuedPackets() const { return !buffered_packets_.empty(); } |
| 679 | // Testing only. TODO(ianswett): Use a peer instead. |
fayang | e62e63c | 2019-12-04 07:16:25 -0800 | [diff] [blame] | 680 | size_t NumQueuedPackets() const { return buffered_packets_.size(); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 681 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 682 | // Returns true if the connection has queued packets or frames. |
| 683 | bool HasQueuedData() const; |
| 684 | |
| 685 | // Sets the handshake and idle state connection timeouts. |
| 686 | void SetNetworkTimeouts(QuicTime::Delta handshake_timeout, |
| 687 | QuicTime::Delta idle_timeout); |
| 688 | |
| 689 | // If the connection has timed out, this will close the connection. |
| 690 | // Otherwise, it will reschedule the timeout alarm. |
| 691 | void CheckForTimeout(); |
| 692 | |
| 693 | // Called when the ping alarm fires. Causes a ping frame to be sent only |
| 694 | // if the retransmission alarm is not running. |
| 695 | void OnPingTimeout(); |
| 696 | |
| 697 | // Sets up a packet with an QuicAckFrame and sends it out. |
| 698 | void SendAck(); |
| 699 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 700 | // Called when an RTO fires. Resets the retransmission alarm if there are |
| 701 | // remaining unacked packets. |
| 702 | void OnRetransmissionTimeout(); |
| 703 | |
renjietang | c008008 | 2020-05-26 18:35:19 -0700 | [diff] [blame] | 704 | // Retransmits all sent 0-RTT encrypted packets. Called when new 0-RTT or |
| 705 | // 1-RTT key is available. |
| 706 | void RetransmitZeroRttPackets(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 707 | |
| 708 | // Calls |sent_packet_manager_|'s NeuterUnencryptedPackets. Used when the |
| 709 | // connection becomes forward secure and hasn't received acks for all packets. |
| 710 | void NeuterUnencryptedPackets(); |
| 711 | |
| 712 | // Changes the encrypter used for level |level| to |encrypter|. |
| 713 | void SetEncrypter(EncryptionLevel level, |
| 714 | std::unique_ptr<QuicEncrypter> encrypter); |
| 715 | |
fayang | b296fb8 | 2020-02-11 08:14:28 -0800 | [diff] [blame] | 716 | // Called to remove encrypter of encryption |level|. |
| 717 | void RemoveEncrypter(EncryptionLevel level); |
| 718 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 719 | // SetNonceForPublicHeader sets the nonce that will be transmitted in the |
| 720 | // header of each packet encrypted at the initial encryption level decrypted. |
| 721 | // This should only be called on the server side. |
| 722 | void SetDiversificationNonce(const DiversificationNonce& nonce); |
| 723 | |
| 724 | // SetDefaultEncryptionLevel sets the encryption level that will be applied |
| 725 | // to new packets. |
| 726 | void SetDefaultEncryptionLevel(EncryptionLevel level); |
| 727 | |
| 728 | // SetDecrypter sets the primary decrypter, replacing any that already exists. |
| 729 | // If an alternative decrypter is in place then the function DCHECKs. This is |
| 730 | // intended for cases where one knows that future packets will be using the |
| 731 | // new decrypter and the previous decrypter is now obsolete. |level| indicates |
| 732 | // the encryption level of the new decrypter. |
| 733 | void SetDecrypter(EncryptionLevel level, |
| 734 | std::unique_ptr<QuicDecrypter> decrypter); |
| 735 | |
| 736 | // SetAlternativeDecrypter sets a decrypter that may be used to decrypt |
| 737 | // future packets. |level| indicates the encryption level of the decrypter. If |
| 738 | // |latch_once_used| is true, then the first time that the decrypter is |
| 739 | // successful it will replace the primary decrypter. Otherwise both |
| 740 | // decrypters will remain active and the primary decrypter will be the one |
| 741 | // last used. |
| 742 | void SetAlternativeDecrypter(EncryptionLevel level, |
| 743 | std::unique_ptr<QuicDecrypter> decrypter, |
| 744 | bool latch_once_used); |
| 745 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 746 | void InstallDecrypter(EncryptionLevel level, |
| 747 | std::unique_ptr<QuicDecrypter> decrypter); |
| 748 | void RemoveDecrypter(EncryptionLevel level); |
| 749 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 750 | const QuicDecrypter* decrypter() const; |
| 751 | const QuicDecrypter* alternative_decrypter() const; |
| 752 | |
| 753 | Perspective perspective() const { return perspective_; } |
| 754 | |
| 755 | // Allow easy overriding of truncated connection IDs. |
| 756 | void set_can_truncate_connection_ids(bool can) { |
| 757 | can_truncate_connection_ids_ = can; |
| 758 | } |
| 759 | |
| 760 | // Returns the underlying sent packet manager. |
| 761 | const QuicSentPacketManager& sent_packet_manager() const { |
| 762 | return sent_packet_manager_; |
| 763 | } |
| 764 | |
| 765 | // Returns the underlying sent packet manager. |
| 766 | QuicSentPacketManager& sent_packet_manager() { return sent_packet_manager_; } |
| 767 | |
ianswett | 309987e | 2019-08-02 13:16:26 -0700 | [diff] [blame] | 768 | UberReceivedPacketManager& received_packet_manager() { |
| 769 | return uber_received_packet_manager_; |
| 770 | } |
| 771 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 772 | bool CanWrite(HasRetransmittableData retransmittable); |
| 773 | |
| 774 | // When the flusher is out of scope, only the outermost flusher will cause a |
| 775 | // flush of the connection and set the retransmission alarm if there is one |
| 776 | // pending. In addition, this flusher can be configured to ensure that an ACK |
| 777 | // frame is included in the first packet created, if there's new ack |
| 778 | // information to be sent. |
| 779 | class QUIC_EXPORT_PRIVATE ScopedPacketFlusher { |
| 780 | public: |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 781 | explicit ScopedPacketFlusher(QuicConnection* connection); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 782 | ~ScopedPacketFlusher(); |
| 783 | |
| 784 | private: |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 785 | QuicConnection* connection_; |
| 786 | // If true, when this flusher goes out of scope, flush connection and set |
| 787 | // retransmission alarm if there is one pending. |
| 788 | bool flush_and_set_pending_retransmission_alarm_on_delete_; |
| 789 | }; |
| 790 | |
| 791 | QuicPacketWriter* writer() { return writer_; } |
| 792 | const QuicPacketWriter* writer() const { return writer_; } |
| 793 | |
| 794 | // Sends an MTU discovery packet of size |target_mtu|. If the packet is |
| 795 | // acknowledged by the peer, the maximum packet size will be increased to |
| 796 | // |target_mtu|. |
| 797 | void SendMtuDiscoveryPacket(QuicByteCount target_mtu); |
| 798 | |
| 799 | // Sends a connectivity probing packet to |peer_address| with |
| 800 | // |probing_writer|. If |probing_writer| is nullptr, will use default |
| 801 | // packet writer to write the packet. Returns true if subsequent packets can |
| 802 | // be written to the probing writer. If connection is V99, a padded IETF QUIC |
| 803 | // PATH_CHALLENGE packet is transmitted; if not V99, a Google QUIC padded PING |
| 804 | // packet is transmitted. |
| 805 | virtual bool SendConnectivityProbingPacket( |
| 806 | QuicPacketWriter* probing_writer, |
| 807 | const QuicSocketAddress& peer_address); |
| 808 | |
| 809 | // Sends response to a connectivity probe. Sends either a Padded Ping |
| 810 | // or an IETF PATH_RESPONSE based on the version of the connection. |
| 811 | // Is the counterpart to SendConnectivityProbingPacket(). |
| 812 | virtual void SendConnectivityProbingResponsePacket( |
| 813 | const QuicSocketAddress& peer_address); |
| 814 | |
wub | 173916e | 2019-11-27 14:36:24 -0800 | [diff] [blame] | 815 | // Sends an MTU discovery packet and updates the MTU discovery alarm. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 816 | void DiscoverMtu(); |
| 817 | |
| 818 | // Sets the session notifier on the SentPacketManager. |
| 819 | void SetSessionNotifier(SessionNotifierInterface* session_notifier); |
| 820 | |
| 821 | // Set data producer in framer. |
| 822 | void SetDataProducer(QuicStreamFrameDataProducer* data_producer); |
| 823 | |
| 824 | // Set transmission type of next sending packets. |
| 825 | void SetTransmissionType(TransmissionType type); |
| 826 | |
| 827 | // Tries to send |message| and returns the message status. |
QUICHE team | 350e9e6 | 2019-11-19 13:16:24 -0800 | [diff] [blame] | 828 | // If |flush| is false, this will return a MESSAGE_STATUS_BLOCKED |
| 829 | // when the connection is deemed unwritable. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 830 | virtual MessageStatus SendMessage(QuicMessageId message_id, |
QUICHE team | 350e9e6 | 2019-11-19 13:16:24 -0800 | [diff] [blame] | 831 | QuicMemSliceSpan message, |
| 832 | bool flush); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 833 | |
| 834 | // Returns the largest payload that will fit into a single MESSAGE frame. |
ianswett | b239f86 | 2019-04-05 09:15:06 -0700 | [diff] [blame] | 835 | // Because overhead can vary during a connection, this method should be |
| 836 | // checked for every message. |
| 837 | QuicPacketLength GetCurrentLargestMessagePayload() const; |
| 838 | // Returns the largest payload that will fit into a single MESSAGE frame at |
| 839 | // any point during the connection. This assumes the version and |
| 840 | // connection ID lengths do not change. |
| 841 | QuicPacketLength GetGuaranteedLargestMessagePayload() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 842 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 843 | // Returns the id of the cipher last used for decrypting packets. |
| 844 | uint32_t cipher_id() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 845 | |
| 846 | std::vector<std::unique_ptr<QuicEncryptedPacket>>* termination_packets() { |
| 847 | return termination_packets_.get(); |
| 848 | } |
| 849 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 850 | bool ack_frame_updated() const; |
| 851 | |
| 852 | QuicConnectionHelperInterface* helper() { return helper_; } |
| 853 | QuicAlarmFactory* alarm_factory() { return alarm_factory_; } |
| 854 | |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 855 | quiche::QuicheStringPiece GetCurrentPacket(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 856 | |
| 857 | const QuicFramer& framer() const { return framer_; } |
| 858 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 859 | const QuicPacketCreator& packet_creator() const { return packet_creator_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 860 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 861 | EncryptionLevel encryption_level() const { return encryption_level_; } |
| 862 | EncryptionLevel last_decrypted_level() const { |
| 863 | return last_decrypted_packet_level_; |
| 864 | } |
| 865 | |
| 866 | const QuicSocketAddress& last_packet_source_address() const { |
| 867 | return last_packet_source_address_; |
| 868 | } |
| 869 | |
| 870 | bool fill_up_link_during_probing() const { |
| 871 | return fill_up_link_during_probing_; |
| 872 | } |
| 873 | void set_fill_up_link_during_probing(bool new_value) { |
| 874 | fill_up_link_during_probing_ = new_value; |
| 875 | } |
| 876 | |
| 877 | // This setting may be changed during the crypto handshake in order to |
| 878 | // enable/disable padding of different packets in the crypto handshake. |
| 879 | // |
| 880 | // This setting should never be set to false in public facing endpoints. It |
| 881 | // can only be set to false if there is some other mechanism of preventing |
| 882 | // amplification attacks, such as ICE (plus its a non-standard quic). |
nharper | 3907ac2 | 2019-09-25 15:32:28 -0700 | [diff] [blame] | 883 | void set_fully_pad_crypto_handshake_packets(bool new_value) { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 884 | packet_creator_.set_fully_pad_crypto_handshake_packets(new_value); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | bool fully_pad_during_crypto_handshake() const { |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 888 | return packet_creator_.fully_pad_crypto_handshake_packets(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | size_t min_received_before_ack_decimation() const; |
| 892 | void set_min_received_before_ack_decimation(size_t new_value); |
| 893 | |
| 894 | size_t ack_frequency_before_ack_decimation() const; |
| 895 | void set_ack_frequency_before_ack_decimation(size_t new_value); |
| 896 | |
| 897 | // If |defer| is true, configures the connection to defer sending packets in |
| 898 | // response to an ACK to the SendAlarm. If |defer| is false, packets may be |
| 899 | // sent immediately after receiving an ACK. |
| 900 | void set_defer_send_in_response_to_packets(bool defer) { |
| 901 | defer_send_in_response_to_packets_ = defer; |
| 902 | } |
| 903 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 904 | // Sets the current per-packet options for the connection. The QuicConnection |
| 905 | // does not take ownership of |options|; |options| must live for as long as |
| 906 | // the QuicConnection is in use. |
| 907 | void set_per_packet_options(PerPacketOptions* options) { |
| 908 | per_packet_options_ = options; |
| 909 | } |
| 910 | |
| 911 | bool IsPathDegrading() const { return is_path_degrading_; } |
| 912 | |
| 913 | // Attempts to process any queued undecryptable packets. |
| 914 | void MaybeProcessUndecryptablePackets(); |
| 915 | |
| 916 | // Queue a coalesced packet. |
| 917 | void QueueCoalescedPacket(const QuicEncryptedPacket& packet); |
| 918 | |
| 919 | // Process previously queued coalesced packets. |
| 920 | void MaybeProcessCoalescedPackets(); |
| 921 | |
| 922 | enum PacketContent : uint8_t { |
| 923 | NO_FRAMES_RECEIVED, |
| 924 | // TODO(fkastenholz): Change name when we get rid of padded ping/ |
| 925 | // pre-version-99. |
| 926 | // Also PATH CHALLENGE and PATH RESPONSE. |
| 927 | FIRST_FRAME_IS_PING, |
| 928 | SECOND_FRAME_IS_PADDING, |
| 929 | NOT_PADDED_PING, // Set if the packet is not {PING, PADDING}. |
| 930 | }; |
| 931 | |
fayang | fa3b1d6 | 2019-11-18 08:02:13 -0800 | [diff] [blame] | 932 | // Whether the handshake completes from this connection's perspective. |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 933 | bool IsHandshakeComplete() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 934 | |
fayang | 5014e92 | 2020-01-22 12:28:11 -0800 | [diff] [blame] | 935 | // Whether peer completes handshake. Only used with TLS handshake. |
| 936 | bool IsHandshakeConfirmed() const; |
| 937 | |
QUICHE team | 1f3de24 | 2019-03-20 07:24:48 -0700 | [diff] [blame] | 938 | // Returns the largest received packet number sent by peer. |
| 939 | QuicPacketNumber GetLargestReceivedPacket() const; |
| 940 | |
dschinazi | 187683d | 2020-05-27 17:34:51 -0400 | [diff] [blame] | 941 | // Sets the original destination connection ID on the connection. |
| 942 | // This is called by QuicDispatcher when it has replaced the connection ID. |
| 943 | void SetOriginalDestinationConnectionId( |
| 944 | const QuicConnectionId& original_destination_connection_id); |
QUICHE team | c65d1d1 | 2019-03-19 20:58:04 -0700 | [diff] [blame] | 945 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 946 | // Returns the original destination connection ID used for this connection. |
| 947 | QuicConnectionId GetOriginalDestinationConnectionId(); |
| 948 | |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 949 | // Called when ACK alarm goes off. Sends ACKs of those packet number spaces |
| 950 | // which have expired ACK timeout. Only used when this connection supports |
| 951 | // multiple packet number spaces. |
| 952 | void SendAllPendingAcks(); |
| 953 | |
| 954 | // Returns true if this connection supports multiple packet number spaces. |
| 955 | bool SupportsMultiplePacketNumberSpaces() const; |
| 956 | |
fayang | 21ffb71 | 2019-05-16 08:39:26 -0700 | [diff] [blame] | 957 | // For logging purpose. |
| 958 | const QuicAckFrame& ack_frame() const; |
| 959 | |
dschinazi | 5c03085 | 2019-07-11 15:45:53 -0700 | [diff] [blame] | 960 | // Install encrypter and decrypter for ENCRYPTION_INITIAL using |
| 961 | // |connection_id| as the first client-sent destination connection ID, |
| 962 | // or the one sent after an IETF Retry. |
| 963 | void InstallInitialCrypters(QuicConnectionId connection_id); |
| 964 | |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 965 | // Called when version is considered negotiated. |
| 966 | void OnSuccessfulVersionNegotiation(); |
| 967 | |
zhongyi | 2da16be | 2020-06-17 11:05:23 -0700 | [diff] [blame^] | 968 | // Called when self migration succeeds after probing. |
| 969 | void OnSuccessfulMigrationAfterProbing(); |
| 970 | |
dschinazi | 631f160 | 2020-05-19 10:10:22 -0700 | [diff] [blame] | 971 | // Called for QUIC+TLS versions when we send transport parameters. |
| 972 | void OnTransportParametersSent( |
| 973 | const TransportParameters& transport_parameters) const; |
| 974 | |
| 975 | // Called for QUIC+TLS versions when we receive transport parameters. |
| 976 | void OnTransportParametersReceived( |
| 977 | const TransportParameters& transport_parameters) const; |
| 978 | |
fayang | 9adfb53 | 2020-06-04 06:58:45 -0700 | [diff] [blame] | 979 | // Returns true if ack_alarm_ is set. |
| 980 | bool HasPendingAcks() const; |
| 981 | |
fayang | 6a25841 | 2020-05-28 08:57:12 -0700 | [diff] [blame] | 982 | size_t anti_amplification_factor() const { |
| 983 | return anti_amplification_factor_; |
| 984 | } |
| 985 | |
wub | be634b7 | 2020-06-16 08:41:26 -0700 | [diff] [blame] | 986 | void OnUserAgentIdKnown() { sent_packet_manager_.OnUserAgentIdKnown(); } |
| 987 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 988 | protected: |
| 989 | // Calls cancel() on all the alarms owned by this connection. |
| 990 | void CancelAllAlarms(); |
| 991 | |
| 992 | // Send a packet to the peer, and takes ownership of the packet if the packet |
| 993 | // cannot be written immediately. |
wub | 8a5dafa | 2020-05-13 12:30:17 -0700 | [diff] [blame] | 994 | virtual void SendOrQueuePacket(SerializedPacket packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 995 | |
| 996 | // Called after a packet is received from a new effective peer address and is |
| 997 | // decrypted. Starts validation of effective peer's address change. Calls |
| 998 | // OnConnectionMigration as soon as the address changed. |
| 999 | void StartEffectivePeerMigration(AddressChangeType type); |
| 1000 | |
| 1001 | // Called when a effective peer address migration is validated. |
| 1002 | virtual void OnEffectivePeerMigrationValidated(); |
| 1003 | |
| 1004 | // Get the effective peer address from the packet being processed. For proxied |
| 1005 | // connections, effective peer address is the address of the endpoint behind |
| 1006 | // the proxy. For non-proxied connections, effective peer address is the same |
| 1007 | // as peer address. |
| 1008 | // |
| 1009 | // Notes for implementations in subclasses: |
| 1010 | // - If the connection is not proxied, the overridden method should use the |
| 1011 | // base implementation: |
| 1012 | // |
| 1013 | // return QuicConnection::GetEffectivePeerAddressFromCurrentPacket(); |
| 1014 | // |
| 1015 | // - If the connection is proxied, the overridden method may return either of |
| 1016 | // the following: |
| 1017 | // a) The address of the endpoint behind the proxy. The address is used to |
| 1018 | // drive effective peer migration. |
| 1019 | // b) An uninitialized address, meaning the effective peer address does not |
| 1020 | // change. |
| 1021 | virtual QuicSocketAddress GetEffectivePeerAddressFromCurrentPacket() const; |
| 1022 | |
| 1023 | // Selects and updates the version of the protocol being used by selecting a |
| 1024 | // version from |available_versions| which is also supported. Returns true if |
| 1025 | // such a version exists, false otherwise. |
| 1026 | bool SelectMutualVersion(const ParsedQuicVersionVector& available_versions); |
| 1027 | |
| 1028 | // Returns the current per-packet options for the connection. |
| 1029 | PerPacketOptions* per_packet_options() { return per_packet_options_; } |
| 1030 | |
| 1031 | AddressChangeType active_effective_peer_migration_type() const { |
| 1032 | return active_effective_peer_migration_type_; |
| 1033 | } |
| 1034 | |
ianswett | dc1e7ab | 2019-05-03 16:10:44 -0700 | [diff] [blame] | 1035 | // Sends a connection close packet to the peer and includes an ACK if the ACK |
| 1036 | // is not empty, the |error| is not PACKET_WRITE_ERROR, and it fits. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1037 | virtual void SendConnectionClosePacket(QuicErrorCode error, |
ianswett | dc1e7ab | 2019-05-03 16:10:44 -0700 | [diff] [blame] | 1038 | const std::string& details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1039 | |
| 1040 | // Returns true if the packet should be discarded and not sent. |
| 1041 | virtual bool ShouldDiscardPacket(const SerializedPacket& packet); |
| 1042 | |
| 1043 | // Retransmits packets continuously until blocked by the congestion control. |
| 1044 | // If there are no packets to retransmit, does not do anything. |
| 1045 | void SendProbingRetransmissions(); |
| 1046 | |
| 1047 | // Decides whether to send probing retransmissions, and does so if required. |
| 1048 | void MaybeSendProbingRetransmissions(); |
| 1049 | |
| 1050 | // Notify various components(SendPacketManager, Session etc.) that this |
| 1051 | // connection has been migrated. |
| 1052 | virtual void OnConnectionMigration(AddressChangeType addr_change_type); |
| 1053 | |
| 1054 | // Return whether the packet being processed is a connectivity probing. |
| 1055 | // A packet is a connectivity probing if it is a padded ping packet with self |
| 1056 | // and/or peer address changes. |
| 1057 | bool IsCurrentPacketConnectivityProbing() const; |
| 1058 | |
| 1059 | // Return true iff the writer is blocked, if blocked, call |
| 1060 | // visitor_->OnWriteBlocked() to add the connection into the write blocked |
| 1061 | // list. |
| 1062 | bool HandleWriteBlocked(); |
| 1063 | |
| 1064 | private: |
| 1065 | friend class test::QuicConnectionPeer; |
| 1066 | |
| 1067 | typedef std::list<SerializedPacket> QueuedPacketList; |
| 1068 | |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1069 | // BufferedPacket stores necessary information (encrypted buffer and self/peer |
| 1070 | // addresses) of those packets which are serialized but failed to send because |
| 1071 | // socket is blocked. From unacked packet map and send algorithm's |
| 1072 | // perspective, buffered packets are treated as sent. |
dschinazi | f25169a | 2019-10-23 08:12:18 -0700 | [diff] [blame] | 1073 | struct QUIC_EXPORT_PRIVATE BufferedPacket { |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1074 | BufferedPacket(const SerializedPacket& packet, |
| 1075 | const QuicSocketAddress& self_address, |
| 1076 | const QuicSocketAddress& peer_address); |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 1077 | BufferedPacket(char* encrypted_buffer, |
| 1078 | QuicPacketLength encrypted_length, |
| 1079 | const QuicSocketAddress& self_address, |
| 1080 | const QuicSocketAddress& peer_address); |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1081 | BufferedPacket(const BufferedPacket& other) = delete; |
| 1082 | BufferedPacket(const BufferedPacket&& other) = delete; |
| 1083 | |
| 1084 | ~BufferedPacket(); |
| 1085 | |
| 1086 | // encrypted_buffer is owned by buffered packet. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1087 | quiche::QuicheStringPiece encrypted_buffer; |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1088 | // Self and peer addresses when the packet is serialized. |
| 1089 | const QuicSocketAddress self_address; |
| 1090 | const QuicSocketAddress peer_address; |
| 1091 | }; |
| 1092 | |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1093 | // UndecrytablePacket comprises a undecryptable packet and the its encryption |
| 1094 | // level. |
| 1095 | struct QUIC_EXPORT_PRIVATE UndecryptablePacket { |
| 1096 | UndecryptablePacket(const QuicEncryptedPacket& packet, |
| 1097 | EncryptionLevel encryption_level) |
| 1098 | : packet(packet.Clone()), encryption_level(encryption_level) {} |
| 1099 | |
| 1100 | std::unique_ptr<QuicEncryptedPacket> packet; |
| 1101 | // Currently, |encryption_level| is only used for logging and does not |
| 1102 | // affect processing of the packet. |
| 1103 | EncryptionLevel encryption_level; |
| 1104 | }; |
| 1105 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1106 | // Notifies the visitor of the close and marks the connection as disconnected. |
fkastenholz | 85f1890 | 2019-05-28 12:47:00 -0700 | [diff] [blame] | 1107 | // Does not send a connection close frame to the peer. It should only be |
| 1108 | // called by CloseConnection or OnConnectionCloseFrame, OnPublicResetPacket, |
| 1109 | // and OnAuthenticatedIetfStatelessResetPacket. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1110 | void TearDownLocalConnectionState(QuicErrorCode error, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1111 | const std::string& details, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1112 | ConnectionCloseSource source); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 1113 | void TearDownLocalConnectionState(const QuicConnectionCloseFrame& frame, |
| 1114 | ConnectionCloseSource source); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1115 | |
| 1116 | // Writes the given packet to socket, encrypted with packet's |
| 1117 | // encryption_level. Returns true on successful write, and false if the writer |
| 1118 | // was blocked and the write needs to be tried again. Notifies the |
| 1119 | // SentPacketManager when the write is successful and sets |
| 1120 | // retransmittable frames to nullptr. |
| 1121 | // Saves the connection close packet for later transmission, even if the |
| 1122 | // writer is write blocked. |
| 1123 | bool WritePacket(SerializedPacket* packet); |
| 1124 | |
| 1125 | // Flush packets buffered in the writer, if any. |
| 1126 | void FlushPackets(); |
| 1127 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1128 | // Make sure a stop waiting we got from our peer is sane. |
| 1129 | // Returns nullptr if the frame is valid or an error string if it was invalid. |
| 1130 | const char* ValidateStopWaitingFrame( |
| 1131 | const QuicStopWaitingFrame& stop_waiting); |
| 1132 | |
| 1133 | // Sends a version negotiation packet to the peer. |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1134 | void SendVersionNegotiationPacket(bool ietf_quic, bool has_length_prefix); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1135 | |
| 1136 | // Clears any accumulated frames from the last received packet. |
| 1137 | void ClearLastFrames(); |
| 1138 | |
| 1139 | // Deletes and clears any queued packets. |
| 1140 | void ClearQueuedPackets(); |
| 1141 | |
| 1142 | // Closes the connection if the sent packet manager is tracking too many |
| 1143 | // outstanding packets. |
| 1144 | void CloseIfTooManyOutstandingSentPackets(); |
| 1145 | |
| 1146 | // Writes as many queued packets as possible. The connection must not be |
| 1147 | // blocked when this is called. |
| 1148 | void WriteQueuedPackets(); |
| 1149 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1150 | // Writes new data if congestion control allows. |
| 1151 | void WriteNewData(); |
| 1152 | |
| 1153 | // Queues |packet| in the hopes that it can be decrypted in the |
| 1154 | // future, when a new key is installed. |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1155 | void QueueUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 1156 | EncryptionLevel decryption_level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1157 | |
| 1158 | // Sends any packets which are a response to the last packet, including both |
| 1159 | // acks and pending writes if an ack opened the congestion window. |
| 1160 | void MaybeSendInResponseToPacket(); |
| 1161 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1162 | // Gets the least unacked packet number, which is the next packet number to be |
| 1163 | // sent if there are no outstanding packets. |
| 1164 | QuicPacketNumber GetLeastUnacked() const; |
| 1165 | |
| 1166 | // Sets the timeout alarm to the appropriate value, if any. |
| 1167 | void SetTimeoutAlarm(); |
| 1168 | |
| 1169 | // Sets the ping alarm to the appropriate value, if any. |
| 1170 | void SetPingAlarm(); |
| 1171 | |
| 1172 | // Sets the retransmission alarm based on SentPacketManager. |
| 1173 | void SetRetransmissionAlarm(); |
| 1174 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1175 | // Sets the MTU discovery alarm if necessary. |
| 1176 | // |sent_packet_number| is the recently sent packet number. |
| 1177 | void MaybeSetMtuAlarm(QuicPacketNumber sent_packet_number); |
| 1178 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1179 | HasRetransmittableData IsRetransmittable(const SerializedPacket& packet); |
| 1180 | bool IsTerminationPacket(const SerializedPacket& packet); |
| 1181 | |
| 1182 | // Set the size of the packet we are targeting while doing path MTU discovery. |
| 1183 | void SetMtuDiscoveryTarget(QuicByteCount target); |
| 1184 | |
| 1185 | // Returns |suggested_max_packet_size| clamped to any limits set by the |
| 1186 | // underlying writer, connection, or protocol. |
| 1187 | QuicByteCount GetLimitedMaxPacketSize( |
| 1188 | QuicByteCount suggested_max_packet_size); |
| 1189 | |
| 1190 | // Do any work which logically would be done in OnPacket but can not be |
| 1191 | // safely done until the packet is validated. Returns true if packet can be |
| 1192 | // handled, false otherwise. |
| 1193 | bool ProcessValidatedPacket(const QuicPacketHeader& header); |
| 1194 | |
QUICHE team | d791e2c | 2019-03-15 10:28:21 -0700 | [diff] [blame] | 1195 | // Returns true if received |packet_number| can be processed. Please note, |
| 1196 | // this is called after packet got decrypted successfully. |
| 1197 | bool ValidateReceivedPacketNumber(QuicPacketNumber packet_number); |
| 1198 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1199 | // Consider receiving crypto frame on non crypto stream as memory corruption. |
| 1200 | bool MaybeConsiderAsMemoryCorruption(const QuicStreamFrame& frame); |
| 1201 | |
| 1202 | // Check if the connection has no outstanding data to send and notify |
| 1203 | // congestion controller if it is the case. |
| 1204 | void CheckIfApplicationLimited(); |
| 1205 | |
| 1206 | // Sets |current_packet_content_| to |type| if applicable. And |
| 1207 | // starts effective peer migration if current packet is confirmed not a |
| 1208 | // connectivity probe and |current_effective_peer_migration_type_| indicates |
| 1209 | // effective peer address change. |
| 1210 | void UpdatePacketContent(PacketContent type); |
| 1211 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1212 | // Called when last received ack frame has been processed. |
| 1213 | // |send_stop_waiting| indicates whether a stop waiting needs to be sent. |
| 1214 | // |acked_new_packet| is true if a previously-unacked packet was acked. |
| 1215 | void PostProcessAfterAckFrame(bool send_stop_waiting, bool acked_new_packet); |
| 1216 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1217 | // Updates the release time into the future. |
| 1218 | void UpdateReleaseTimeIntoFuture(); |
| 1219 | |
| 1220 | // Sends generic path probe packet to the peer. If we are not IETF QUIC, will |
| 1221 | // always send a padded ping, regardless of whether this is a request or |
| 1222 | // response. If version 99/ietf quic, will send a PATH_RESPONSE if |
| 1223 | // |is_response| is true, a PATH_CHALLENGE if not. |
| 1224 | bool SendGenericPathProbePacket(QuicPacketWriter* probing_writer, |
| 1225 | const QuicSocketAddress& peer_address, |
| 1226 | bool is_response); |
| 1227 | |
| 1228 | // Called when an ACK is about to send. Resets ACK related internal states, |
| 1229 | // e.g., cancels ack_alarm_, resets |
| 1230 | // num_retransmittable_packets_received_since_last_ack_sent_ etc. |
| 1231 | void ResetAckStates(); |
| 1232 | |
ianswett | 6083a10 | 2020-02-09 12:04:04 -0800 | [diff] [blame] | 1233 | // Returns true if the ACK frame should be bundled with ACK-eliciting frame. |
| 1234 | bool ShouldBundleRetransmittableFrameWithAck() const; |
| 1235 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 1236 | void PopulateStopWaitingFrame(QuicStopWaitingFrame* stop_waiting); |
| 1237 | |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 1238 | // Enables multiple packet number spaces support based on handshake protocol |
| 1239 | // and flags. |
| 1240 | void MaybeEnableMultiplePacketNumberSpacesSupport(); |
| 1241 | |
fayang | 9f430a5 | 2020-05-08 07:28:33 -0700 | [diff] [blame] | 1242 | // Called to update ACK timeout when an retransmittable frame has been parsed. |
| 1243 | void MaybeUpdateAckTimeout(); |
| 1244 | |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 1245 | // Returns packet fate when trying to write a packet via WritePacket(). |
| 1246 | SerializedPacketFate DeterminePacketFate(bool is_mtu_discovery); |
| 1247 | |
| 1248 | // Serialize and send coalesced_packet. Returns false if serialization fails |
| 1249 | // or the write causes errors, otherwise, returns true. |
| 1250 | bool FlushCoalescedPacket(); |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1251 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1252 | // Returns the encryption level the connection close packet should be sent at, |
| 1253 | // which is the highest encryption level that peer can guarantee to process. |
| 1254 | EncryptionLevel GetConnectionCloseEncryptionLevel() const; |
| 1255 | |
QUICHE team | 76e1c62 | 2019-03-19 14:36:39 -0700 | [diff] [blame] | 1256 | // Called after an ACK frame is successfully processed to update largest |
| 1257 | // received packet number which contains an ACK frame. |
| 1258 | void SetLargestReceivedPacketWithAck(QuicPacketNumber new_value); |
| 1259 | |
fayang | 656cbb5 | 2020-06-09 13:29:35 -0700 | [diff] [blame] | 1260 | // Called when new packets have been acknowledged or old keys have been |
| 1261 | // discarded. |
| 1262 | void OnForwardProgressMade(); |
| 1263 | |
QUICHE team | 76e1c62 | 2019-03-19 14:36:39 -0700 | [diff] [blame] | 1264 | // Returns largest received packet number which contains an ACK frame. |
| 1265 | QuicPacketNumber GetLargestReceivedPacketWithAck() const; |
| 1266 | |
| 1267 | // Returns the largest packet number that has been sent. |
| 1268 | QuicPacketNumber GetLargestSentPacket() const; |
| 1269 | |
| 1270 | // Returns the largest sent packet number that has been ACKed by peer. |
| 1271 | QuicPacketNumber GetLargestAckedPacket() const; |
| 1272 | |
QUICHE team | c65d1d1 | 2019-03-19 20:58:04 -0700 | [diff] [blame] | 1273 | // Whether incoming_connection_ids_ contains connection_id. |
| 1274 | bool HasIncomingConnectionId(QuicConnectionId connection_id); |
| 1275 | |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 1276 | // Whether connection enforces anti-amplification limit. |
| 1277 | bool EnforceAntiAmplificationLimit() const; |
| 1278 | |
| 1279 | // Whether connection is limited by amplification factor. |
| 1280 | bool LimitedByAmplificationFactor() const; |
| 1281 | |
wub | ed245d2 | 2020-05-07 10:46:00 -0700 | [diff] [blame] | 1282 | // Called before sending a packet to get packet send time and to set the |
| 1283 | // release time delay in |per_packet_options_|. Return the time when the |
| 1284 | // packet is scheduled to be released(a.k.a send time), which is NOW + delay. |
| 1285 | // Returns Now() and does not update release time delay if |
| 1286 | // |supports_release_time_| is false. |
| 1287 | QuicTime CalculatePacketSentTime(); |
| 1288 | |
wub | 748e20b | 2020-03-20 14:33:59 -0700 | [diff] [blame] | 1289 | // We've got a packet write error, should we ignore it? |
| 1290 | // NOTE: This is not a const function - if return true, the max packet size is |
| 1291 | // reverted to a previous(smaller) value to avoid write errors in the future. |
| 1292 | bool ShouldIgnoreWriteError(); |
| 1293 | |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 1294 | // Returns path degrading deadline. QuicTime::Zero() means no path degrading |
| 1295 | // detection is needed. |
| 1296 | QuicTime GetPathDegradingDeadline() const; |
| 1297 | |
| 1298 | // Returns true if path degrading should be detected. |
| 1299 | bool ShouldDetectPathDegrading() const; |
| 1300 | |
| 1301 | // Returns network blackhole deadline. QuicTime::Zero() means no blackhole |
| 1302 | // detection is needed. |
| 1303 | QuicTime GetNetworkBlackholeDeadline() const; |
| 1304 | |
| 1305 | // Returns true if network blackhole should be detected. |
| 1306 | bool ShouldDetectBlackhole() const; |
| 1307 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1308 | // Remove these two when deprecating quic_use_idle_network_detector. |
| 1309 | QuicTime::Delta GetHandshakeTimeout() const; |
| 1310 | QuicTime GetTimeOfLastReceivedPacket() const; |
| 1311 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 1312 | // Validate connection IDs used during the handshake. Closes the connection |
| 1313 | // on validation failure. |
| 1314 | bool ValidateConfigConnectionIds(const QuicConfig& config); |
| 1315 | bool ValidateConfigConnectionIdsOld(const QuicConfig& config); |
| 1316 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1317 | QuicFramer framer_; |
| 1318 | |
| 1319 | // Contents received in the current packet, especially used to identify |
| 1320 | // whether the current packet is a padded PING packet. |
| 1321 | PacketContent current_packet_content_; |
| 1322 | // Set to true as soon as the packet currently being processed has been |
| 1323 | // detected as a connectivity probing. |
| 1324 | // Always false outside the context of ProcessUdpPacket(). |
| 1325 | bool is_current_packet_connectivity_probing_; |
| 1326 | |
| 1327 | // Caches the current effective peer migration type if a effective peer |
| 1328 | // migration might be initiated. As soon as the current packet is confirmed |
| 1329 | // not a connectivity probe, effective peer migration will start. |
| 1330 | AddressChangeType current_effective_peer_migration_type_; |
| 1331 | QuicConnectionHelperInterface* helper_; // Not owned. |
| 1332 | QuicAlarmFactory* alarm_factory_; // Not owned. |
| 1333 | PerPacketOptions* per_packet_options_; // Not owned. |
| 1334 | QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. |
| 1335 | bool owns_writer_; |
| 1336 | // Encryption level for new packets. Should only be changed via |
| 1337 | // SetDefaultEncryptionLevel(). |
| 1338 | EncryptionLevel encryption_level_; |
| 1339 | const QuicClock* clock_; |
| 1340 | QuicRandom* random_generator_; |
| 1341 | |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 1342 | QuicConnectionId server_connection_id_; |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1343 | QuicConnectionId client_connection_id_; |
| 1344 | // On the server, the connection ID is set when receiving the first packet. |
| 1345 | // This variable ensures we only set it this way once. |
| 1346 | bool client_connection_id_is_set_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1347 | // Address on the last successfully processed packet received from the |
| 1348 | // direct peer. |
| 1349 | QuicSocketAddress self_address_; |
| 1350 | QuicSocketAddress peer_address_; |
| 1351 | |
| 1352 | QuicSocketAddress direct_peer_address_; |
| 1353 | // Address of the endpoint behind the proxy if the connection is proxied. |
| 1354 | // Otherwise it is the same as |peer_address_|. |
| 1355 | // NOTE: Currently |effective_peer_address_| and |peer_address_| are always |
| 1356 | // the same(the address of the direct peer), but soon we'll change |
| 1357 | // |effective_peer_address_| to be the address of the endpoint behind the |
| 1358 | // proxy if the connection is proxied. |
| 1359 | QuicSocketAddress effective_peer_address_; |
| 1360 | |
| 1361 | // Records change type when the effective peer initiates migration to a new |
| 1362 | // address. Reset to NO_CHANGE after effective peer migration is validated. |
| 1363 | AddressChangeType active_effective_peer_migration_type_; |
| 1364 | |
| 1365 | // Records highest sent packet number when effective peer migration is |
| 1366 | // started. |
| 1367 | QuicPacketNumber highest_packet_sent_before_effective_peer_migration_; |
| 1368 | |
| 1369 | // True if the last packet has gotten far enough in the framer to be |
| 1370 | // decrypted. |
| 1371 | bool last_packet_decrypted_; |
| 1372 | QuicByteCount last_size_; // Size of the last received packet. |
| 1373 | // TODO(rch): remove this when b/27221014 is fixed. |
| 1374 | const char* current_packet_data_; // UDP payload of packet currently being |
| 1375 | // parsed or nullptr. |
| 1376 | EncryptionLevel last_decrypted_packet_level_; |
| 1377 | QuicPacketHeader last_header_; |
| 1378 | bool should_last_packet_instigate_acks_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1379 | |
| 1380 | // Track some peer state so we can do less bookkeeping |
| 1381 | // 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] | 1382 | // Do not read or write directly, use GetLargestReceivedPacketWithAck() and |
| 1383 | // SetLargestReceivedPacketWithAck() instead. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1384 | QuicPacketNumber largest_seen_packet_with_ack_; |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 1385 | // Largest packet number sent by the peer which had an ACK frame per packet |
| 1386 | // number space. Only used when this connection supports multiple packet |
| 1387 | // number spaces. |
| 1388 | QuicPacketNumber largest_seen_packets_with_ack_[NUM_PACKET_NUMBER_SPACES]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1389 | |
| 1390 | // Largest packet number sent by the peer which had a stop waiting frame. |
| 1391 | QuicPacketNumber largest_seen_packet_with_stop_waiting_; |
| 1392 | |
| 1393 | // Collection of packets which were received before encryption was |
| 1394 | // established, but which could not be decrypted. We buffer these on |
| 1395 | // the assumption that they could not be processed because they were |
| 1396 | // sent with the INITIAL encryption and the CHLO message was lost. |
fayang | 9dcfaca | 2020-04-24 06:57:14 -0700 | [diff] [blame] | 1397 | QuicCircularDeque<UndecryptablePacket> undecryptable_packets_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1398 | |
| 1399 | // Collection of coalesced packets which were received while processing |
| 1400 | // the current packet. |
wub | a750aab | 2020-02-10 06:43:15 -0800 | [diff] [blame] | 1401 | QuicCircularDeque<std::unique_ptr<QuicEncryptedPacket>> |
| 1402 | received_coalesced_packets_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1403 | |
| 1404 | // Maximum number of undecryptable packets the connection will store. |
| 1405 | size_t max_undecryptable_packets_; |
| 1406 | |
| 1407 | // Maximum number of tracked packets. |
| 1408 | QuicPacketCount max_tracked_packets_; |
| 1409 | |
| 1410 | // When the version negotiation packet could not be sent because the socket |
| 1411 | // was not writable, this is set to true. |
| 1412 | bool pending_version_negotiation_packet_; |
| 1413 | // Used when pending_version_negotiation_packet_ is true. |
| 1414 | bool send_ietf_version_negotiation_packet_; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1415 | bool send_version_negotiation_packet_with_prefixed_lengths_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1416 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1417 | // Contains the connection close packets if the connection has been closed. |
| 1418 | std::unique_ptr<std::vector<std::unique_ptr<QuicEncryptedPacket>>> |
| 1419 | termination_packets_; |
| 1420 | |
| 1421 | // Determines whether or not a connection close packet is sent to the peer |
dschinazi | 9a6194e | 2020-04-30 16:21:09 -0700 | [diff] [blame] | 1422 | // after idle timeout due to lack of network activity. During the handshake, |
| 1423 | // a connection close packet is sent, but not after. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1424 | ConnectionCloseBehavior idle_timeout_connection_close_behavior_; |
| 1425 | |
fayang | ddd3e9d | 2020-06-03 11:00:19 -0700 | [diff] [blame] | 1426 | // When > 0, close the QUIC connection after this number of RTOs. |
| 1427 | size_t num_rtos_for_blackhole_detection_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1428 | |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 1429 | UberReceivedPacketManager uber_received_packet_manager_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1430 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1431 | // Indicates how many consecutive times an ack has arrived which indicates |
| 1432 | // the peer needs to stop waiting for some packets. |
fayang | 8a27b0f | 2019-11-04 11:27:40 -0800 | [diff] [blame] | 1433 | // TODO(fayang): remove this when deprecating QUIC_VERSION_43. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1434 | int stop_waiting_count_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1435 | |
| 1436 | // Indicates the retransmission alarm needs to be set. |
| 1437 | bool pending_retransmission_alarm_; |
| 1438 | |
| 1439 | // If true, defer sending data in response to received packets to the |
| 1440 | // SendAlarm. |
| 1441 | bool defer_send_in_response_to_packets_; |
| 1442 | |
| 1443 | // The timeout for PING. |
| 1444 | QuicTime::Delta ping_timeout_; |
| 1445 | |
zhongyi | 79ace16 | 2019-10-21 15:57:09 -0700 | [diff] [blame] | 1446 | // Initial timeout for how long the wire can have no retransmittable packets. |
| 1447 | QuicTime::Delta initial_retransmittable_on_wire_timeout_; |
| 1448 | |
| 1449 | // Indicates how many retransmittable-on-wire pings have been emitted without |
| 1450 | // receiving any new data in between. |
| 1451 | int consecutive_retransmittable_on_wire_ping_count_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1452 | |
| 1453 | // Arena to store class implementations within the QuicConnection. |
| 1454 | QuicConnectionArena arena_; |
| 1455 | |
| 1456 | // An alarm that fires when an ACK should be sent to the peer. |
| 1457 | QuicArenaScopedPtr<QuicAlarm> ack_alarm_; |
| 1458 | // An alarm that fires when a packet needs to be retransmitted. |
| 1459 | QuicArenaScopedPtr<QuicAlarm> retransmission_alarm_; |
| 1460 | // An alarm that is scheduled when the SentPacketManager requires a delay |
| 1461 | // before sending packets and fires when the packet may be sent. |
| 1462 | QuicArenaScopedPtr<QuicAlarm> send_alarm_; |
| 1463 | // An alarm that is scheduled when the connection can still write and there |
| 1464 | // may be more data to send. |
| 1465 | // An alarm that fires when the connection may have timed out. |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1466 | // TODO(fayang): Remove this when deprecating quic_use_idle_network_detector. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1467 | QuicArenaScopedPtr<QuicAlarm> timeout_alarm_; |
| 1468 | // An alarm that fires when a ping should be sent. |
| 1469 | QuicArenaScopedPtr<QuicAlarm> ping_alarm_; |
| 1470 | // An alarm that fires when an MTU probe should be sent. |
| 1471 | QuicArenaScopedPtr<QuicAlarm> mtu_discovery_alarm_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1472 | // An alarm that fires to process undecryptable packets when new decyrption |
| 1473 | // keys are available. |
| 1474 | QuicArenaScopedPtr<QuicAlarm> process_undecryptable_packets_alarm_; |
| 1475 | // Neither visitor is owned by this class. |
| 1476 | QuicConnectionVisitorInterface* visitor_; |
| 1477 | QuicConnectionDebugVisitor* debug_visitor_; |
| 1478 | |
fayang | 4245c21 | 2019-11-05 13:33:46 -0800 | [diff] [blame] | 1479 | QuicPacketCreator packet_creator_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1480 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1481 | // TODO(fayang): Remove these two when deprecating |
| 1482 | // quic_use_idle_network_detector. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1483 | // Network idle time before this connection is closed. |
| 1484 | QuicTime::Delta idle_network_timeout_; |
| 1485 | // The connection will wait this long for the handshake to complete. |
| 1486 | QuicTime::Delta handshake_timeout_; |
| 1487 | |
| 1488 | // Statistics for this session. |
| 1489 | QuicConnectionStats stats_; |
| 1490 | |
| 1491 | // Timestamps used for timeouts. |
| 1492 | // The time of the first retransmittable packet that was sent after the most |
| 1493 | // recently received packet. |
fayang | e930400 | 2020-05-07 11:57:48 -0700 | [diff] [blame] | 1494 | // TODO(fayang): Remove time_of_first_packet_sent_after_receiving_ when |
| 1495 | // deprecating quic_use_idle_network_detector. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1496 | QuicTime time_of_first_packet_sent_after_receiving_; |
| 1497 | // The time that a packet is received for this connection. Initialized to |
| 1498 | // connection creation time. |
fayang | e930400 | 2020-05-07 11:57:48 -0700 | [diff] [blame] | 1499 | // This does not indicate the packet was processed. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1500 | QuicTime time_of_last_received_packet_; |
fayang | e930400 | 2020-05-07 11:57:48 -0700 | [diff] [blame] | 1501 | // This gets set to time_of_last_received_packet_ when a packet gets |
| 1502 | // decrypted. Please note, this is not necessarily the original receive time |
| 1503 | // of this decrypt packet because connection can decryptable packet out of |
| 1504 | // order. |
| 1505 | // TODO(fayang): Remove time_of_last_decryptable_packet_ when |
| 1506 | // deprecating quic_use_idle_network_detector. |
| 1507 | QuicTime time_of_last_decryptable_packet_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1508 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1509 | // Sent packet manager which tracks the status of packets sent by this |
| 1510 | // connection and contains the send and receive algorithms to determine when |
| 1511 | // to send packets. |
| 1512 | QuicSentPacketManager sent_packet_manager_; |
| 1513 | |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 1514 | // Indicates whether connection version has been negotiated. |
wub | 256b2d6 | 2019-11-25 08:46:55 -0800 | [diff] [blame] | 1515 | // Always true for server connections. |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 1516 | bool version_negotiated_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1517 | |
| 1518 | // Tracks if the connection was created by the server or the client. |
| 1519 | Perspective perspective_; |
| 1520 | |
| 1521 | // True by default. False if we've received or sent an explicit connection |
| 1522 | // close. |
| 1523 | bool connected_; |
| 1524 | |
| 1525 | // Destination address of the last received packet. |
| 1526 | QuicSocketAddress last_packet_destination_address_; |
| 1527 | |
| 1528 | // Source address of the last received packet. |
| 1529 | QuicSocketAddress last_packet_source_address_; |
| 1530 | |
| 1531 | // Set to false if the connection should not send truncated connection IDs to |
| 1532 | // the peer, even if the peer supports it. |
| 1533 | bool can_truncate_connection_ids_; |
| 1534 | |
| 1535 | // If non-empty this contains the set of versions received in a |
| 1536 | // version negotiation packet. |
| 1537 | ParsedQuicVersionVector server_supported_versions_; |
| 1538 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1539 | // The number of MTU probes already sent. |
| 1540 | size_t mtu_probe_count_; |
| 1541 | |
wub | ecb643f | 2020-03-19 08:58:46 -0700 | [diff] [blame] | 1542 | // The value of |long_term_mtu_| prior to the last successful MTU increase. |
| 1543 | // 0 means either |
| 1544 | // - MTU discovery has never been enabled, or |
| 1545 | // - MTU discovery has been enabled, but the connection got a packet write |
| 1546 | // error with a new (successfully probed) MTU, so it reverted |
wub | 748e20b | 2020-03-20 14:33:59 -0700 | [diff] [blame] | 1547 | // |long_term_mtu_| to the value before the last increase. |
wub | ecb643f | 2020-03-19 08:58:46 -0700 | [diff] [blame] | 1548 | QuicPacketLength previous_validated_mtu_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1549 | // The value of the MTU regularly used by the connection. This is different |
| 1550 | // from the value returned by max_packet_size(), as max_packet_size() returns |
| 1551 | // the value of the MTU as currently used by the serializer, so if |
| 1552 | // serialization of an MTU probe is in progress, those two values will be |
| 1553 | // different. |
| 1554 | QuicByteCount long_term_mtu_; |
| 1555 | |
dschinazi | 4ad1f46 | 2020-01-16 11:56:52 -0800 | [diff] [blame] | 1556 | // The maximum UDP payload size that our peer has advertised support for. |
| 1557 | // Defaults to kDefaultMaxPacketSizeTransportParam until received from peer. |
| 1558 | QuicByteCount peer_max_packet_size_; |
| 1559 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1560 | // The size of the largest packet received from peer. |
| 1561 | QuicByteCount largest_received_packet_size_; |
| 1562 | |
| 1563 | // Indicates whether a write error is encountered currently. This is used to |
| 1564 | // avoid infinite write errors. |
| 1565 | bool write_error_occurred_; |
| 1566 | |
| 1567 | // Indicates not to send or process stop waiting frames. |
| 1568 | bool no_stop_waiting_frames_; |
| 1569 | |
| 1570 | // Consecutive number of sent packets which have no retransmittable frames. |
| 1571 | size_t consecutive_num_packets_with_no_retransmittable_frames_; |
| 1572 | |
| 1573 | // After this many packets sent without retransmittable frames, an artificial |
| 1574 | // retransmittable frame(a WINDOW_UPDATE) will be created to solicit an ack |
| 1575 | // from the peer. Default to kMaxConsecutiveNonRetransmittablePackets. |
| 1576 | size_t max_consecutive_num_packets_with_no_retransmittable_frames_; |
| 1577 | |
ianswett | 6083a10 | 2020-02-09 12:04:04 -0800 | [diff] [blame] | 1578 | // If true, bundle an ack-eliciting frame with an ACK if the PTO or RTO alarm |
| 1579 | // have previously fired. |
| 1580 | bool bundle_retransmittable_with_pto_ack_; |
| 1581 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1582 | // If true, the connection will fill up the pipe with extra data whenever the |
| 1583 | // congestion controller needs it in order to make a bandwidth estimate. This |
| 1584 | // is useful if the application pesistently underutilizes the link, but still |
| 1585 | // relies on having a reasonable bandwidth estimate from the connection, e.g. |
| 1586 | // for real time applications. |
| 1587 | bool fill_up_link_during_probing_; |
| 1588 | |
| 1589 | // If true, the probing retransmission will not be started again. This is |
| 1590 | // used to safeguard against an accidental tail recursion in probing |
| 1591 | // retransmission code. |
| 1592 | bool probing_retransmission_pending_; |
| 1593 | |
| 1594 | // Indicates whether a stateless reset token has been received from peer. |
| 1595 | bool stateless_reset_token_received_; |
| 1596 | // Stores received stateless reset token from peer. Used to verify whether a |
| 1597 | // packet is a stateless reset packet. |
| 1598 | QuicUint128 received_stateless_reset_token_; |
| 1599 | |
| 1600 | // Id of latest sent control frame. 0 if no control frame has been sent. |
| 1601 | QuicControlFrameId last_control_frame_id_; |
| 1602 | |
| 1603 | // True if the peer is unreachable on the current path. |
| 1604 | bool is_path_degrading_; |
| 1605 | |
| 1606 | // True if an ack frame is being processed. |
| 1607 | bool processing_ack_frame_; |
| 1608 | |
| 1609 | // True if the writer supports release timestamp. |
| 1610 | bool supports_release_time_; |
| 1611 | |
| 1612 | // Time this connection can release packets into the future. |
| 1613 | QuicTime::Delta release_time_into_future_; |
| 1614 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 1615 | // Payload of most recently transmitted IETF QUIC connectivity |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1616 | // probe packet (the PATH_CHALLENGE payload). This implementation transmits |
| 1617 | // only one PATH_CHALLENGE per connectivity probe, so only one |
| 1618 | // QuicPathFrameBuffer is needed. |
| 1619 | std::unique_ptr<QuicPathFrameBuffer> transmitted_connectivity_probe_payload_; |
| 1620 | |
| 1621 | // Payloads that were received in the most recent probe. This needs to be a |
| 1622 | // Deque because the peer might no be using this implementation, and others |
| 1623 | // might send a packet with more than one PATH_CHALLENGE, so all need to be |
| 1624 | // saved and responded to. |
wub | a750aab | 2020-02-10 06:43:15 -0800 | [diff] [blame] | 1625 | QuicCircularDeque<QuicPathFrameBuffer> received_path_challenge_payloads_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1626 | |
QUICHE team | c65d1d1 | 2019-03-19 20:58:04 -0700 | [diff] [blame] | 1627 | // Set of connection IDs that should be accepted as destination on |
| 1628 | // received packets. This is conceptually a set but is implemented as a |
| 1629 | // vector to improve performance since it is expected to be very small. |
| 1630 | std::vector<QuicConnectionId> incoming_connection_ids_; |
| 1631 | |
dschinazi | e7c38a5 | 2020-05-29 15:25:45 -0700 | [diff] [blame] | 1632 | // When we receive a RETRY packet or some INITIAL packets, we replace |
| 1633 | // |server_connection_id_| with the value from that packet and save off the |
| 1634 | // original value of |server_connection_id_| into |
| 1635 | // |original_destination_connection_id_| for validation. |
| 1636 | quiche::QuicheOptional<QuicConnectionId> original_destination_connection_id_; |
| 1637 | |
| 1638 | // After we receive a RETRY packet, |retry_source_connection_id_| contains |
| 1639 | // the source connection ID from that packet. |
| 1640 | quiche::QuicheOptional<QuicConnectionId> retry_source_connection_id_; |
dschinazi | 39e5e55 | 2020-05-06 13:55:24 -0700 | [diff] [blame] | 1641 | |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 1642 | // Indicates whether received RETRY packets should be dropped. |
| 1643 | bool drop_incoming_retry_packets_; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1644 | |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 1645 | // Bytes received before address validation. Only used when |
| 1646 | // EnforceAntiAmplificationLimit returns true. |
| 1647 | size_t bytes_received_before_address_validation_; |
| 1648 | |
| 1649 | // Bytes sent before address validation. Only used when |
| 1650 | // EnforceAntiAmplificationLimit returns true. |
| 1651 | size_t bytes_sent_before_address_validation_; |
| 1652 | |
| 1653 | // True if peer address has been validated. Address is considered validated |
| 1654 | // when 1) an address token is received and validated, or 2) a HANDSHAKE |
| 1655 | // packet has been successfully processed. Only used when |
| 1656 | // EnforceAntiAmplificationLimit returns true. |
| 1657 | bool address_validated_; |
fayang | 4c1c236 | 2019-09-13 07:20:01 -0700 | [diff] [blame] | 1658 | |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1659 | // Used to store content of packets which cannot be sent because of write |
| 1660 | // blocked. Packets' encrypted buffers are copied and owned by |
| 1661 | // buffered_packets_. From unacked_packet_map (and congestion control)'s |
fayang | e62e63c | 2019-12-04 07:16:25 -0800 | [diff] [blame] | 1662 | // perspective, those packets are considered sent. |
fayang | 2ce6608 | 2019-10-02 06:29:04 -0700 | [diff] [blame] | 1663 | std::list<BufferedPacket> buffered_packets_; |
| 1664 | |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 1665 | // Used to coalesce packets of different encryption level into the same UDP |
| 1666 | // datagram. Connection stops trying to coalesce packets if a forward secure |
| 1667 | // packet gets acknowledged. |
| 1668 | QuicCoalescedPacket coalesced_packet_; |
| 1669 | |
wub | f76cf2a | 2019-10-11 18:49:07 -0700 | [diff] [blame] | 1670 | QuicConnectionMtuDiscoverer mtu_discoverer_; |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 1671 | |
| 1672 | QuicNetworkBlackholeDetector blackhole_detector_; |
| 1673 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1674 | QuicIdleNetworkDetector idle_network_detector_; |
| 1675 | |
fayang | f78b693 | 2020-06-08 08:36:45 -0700 | [diff] [blame] | 1676 | bool blackhole_detection_disabled_ = false; |
| 1677 | |
fayang | 5c36288 | 2020-06-16 07:39:39 -0700 | [diff] [blame] | 1678 | // True if this connection supports handshake done frame. |
| 1679 | bool support_handshake_done_; |
| 1680 | |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1681 | const bool use_idle_network_detector_ = |
fayang | b9c8844 | 2020-03-26 07:03:57 -0700 | [diff] [blame] | 1682 | GetQuicReloadableFlag(quic_use_idle_network_detector); |
fayang | e930400 | 2020-05-07 11:57:48 -0700 | [diff] [blame] | 1683 | |
| 1684 | const bool extend_idle_time_on_decryptable_packets_ = |
| 1685 | GetQuicReloadableFlag(quic_extend_idle_time_on_decryptable_packets); |
fayang | 9f430a5 | 2020-05-08 07:28:33 -0700 | [diff] [blame] | 1686 | |
| 1687 | const bool advance_ack_timeout_update_ = |
| 1688 | GetQuicReloadableFlag(quic_advance_ack_timeout_update); |
wub | 9e7b492 | 2020-05-20 10:39:44 -0700 | [diff] [blame] | 1689 | |
| 1690 | const bool update_ack_alarm_in_send_all_pending_acks_ = |
| 1691 | GetQuicReloadableFlag(quic_update_ack_alarm_in_send_all_pending_acks); |
fayang | 6a25841 | 2020-05-28 08:57:12 -0700 | [diff] [blame] | 1692 | |
| 1693 | const bool move_amplification_limit_ = |
| 1694 | GetQuicReloadableFlag(quic_move_amplification_limit); |
| 1695 | |
| 1696 | // TODO(fayang): Change the default value of quic_anti_amplification_factor to |
| 1697 | // 5 when deprecating quic_move_amplification_limit. |
| 1698 | // TODO(b/153892665): Change the default value of |
| 1699 | // quic_anti_amplification_factor back to 3 when cert compression is |
| 1700 | // supported. |
| 1701 | const size_t anti_amplification_factor_ = |
| 1702 | move_amplification_limit_ |
| 1703 | ? 5 |
| 1704 | : GetQuicFlag(FLAGS_quic_anti_amplification_factor); |
fayang | aa4f3f2 | 2020-06-05 16:22:00 -0700 | [diff] [blame] | 1705 | |
| 1706 | const bool default_enable_5rto_blackhole_detection_ = |
fayang | 656cbb5 | 2020-06-09 13:29:35 -0700 | [diff] [blame] | 1707 | GetQuicReloadableFlag(quic_default_enable_5rto_blackhole_detection2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1708 | }; |
| 1709 | |
| 1710 | } // namespace quic |
| 1711 | |
| 1712 | #endif // QUICHE_QUIC_CORE_QUIC_CONNECTION_H_ |