Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / quic / quic_connection.h
blob4aa51299685c9a0e2cd7d9981d1f55f14a6affc6
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.
11 // On the client side, the Connection handles the raw reads, as well as the
12 // processing.
14 // Note: this class is not thread-safe.
16 #ifndef NET_QUIC_QUIC_CONNECTION_H_
17 #define NET_QUIC_QUIC_CONNECTION_H_
19 #include <stddef.h>
20 #include <deque>
21 #include <list>
22 #include <map>
23 #include <queue>
24 #include <string>
25 #include <vector>
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 namespace net {
46 class QuicClock;
47 class QuicConfig;
48 class QuicConnection;
49 class QuicDecrypter;
50 class QuicEncrypter;
51 class QuicFecGroup;
52 class QuicRandom;
54 namespace test {
55 class QuicConnectionPeer;
56 } // namespace test
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 {
61 public:
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 // Called when the stream is reset by the peer.
71 virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0;
73 // Called when the connection is going away according to the peer.
74 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0;
76 // Called when the connection is closed either locally by the framer, or
77 // remotely by the peer.
78 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) = 0;
80 // Called when the connection failed to write because the socket was blocked.
81 virtual void OnWriteBlocked() = 0;
83 // Called once a specific QUIC version is agreed by both endpoints.
84 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0;
86 // Indicates a new QuicConfig has been negotiated.
87 virtual void OnConfigNegotiated() = 0;
89 // Called when a blocked socket becomes writable. If all pending bytes for
90 // this visitor are consumed by the connection successfully this should
91 // return true, otherwise it should return false.
92 virtual bool OnCanWrite() = 0;
94 // Called to ask if any handshake messages are pending in this visitor.
95 virtual bool HasPendingHandshake() const = 0;
98 // Interface which gets callbacks from the QuicConnection at interesting
99 // points. Implementations must not mutate the state of the connection
100 // as a result of these callbacks.
101 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface
102 : public QuicPacketGenerator::DebugDelegateInterface {
103 public:
104 virtual ~QuicConnectionDebugVisitorInterface() {}
106 // Called when a packet has been sent.
107 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number,
108 EncryptionLevel level,
109 const QuicEncryptedPacket& packet,
110 WriteResult result) = 0;
112 // Called when the contents of a packet have been retransmitted as
113 // a new packet.
114 virtual void OnPacketRetransmitted(
115 QuicPacketSequenceNumber old_sequence_number,
116 QuicPacketSequenceNumber new_sequence_number) = 0;
118 // Called when a packet has been received, but before it is
119 // validated or parsed.
120 virtual void OnPacketReceived(const IPEndPoint& self_address,
121 const IPEndPoint& peer_address,
122 const QuicEncryptedPacket& packet) = 0;
124 // Called when the protocol version on the received packet doensn't match
125 // current protocol version of the connection.
126 virtual void OnProtocolVersionMismatch(QuicVersion version) = 0;
128 // Called when the complete header of a packet has been parsed.
129 virtual void OnPacketHeader(const QuicPacketHeader& header) = 0;
131 // Called when a StreamFrame has been parsed.
132 virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0;
134 // Called when a AckFrame has been parsed.
135 virtual void OnAckFrame(const QuicAckFrame& frame) = 0;
137 // Called when a CongestionFeedbackFrame has been parsed.
138 virtual void OnCongestionFeedbackFrame(
139 const QuicCongestionFeedbackFrame& frame) = 0;
141 // Called when a RstStreamFrame has been parsed.
142 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0;
144 // Called when a ConnectionCloseFrame has been parsed.
145 virtual void OnConnectionCloseFrame(
146 const QuicConnectionCloseFrame& frame) = 0;
148 // Called when a public reset packet has been received.
149 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0;
151 // Called when a version negotiation packet has been received.
152 virtual void OnVersionNegotiationPacket(
153 const QuicVersionNegotiationPacket& packet) = 0;
155 // Called after a packet has been successfully parsed which results
156 // in the revival of a packet via FEC.
157 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header,
158 base::StringPiece payload) = 0;
161 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface {
162 public:
163 virtual ~QuicConnectionHelperInterface() {}
165 // Returns a QuicClock to be used for all time related functions.
166 virtual const QuicClock* GetClock() const = 0;
168 // Returns a QuicRandom to be used for all random number related functions.
169 virtual QuicRandom* GetRandomGenerator() = 0;
171 // Creates a new platform-specific alarm which will be configured to
172 // notify |delegate| when the alarm fires. Caller takes ownership
173 // of the new alarm, which will not yet be "set" to fire.
174 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0;
177 class NET_EXPORT_PRIVATE QuicConnection
178 : public QuicFramerVisitorInterface,
179 public QuicBlockedWriterInterface,
180 public QuicPacketGenerator::DelegateInterface,
181 public QuicSentPacketManager::HelperInterface {
182 public:
183 enum Force {
184 NO_FORCE,
185 FORCE
188 // Constructs a new QuicConnection for the specified |guid| and |address|.
189 // |helper| and |writer| must outlive this connection.
190 QuicConnection(QuicGuid guid,
191 IPEndPoint address,
192 QuicConnectionHelperInterface* helper,
193 QuicPacketWriter* writer,
194 bool is_server,
195 const QuicVersionVector& supported_versions);
196 virtual ~QuicConnection();
198 // Sets connection parameters from the supplied |config|.
199 void SetFromConfig(const QuicConfig& config);
201 // Send the data in |data| to the peer in as few packets as possible.
202 // Returns a pair with the number of bytes consumed from data, and a boolean
203 // indicating if the fin bit was consumed. This does not indicate the data
204 // has been sent on the wire: it may have been turned into a packet and queued
205 // if the socket was unexpectedly blocked.
206 // If |delegate| is provided, then it will be informed once ACKs have been
207 // received for all the packets written in this call.
208 // The |delegate| is not owned by the QuicConnection and must outlive it.
209 QuicConsumedData SendStreamData(QuicStreamId id,
210 const IOVector& data,
211 QuicStreamOffset offset,
212 bool fin,
213 QuicAckNotifier::DelegateInterface* delegate);
215 // Send a stream reset frame to the peer.
216 virtual void SendRstStream(QuicStreamId id,
217 QuicRstStreamErrorCode error);
219 // Sends the connection close packet without affecting the state of the
220 // connection. This should only be called if the session is actively being
221 // destroyed: otherwise call SendConnectionCloseWithDetails instead.
222 virtual void SendConnectionClosePacket(QuicErrorCode error,
223 const std::string& details);
225 // Sends a connection close frame to the peer, and closes the connection by
226 // calling CloseConnection(notifying the visitor as it does so).
227 virtual void SendConnectionClose(QuicErrorCode error);
228 virtual void SendConnectionCloseWithDetails(QuicErrorCode error,
229 const std::string& details);
230 // Notifies the visitor of the close and marks the connection as disconnected.
231 virtual void CloseConnection(QuicErrorCode error, bool from_peer) OVERRIDE;
232 virtual void SendGoAway(QuicErrorCode error,
233 QuicStreamId last_good_stream_id,
234 const std::string& reason);
236 // Returns statistics tracked for this connection.
237 const QuicConnectionStats& GetStats();
239 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from
240 // the peer. If processing this packet permits a packet to be revived from
241 // its FEC group that packet will be revived and processed.
242 virtual void ProcessUdpPacket(const IPEndPoint& self_address,
243 const IPEndPoint& peer_address,
244 const QuicEncryptedPacket& packet);
246 // QuicBlockedWriterInterface
247 // Called when the underlying connection becomes writable to allow queued
248 // writes to happen. Returns false if the socket has become blocked.
249 virtual bool OnCanWrite() OVERRIDE;
251 // Called when a packet has been finally sent to the network.
252 bool OnPacketSent(WriteResult result);
254 // If the socket is not blocked, writes queued packets.
255 void WriteIfNotBlocked();
257 // Do any work which logically would be done in OnPacket but can not be
258 // safely done until the packet is validated. Returns true if the packet
259 // can be handled, false otherwise.
260 bool ProcessValidatedPacket();
262 // The version of the protocol this connection is using.
263 QuicVersion version() const { return framer_.version(); }
265 // The versions of the protocol that this connection supports.
266 const QuicVersionVector& supported_versions() const {
267 return framer_.supported_versions();
270 // From QuicFramerVisitorInterface
271 virtual void OnError(QuicFramer* framer) OVERRIDE;
272 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) OVERRIDE;
273 virtual void OnPacket() OVERRIDE;
274 virtual void OnPublicResetPacket(
275 const QuicPublicResetPacket& packet) OVERRIDE;
276 virtual void OnVersionNegotiationPacket(
277 const QuicVersionNegotiationPacket& packet) OVERRIDE;
278 virtual void OnRevivedPacket() OVERRIDE;
279 virtual bool OnUnauthenticatedPublicHeader(
280 const QuicPacketPublicHeader& header) OVERRIDE;
281 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) OVERRIDE;
282 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE;
283 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE;
284 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE;
285 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE;
286 virtual bool OnCongestionFeedbackFrame(
287 const QuicCongestionFeedbackFrame& frame) OVERRIDE;
288 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE;
289 virtual bool OnConnectionCloseFrame(
290 const QuicConnectionCloseFrame& frame) OVERRIDE;
291 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE;
292 virtual void OnFecData(const QuicFecData& fec) OVERRIDE;
293 virtual void OnPacketComplete() OVERRIDE;
295 // QuicPacketGenerator::DelegateInterface
296 virtual bool ShouldGeneratePacket(TransmissionType transmission_type,
297 HasRetransmittableData retransmittable,
298 IsHandshake handshake) OVERRIDE;
299 virtual QuicAckFrame* CreateAckFrame() OVERRIDE;
300 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE;
301 virtual bool OnSerializedPacket(const SerializedPacket& packet) OVERRIDE;
303 // QuicSentPacketManager::HelperInterface
304 virtual QuicPacketSequenceNumber GetNextPacketSequenceNumber() OVERRIDE;
306 // Accessors
307 void set_visitor(QuicConnectionVisitorInterface* visitor) {
308 visitor_ = visitor;
310 void set_debug_visitor(QuicConnectionDebugVisitorInterface* debug_visitor) {
311 debug_visitor_ = debug_visitor;
312 packet_generator_.set_debug_delegate(debug_visitor);
314 const IPEndPoint& self_address() const { return self_address_; }
315 const IPEndPoint& peer_address() const { return peer_address_; }
316 QuicGuid guid() const { return guid_; }
317 const QuicClock* clock() const { return clock_; }
318 QuicRandom* random_generator() const { return random_generator_; }
320 QuicPacketCreator::Options* options() { return packet_creator_.options(); }
322 bool connected() const { return connected_; }
324 // Must only be called on client connections.
325 const QuicVersionVector& server_supported_versions() const {
326 DCHECK(!is_server_);
327 return server_supported_versions_;
330 size_t NumFecGroups() const { return group_map_.size(); }
332 // Testing only.
333 size_t NumQueuedPackets() const { return queued_packets_.size(); }
335 QuicEncryptedPacket* ReleaseConnectionClosePacket() {
336 return connection_close_packet_.release();
339 // Flush any queued frames immediately. Preserves the batch write mode and
340 // does nothing if there are no pending frames.
341 void Flush();
343 // Returns true if the underlying UDP socket is writable, there is
344 // no queued data and the connection is not congestion-control
345 // blocked.
346 bool CanWriteStreamData();
348 // Returns true if the connection has queued packets or frames.
349 bool HasQueuedData() const;
351 // Sets (or resets) the idle state connection timeout. Also, checks and times
352 // out the connection if network timer has expired for |timeout|.
353 void SetIdleNetworkTimeout(QuicTime::Delta timeout);
354 // Sets (or resets) the total time delta the connection can be alive for.
355 // Also, checks and times out the connection if timer has expired for
356 // |timeout|. Used to limit the time a connection can be alive before crypto
357 // handshake finishes.
358 void SetOverallConnectionTimeout(QuicTime::Delta timeout);
360 // If the connection has timed out, this will close the connection and return
361 // true. Otherwise, it will return false and will reset the timeout alarm.
362 bool CheckForTimeout();
364 // Sets up a packet with an QuicAckFrame and sends it out.
365 void SendAck();
367 // Called when an RTO fires. Resets the retransmission alarm if there are
368 // remaining unacked packets.
369 void OnRetransmissionTimeout();
371 // Retransmits all unacked packets with retransmittable frames if
372 // |retransmission_type| is ALL_PACKETS, otherwise retransmits only initially
373 // encrypted packets. Used when the negotiated protocol version is different
374 // from what was initially assumed and when the visitor wants to re-transmit
375 // initially encrypted packets when the initial encrypter changes.
376 void RetransmitUnackedPackets(RetransmissionType retransmission_type);
378 // Changes the encrypter used for level |level| to |encrypter|. The function
379 // takes ownership of |encrypter|.
380 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter);
381 const QuicEncrypter* encrypter(EncryptionLevel level) const;
383 // SetDefaultEncryptionLevel sets the encryption level that will be applied
384 // to new packets.
385 void SetDefaultEncryptionLevel(EncryptionLevel level);
387 // SetDecrypter sets the primary decrypter, replacing any that already exists,
388 // and takes ownership. If an alternative decrypter is in place then the
389 // function DCHECKs. This is intended for cases where one knows that future
390 // packets will be using the new decrypter and the previous decrypter is now
391 // obsolete.
392 void SetDecrypter(QuicDecrypter* decrypter);
394 // SetAlternativeDecrypter sets a decrypter that may be used to decrypt
395 // future packets and takes ownership of it. If |latch_once_used| is true,
396 // then the first time that the decrypter is successful it will replace the
397 // primary decrypter. Otherwise both decrypters will remain active and the
398 // primary decrypter will be the one last used.
399 void SetAlternativeDecrypter(QuicDecrypter* decrypter,
400 bool latch_once_used);
402 const QuicDecrypter* decrypter() const;
403 const QuicDecrypter* alternative_decrypter() const;
405 bool is_server() const { return is_server_; }
407 // Returns the underlying sent packet manager.
408 const QuicSentPacketManager& sent_packet_manager() const {
409 return sent_packet_manager_;
412 bool CanWrite(TransmissionType transmission_type,
413 HasRetransmittableData retransmittable,
414 IsHandshake handshake);
416 protected:
417 // Send a packet to the peer using encryption |level|. If |sequence_number|
418 // is present in the |retransmission_map_|, then contents of this packet will
419 // be retransmitted with a new sequence number if it's not acked by the peer.
420 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to
421 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the
422 // entropy map corresponding to |sequence_number| using |entropy_hash|.
423 // |transmission_type| and |retransmittable| are supplied to the congestion
424 // manager, and when |forced| is true, it bypasses the congestion manager.
425 // TODO(wtc): none of the callers check the return value.
426 virtual bool SendOrQueuePacket(EncryptionLevel level,
427 const SerializedPacket& packet,
428 TransmissionType transmission_type);
430 // Writes the given packet to socket, encrypted with |level|, with the help
431 // of helper. Returns true on successful write, false otherwise. However,
432 // behavior is undefined if connection is not established or broken. In any
433 // circumstances, a return value of true implies that |packet| has been
434 // transmitted and may be destroyed. If |sequence_number| is present in
435 // |retransmission_map_| it also sets up retransmission of the given packet
436 // in case of successful write. If |force| is FORCE, then the packet will be
437 // sent immediately and the send scheduler will not be consulted.
438 bool WritePacket(EncryptionLevel level,
439 QuicPacketSequenceNumber sequence_number,
440 QuicPacket* packet,
441 TransmissionType transmission_type,
442 HasRetransmittableData retransmittable,
443 IsHandshake handshake,
444 Force force);
446 // Make sure an ack we got from our peer is sane.
447 bool ValidateAckFrame(const QuicAckFrame& incoming_ack);
449 QuicConnectionHelperInterface* helper() { return helper_; }
451 // Selects and updates the version of the protocol being used by selecting a
452 // version from |available_versions| which is also supported. Returns true if
453 // such a version exists, false otherwise.
454 bool SelectMutualVersion(const QuicVersionVector& available_versions);
456 QuicFramer framer_;
458 private:
459 // Stores current batch state for connection, puts the connection
460 // into batch mode, and destruction restores the stored batch state.
461 // While the bundler is in scope, any generated frames are bundled
462 // as densely as possible into packets. In addition, this bundler
463 // can be configured to ensure that an ACK frame is included in the
464 // first packet created, if there's new ack information to be sent.
465 class ScopedPacketBundler {
466 public:
467 // In addition to all outgoing frames being bundled when the
468 // bundler is in scope, setting |include_ack| to true ensures that
469 // an ACK frame is opportunistically bundled with the first
470 // outgoing packet.
471 ScopedPacketBundler(QuicConnection* connection, bool include_ack);
472 ~ScopedPacketBundler();
474 private:
475 QuicConnection* connection_;
476 bool already_in_batch_mode_;
479 friend class ScopedPacketBundler;
480 friend class test::QuicConnectionPeer;
482 // Packets which have not been written to the wire.
483 // Owns the QuicPacket* packet.
484 struct QueuedPacket {
485 QueuedPacket(QuicPacketSequenceNumber sequence_number,
486 QuicPacket* packet,
487 EncryptionLevel level,
488 TransmissionType transmission_type,
489 HasRetransmittableData retransmittable,
490 IsHandshake handshake,
491 Force forced)
492 : sequence_number(sequence_number),
493 packet(packet),
494 encryption_level(level),
495 transmission_type(transmission_type),
496 retransmittable(retransmittable),
497 handshake(handshake),
498 forced(forced) {
501 QuicPacketSequenceNumber sequence_number;
502 QuicPacket* packet;
503 const EncryptionLevel encryption_level;
504 TransmissionType transmission_type;
505 HasRetransmittableData retransmittable;
506 IsHandshake handshake;
507 Force forced;
510 struct PendingWrite {
511 PendingWrite(QuicPacketSequenceNumber sequence_number,
512 TransmissionType transmission_type,
513 HasRetransmittableData retransmittable,
514 EncryptionLevel level,
515 bool is_fec_packet,
516 size_t length)
517 : sequence_number(sequence_number),
518 transmission_type(transmission_type),
519 retransmittable(retransmittable),
520 level(level),
521 is_fec_packet(is_fec_packet),
522 length(length) { }
524 QuicPacketSequenceNumber sequence_number;
525 TransmissionType transmission_type;
526 HasRetransmittableData retransmittable;
527 EncryptionLevel level;
528 bool is_fec_packet;
529 size_t length;
532 typedef std::list<QueuedPacket> QueuedPacketList;
533 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap;
535 // Sends a version negotiation packet to the peer.
536 void SendVersionNegotiationPacket();
538 // Clears any accumulated frames from the last received packet.
539 void ClearLastFrames();
541 // Calculates the smallest sequence number length that can also represent four
542 // times the maximum of the congestion window and the difference between the
543 // least_packet_awaited_by_peer_ and |sequence_number|.
544 QuicSequenceNumberLength CalculateSequenceNumberLength(
545 QuicPacketSequenceNumber sequence_number);
547 // Drop packet corresponding to |sequence_number| by deleting entries from
548 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop
549 // all packets with encryption level NONE after the default level has been set
550 // to FORWARD_SECURE.
551 void DropPacket(QuicPacketSequenceNumber sequence_number);
553 // Writes as many queued packets as possible. The connection must not be
554 // blocked when this is called.
555 void WriteQueuedPackets();
557 // Writes as many pending retransmissions as possible.
558 void WritePendingRetransmissions();
560 // Returns true if the packet should be discarded and not sent.
561 bool ShouldDiscardPacket(EncryptionLevel level,
562 QuicPacketSequenceNumber sequence_number,
563 HasRetransmittableData retransmittable);
565 // Queues |packet| in the hopes that it can be decrypted in the
566 // future, when a new key is installed.
567 void QueueUndecryptablePacket(const QuicEncryptedPacket& packet);
569 // Attempts to process any queued undecryptable packets.
570 void MaybeProcessUndecryptablePackets();
572 // If a packet can be revived from the current FEC group, then
573 // revive and process the packet.
574 void MaybeProcessRevivedPacket();
576 void ProcessAckFrame(const QuicAckFrame& incoming_ack);
578 // Update the |sent_info| for an outgoing ack.
579 void UpdateSentPacketInfo(SentPacketInfo* sent_info);
581 // Checks if the last packet should instigate an ack.
582 bool ShouldLastPacketInstigateAck();
584 // Sends any packets which are a response to the last packet, including both
585 // acks and pending writes if an ack opened the congestion window.
586 void MaybeSendInResponseToPacket(bool send_ack_immediately,
587 bool last_packet_should_instigate_ack);
589 // Get the FEC group associate with the last processed packet or NULL, if the
590 // group has already been deleted.
591 QuicFecGroup* GetFecGroup();
593 // Closes any FEC groups protecting packets before |sequence_number|.
594 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number);
596 QuicConnectionHelperInterface* helper_; // Not owned.
597 QuicPacketWriter* writer_; // Not owned.
598 EncryptionLevel encryption_level_;
599 const QuicClock* clock_;
600 QuicRandom* random_generator_;
602 const QuicGuid guid_;
603 // Address on the last successfully processed packet received from the
604 // client.
605 IPEndPoint self_address_;
606 IPEndPoint peer_address_;
608 bool last_packet_revived_; // True if the last packet was revived from FEC.
609 size_t last_size_; // Size of the last received packet.
610 QuicPacketHeader last_header_;
611 std::vector<QuicStreamFrame> last_stream_frames_;
612 std::vector<QuicAckFrame> last_ack_frames_;
613 std::vector<QuicCongestionFeedbackFrame> last_congestion_frames_;
614 std::vector<QuicRstStreamFrame> last_rst_frames_;
615 std::vector<QuicGoAwayFrame> last_goaway_frames_;
616 std::vector<QuicConnectionCloseFrame> last_close_frames_;
618 QuicCongestionFeedbackFrame outgoing_congestion_feedback_;
620 // Track some peer state so we can do less bookkeeping
621 // Largest sequence sent by the peer which had an ack frame (latest ack info).
622 QuicPacketSequenceNumber largest_seen_packet_with_ack_;
624 // Collection of packets which were received before encryption was
625 // established, but which could not be decrypted. We buffer these on
626 // the assumption that they could not be processed because they were
627 // sent with the INITIAL encryption and the CHLO message was lost.
628 std::deque<QuicEncryptedPacket*> undecryptable_packets_;
630 // When the version negotiation packet could not be sent because the socket
631 // was not writable, this is set to true.
632 bool pending_version_negotiation_packet_;
634 // When packets could not be sent because the socket was not writable,
635 // they are added to this list. All corresponding frames are in
636 // unacked_packets_ if they are to be retransmitted.
637 QueuedPacketList queued_packets_;
639 // Contains information about the current write in progress, if any.
640 scoped_ptr<PendingWrite> pending_write_;
642 // Contains the connection close packet if the connection has been closed.
643 scoped_ptr<QuicEncryptedPacket> connection_close_packet_;
645 FecGroupMap group_map_;
647 QuicReceivedPacketManager received_packet_manager_;
648 QuicSentEntropyManager sent_entropy_manager_;
650 // An alarm that fires when an ACK should be sent to the peer.
651 scoped_ptr<QuicAlarm> ack_alarm_;
652 // An alarm that fires when a packet needs to be retransmitted.
653 scoped_ptr<QuicAlarm> retransmission_alarm_;
654 // An alarm that is scheduled when the sent scheduler requires a
655 // a delay before sending packets and fires when the packet may be sent.
656 scoped_ptr<QuicAlarm> send_alarm_;
657 // An alarm that is scheduled when the connection can still write and there
658 // may be more data to send.
659 scoped_ptr<QuicAlarm> resume_writes_alarm_;
660 // An alarm that fires when the connection may have timed out.
661 scoped_ptr<QuicAlarm> timeout_alarm_;
663 QuicConnectionVisitorInterface* visitor_;
664 QuicConnectionDebugVisitorInterface* debug_visitor_;
665 QuicPacketCreator packet_creator_;
666 QuicPacketGenerator packet_generator_;
668 // Network idle time before we kill of this connection.
669 QuicTime::Delta idle_network_timeout_;
670 // Overall connection timeout.
671 QuicTime::Delta overall_connection_timeout_;
672 // Connection creation time.
673 QuicTime creation_time_;
675 // Statistics for this session.
676 QuicConnectionStats stats_;
678 // The time that we got a packet for this connection.
679 // This is used for timeouts, and does not indicate the packet was processed.
680 QuicTime time_of_last_received_packet_;
682 // The last time a new (non-retransmitted) packet was sent for this
683 // connection.
684 QuicTime time_of_last_sent_new_packet_;
686 // Sequence number of the last packet guaranteed to be sent in packet sequence
687 // number order. Not set when packets are queued, since that may cause
688 // re-ordering.
689 QuicPacketSequenceNumber sequence_number_of_last_inorder_packet_;
691 // Sent packet manager which tracks the status of packets sent by this
692 // connection and contains the send and receive algorithms to determine when
693 // to send packets.
694 QuicSentPacketManager sent_packet_manager_;
696 // The state of connection in version negotiation finite state machine.
697 QuicVersionNegotiationState version_negotiation_state_;
699 // Tracks if the connection was created by the server.
700 bool is_server_;
702 // True by default. False if we've received or sent an explicit connection
703 // close.
704 bool connected_;
706 // Set to true if the udp packet headers have a new self or peer address.
707 // This is checked later on validating a data or version negotiation packet.
708 bool address_migrating_;
710 // If non-empty this contains the set of versions received in a
711 // version negotiation packet.
712 QuicVersionVector server_supported_versions_;
714 DISALLOW_COPY_AND_ASSIGN(QuicConnection);
717 } // namespace net
719 #endif // NET_QUIC_QUIC_CONNECTION_H_