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