| 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 virtual void OnVersionNegotiationPacket( | 197 virtual void OnVersionNegotiationPacket( |
| 198 const QuicVersionNegotiationPacket& packet) {} | 198 const QuicVersionNegotiationPacket& packet) {} |
| 199 | 199 |
| 200 // Called after a packet has been successfully parsed which results | 200 // Called after a packet has been successfully parsed which results |
| 201 // in the revival of a packet via FEC. | 201 // in the revival of a packet via FEC. |
| 202 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header, | 202 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header, |
| 203 base::StringPiece payload) {} | 203 base::StringPiece payload) {} |
| 204 | 204 |
| 205 // Called when the connection is closed. | 205 // Called when the connection is closed. |
| 206 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) {} | 206 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) {} |
| 207 |
| 208 // Called when the version negotiation is successful. |
| 209 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) {} |
| 207 }; | 210 }; |
| 208 | 211 |
| 209 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { | 212 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { |
| 210 public: | 213 public: |
| 211 virtual ~QuicConnectionHelperInterface() {} | 214 virtual ~QuicConnectionHelperInterface() {} |
| 212 | 215 |
| 213 // Returns a QuicClock to be used for all time related functions. | 216 // Returns a QuicClock to be used for all time related functions. |
| 214 virtual const QuicClock* GetClock() const = 0; | 217 virtual const QuicClock* GetClock() const = 0; |
| 215 | 218 |
| 216 // Returns a QuicRandom to be used for all random number related functions. | 219 // Returns a QuicRandom to be used for all random number related functions. |
| 217 virtual QuicRandom* GetRandomGenerator() = 0; | 220 virtual QuicRandom* GetRandomGenerator() = 0; |
| 218 | 221 |
| 219 // Creates a new platform-specific alarm which will be configured to | 222 // Creates a new platform-specific alarm which will be configured to |
| 220 // notify |delegate| when the alarm fires. Caller takes ownership | 223 // notify |delegate| when the alarm fires. Caller takes ownership |
| 221 // of the new alarm, which will not yet be "set" to fire. | 224 // of the new alarm, which will not yet be "set" to fire. |
| 222 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; | 225 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; |
| 223 }; | 226 }; |
| 224 | 227 |
| 225 class NET_EXPORT_PRIVATE QuicConnection | 228 class NET_EXPORT_PRIVATE QuicConnection |
| 226 : public QuicFramerVisitorInterface, | 229 : public QuicFramerVisitorInterface, |
| 227 public QuicBlockedWriterInterface, | 230 public QuicBlockedWriterInterface, |
| 228 public QuicPacketGenerator::DelegateInterface, | 231 public QuicPacketGenerator::DelegateInterface, |
| 229 public QuicSentPacketManager::NetworkChangeVisitor { | 232 public QuicSentPacketManager::NetworkChangeVisitor { |
| 230 public: | 233 public: |
| 231 enum PacketType { | |
| 232 NORMAL, | |
| 233 QUEUED, | |
| 234 CONNECTION_CLOSE | |
| 235 }; | |
| 236 | |
| 237 enum AckBundling { | 234 enum AckBundling { |
| 238 NO_ACK = 0, | 235 NO_ACK = 0, |
| 239 SEND_ACK = 1, | 236 SEND_ACK = 1, |
| 240 BUNDLE_PENDING_ACK = 2, | 237 BUNDLE_PENDING_ACK = 2, |
| 241 }; | 238 }; |
| 242 | 239 |
| 243 class PacketWriterFactory { | 240 class PacketWriterFactory { |
| 244 public: | 241 public: |
| 245 virtual ~PacketWriterFactory() {} | 242 virtual ~PacketWriterFactory() {} |
| 246 | 243 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 private: | 557 private: |
| 561 friend class test::QuicConnectionPeer; | 558 friend class test::QuicConnectionPeer; |
| 562 | 559 |
| 563 // Packets which have not been written to the wire. | 560 // Packets which have not been written to the wire. |
| 564 // Owns the QuicPacket* packet. | 561 // Owns the QuicPacket* packet. |
| 565 struct QueuedPacket { | 562 struct QueuedPacket { |
| 566 QueuedPacket(SerializedPacket packet, | 563 QueuedPacket(SerializedPacket packet, |
| 567 EncryptionLevel level, | 564 EncryptionLevel level, |
| 568 TransmissionType transmission_type); | 565 TransmissionType transmission_type); |
| 569 | 566 |
| 570 QuicPacketSequenceNumber sequence_number; | 567 SerializedPacket serialized_packet; |
| 571 QuicPacket* packet; | |
| 572 const EncryptionLevel encryption_level; | 568 const EncryptionLevel encryption_level; |
| 573 TransmissionType transmission_type; | 569 TransmissionType transmission_type; |
| 574 HasRetransmittableData retransmittable; | |
| 575 IsHandshake handshake; | |
| 576 PacketType type; | |
| 577 QuicByteCount length; | |
| 578 }; | 570 }; |
| 579 | 571 |
| 580 typedef std::list<QueuedPacket> QueuedPacketList; | 572 typedef std::list<QueuedPacket> QueuedPacketList; |
| 581 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 573 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
| 582 | 574 |
| 583 // Writes the given packet to socket, encrypted with packet's | 575 // Writes the given packet to socket, encrypted with packet's |
| 584 // encryption_level. Returns true on successful write. Behavior is undefined | 576 // encryption_level. Returns true on successful write, and false if the writer |
| 585 // if connection is not established or broken. A return value of true means | 577 // was blocked and the write needs to be tried again. Behavior is undefined |
| 586 // the packet was transmitted and may be destroyed. If the packet is | 578 // if connection is not established or broken. Notifies the SentPacketManager |
| 587 // retransmittable, WritePacket sets up retransmission for a successful write. | 579 // when the write is successful. |
| 588 // If packet is FORCE, then it will be sent immediately and the send scheduler | 580 // Saves the connection close packet for later transmission, even if the |
| 589 // will not be consulted. | 581 // writer is write blocked. |
| 590 bool WritePacket(QueuedPacket packet); | 582 bool WritePacket(const QueuedPacket& packet); |
| 591 | 583 |
| 592 // Make sure an ack we got from our peer is sane. | 584 // Make sure an ack we got from our peer is sane. |
| 593 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); | 585 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); |
| 594 | 586 |
| 595 // Make sure a stop waiting we got from our peer is sane. | 587 // Make sure a stop waiting we got from our peer is sane. |
| 596 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); | 588 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); |
| 597 | 589 |
| 598 // Sends a version negotiation packet to the peer. | 590 // Sends a version negotiation packet to the peer. |
| 599 void SendVersionNegotiationPacket(); | 591 void SendVersionNegotiationPacket(); |
| 600 | 592 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number); | 650 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number); |
| 659 | 651 |
| 660 // Sets the ping alarm to the appropriate value, if any. | 652 // Sets the ping alarm to the appropriate value, if any. |
| 661 void SetPingAlarm(); | 653 void SetPingAlarm(); |
| 662 | 654 |
| 663 // On arrival of a new packet, checks to see if the socket addresses have | 655 // On arrival of a new packet, checks to see if the socket addresses have |
| 664 // changed since the last packet we saw on this connection. | 656 // changed since the last packet we saw on this connection. |
| 665 void CheckForAddressMigration(const IPEndPoint& self_address, | 657 void CheckForAddressMigration(const IPEndPoint& self_address, |
| 666 const IPEndPoint& peer_address); | 658 const IPEndPoint& peer_address); |
| 667 | 659 |
| 660 HasRetransmittableData IsRetransmittable(QueuedPacket packet); |
| 661 bool IsConnectionClose(QueuedPacket packet); |
| 662 |
| 668 QuicFramer framer_; | 663 QuicFramer framer_; |
| 669 QuicConnectionHelperInterface* helper_; // Not owned. | 664 QuicConnectionHelperInterface* helper_; // Not owned. |
| 670 QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. | 665 QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. |
| 671 bool owns_writer_; | 666 bool owns_writer_; |
| 672 EncryptionLevel encryption_level_; | 667 EncryptionLevel encryption_level_; |
| 673 const QuicClock* clock_; | 668 const QuicClock* clock_; |
| 674 QuicRandom* random_generator_; | 669 QuicRandom* random_generator_; |
| 675 | 670 |
| 676 const QuicConnectionId connection_id_; | 671 const QuicConnectionId connection_id_; |
| 677 // Address on the last successfully processed packet received from the | 672 // Address on the last successfully processed packet received from the |
| 678 // client. | 673 // client. |
| 679 IPEndPoint self_address_; | 674 IPEndPoint self_address_; |
| 680 IPEndPoint peer_address_; | 675 IPEndPoint peer_address_; |
| 681 // Used to store latest peer port to possibly migrate to later. | 676 // Used to store latest peer port to possibly migrate to later. |
| 682 int migrating_peer_port_; | 677 int migrating_peer_port_; |
| 683 | 678 |
| 684 bool last_packet_revived_; // True if the last packet was revived from FEC. | 679 bool last_packet_revived_; // True if the last packet was revived from FEC. |
| 685 size_t last_size_; // Size of the last received packet. | 680 size_t last_size_; // Size of the last received packet. |
| 686 EncryptionLevel last_decrypted_packet_level_; | 681 EncryptionLevel last_decrypted_packet_level_; |
| 687 QuicPacketHeader last_header_; | 682 QuicPacketHeader last_header_; |
| 688 std::vector<QuicStreamFrame> last_stream_frames_; | 683 std::vector<QuicStreamFrame> last_stream_frames_; |
| 689 std::vector<QuicAckFrame> last_ack_frames_; | 684 std::vector<QuicAckFrame> last_ack_frames_; |
| 690 std::vector<QuicCongestionFeedbackFrame> last_congestion_frames_; | 685 std::vector<QuicCongestionFeedbackFrame> last_congestion_frames_; |
| 691 std::vector<QuicStopWaitingFrame> last_stop_waiting_frames_; | 686 std::vector<QuicStopWaitingFrame> last_stop_waiting_frames_; |
| 692 std::vector<QuicRstStreamFrame> last_rst_frames_; | 687 std::vector<QuicRstStreamFrame> last_rst_frames_; |
| 693 std::vector<QuicGoAwayFrame> last_goaway_frames_; | 688 std::vector<QuicGoAwayFrame> last_goaway_frames_; |
| 694 std::vector<QuicWindowUpdateFrame> last_window_update_frames_; | 689 std::vector<QuicWindowUpdateFrame> last_window_update_frames_; |
| 695 std::vector<QuicBlockedFrame> last_blocked_frames_; | 690 std::vector<QuicBlockedFrame> last_blocked_frames_; |
| 691 std::vector<QuicPingFrame> last_ping_frames_; |
| 696 std::vector<QuicConnectionCloseFrame> last_close_frames_; | 692 std::vector<QuicConnectionCloseFrame> last_close_frames_; |
| 697 | 693 |
| 698 QuicCongestionFeedbackFrame outgoing_congestion_feedback_; | 694 QuicCongestionFeedbackFrame outgoing_congestion_feedback_; |
| 699 | 695 |
| 700 // Track some peer state so we can do less bookkeeping | 696 // Track some peer state so we can do less bookkeeping |
| 701 // Largest sequence sent by the peer which had an ack frame (latest ack info). | 697 // Largest sequence sent by the peer which had an ack frame (latest ack info). |
| 702 QuicPacketSequenceNumber largest_seen_packet_with_ack_; | 698 QuicPacketSequenceNumber largest_seen_packet_with_ack_; |
| 703 | 699 |
| 704 // Largest sequence number sent by the peer which had a stop waiting frame. | 700 // Largest sequence number sent by the peer which had a stop waiting frame. |
| 705 QuicPacketSequenceNumber largest_seen_packet_with_stop_waiting_; | 701 QuicPacketSequenceNumber largest_seen_packet_with_stop_waiting_; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 // If non-empty this contains the set of versions received in a | 802 // If non-empty this contains the set of versions received in a |
| 807 // version negotiation packet. | 803 // version negotiation packet. |
| 808 QuicVersionVector server_supported_versions_; | 804 QuicVersionVector server_supported_versions_; |
| 809 | 805 |
| 810 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 806 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
| 811 }; | 807 }; |
| 812 | 808 |
| 813 } // namespace net | 809 } // namespace net |
| 814 | 810 |
| 815 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 811 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
| OLD | NEW |