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