| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // The entity that handles framing writes for a Quic client or server. | 5 // The entity that handles framing writes for a Quic client or server. |
| 6 // Each QuicSession will have a connection associated with it. | 6 // Each QuicSession will have a connection associated with it. |
| 7 // | 7 // |
| 8 // On the server side, the Dispatcher handles the raw reads, and hands off | 8 // On the server side, the Dispatcher handles the raw reads, and hands off |
| 9 // packets via ProcessUdpPacket for framing and processing. | 9 // packets via ProcessUdpPacket for framing and processing. |
| 10 // | 10 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include <set> | 23 #include <set> |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/containers/hash_tables.h" | 26 #include "base/containers/hash_tables.h" |
| 27 #include "net/base/ip_endpoint.h" | 27 #include "net/base/ip_endpoint.h" |
| 28 #include "net/base/linked_hash_map.h" | 28 #include "net/base/linked_hash_map.h" |
| 29 #include "net/quic/congestion_control/quic_congestion_manager.h" | 29 #include "net/quic/congestion_control/quic_congestion_manager.h" |
| 30 #include "net/quic/quic_blocked_writer_interface.h" | 30 #include "net/quic/quic_blocked_writer_interface.h" |
| 31 #include "net/quic/quic_framer.h" | 31 #include "net/quic/quic_framer.h" |
| 32 #include "net/quic/quic_packet_creator.h" | 32 #include "net/quic/quic_packet_creator.h" |
| 33 #include "net/quic/quic_packet_entropy_manager.h" | |
| 34 #include "net/quic/quic_packet_generator.h" | 33 #include "net/quic/quic_packet_generator.h" |
| 35 #include "net/quic/quic_protocol.h" | 34 #include "net/quic/quic_protocol.h" |
| 35 #include "net/quic/quic_received_entropy_manager.h" |
| 36 #include "net/quic/quic_sent_entropy_manager.h" |
| 36 #include "net/quic/quic_stats.h" | 37 #include "net/quic/quic_stats.h" |
| 37 | 38 |
| 38 namespace net { | 39 namespace net { |
| 39 | 40 |
| 40 class QuicClock; | 41 class QuicClock; |
| 41 class QuicConnection; | 42 class QuicConnection; |
| 42 class QuicFecGroup; | 43 class QuicFecGroup; |
| 43 class QuicRandom; | 44 class QuicRandom; |
| 44 | 45 |
| 45 namespace test { | 46 namespace test { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 int rv) = 0; | 95 int rv) = 0; |
| 95 | 96 |
| 96 // Called when a packet has been received, but before it is | 97 // Called when a packet has been received, but before it is |
| 97 // validated or parsed. | 98 // validated or parsed. |
| 98 virtual void OnPacketReceived(const IPEndPoint& self_address, | 99 virtual void OnPacketReceived(const IPEndPoint& self_address, |
| 99 const IPEndPoint& peer_address, | 100 const IPEndPoint& peer_address, |
| 100 const QuicEncryptedPacket& packet) = 0; | 101 const QuicEncryptedPacket& packet) = 0; |
| 101 | 102 |
| 102 // Called when the protocol version on the received packet doensn't match | 103 // Called when the protocol version on the received packet doensn't match |
| 103 // current protocol version of the connection. | 104 // current protocol version of the connection. |
| 104 virtual void OnProtocolVersionMismatch(QuicTag version) = 0; | 105 virtual void OnProtocolVersionMismatch(QuicVersion version) = 0; |
| 105 | 106 |
| 106 // Called when the complete header of a packet has been parsed. | 107 // Called when the complete header of a packet has been parsed. |
| 107 virtual void OnPacketHeader(const QuicPacketHeader& header) = 0; | 108 virtual void OnPacketHeader(const QuicPacketHeader& header) = 0; |
| 108 | 109 |
| 109 // Called when a StreamFrame has been parsed. | 110 // Called when a StreamFrame has been parsed. |
| 110 virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; | 111 virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; |
| 111 | 112 |
| 112 // Called when a AckFrame has been parsed. | 113 // Called when a AckFrame has been parsed. |
| 113 virtual void OnAckFrame(const QuicAckFrame& frame) = 0; | 114 virtual void OnAckFrame(const QuicAckFrame& frame) = 0; |
| 114 | 115 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 enum RetransmissionType { | 214 enum RetransmissionType { |
| 214 INITIAL_ENCRYPTION_ONLY, | 215 INITIAL_ENCRYPTION_ONLY, |
| 215 ALL_PACKETS | 216 ALL_PACKETS |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 // Constructs a new QuicConnection for the specified |guid| and |address|. | 219 // Constructs a new QuicConnection for the specified |guid| and |address|. |
| 219 // |helper| will be owned by this connection. | 220 // |helper| will be owned by this connection. |
| 220 QuicConnection(QuicGuid guid, | 221 QuicConnection(QuicGuid guid, |
| 221 IPEndPoint address, | 222 IPEndPoint address, |
| 222 QuicConnectionHelperInterface* helper, | 223 QuicConnectionHelperInterface* helper, |
| 223 bool is_server); | 224 bool is_server, |
| 225 QuicVersion version); |
| 224 virtual ~QuicConnection(); | 226 virtual ~QuicConnection(); |
| 225 | 227 |
| 226 static void DeleteEnclosedFrame(QuicFrame* frame); | 228 static void DeleteEnclosedFrame(QuicFrame* frame); |
| 227 | 229 |
| 228 // Send the data payload to the peer. | 230 // Send the data payload to the peer. |
| 229 // Returns a pair with the number of bytes consumed from data, and a boolean | 231 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 230 // indicating if the fin bit was consumed. This does not indicate the data | 232 // indicating if the fin bit was consumed. This does not indicate the data |
| 231 // has been sent on the wire: it may have been turned into a packet and queued | 233 // has been sent on the wire: it may have been turned into a packet and queued |
| 232 // if the socket was unexpectedly blocked. | 234 // if the socket was unexpectedly blocked. |
| 233 QuicConsumedData SendStreamData(QuicStreamId id, | 235 QuicConsumedData SendStreamData(QuicStreamId id, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // Called when the underlying connection becomes writable to allow | 271 // Called when the underlying connection becomes writable to allow |
| 270 // queued writes to happen. Returns false if the socket has become blocked. | 272 // queued writes to happen. Returns false if the socket has become blocked. |
| 271 virtual bool OnCanWrite() OVERRIDE; | 273 virtual bool OnCanWrite() OVERRIDE; |
| 272 | 274 |
| 273 // Do any work which logically would be done in OnPacket but can not be | 275 // Do any work which logically would be done in OnPacket but can not be |
| 274 // safely done until the packet is validated. Returns true if the packet | 276 // safely done until the packet is validated. Returns true if the packet |
| 275 // can be handled, false otherwise. | 277 // can be handled, false otherwise. |
| 276 bool ProcessValidatedPacket(); | 278 bool ProcessValidatedPacket(); |
| 277 | 279 |
| 278 // The version of the protocol this connection is using. | 280 // The version of the protocol this connection is using. |
| 279 QuicTag version() const { return framer_.version(); } | 281 QuicVersion version() const { return framer_.version(); } |
| 280 | 282 |
| 281 // From QuicFramerVisitorInterface | 283 // From QuicFramerVisitorInterface |
| 282 virtual void OnError(QuicFramer* framer) OVERRIDE; | 284 virtual void OnError(QuicFramer* framer) OVERRIDE; |
| 283 virtual bool OnProtocolVersionMismatch(QuicTag received_version) OVERRIDE; | 285 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) OVERRIDE; |
| 284 virtual void OnPacket() OVERRIDE; | 286 virtual void OnPacket() OVERRIDE; |
| 285 virtual void OnPublicResetPacket( | 287 virtual void OnPublicResetPacket( |
| 286 const QuicPublicResetPacket& packet) OVERRIDE; | 288 const QuicPublicResetPacket& packet) OVERRIDE; |
| 287 virtual void OnVersionNegotiationPacket( | 289 virtual void OnVersionNegotiationPacket( |
| 288 const QuicVersionNegotiationPacket& packet) OVERRIDE; | 290 const QuicVersionNegotiationPacket& packet) OVERRIDE; |
| 289 virtual void OnRevivedPacket() OVERRIDE; | 291 virtual void OnRevivedPacket() OVERRIDE; |
| 290 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; | 292 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; |
| 291 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE; | 293 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE; |
| 292 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; | 294 virtual bool OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; |
| 293 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE; | 295 virtual bool OnAckFrame(const QuicAckFrame& frame) OVERRIDE; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 int WritePacketToWire(QuicPacketSequenceNumber sequence_number, | 443 int WritePacketToWire(QuicPacketSequenceNumber sequence_number, |
| 442 EncryptionLevel level, | 444 EncryptionLevel level, |
| 443 const QuicEncryptedPacket& packet, | 445 const QuicEncryptedPacket& packet, |
| 444 int* error); | 446 int* error); |
| 445 | 447 |
| 446 // Make sure an ack we got from our peer is sane. | 448 // Make sure an ack we got from our peer is sane. |
| 447 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); | 449 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); |
| 448 | 450 |
| 449 QuicConnectionHelperInterface* helper() { return helper_.get(); } | 451 QuicConnectionHelperInterface* helper() { return helper_.get(); } |
| 450 | 452 |
| 451 protected: | 453 // Selects and updates the version of the protocol being used by selecting a |
| 454 // version from |available_versions| which is also supported. Returns true if |
| 455 // such a version exists, false otherwise. |
| 456 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
| 457 |
| 452 QuicFramer framer_; | 458 QuicFramer framer_; |
| 453 | 459 |
| 454 private: | 460 private: |
| 455 friend class test::QuicConnectionPeer; | 461 friend class test::QuicConnectionPeer; |
| 456 | 462 |
| 457 // Packets which have not been written to the wire. | 463 // Packets which have not been written to the wire. |
| 458 // Owns the QuicPacket* packet. | 464 // Owns the QuicPacket* packet. |
| 459 struct QueuedPacket { | 465 struct QueuedPacket { |
| 460 QueuedPacket(QuicPacketSequenceNumber sequence_number, | 466 QueuedPacket(QuicPacketSequenceNumber sequence_number, |
| 461 QuicPacket* packet, | 467 QuicPacket* packet, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 typedef linked_hash_map<QuicPacketSequenceNumber, | 518 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 513 RetransmittableFrames*> UnackedPacketMap; | 519 RetransmittableFrames*> UnackedPacketMap; |
| 514 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 520 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
| 515 typedef base::hash_map<QuicPacketSequenceNumber, | 521 typedef base::hash_map<QuicPacketSequenceNumber, |
| 516 RetransmissionInfo> RetransmissionMap; | 522 RetransmissionInfo> RetransmissionMap; |
| 517 typedef std::priority_queue<RetransmissionTime, | 523 typedef std::priority_queue<RetransmissionTime, |
| 518 std::vector<RetransmissionTime>, | 524 std::vector<RetransmissionTime>, |
| 519 RetransmissionTimeComparator> | 525 RetransmissionTimeComparator> |
| 520 RetransmissionTimeouts; | 526 RetransmissionTimeouts; |
| 521 | 527 |
| 522 // Selects and updates the version of the protocol being used by selecting a | |
| 523 // version from |available_versions| which is also supported. Returns true if | |
| 524 // such a version exists, false otherwise. | |
| 525 bool SelectMutualVersion(const QuicTagVector& available_versions); | |
| 526 // Sends a version negotiation packet to the peer. | 528 // Sends a version negotiation packet to the peer. |
| 527 void SendVersionNegotiationPacket(); | 529 void SendVersionNegotiationPacket(); |
| 528 | 530 |
| 529 void SetupRetransmission(QuicPacketSequenceNumber sequence_number, | 531 void SetupRetransmission(QuicPacketSequenceNumber sequence_number, |
| 530 EncryptionLevel level); | 532 EncryptionLevel level); |
| 531 bool IsRetransmission(QuicPacketSequenceNumber sequence_number); | 533 bool IsRetransmission(QuicPacketSequenceNumber sequence_number); |
| 532 | 534 |
| 533 void SetupAbandonFecTimer(QuicPacketSequenceNumber sequence_number); | 535 void SetupAbandonFecTimer(QuicPacketSequenceNumber sequence_number); |
| 534 | 536 |
| 535 // Drop packet corresponding to |sequence_number| by deleting entries from | 537 // Drop packet corresponding to |sequence_number| by deleting entries from |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 // When packets could not be sent because the socket was not writable, | 646 // When packets could not be sent because the socket was not writable, |
| 645 // they are added to this list. All corresponding frames are in | 647 // they are added to this list. All corresponding frames are in |
| 646 // unacked_packets_ if they are to be retransmitted. | 648 // unacked_packets_ if they are to be retransmitted. |
| 647 QueuedPacketList queued_packets_; | 649 QueuedPacketList queued_packets_; |
| 648 | 650 |
| 649 // True when the socket becomes unwritable. | 651 // True when the socket becomes unwritable. |
| 650 bool write_blocked_; | 652 bool write_blocked_; |
| 651 | 653 |
| 652 FecGroupMap group_map_; | 654 FecGroupMap group_map_; |
| 653 | 655 |
| 654 QuicPacketEntropyManager entropy_manager_; | 656 QuicReceivedEntropyManager received_entropy_manager_; |
| 657 QuicSentEntropyManager sent_entropy_manager_; |
| 655 | 658 |
| 656 QuicConnectionVisitorInterface* visitor_; | 659 QuicConnectionVisitorInterface* visitor_; |
| 657 QuicConnectionDebugVisitorInterface* debug_visitor_; | 660 QuicConnectionDebugVisitorInterface* debug_visitor_; |
| 658 QuicPacketCreator packet_creator_; | 661 QuicPacketCreator packet_creator_; |
| 659 QuicPacketGenerator packet_generator_; | 662 QuicPacketGenerator packet_generator_; |
| 660 | 663 |
| 661 // Network idle time before we kill of this connection. | 664 // Network idle time before we kill of this connection. |
| 662 QuicTime::Delta idle_network_timeout_; | 665 QuicTime::Delta idle_network_timeout_; |
| 663 // Overall connection timeout. | 666 // Overall connection timeout. |
| 664 QuicTime::Delta overall_connection_timeout_; | 667 QuicTime::Delta overall_connection_timeout_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 // Set to true if the udp packet headers have a new self or peer address. | 705 // Set to true if the udp packet headers have a new self or peer address. |
| 703 // This is checked later on validating a data or version negotiation packet. | 706 // This is checked later on validating a data or version negotiation packet. |
| 704 bool address_migrating_; | 707 bool address_migrating_; |
| 705 | 708 |
| 706 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 709 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
| 707 }; | 710 }; |
| 708 | 711 |
| 709 } // namespace net | 712 } // namespace net |
| 710 | 713 |
| 711 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 714 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
| OLD | NEW |