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.
5 // The entity that handles framing writes for a Quic client or server.
6 // Each QuicSession will have a connection associated with it.
8 // On the server side, the Dispatcher handles the raw reads, and hands off
9 // packets via ProcessUdpPacket for framing and processing.
11 // On the client side, the Connection handles the raw reads, as well as the
14 // Note: this class is not thread-safe.
16 #ifndef NET_QUIC_QUIC_CONNECTION_H_
17 #define NET_QUIC_QUIC_CONNECTION_H_
27 #include "base/logging.h"
28 #include "net/base/iovec.h"
29 #include "net/base/ip_endpoint.h"
30 #include "net/quic/iovector.h"
31 #include "net/quic/quic_ack_notifier.h"
32 #include "net/quic/quic_ack_notifier_manager.h"
33 #include "net/quic/quic_alarm.h"
34 #include "net/quic/quic_blocked_writer_interface.h"
35 #include "net/quic/quic_connection_stats.h"
36 #include "net/quic/quic_packet_creator.h"
37 #include "net/quic/quic_packet_generator.h"
38 #include "net/quic/quic_packet_writer.h"
39 #include "net/quic/quic_protocol.h"
40 #include "net/quic/quic_received_packet_manager.h"
41 #include "net/quic/quic_sent_entropy_manager.h"
42 #include "net/quic/quic_sent_packet_manager.h"
44 NET_EXPORT_PRIVATE
extern int FLAGS_fake_packet_loss_percentage
;
45 NET_EXPORT_PRIVATE
extern bool FLAGS_bundle_ack_with_outgoing_packet
;
58 class QuicConnectionPeer
;
61 // Class that receives callbacks from the connection when frames are received
62 // and when other interesting events happen.
63 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface
{
65 virtual ~QuicConnectionVisitorInterface() {}
67 // A simple visitor interface for dealing with data frames. The session
68 // should determine if all frames will be accepted, and return true if so.
69 // If any frames can't be processed or buffered, none of the data should
70 // be used, and the callee should return false.
71 virtual bool OnStreamFrames(const std::vector
<QuicStreamFrame
>& frames
) = 0;
73 // Called when the stream is reset by the peer.
74 virtual void OnRstStream(const QuicRstStreamFrame
& frame
) = 0;
76 // Called when the connection is going away according to the peer.
77 virtual void OnGoAway(const QuicGoAwayFrame
& frame
) = 0;
79 // Called when the connection is closed either locally by the framer, or
80 // remotely by the peer.
81 virtual void OnConnectionClosed(QuicErrorCode error
,
84 // Called once a specific QUIC version is agreed by both endpoints.
85 virtual void OnSuccessfulVersionNegotiation(const QuicVersion
& version
) = 0;
87 // Indicates a new QuicConfig has been negotiated.
88 virtual void OnConfigNegotiated() = 0;
90 // Called when a blocked socket becomes writable. If all pending bytes for
91 // this visitor are consumed by the connection successfully this should
92 // return true, otherwise it should return false.
93 virtual bool OnCanWrite() = 0;
95 // Called to ask if any handshake messages are pending in this visitor.
96 virtual bool HasPendingHandshake() const = 0;
99 // Interface which gets callbacks from the QuicConnection at interesting
100 // points. Implementations must not mutate the state of the connection
101 // as a result of these callbacks.
102 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface
103 : public QuicPacketGenerator::DebugDelegateInterface
{
105 virtual ~QuicConnectionDebugVisitorInterface() {}
107 // Called when a packet has been sent.
108 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number
,
109 EncryptionLevel level
,
110 const QuicEncryptedPacket
& packet
,
111 WriteResult result
) = 0;
113 // Called when the contents of a packet have been retransmitted as
115 virtual void OnPacketRetransmitted(
116 QuicPacketSequenceNumber old_sequence_number
,
117 QuicPacketSequenceNumber new_sequence_number
) = 0;
119 // Called when a packet has been received, but before it is
120 // validated or parsed.
121 virtual void OnPacketReceived(const IPEndPoint
& self_address
,
122 const IPEndPoint
& peer_address
,
123 const QuicEncryptedPacket
& packet
) = 0;
125 // Called when the protocol version on the received packet doensn't match
126 // current protocol version of the connection.
127 virtual void OnProtocolVersionMismatch(QuicVersion version
) = 0;
129 // Called when the complete header of a packet has been parsed.
130 virtual void OnPacketHeader(const QuicPacketHeader
& header
) = 0;
132 // Called when a StreamFrame has been parsed.
133 virtual void OnStreamFrame(const QuicStreamFrame
& frame
) = 0;
135 // Called when a AckFrame has been parsed.
136 virtual void OnAckFrame(const QuicAckFrame
& frame
) = 0;
138 // Called when a CongestionFeedbackFrame has been parsed.
139 virtual void OnCongestionFeedbackFrame(
140 const QuicCongestionFeedbackFrame
& frame
) = 0;
142 // Called when a RstStreamFrame has been parsed.
143 virtual void OnRstStreamFrame(const QuicRstStreamFrame
& frame
) = 0;
145 // Called when a ConnectionCloseFrame has been parsed.
146 virtual void OnConnectionCloseFrame(
147 const QuicConnectionCloseFrame
& frame
) = 0;
149 // Called when a public reset packet has been received.
150 virtual void OnPublicResetPacket(const QuicPublicResetPacket
& packet
) = 0;
152 // Called when a version negotiation packet has been received.
153 virtual void OnVersionNegotiationPacket(
154 const QuicVersionNegotiationPacket
& packet
) = 0;
156 // Called after a packet has been successfully parsed which results
157 // in the revival of a packet via FEC.
158 virtual void OnRevivedPacket(const QuicPacketHeader
& revived_header
,
159 base::StringPiece payload
) = 0;
162 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface
{
164 virtual ~QuicConnectionHelperInterface() {}
166 // Returns a QuicClock to be used for all time related functions.
167 virtual const QuicClock
* GetClock() const = 0;
169 // Returns a QuicRandom to be used for all random number related functions.
170 virtual QuicRandom
* GetRandomGenerator() = 0;
172 // Creates a new platform-specific alarm which will be configured to
173 // notify |delegate| when the alarm fires. Caller takes ownership
174 // of the new alarm, which will not yet be "set" to fire.
175 virtual QuicAlarm
* CreateAlarm(QuicAlarm::Delegate
* delegate
) = 0;
178 class NET_EXPORT_PRIVATE QuicConnection
179 : public QuicFramerVisitorInterface
,
180 public QuicBlockedWriterInterface
,
181 public QuicPacketGenerator::DelegateInterface
,
182 public QuicSentPacketManager::HelperInterface
{
189 // Constructs a new QuicConnection for the specified |guid| and |address|.
190 // |helper| and |writer| must outlive this connection.
191 QuicConnection(QuicGuid guid
,
193 QuicConnectionHelperInterface
* helper
,
194 QuicPacketWriter
* writer
,
196 const QuicVersionVector
& supported_versions
);
197 virtual ~QuicConnection();
199 // Sets connection parameters from the supplied |config|.
200 void SetFromConfig(const QuicConfig
& config
);
202 // Send the data in |data| to the peer in as few packets as possible.
203 // Returns a pair with the number of bytes consumed from data, and a boolean
204 // indicating if the fin bit was consumed. This does not indicate the data
205 // has been sent on the wire: it may have been turned into a packet and queued
206 // if the socket was unexpectedly blocked.
207 // If |delegate| is provided, then it will be informed once ACKs have been
208 // received for all the packets written in this call.
209 // The |delegate| is not owned by the QuicConnection and must outlive it.
210 QuicConsumedData
SendStreamData(QuicStreamId id
,
211 const IOVector
& data
,
212 QuicStreamOffset offset
,
214 QuicAckNotifier::DelegateInterface
* delegate
);
216 // Send a stream reset frame to the peer.
217 virtual void SendRstStream(QuicStreamId id
,
218 QuicRstStreamErrorCode error
);
220 // Sends the connection close packet without affecting the state of the
221 // connection. This should only be called if the session is actively being
222 // destroyed: otherwise call SendConnectionCloseWithDetails instead.
223 virtual void SendConnectionClosePacket(QuicErrorCode error
,
224 const std::string
& details
);
226 // Sends a connection close frame to the peer, and closes the connection by
227 // calling CloseConnection(notifying the visitor as it does so).
228 virtual void SendConnectionClose(QuicErrorCode error
);
229 virtual void SendConnectionCloseWithDetails(QuicErrorCode error
,
230 const std::string
& details
);
231 // Notifies the visitor of the close and marks the connection as disconnected.
232 virtual void CloseConnection(QuicErrorCode error
, bool from_peer
) OVERRIDE
;
233 virtual void SendGoAway(QuicErrorCode error
,
234 QuicStreamId last_good_stream_id
,
235 const std::string
& reason
);
237 // Returns statistics tracked for this connection.
238 const QuicConnectionStats
& GetStats();
240 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from
241 // the peer. If processing this packet permits a packet to be revived from
242 // its FEC group that packet will be revived and processed.
243 virtual void ProcessUdpPacket(const IPEndPoint
& self_address
,
244 const IPEndPoint
& peer_address
,
245 const QuicEncryptedPacket
& packet
);
247 // QuicBlockedWriterInterface
248 // Called when the underlying connection becomes writable to allow queued
249 // writes to happen. Returns false if the socket has become blocked.
250 virtual bool OnCanWrite() OVERRIDE
;
252 // Called when a packet has been finally sent to the network.
253 bool OnPacketSent(WriteResult result
);
255 // If the socket is not blocked, this allows queued writes to happen. Returns
256 // false if the socket has become blocked.
257 bool WriteIfNotBlocked();
259 // Do any work which logically would be done in OnPacket but can not be
260 // safely done until the packet is validated. Returns true if the packet
261 // can be handled, false otherwise.
262 bool ProcessValidatedPacket();
264 // The version of the protocol this connection is using.
265 QuicVersion
version() const { return framer_
.version(); }
267 // The versions of the protocol that this connection supports.
268 const QuicVersionVector
& supported_versions() const {
269 return framer_
.supported_versions();
272 // From QuicFramerVisitorInterface
273 virtual void OnError(QuicFramer
* framer
) OVERRIDE
;
274 virtual bool OnProtocolVersionMismatch(QuicVersion received_version
) OVERRIDE
;
275 virtual void OnPacket() OVERRIDE
;
276 virtual void OnPublicResetPacket(
277 const QuicPublicResetPacket
& packet
) OVERRIDE
;
278 virtual void OnVersionNegotiationPacket(
279 const QuicVersionNegotiationPacket
& packet
) OVERRIDE
;
280 virtual void OnRevivedPacket() OVERRIDE
;
281 virtual bool OnUnauthenticatedPublicHeader(
282 const QuicPacketPublicHeader
& header
) OVERRIDE
;
283 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader
& header
) OVERRIDE
;
284 virtual bool OnPacketHeader(const QuicPacketHeader
& header
) OVERRIDE
;
285 virtual void OnFecProtectedPayload(base::StringPiece payload
) OVERRIDE
;
286 virtual bool OnStreamFrame(const QuicStreamFrame
& frame
) OVERRIDE
;
287 virtual bool OnAckFrame(const QuicAckFrame
& frame
) OVERRIDE
;
288 virtual bool OnCongestionFeedbackFrame(
289 const QuicCongestionFeedbackFrame
& frame
) OVERRIDE
;
290 virtual bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) OVERRIDE
;
291 virtual bool OnConnectionCloseFrame(
292 const QuicConnectionCloseFrame
& frame
) OVERRIDE
;
293 virtual bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) OVERRIDE
;
294 virtual void OnFecData(const QuicFecData
& fec
) OVERRIDE
;
295 virtual void OnPacketComplete() OVERRIDE
;
297 // QuicPacketGenerator::DelegateInterface
298 virtual bool ShouldGeneratePacket(TransmissionType transmission_type
,
299 HasRetransmittableData retransmittable
,
300 IsHandshake handshake
) OVERRIDE
;
301 virtual QuicAckFrame
* CreateAckFrame() OVERRIDE
;
302 virtual QuicCongestionFeedbackFrame
* CreateFeedbackFrame() OVERRIDE
;
303 virtual bool OnSerializedPacket(const SerializedPacket
& packet
) OVERRIDE
;
305 // QuicSentPacketManager::HelperInterface
306 virtual QuicPacketSequenceNumber
GetNextPacketSequenceNumber() OVERRIDE
;
309 void set_visitor(QuicConnectionVisitorInterface
* visitor
) {
312 void set_debug_visitor(QuicConnectionDebugVisitorInterface
* debug_visitor
) {
313 debug_visitor_
= debug_visitor
;
314 packet_generator_
.set_debug_delegate(debug_visitor
);
316 const IPEndPoint
& self_address() const { return self_address_
; }
317 const IPEndPoint
& peer_address() const { return peer_address_
; }
318 QuicGuid
guid() const { return guid_
; }
319 const QuicClock
* clock() const { return clock_
; }
320 QuicRandom
* random_generator() const { return random_generator_
; }
322 QuicPacketCreator::Options
* options() { return packet_creator_
.options(); }
324 bool connected() const { return connected_
; }
326 // Must only be called on client connections.
327 const QuicVersionVector
& server_supported_versions() const {
329 return server_supported_versions_
;
332 size_t NumFecGroups() const { return group_map_
.size(); }
335 size_t NumQueuedPackets() const { return queued_packets_
.size(); }
337 QuicEncryptedPacket
* ReleaseConnectionClosePacket() {
338 return connection_close_packet_
.release();
341 // Flush any queued frames immediately. Preserves the batch write mode and
342 // does nothing if there are no pending frames.
345 // Returns true if the connection has queued packets or frames.
346 bool HasQueuedData() const;
348 // Sets (or resets) the idle state connection timeout. Also, checks and times
349 // out the connection if network timer has expired for |timeout|.
350 void SetIdleNetworkTimeout(QuicTime::Delta timeout
);
351 // Sets (or resets) the total time delta the connection can be alive for.
352 // Also, checks and times out the connection if timer has expired for
353 // |timeout|. Used to limit the time a connection can be alive before crypto
354 // handshake finishes.
355 void SetOverallConnectionTimeout(QuicTime::Delta timeout
);
357 // If the connection has timed out, this will close the connection and return
358 // true. Otherwise, it will return false and will reset the timeout alarm.
359 bool CheckForTimeout();
361 // Sets up a packet with an QuicAckFrame and sends it out.
364 // Called when an RTO fires. Resets the retransmission alarm if there are
365 // remaining unacked packets.
366 void OnRetransmissionTimeout();
368 // Retransmits all unacked packets with retransmittable frames if
369 // |retransmission_type| is ALL_PACKETS, otherwise retransmits only initially
370 // encrypted packets. Used when the negotiated protocol version is different
371 // from what was initially assumed and when the visitor wants to re-transmit
372 // initially encrypted packets when the initial encrypter changes.
373 void RetransmitUnackedPackets(RetransmissionType retransmission_type
);
375 // Changes the encrypter used for level |level| to |encrypter|. The function
376 // takes ownership of |encrypter|.
377 void SetEncrypter(EncryptionLevel level
, QuicEncrypter
* encrypter
);
378 const QuicEncrypter
* encrypter(EncryptionLevel level
) const;
380 // SetDefaultEncryptionLevel sets the encryption level that will be applied
382 void SetDefaultEncryptionLevel(EncryptionLevel level
);
384 // SetDecrypter sets the primary decrypter, replacing any that already exists,
385 // and takes ownership. If an alternative decrypter is in place then the
386 // function DCHECKs. This is intended for cases where one knows that future
387 // packets will be using the new decrypter and the previous decrypter is now
389 void SetDecrypter(QuicDecrypter
* decrypter
);
391 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt
392 // future packets and takes ownership of it. If |latch_once_used| is true,
393 // then the first time that the decrypter is successful it will replace the
394 // primary decrypter. Otherwise both decrypters will remain active and the
395 // primary decrypter will be the one last used.
396 void SetAlternativeDecrypter(QuicDecrypter
* decrypter
,
397 bool latch_once_used
);
399 const QuicDecrypter
* decrypter() const;
400 const QuicDecrypter
* alternative_decrypter() const;
402 bool is_server() const { return is_server_
; }
404 // Returns the underlying sent packet manager.
405 const QuicSentPacketManager
& sent_packet_manager() const {
406 return sent_packet_manager_
;
409 bool CanWrite(TransmissionType transmission_type
,
410 HasRetransmittableData retransmittable
,
411 IsHandshake handshake
);
414 // Send a packet to the peer using encryption |level|. If |sequence_number|
415 // is present in the |retransmission_map_|, then contents of this packet will
416 // be retransmitted with a new sequence number if it's not acked by the peer.
417 // Deletes |packet| via WritePacket call or transfers ownership to
418 // QueuedPacket, ultimately deleted via WritePacket. Updates the
419 // entropy map corresponding to |sequence_number| using |entropy_hash|.
420 // |transmission_type| and |retransmittable| are supplied to the congestion
421 // manager, and when |forced| is true, it bypasses the congestion manager.
422 // TODO(wtc): none of the callers check the return value.
423 virtual bool SendOrQueuePacket(EncryptionLevel level
,
424 const SerializedPacket
& packet
,
425 TransmissionType transmission_type
);
427 // Writes the given packet to socket, encrypted with |level|, with the help
428 // of helper. Returns true on successful write, false otherwise. However,
429 // behavior is undefined if connection is not established or broken. In any
430 // circumstances, a return value of true implies that |packet| has been
431 // deleted and should not be accessed. If |sequence_number| is present in
432 // |retransmission_map_| it also sets up retransmission of the given packet
433 // in case of successful write. If |force| is FORCE, then the packet will be
434 // sent immediately and the send scheduler will not be consulted.
435 bool WritePacket(EncryptionLevel level
,
436 QuicPacketSequenceNumber sequence_number
,
438 TransmissionType transmission_type
,
439 HasRetransmittableData retransmittable
,
440 IsHandshake handshake
,
443 // Make sure an ack we got from our peer is sane.
444 bool ValidateAckFrame(const QuicAckFrame
& incoming_ack
);
446 QuicConnectionHelperInterface
* helper() { return helper_
; }
448 // Selects and updates the version of the protocol being used by selecting a
449 // version from |available_versions| which is also supported. Returns true if
450 // such a version exists, false otherwise.
451 bool SelectMutualVersion(const QuicVersionVector
& available_versions
);
456 // Stores current batch state for connection, puts the connection
457 // into batch mode, and destruction restores the stored batch state.
458 // While the bundler is in scope, any generated frames are bundled
459 // as densely as possible into packets. In addition, this bundler
460 // can be configured to ensure that an ACK frame is included in the
461 // first packet created, if there's new ack information to be sent.
462 class ScopedPacketBundler
{
464 // In addition to all outgoing frames being bundled when the
465 // bundler is in scope, setting |include_ack| to true ensures that
466 // an ACK frame is opportunistically bundled with the first
468 ScopedPacketBundler(QuicConnection
* connection
, bool include_ack
);
469 ~ScopedPacketBundler();
472 QuicConnection
* connection_
;
473 bool already_in_batch_mode_
;
476 friend class ScopedPacketBundler
;
477 friend class test::QuicConnectionPeer
;
479 // Packets which have not been written to the wire.
480 // Owns the QuicPacket* packet.
481 struct QueuedPacket
{
482 QueuedPacket(QuicPacketSequenceNumber sequence_number
,
484 EncryptionLevel level
,
485 TransmissionType transmission_type
,
486 HasRetransmittableData retransmittable
,
487 IsHandshake handshake
,
489 : sequence_number(sequence_number
),
491 encryption_level(level
),
492 transmission_type(transmission_type
),
493 retransmittable(retransmittable
),
494 handshake(handshake
),
498 QuicPacketSequenceNumber sequence_number
;
500 const EncryptionLevel encryption_level
;
501 TransmissionType transmission_type
;
502 HasRetransmittableData retransmittable
;
503 IsHandshake handshake
;
507 struct PendingWrite
{
508 PendingWrite(QuicPacketSequenceNumber sequence_number
,
509 TransmissionType transmission_type
,
510 HasRetransmittableData retransmittable
,
511 EncryptionLevel level
,
514 : sequence_number(sequence_number
),
515 transmission_type(transmission_type
),
516 retransmittable(retransmittable
),
518 is_fec_packet(is_fec_packet
),
521 QuicPacketSequenceNumber sequence_number
;
522 TransmissionType transmission_type
;
523 HasRetransmittableData retransmittable
;
524 EncryptionLevel level
;
529 typedef std::list
<QueuedPacket
> QueuedPacketList
;
530 typedef std::map
<QuicFecGroupNumber
, QuicFecGroup
*> FecGroupMap
;
532 // Sends a version negotiation packet to the peer.
533 void SendVersionNegotiationPacket();
535 // Clears any accumulated frames from the last received packet.
536 void ClearLastFrames();
538 // Called from OnCanWrite and WriteIfNotBlocked to write queued packets.
539 // Returns false if the socket has become blocked.
542 // Calculates the smallest sequence number length that can also represent four
543 // times the maximum of the congestion window and the difference between the
544 // least_packet_awaited_by_peer_ and |sequence_number|.
545 QuicSequenceNumberLength
CalculateSequenceNumberLength(
546 QuicPacketSequenceNumber sequence_number
);
548 // Drop packet corresponding to |sequence_number| by deleting entries from
549 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop
550 // all packets with encryption level NONE after the default level has been set
551 // to FORWARD_SECURE.
552 void DropPacket(QuicPacketSequenceNumber sequence_number
);
554 // Writes as many queued packets as possible. The connection must not be
555 // blocked when this is called.
556 bool WriteQueuedPackets();
558 // Writes as many pending retransmissions as possible.
559 void WritePendingRetransmissions();
561 // Returns true if the packet should be discarded and not sent.
562 bool ShouldDiscardPacket(EncryptionLevel level
,
563 QuicPacketSequenceNumber sequence_number
,
564 HasRetransmittableData retransmittable
);
566 // Queues |packet| in the hopes that it can be decrypted in the
567 // future, when a new key is installed.
568 void QueueUndecryptablePacket(const QuicEncryptedPacket
& packet
);
570 // Attempts to process any queued undecryptable packets.
571 void MaybeProcessUndecryptablePackets();
573 // If a packet can be revived from the current FEC group, then
574 // revive and process the packet.
575 void MaybeProcessRevivedPacket();
577 void ProcessAckFrame(const QuicAckFrame
& incoming_ack
);
579 // Update the |sent_info| for an outgoing ack.
580 void UpdateSentPacketInfo(SentPacketInfo
* sent_info
);
582 // Checks if the last packet should instigate an ack.
583 bool ShouldLastPacketInstigateAck();
585 // Sends any packets which are a response to the last packet, including both
586 // acks and pending writes if an ack opened the congestion window.
587 void MaybeSendInResponseToPacket(bool send_ack_immediately
,
588 bool last_packet_should_instigate_ack
);
590 // Get the FEC group associate with the last processed packet or NULL, if the
591 // group has already been deleted.
592 QuicFecGroup
* GetFecGroup();
594 // Closes any FEC groups protecting packets before |sequence_number|.
595 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number
);
597 QuicConnectionHelperInterface
* helper_
; // Not owned.
598 QuicPacketWriter
* writer_
; // Not owned.
599 EncryptionLevel encryption_level_
;
600 const QuicClock
* clock_
;
601 QuicRandom
* random_generator_
;
603 const QuicGuid guid_
;
604 // Address on the last successfully processed packet received from the
606 IPEndPoint self_address_
;
607 IPEndPoint peer_address_
;
609 bool last_packet_revived_
; // True if the last packet was revived from FEC.
610 size_t last_size_
; // Size of the last received packet.
611 QuicPacketHeader last_header_
;
612 std::vector
<QuicStreamFrame
> last_stream_frames_
;
613 std::vector
<QuicAckFrame
> last_ack_frames_
;
614 std::vector
<QuicCongestionFeedbackFrame
> last_congestion_frames_
;
615 std::vector
<QuicRstStreamFrame
> last_rst_frames_
;
616 std::vector
<QuicGoAwayFrame
> last_goaway_frames_
;
617 std::vector
<QuicConnectionCloseFrame
> last_close_frames_
;
619 QuicCongestionFeedbackFrame outgoing_congestion_feedback_
;
621 // Track some peer state so we can do less bookkeeping
622 // Largest sequence sent by the peer which had an ack frame (latest ack info).
623 QuicPacketSequenceNumber largest_seen_packet_with_ack_
;
625 // Collection of packets which were received before encryption was
626 // established, but which could not be decrypted. We buffer these on
627 // the assumption that they could not be processed because they were
628 // sent with the INITIAL encryption and the CHLO message was lost.
629 std::deque
<QuicEncryptedPacket
*> undecryptable_packets_
;
631 // When the version negotiation packet could not be sent because the socket
632 // was not writable, this is set to true.
633 bool pending_version_negotiation_packet_
;
635 // When packets could not be sent because the socket was not writable,
636 // they are added to this list. All corresponding frames are in
637 // unacked_packets_ if they are to be retransmitted.
638 QueuedPacketList queued_packets_
;
640 // Contains information about the current write in progress, if any.
641 scoped_ptr
<PendingWrite
> pending_write_
;
643 // Contains the connection close packet if the connection has been closed.
644 scoped_ptr
<QuicEncryptedPacket
> connection_close_packet_
;
646 // True when the socket becomes unwritable.
649 FecGroupMap group_map_
;
651 QuicReceivedPacketManager received_packet_manager_
;
652 QuicSentEntropyManager sent_entropy_manager_
;
654 // An alarm that fires when an ACK should be sent to the peer.
655 scoped_ptr
<QuicAlarm
> ack_alarm_
;
656 // An alarm that fires when a packet needs to be retransmitted.
657 scoped_ptr
<QuicAlarm
> retransmission_alarm_
;
658 // An alarm that is scheduled when the sent scheduler requires a
659 // a delay before sending packets and fires when the packet may be sent.
660 scoped_ptr
<QuicAlarm
> send_alarm_
;
661 // An alarm that is scheduled when the connection can still write and there
662 // may be more data to send.
663 scoped_ptr
<QuicAlarm
> resume_writes_alarm_
;
664 // An alarm that fires when the connection may have timed out.
665 scoped_ptr
<QuicAlarm
> timeout_alarm_
;
667 QuicConnectionVisitorInterface
* visitor_
;
668 QuicConnectionDebugVisitorInterface
* debug_visitor_
;
669 QuicPacketCreator packet_creator_
;
670 QuicPacketGenerator packet_generator_
;
672 // Network idle time before we kill of this connection.
673 QuicTime::Delta idle_network_timeout_
;
674 // Overall connection timeout.
675 QuicTime::Delta overall_connection_timeout_
;
676 // Connection creation time.
677 QuicTime creation_time_
;
679 // Statistics for this session.
680 QuicConnectionStats stats_
;
682 // The time that we got a packet for this connection.
683 // This is used for timeouts, and does not indicate the packet was processed.
684 QuicTime time_of_last_received_packet_
;
686 // The last time a new (non-retransmitted) packet was sent for this
688 QuicTime time_of_last_sent_new_packet_
;
690 // Sequence number of the last packet guaranteed to be sent in packet sequence
691 // number order. Not set when packets are queued, since that may cause
693 QuicPacketSequenceNumber sequence_number_of_last_inorder_packet_
;
695 // Sent packet manager which tracks the status of packets sent by this
696 // connection and contains the send and receive algorithms to determine when
698 QuicSentPacketManager sent_packet_manager_
;
700 // The state of connection in version negotiation finite state machine.
701 QuicVersionNegotiationState version_negotiation_state_
;
703 // Tracks if the connection was created by the server.
706 // True by default. False if we've received or sent an explicit connection
710 // Set to true if the udp packet headers have a new self or peer address.
711 // This is checked later on validating a data or version negotiation packet.
712 bool address_migrating_
;
714 // If non-empty this contains the set of versions received in a
715 // version negotiation packet.
716 QuicVersionVector server_supported_versions_
;
718 DISALLOW_COPY_AND_ASSIGN(QuicConnection
);
723 #endif // NET_QUIC_QUIC_CONNECTION_H_