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"
55 class QuicConnectionPeer
;
58 // Class that receives callbacks from the connection when frames are received
59 // and when other interesting events happen.
60 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface
{
62 virtual ~QuicConnectionVisitorInterface() {}
64 // A simple visitor interface for dealing with data frames. The session
65 // should determine if all frames will be accepted, and return true if so.
66 // If any frames can't be processed or buffered, none of the data should
67 // be used, and the callee should return false.
68 virtual bool OnStreamFrames(const std::vector
<QuicStreamFrame
>& frames
) = 0;
70 // The session should process all WINDOW_UPDATE frames, adjusting both stream
71 // and connection level flow control windows.
72 virtual void OnWindowUpdateFrames(
73 const std::vector
<QuicWindowUpdateFrame
>& frames
) = 0;
75 // BLOCKED frames tell us that the peer believes it is flow control blocked on
76 // a specified stream. If the session at this end disagrees, something has
77 // gone wrong with our flow control accounting.
78 virtual void OnBlockedFrames(const std::vector
<QuicBlockedFrame
>& frames
) = 0;
80 // Called when the stream is reset by the peer.
81 virtual void OnRstStream(const QuicRstStreamFrame
& frame
) = 0;
83 // Called when the connection is going away according to the peer.
84 virtual void OnGoAway(const QuicGoAwayFrame
& frame
) = 0;
86 // Called when the connection is closed either locally by the framer, or
87 // remotely by the peer.
88 virtual void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) = 0;
90 // Called when the connection failed to write because the socket was blocked.
91 virtual void OnWriteBlocked() = 0;
93 // Called once a specific QUIC version is agreed by both endpoints.
94 virtual void OnSuccessfulVersionNegotiation(const QuicVersion
& version
) = 0;
96 // Called when a blocked socket becomes writable.
97 virtual void OnCanWrite() = 0;
99 // Called to ask if any writes are pending in this visitor. Writes may be
100 // pending because they were write-blocked, congestion-throttled or
101 // yielded to other connections.
102 virtual bool HasPendingWrites() const = 0;
104 // Called to ask if any handshake messages are pending in this visitor.
105 virtual bool HasPendingHandshake() const = 0;
108 // Interface which gets callbacks from the QuicConnection at interesting
109 // points. Implementations must not mutate the state of the connection
110 // as a result of these callbacks.
111 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface
112 : public QuicPacketGenerator::DebugDelegateInterface
{
114 virtual ~QuicConnectionDebugVisitorInterface() {}
116 // Called when a packet has been sent.
117 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number
,
118 EncryptionLevel level
,
119 const QuicEncryptedPacket
& packet
,
120 WriteResult result
) = 0;
122 // Called when the contents of a packet have been retransmitted as
124 virtual void OnPacketRetransmitted(
125 QuicPacketSequenceNumber old_sequence_number
,
126 QuicPacketSequenceNumber new_sequence_number
) = 0;
128 // Called when a packet has been received, but before it is
129 // validated or parsed.
130 virtual void OnPacketReceived(const IPEndPoint
& self_address
,
131 const IPEndPoint
& peer_address
,
132 const QuicEncryptedPacket
& packet
) = 0;
134 // Called when the protocol version on the received packet doensn't match
135 // current protocol version of the connection.
136 virtual void OnProtocolVersionMismatch(QuicVersion version
) = 0;
138 // Called when the complete header of a packet has been parsed.
139 virtual void OnPacketHeader(const QuicPacketHeader
& header
) = 0;
141 // Called when a StreamFrame has been parsed.
142 virtual void OnStreamFrame(const QuicStreamFrame
& frame
) = 0;
144 // Called when a AckFrame has been parsed.
145 virtual void OnAckFrame(const QuicAckFrame
& frame
) = 0;
147 // Called when a CongestionFeedbackFrame has been parsed.
148 virtual void OnCongestionFeedbackFrame(
149 const QuicCongestionFeedbackFrame
& frame
) = 0;
151 // Called when a RstStreamFrame has been parsed.
152 virtual void OnRstStreamFrame(const QuicRstStreamFrame
& frame
) = 0;
154 // Called when a ConnectionCloseFrame has been parsed.
155 virtual void OnConnectionCloseFrame(
156 const QuicConnectionCloseFrame
& frame
) = 0;
158 // Called when a public reset packet has been received.
159 virtual void OnPublicResetPacket(const QuicPublicResetPacket
& packet
) = 0;
161 // Called when a version negotiation packet has been received.
162 virtual void OnVersionNegotiationPacket(
163 const QuicVersionNegotiationPacket
& packet
) = 0;
165 // Called after a packet has been successfully parsed which results
166 // in the revival of a packet via FEC.
167 virtual void OnRevivedPacket(const QuicPacketHeader
& revived_header
,
168 base::StringPiece payload
) = 0;
171 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface
{
173 virtual ~QuicConnectionHelperInterface() {}
175 // Returns a QuicClock to be used for all time related functions.
176 virtual const QuicClock
* GetClock() const = 0;
178 // Returns a QuicRandom to be used for all random number related functions.
179 virtual QuicRandom
* GetRandomGenerator() = 0;
181 // Creates a new platform-specific alarm which will be configured to
182 // notify |delegate| when the alarm fires. Caller takes ownership
183 // of the new alarm, which will not yet be "set" to fire.
184 virtual QuicAlarm
* CreateAlarm(QuicAlarm::Delegate
* delegate
) = 0;
187 class NET_EXPORT_PRIVATE QuicConnection
188 : public QuicFramerVisitorInterface
,
189 public QuicBlockedWriterInterface
,
190 public QuicPacketGenerator::DelegateInterface
{
201 BUNDLE_PENDING_ACK
= 2,
204 // Constructs a new QuicConnection for the specified |guid| and |address|.
205 // |helper| and |writer| must outlive this connection.
206 QuicConnection(QuicGuid guid
,
208 QuicConnectionHelperInterface
* helper
,
209 QuicPacketWriter
* writer
,
211 const QuicVersionVector
& supported_versions
);
212 virtual ~QuicConnection();
214 // Sets connection parameters from the supplied |config|.
215 void SetFromConfig(const QuicConfig
& config
);
217 // Send the data in |data| to the peer in as few packets as possible.
218 // Returns a pair with the number of bytes consumed from data, and a boolean
219 // indicating if the fin bit was consumed. This does not indicate the data
220 // has been sent on the wire: it may have been turned into a packet and queued
221 // if the socket was unexpectedly blocked.
222 // If |delegate| is provided, then it will be informed once ACKs have been
223 // received for all the packets written in this call.
224 // The |delegate| is not owned by the QuicConnection and must outlive it.
225 QuicConsumedData
SendStreamData(QuicStreamId id
,
226 const IOVector
& data
,
227 QuicStreamOffset offset
,
229 QuicAckNotifier::DelegateInterface
* delegate
);
231 // Send a stream reset frame to the peer.
232 virtual void SendRstStream(QuicStreamId id
,
233 QuicRstStreamErrorCode error
,
234 QuicStreamOffset bytes_written
);
236 // Sends the connection close packet without affecting the state of the
237 // connection. This should only be called if the session is actively being
238 // destroyed: otherwise call SendConnectionCloseWithDetails instead.
239 virtual void SendConnectionClosePacket(QuicErrorCode error
,
240 const std::string
& details
);
242 // Sends a connection close frame to the peer, and closes the connection by
243 // calling CloseConnection(notifying the visitor as it does so).
244 virtual void SendConnectionClose(QuicErrorCode error
);
245 virtual void SendConnectionCloseWithDetails(QuicErrorCode error
,
246 const std::string
& details
);
247 // Notifies the visitor of the close and marks the connection as disconnected.
248 virtual void CloseConnection(QuicErrorCode error
, bool from_peer
) OVERRIDE
;
249 virtual void SendGoAway(QuicErrorCode error
,
250 QuicStreamId last_good_stream_id
,
251 const std::string
& reason
);
253 // Returns statistics tracked for this connection.
254 const QuicConnectionStats
& GetStats();
256 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from
257 // the peer. If processing this packet permits a packet to be revived from
258 // its FEC group that packet will be revived and processed.
259 virtual void ProcessUdpPacket(const IPEndPoint
& self_address
,
260 const IPEndPoint
& peer_address
,
261 const QuicEncryptedPacket
& packet
);
263 // QuicBlockedWriterInterface
264 // Called when the underlying connection becomes writable to allow queued
266 virtual void OnCanWrite() OVERRIDE
;
268 // Called when a packet has been finally sent to the network.
269 bool OnPacketSent(WriteResult result
);
271 // If the socket is not blocked, writes queued packets.
272 void WriteIfNotBlocked();
274 // Do any work which logically would be done in OnPacket but can not be
275 // safely done until the packet is validated. Returns true if the packet
276 // can be handled, false otherwise.
277 bool ProcessValidatedPacket();
279 // The version of the protocol this connection is using.
280 QuicVersion
version() const { return framer_
.version(); }
282 // The versions of the protocol that this connection supports.
283 const QuicVersionVector
& supported_versions() const {
284 return framer_
.supported_versions();
287 // From QuicFramerVisitorInterface
288 virtual void OnError(QuicFramer
* framer
) OVERRIDE
;
289 virtual bool OnProtocolVersionMismatch(QuicVersion received_version
) OVERRIDE
;
290 virtual void OnPacket() OVERRIDE
;
291 virtual void OnPublicResetPacket(
292 const QuicPublicResetPacket
& packet
) OVERRIDE
;
293 virtual void OnVersionNegotiationPacket(
294 const QuicVersionNegotiationPacket
& packet
) OVERRIDE
;
295 virtual void OnRevivedPacket() OVERRIDE
;
296 virtual bool OnUnauthenticatedPublicHeader(
297 const QuicPacketPublicHeader
& header
) OVERRIDE
;
298 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader
& header
) OVERRIDE
;
299 virtual bool OnPacketHeader(const QuicPacketHeader
& header
) OVERRIDE
;
300 virtual void OnFecProtectedPayload(base::StringPiece payload
) OVERRIDE
;
301 virtual bool OnStreamFrame(const QuicStreamFrame
& frame
) OVERRIDE
;
302 virtual bool OnAckFrame(const QuicAckFrame
& frame
) OVERRIDE
;
303 virtual bool OnCongestionFeedbackFrame(
304 const QuicCongestionFeedbackFrame
& frame
) OVERRIDE
;
305 virtual bool OnRstStreamFrame(const QuicRstStreamFrame
& frame
) OVERRIDE
;
306 virtual bool OnConnectionCloseFrame(
307 const QuicConnectionCloseFrame
& frame
) OVERRIDE
;
308 virtual bool OnGoAwayFrame(const QuicGoAwayFrame
& frame
) OVERRIDE
;
309 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame
& frame
) OVERRIDE
;
310 virtual bool OnBlockedFrame(const QuicBlockedFrame
& frame
) OVERRIDE
;
311 virtual void OnFecData(const QuicFecData
& fec
) OVERRIDE
;
312 virtual void OnPacketComplete() OVERRIDE
;
314 // QuicPacketGenerator::DelegateInterface
315 virtual bool ShouldGeneratePacket(TransmissionType transmission_type
,
316 HasRetransmittableData retransmittable
,
317 IsHandshake handshake
) OVERRIDE
;
318 virtual QuicAckFrame
* CreateAckFrame() OVERRIDE
;
319 virtual QuicCongestionFeedbackFrame
* CreateFeedbackFrame() OVERRIDE
;
320 virtual bool OnSerializedPacket(const SerializedPacket
& packet
) OVERRIDE
;
323 void set_visitor(QuicConnectionVisitorInterface
* visitor
) {
326 void set_debug_visitor(QuicConnectionDebugVisitorInterface
* debug_visitor
) {
327 debug_visitor_
= debug_visitor
;
328 packet_generator_
.set_debug_delegate(debug_visitor
);
330 const IPEndPoint
& self_address() const { return self_address_
; }
331 const IPEndPoint
& peer_address() const { return peer_address_
; }
332 QuicGuid
guid() const { return guid_
; }
333 const QuicClock
* clock() const { return clock_
; }
334 QuicRandom
* random_generator() const { return random_generator_
; }
336 QuicPacketCreator::Options
* options() { return packet_creator_
.options(); }
338 bool connected() const { return connected_
; }
340 // Must only be called on client connections.
341 const QuicVersionVector
& server_supported_versions() const {
343 return server_supported_versions_
;
346 size_t NumFecGroups() const { return group_map_
.size(); }
349 size_t NumQueuedPackets() const { return queued_packets_
.size(); }
351 QuicEncryptedPacket
* ReleaseConnectionClosePacket() {
352 return connection_close_packet_
.release();
355 // Flush any queued frames immediately. Preserves the batch write mode and
356 // does nothing if there are no pending frames.
359 // Returns true if the underlying UDP socket is writable, there is
360 // no queued data and the connection is not congestion-control
362 bool CanWriteStreamData();
364 // Returns true if the connection has queued packets or frames.
365 bool HasQueuedData() const;
367 // Sets (or resets) the idle state connection timeout. Also, checks and times
368 // out the connection if network timer has expired for |timeout|.
369 void SetIdleNetworkTimeout(QuicTime::Delta timeout
);
370 // Sets (or resets) the total time delta the connection can be alive for.
371 // Also, checks and times out the connection if timer has expired for
372 // |timeout|. Used to limit the time a connection can be alive before crypto
373 // handshake finishes.
374 void SetOverallConnectionTimeout(QuicTime::Delta timeout
);
376 // If the connection has timed out, this will close the connection and return
377 // true. Otherwise, it will return false and will reset the timeout alarm.
378 bool CheckForTimeout();
380 // Sets up a packet with an QuicAckFrame and sends it out.
383 // Called when an RTO fires. Resets the retransmission alarm if there are
384 // remaining unacked packets.
385 void OnRetransmissionTimeout();
387 // Retransmits all unacked packets with retransmittable frames if
388 // |retransmission_type| is ALL_PACKETS, otherwise retransmits only initially
389 // encrypted packets. Used when the negotiated protocol version is different
390 // from what was initially assumed and when the visitor wants to re-transmit
391 // initially encrypted packets when the initial encrypter changes.
392 void RetransmitUnackedPackets(RetransmissionType retransmission_type
);
394 // Changes the encrypter used for level |level| to |encrypter|. The function
395 // takes ownership of |encrypter|.
396 void SetEncrypter(EncryptionLevel level
, QuicEncrypter
* encrypter
);
397 const QuicEncrypter
* encrypter(EncryptionLevel level
) const;
399 // SetDefaultEncryptionLevel sets the encryption level that will be applied
401 void SetDefaultEncryptionLevel(EncryptionLevel level
);
403 // SetDecrypter sets the primary decrypter, replacing any that already exists,
404 // and takes ownership. If an alternative decrypter is in place then the
405 // function DCHECKs. This is intended for cases where one knows that future
406 // packets will be using the new decrypter and the previous decrypter is now
408 void SetDecrypter(QuicDecrypter
* decrypter
);
410 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt
411 // future packets and takes ownership of it. If |latch_once_used| is true,
412 // then the first time that the decrypter is successful it will replace the
413 // primary decrypter. Otherwise both decrypters will remain active and the
414 // primary decrypter will be the one last used.
415 void SetAlternativeDecrypter(QuicDecrypter
* decrypter
,
416 bool latch_once_used
);
418 const QuicDecrypter
* decrypter() const;
419 const QuicDecrypter
* alternative_decrypter() const;
421 bool is_server() const { return is_server_
; }
423 // Returns the underlying sent packet manager.
424 const QuicSentPacketManager
& sent_packet_manager() const {
425 return sent_packet_manager_
;
428 bool CanWrite(TransmissionType transmission_type
,
429 HasRetransmittableData retransmittable
,
430 IsHandshake handshake
);
433 // Send a packet to the peer using encryption |level|. If |sequence_number|
434 // is present in the |retransmission_map_|, then contents of this packet will
435 // be retransmitted with a new sequence number if it's not acked by the peer.
436 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to
437 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the
438 // entropy map corresponding to |sequence_number| using |entropy_hash|.
439 // |transmission_type| and |retransmittable| are supplied to the congestion
440 // manager, and when |forced| is true, it bypasses the congestion manager.
441 // TODO(wtc): none of the callers check the return value.
442 virtual bool SendOrQueuePacket(EncryptionLevel level
,
443 const SerializedPacket
& packet
,
444 TransmissionType transmission_type
);
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
);
454 // Stores current batch state for connection, puts the connection
455 // into batch mode, and destruction restores the stored batch state.
456 // While the bundler is in scope, any generated frames are bundled
457 // as densely as possible into packets. In addition, this bundler
458 // can be configured to ensure that an ACK frame is included in the
459 // first packet created, if there's new ack information to be sent.
460 class ScopedPacketBundler
{
462 // In addition to all outgoing frames being bundled when the
463 // bundler is in scope, setting |include_ack| to true ensures that
464 // an ACK frame is opportunistically bundled with the first
466 ScopedPacketBundler(QuicConnection
* connection
, AckBundling send_ack
);
467 ~ScopedPacketBundler();
470 QuicConnection
* connection_
;
471 bool already_in_batch_mode_
;
474 friend class ScopedPacketBundler
;
475 friend class test::QuicConnectionPeer
;
477 // Packets which have not been written to the wire.
478 // Owns the QuicPacket* packet.
479 struct QueuedPacket
{
480 QueuedPacket(SerializedPacket packet
,
481 EncryptionLevel level
,
482 TransmissionType transmission_type
);
484 QuicPacketSequenceNumber sequence_number
;
486 const EncryptionLevel encryption_level
;
487 TransmissionType transmission_type
;
488 HasRetransmittableData retransmittable
;
489 IsHandshake handshake
;
491 QuicByteCount length
;
494 typedef std::list
<QueuedPacket
> QueuedPacketList
;
495 typedef std::map
<QuicFecGroupNumber
, QuicFecGroup
*> FecGroupMap
;
497 // Writes the given packet to socket, encrypted with packet's
498 // encryption_level. Returns true on successful write. Behavior is undefined
499 // if connection is not established or broken. A return value of true means
500 // the packet was transmitted and may be destroyed. If the packet is
501 // retransmittable, WritePacket sets up retransmission for a successful write.
502 // If packet is FORCE, then it will be sent immediately and the send scheduler
503 // will not be consulted.
504 bool WritePacket(QueuedPacket packet
);
506 // Make sure an ack we got from our peer is sane.
507 bool ValidateAckFrame(const QuicAckFrame
& incoming_ack
);
509 // Sends a version negotiation packet to the peer.
510 void SendVersionNegotiationPacket();
512 // Clears any accumulated frames from the last received packet.
513 void ClearLastFrames();
515 // Calculates the smallest sequence number length that can also represent four
516 // times the maximum of the congestion window and the difference between the
517 // least_packet_awaited_by_peer_ and |sequence_number|.
518 QuicSequenceNumberLength
CalculateSequenceNumberLength(
519 QuicPacketSequenceNumber sequence_number
);
521 // Drop packet corresponding to |sequence_number| by deleting entries from
522 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop
523 // all packets with encryption level NONE after the default level has been set
524 // to FORWARD_SECURE.
525 void DropPacket(QuicPacketSequenceNumber sequence_number
);
527 // Writes as many queued packets as possible. The connection must not be
528 // blocked when this is called.
529 void WriteQueuedPackets();
531 // Writes as many pending retransmissions as possible.
532 void WritePendingRetransmissions();
534 // Returns true if the packet should be discarded and not sent.
535 bool ShouldDiscardPacket(EncryptionLevel level
,
536 QuicPacketSequenceNumber sequence_number
,
537 HasRetransmittableData retransmittable
);
539 // Queues |packet| in the hopes that it can be decrypted in the
540 // future, when a new key is installed.
541 void QueueUndecryptablePacket(const QuicEncryptedPacket
& packet
);
543 // Attempts to process any queued undecryptable packets.
544 void MaybeProcessUndecryptablePackets();
546 // If a packet can be revived from the current FEC group, then
547 // revive and process the packet.
548 void MaybeProcessRevivedPacket();
550 void ProcessAckFrame(const QuicAckFrame
& incoming_ack
);
552 // Update the |sent_info| for an outgoing ack.
553 void UpdateSentPacketInfo(SentPacketInfo
* sent_info
);
555 // Queues an ack or sets the ack alarm when an incoming packet arrives that
557 void MaybeQueueAck();
559 // Checks if the last packet should instigate an ack.
560 bool ShouldLastPacketInstigateAck() const;
562 // Checks if the peer is waiting for packets that have been given up on, and
563 // therefore an ack frame should be sent with a larger least_unacked.
564 void UpdateStopWaitingCount();
566 // Sends any packets which are a response to the last packet, including both
567 // acks and pending writes if an ack opened the congestion window.
568 void MaybeSendInResponseToPacket();
570 // Gets the least unacked sequence number, which is the next sequence number
571 // to be sent if there are no outstanding packets.
572 QuicPacketSequenceNumber
GetLeastUnacked() const;
574 // Get the FEC group associate with the last processed packet or NULL, if the
575 // group has already been deleted.
576 QuicFecGroup
* GetFecGroup();
578 // Closes any FEC groups protecting packets before |sequence_number|.
579 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number
);
582 QuicConnectionHelperInterface
* helper_
; // Not owned.
583 QuicPacketWriter
* writer_
; // Not owned.
584 EncryptionLevel encryption_level_
;
585 const QuicClock
* clock_
;
586 QuicRandom
* random_generator_
;
588 const QuicGuid guid_
;
589 // Address on the last successfully processed packet received from the
591 IPEndPoint self_address_
;
592 IPEndPoint peer_address_
;
594 bool last_packet_revived_
; // True if the last packet was revived from FEC.
595 size_t last_size_
; // Size of the last received packet.
596 QuicPacketHeader last_header_
;
597 std::vector
<QuicStreamFrame
> last_stream_frames_
;
598 std::vector
<QuicAckFrame
> last_ack_frames_
;
599 std::vector
<QuicCongestionFeedbackFrame
> last_congestion_frames_
;
600 std::vector
<QuicRstStreamFrame
> last_rst_frames_
;
601 std::vector
<QuicGoAwayFrame
> last_goaway_frames_
;
602 std::vector
<QuicWindowUpdateFrame
> last_window_update_frames_
;
603 std::vector
<QuicBlockedFrame
> last_blocked_frames_
;
604 std::vector
<QuicConnectionCloseFrame
> last_close_frames_
;
606 QuicCongestionFeedbackFrame outgoing_congestion_feedback_
;
608 // Track some peer state so we can do less bookkeeping
609 // Largest sequence sent by the peer which had an ack frame (latest ack info).
610 QuicPacketSequenceNumber largest_seen_packet_with_ack_
;
612 // Collection of packets which were received before encryption was
613 // established, but which could not be decrypted. We buffer these on
614 // the assumption that they could not be processed because they were
615 // sent with the INITIAL encryption and the CHLO message was lost.
616 std::deque
<QuicEncryptedPacket
*> undecryptable_packets_
;
618 // When the version negotiation packet could not be sent because the socket
619 // was not writable, this is set to true.
620 bool pending_version_negotiation_packet_
;
622 // When packets could not be sent because the socket was not writable,
623 // they are added to this list. All corresponding frames are in
624 // unacked_packets_ if they are to be retransmitted.
625 QueuedPacketList queued_packets_
;
627 // Contains information about the current write in progress, if any.
628 scoped_ptr
<QueuedPacket
> pending_write_
;
630 // Contains the connection close packet if the connection has been closed.
631 scoped_ptr
<QuicEncryptedPacket
> connection_close_packet_
;
633 FecGroupMap group_map_
;
635 QuicReceivedPacketManager received_packet_manager_
;
636 QuicSentEntropyManager sent_entropy_manager_
;
638 // Indicates whether an ack should be sent the next time we try to write.
640 // Indicates how many consecutive times an ack has arrived which indicates
641 // the peer needs to stop waiting for some packets.
642 int stop_waiting_count_
;
644 // An alarm that fires when an ACK should be sent to the peer.
645 scoped_ptr
<QuicAlarm
> ack_alarm_
;
646 // An alarm that fires when a packet needs to be retransmitted.
647 scoped_ptr
<QuicAlarm
> retransmission_alarm_
;
648 // An alarm that is scheduled when the sent scheduler requires a
649 // a delay before sending packets and fires when the packet may be sent.
650 scoped_ptr
<QuicAlarm
> send_alarm_
;
651 // An alarm that is scheduled when the connection can still write and there
652 // may be more data to send.
653 scoped_ptr
<QuicAlarm
> resume_writes_alarm_
;
654 // An alarm that fires when the connection may have timed out.
655 scoped_ptr
<QuicAlarm
> timeout_alarm_
;
657 QuicConnectionVisitorInterface
* visitor_
;
658 QuicConnectionDebugVisitorInterface
* debug_visitor_
;
659 QuicPacketCreator packet_creator_
;
660 QuicPacketGenerator packet_generator_
;
662 // Network idle time before we kill of this connection.
663 QuicTime::Delta idle_network_timeout_
;
664 // Overall connection timeout.
665 QuicTime::Delta overall_connection_timeout_
;
666 // Connection creation time.
667 QuicTime creation_time_
;
669 // Statistics for this session.
670 QuicConnectionStats stats_
;
672 // The time that we got a packet for this connection.
673 // This is used for timeouts, and does not indicate the packet was processed.
674 QuicTime time_of_last_received_packet_
;
676 // The last time a new (non-retransmitted) packet was sent for this
678 QuicTime time_of_last_sent_new_packet_
;
680 // Sequence number of the last sent packet. Packets are guaranteed to be sent
681 // in sequence number order.
682 QuicPacketSequenceNumber sequence_number_of_last_sent_packet_
;
684 // Sent packet manager which tracks the status of packets sent by this
685 // connection and contains the send and receive algorithms to determine when
687 QuicSentPacketManager sent_packet_manager_
;
689 // The state of connection in version negotiation finite state machine.
690 QuicVersionNegotiationState version_negotiation_state_
;
692 // Tracks if the connection was created by the server.
695 // True by default. False if we've received or sent an explicit connection
699 // Set to true if the udp packet headers have a new self or peer address.
700 // This is checked later on validating a data or version negotiation packet.
701 bool address_migrating_
;
703 // If non-empty this contains the set of versions received in a
704 // version negotiation packet.
705 QuicVersionVector server_supported_versions_
;
707 DISALLOW_COPY_AND_ASSIGN(QuicConnection
);
712 #endif // NET_QUIC_QUIC_CONNECTION_H_