| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 virtual QuicBufferAllocator* GetBufferAllocator() = 0; | 289 virtual QuicBufferAllocator* GetBufferAllocator() = 0; |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 class NET_EXPORT_PRIVATE QuicConnection | 292 class NET_EXPORT_PRIVATE QuicConnection |
| 293 : public QuicFramerVisitorInterface, | 293 : public QuicFramerVisitorInterface, |
| 294 public QuicBlockedWriterInterface, | 294 public QuicBlockedWriterInterface, |
| 295 public QuicPacketGenerator::DelegateInterface, | 295 public QuicPacketGenerator::DelegateInterface, |
| 296 public QuicSentPacketManager::NetworkChangeVisitor { | 296 public QuicSentPacketManager::NetworkChangeVisitor { |
| 297 public: | 297 public: |
| 298 enum AckBundling { | 298 enum AckBundling { |
| 299 NO_ACK = 0, | 299 // Send an ack if it's already queued in the connection. |
| 300 SEND_ACK = 1, | 300 SEND_ACK_IF_QUEUED, |
| 301 BUNDLE_PENDING_ACK = 2, | 301 // Always send an ack. |
| 302 SEND_ACK, |
| 303 // Bundle an ack with outgoing data. |
| 304 SEND_ACK_IF_PENDING, |
| 302 }; | 305 }; |
| 303 | 306 |
| 304 enum AckMode { TCP_ACKING, ACK_DECIMATION, ACK_DECIMATION_WITH_REORDERING }; | 307 enum AckMode { TCP_ACKING, ACK_DECIMATION, ACK_DECIMATION_WITH_REORDERING }; |
| 305 | 308 |
| 306 // Constructs a new QuicConnection for |connection_id| and |address| using | 309 // Constructs a new QuicConnection for |connection_id| and |address| using |
| 307 // |writer| to write packets. |owns_writer| specifies whether the connection | 310 // |writer| to write packets. |owns_writer| specifies whether the connection |
| 308 // takes ownership of |writer|. |helper| must outlive this connection. | 311 // takes ownership of |writer|. |helper| must outlive this connection. |
| 309 QuicConnection(QuicConnectionId connection_id, | 312 QuicConnection(QuicConnectionId connection_id, |
| 310 IPEndPoint address, | 313 IPEndPoint address, |
| 311 QuicConnectionHelperInterface* helper, | 314 QuicConnectionHelperInterface* helper, |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; | 452 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
| 450 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 453 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
| 451 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; | 454 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
| 452 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; | 455 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override; |
| 453 void OnPacketComplete() override; | 456 void OnPacketComplete() override; |
| 454 | 457 |
| 455 // QuicPacketGenerator::DelegateInterface | 458 // QuicPacketGenerator::DelegateInterface |
| 456 bool ShouldGeneratePacket(HasRetransmittableData retransmittable, | 459 bool ShouldGeneratePacket(HasRetransmittableData retransmittable, |
| 457 IsHandshake handshake) override; | 460 IsHandshake handshake) override; |
| 458 void PopulateAckFrame(QuicAckFrame* ack) override; | 461 void PopulateAckFrame(QuicAckFrame* ack) override; |
| 462 const QuicFrame GetUpdatedAckFrame() override; |
| 459 void PopulateStopWaitingFrame(QuicStopWaitingFrame* stop_waiting) override; | 463 void PopulateStopWaitingFrame(QuicStopWaitingFrame* stop_waiting) override; |
| 460 | 464 |
| 461 // QuicPacketCreator::DelegateInterface | 465 // QuicPacketCreator::DelegateInterface |
| 462 void OnSerializedPacket(SerializedPacket* packet) override; | 466 void OnSerializedPacket(SerializedPacket* packet) override; |
| 463 void OnUnrecoverableError(QuicErrorCode error, | 467 void OnUnrecoverableError(QuicErrorCode error, |
| 464 ConnectionCloseSource source) override; | 468 ConnectionCloseSource source) override; |
| 465 | 469 |
| 466 // QuicSentPacketManager::NetworkChangeVisitor | 470 // QuicSentPacketManager::NetworkChangeVisitor |
| 467 void OnCongestionWindowChange() override; | 471 void OnCongestionWindowChange() override; |
| 468 void OnRttChange() override; | 472 void OnRttChange() override; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 class NET_EXPORT_PRIVATE ScopedPacketBundler { | 610 class NET_EXPORT_PRIVATE ScopedPacketBundler { |
| 607 public: | 611 public: |
| 608 // In addition to all outgoing frames being bundled when the | 612 // In addition to all outgoing frames being bundled when the |
| 609 // bundler is in scope, setting |include_ack| to true ensures that | 613 // bundler is in scope, setting |include_ack| to true ensures that |
| 610 // an ACK frame is opportunistically bundled with the first | 614 // an ACK frame is opportunistically bundled with the first |
| 611 // outgoing packet. | 615 // outgoing packet. |
| 612 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); | 616 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); |
| 613 ~ScopedPacketBundler(); | 617 ~ScopedPacketBundler(); |
| 614 | 618 |
| 615 private: | 619 private: |
| 620 bool ShouldSendAck(AckBundling ack_mode) const; |
| 621 |
| 616 QuicConnection* connection_; | 622 QuicConnection* connection_; |
| 617 bool already_in_batch_mode_; | 623 bool already_in_batch_mode_; |
| 618 }; | 624 }; |
| 619 | 625 |
| 620 // Delays setting the retransmission alarm until the scope is exited. | 626 // Delays setting the retransmission alarm until the scope is exited. |
| 621 // When nested, only the outermost scheduler will set the alarm, and inner | 627 // When nested, only the outermost scheduler will set the alarm, and inner |
| 622 // ones have no effect. | 628 // ones have no effect. |
| 623 class NET_EXPORT_PRIVATE ScopedRetransmissionScheduler { | 629 class NET_EXPORT_PRIVATE ScopedRetransmissionScheduler { |
| 624 public: | 630 public: |
| 625 explicit ScopedRetransmissionScheduler(QuicConnection* connection); | 631 explicit ScopedRetransmissionScheduler(QuicConnection* connection); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 650 | 656 |
| 651 // Return the name of the cipher of the primary decrypter of the framer. | 657 // Return the name of the cipher of the primary decrypter of the framer. |
| 652 const char* cipher_name() const { return framer_.decrypter()->cipher_name(); } | 658 const char* cipher_name() const { return framer_.decrypter()->cipher_name(); } |
| 653 // Return the id of the cipher of the primary decrypter of the framer. | 659 // Return the id of the cipher of the primary decrypter of the framer. |
| 654 uint32_t cipher_id() const { return framer_.decrypter()->cipher_id(); } | 660 uint32_t cipher_id() const { return framer_.decrypter()->cipher_id(); } |
| 655 | 661 |
| 656 std::vector<QuicEncryptedPacket*>* termination_packets() { | 662 std::vector<QuicEncryptedPacket*>* termination_packets() { |
| 657 return termination_packets_.get(); | 663 return termination_packets_.get(); |
| 658 } | 664 } |
| 659 | 665 |
| 666 bool ack_queued() const { return ack_queued_; } |
| 667 |
| 660 bool ack_frame_updated() const; | 668 bool ack_frame_updated() const; |
| 661 | 669 |
| 662 QuicConnectionHelperInterface* helper() { return helper_; } | 670 QuicConnectionHelperInterface* helper() { return helper_; } |
| 663 | 671 |
| 664 base::StringPiece GetCurrentPacket(); | 672 base::StringPiece GetCurrentPacket(); |
| 665 | 673 |
| 666 protected: | 674 protected: |
| 667 // Send a packet to the peer, and takes ownership of the packet if the packet | 675 // Send a packet to the peer, and takes ownership of the packet if the packet |
| 668 // cannot be written immediately. | 676 // cannot be written immediately. |
| 669 virtual void SendOrQueuePacket(SerializedPacket* packet); | 677 virtual void SendOrQueuePacket(SerializedPacket* packet); |
| 670 | 678 |
| 671 // Migrate the connection if peer address changes. This function should only | 679 // Migrate the connection if peer address changes. This function should only |
| 672 // be called after the packet is validated. | 680 // be called after the packet is validated. |
| 673 virtual void MaybeMigrateConnectionToNewPeerAddress(); | 681 virtual void MaybeMigrateConnectionToNewPeerAddress(); |
| 674 | 682 |
| 675 // Selects and updates the version of the protocol being used by selecting a | 683 // Selects and updates the version of the protocol being used by selecting a |
| 676 // version from |available_versions| which is also supported. Returns true if | 684 // version from |available_versions| which is also supported. Returns true if |
| 677 // such a version exists, false otherwise. | 685 // such a version exists, false otherwise. |
| 678 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 686 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
| 679 | 687 |
| 680 bool peer_ip_changed() const { return peer_ip_changed_; } | |
| 681 | |
| 682 bool peer_port_changed() const { return peer_port_changed_; } | |
| 683 | |
| 684 const IPAddress& migrating_peer_ip() const { return migrating_peer_ip_; } | |
| 685 | |
| 686 uint16_t migrating_peer_port() const { return migrating_peer_port_; } | |
| 687 | |
| 688 const IPEndPoint& last_packet_source_address() const { | 688 const IPEndPoint& last_packet_source_address() const { |
| 689 return last_packet_source_address_; | 689 return last_packet_source_address_; |
| 690 } | 690 } |
| 691 | 691 |
| 692 // Returns the current per-packet options for the connection. | 692 // Returns the current per-packet options for the connection. |
| 693 PerPacketOptions* per_packet_options() { return per_packet_options_; } | 693 PerPacketOptions* per_packet_options() { return per_packet_options_; } |
| 694 // Sets the current per-packet options for the connection. The QuicConnection | 694 // Sets the current per-packet options for the connection. The QuicConnection |
| 695 // does not take ownership of |options|; |options| must live for as long as | 695 // does not take ownership of |options|; |options| must live for as long as |
| 696 // the QuicConnection is in use. | 696 // the QuicConnection is in use. |
| 697 void set_per_packet_options(PerPacketOptions* options) { | 697 void set_per_packet_options(PerPacketOptions* options) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 QuicPacketNumber first_required_forward_secure_packet_; | 832 QuicPacketNumber first_required_forward_secure_packet_; |
| 833 const QuicClock* clock_; | 833 const QuicClock* clock_; |
| 834 QuicRandom* random_generator_; | 834 QuicRandom* random_generator_; |
| 835 | 835 |
| 836 const QuicConnectionId connection_id_; | 836 const QuicConnectionId connection_id_; |
| 837 // Address on the last successfully processed packet received from the | 837 // Address on the last successfully processed packet received from the |
| 838 // client. | 838 // client. |
| 839 IPEndPoint self_address_; | 839 IPEndPoint self_address_; |
| 840 IPEndPoint peer_address_; | 840 IPEndPoint peer_address_; |
| 841 | 841 |
| 842 // Used to store latest peer IP address for IP address migration. | |
| 843 IPAddress migrating_peer_ip_; | |
| 844 // Used to store latest peer port to possibly migrate to later. | |
| 845 uint16_t migrating_peer_port_; | |
| 846 | |
| 847 // True if the last packet has gotten far enough in the framer to be | 842 // True if the last packet has gotten far enough in the framer to be |
| 848 // decrypted. | 843 // decrypted. |
| 849 bool last_packet_decrypted_; | 844 bool last_packet_decrypted_; |
| 850 QuicByteCount last_size_; // Size of the last received packet. | 845 QuicByteCount last_size_; // Size of the last received packet. |
| 851 // TODO(rch): remove this when b/27221014 is fixed. | 846 // TODO(rch): remove this when b/27221014 is fixed. |
| 852 const char* current_packet_data_; // UDP payload of packet currently being | 847 const char* current_packet_data_; // UDP payload of packet currently being |
| 853 // parsed or nullptr. | 848 // parsed or nullptr. |
| 854 EncryptionLevel last_decrypted_packet_level_; | 849 EncryptionLevel last_decrypted_packet_level_; |
| 855 QuicPacketHeader last_header_; | 850 QuicPacketHeader last_header_; |
| 856 QuicStopWaitingFrame last_stop_waiting_frame_; | 851 QuicStopWaitingFrame last_stop_waiting_frame_; |
| 857 bool should_last_packet_instigate_acks_; | 852 bool should_last_packet_instigate_acks_; |
| 858 | 853 |
| 859 // Track some peer state so we can do less bookkeeping | 854 // Track some peer state so we can do less bookkeeping |
| 860 // Largest sequence sent by the peer which had an ack frame (latest ack info). | 855 // Largest sequence sent by the peer which had an ack frame (latest ack info). |
| (...skipping 26 matching lines...) Expand all Loading... |
| 887 bool save_crypto_packets_as_termination_packets_; | 882 bool save_crypto_packets_as_termination_packets_; |
| 888 | 883 |
| 889 // Contains the connection close packets if the connection has been closed. | 884 // Contains the connection close packets if the connection has been closed. |
| 890 scoped_ptr<std::vector<QuicEncryptedPacket*>> termination_packets_; | 885 scoped_ptr<std::vector<QuicEncryptedPacket*>> termination_packets_; |
| 891 | 886 |
| 892 // When true, the connection does not send a close packet on idle timeout due | 887 // When true, the connection does not send a close packet on idle timeout due |
| 893 // to lack of network activity. | 888 // to lack of network activity. |
| 894 // This is particularly important on mobile, where connections are short. | 889 // This is particularly important on mobile, where connections are short. |
| 895 bool silent_close_enabled_; | 890 bool silent_close_enabled_; |
| 896 | 891 |
| 892 // When true, close the QUIC connection after 5 RTOs. Due to the min rto of |
| 893 // 200ms, this is over 5 seconds. |
| 894 bool close_connection_after_five_rtos_; |
| 895 |
| 897 QuicReceivedPacketManager received_packet_manager_; | 896 QuicReceivedPacketManager received_packet_manager_; |
| 898 QuicSentEntropyManager sent_entropy_manager_; | 897 QuicSentEntropyManager sent_entropy_manager_; |
| 899 | 898 |
| 900 // Indicates whether an ack should be sent the next time we try to write. | 899 // Indicates whether an ack should be sent the next time we try to write. |
| 901 bool ack_queued_; | 900 bool ack_queued_; |
| 902 // How many retransmittable packets have arrived without sending an ack. | 901 // How many retransmittable packets have arrived without sending an ack. |
| 903 QuicPacketCount num_retransmittable_packets_received_since_last_ack_sent_; | 902 QuicPacketCount num_retransmittable_packets_received_since_last_ack_sent_; |
| 904 // Whether there were missing packets in the last sent ack. | 903 // Whether there were missing packets in the last sent ack. |
| 905 bool last_ack_had_missing_packets_; | 904 bool last_ack_had_missing_packets_; |
| 906 // How many consecutive packets have arrived without sending an ack. | 905 // How many consecutive packets have arrived without sending an ack. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 // The state of connection in version negotiation finite state machine. | 978 // The state of connection in version negotiation finite state machine. |
| 980 QuicVersionNegotiationState version_negotiation_state_; | 979 QuicVersionNegotiationState version_negotiation_state_; |
| 981 | 980 |
| 982 // Tracks if the connection was created by the server or the client. | 981 // Tracks if the connection was created by the server or the client. |
| 983 Perspective perspective_; | 982 Perspective perspective_; |
| 984 | 983 |
| 985 // True by default. False if we've received or sent an explicit connection | 984 // True by default. False if we've received or sent an explicit connection |
| 986 // close. | 985 // close. |
| 987 bool connected_; | 986 bool connected_; |
| 988 | 987 |
| 989 // Set to true if the UDP packet headers have a new IP address for the peer. | |
| 990 bool peer_ip_changed_; | |
| 991 | |
| 992 // Set to true if the UDP packet headers have a new port for the peer. | |
| 993 bool peer_port_changed_; | |
| 994 | |
| 995 // Set to true if the UDP packet headers are addressed to a different IP. | |
| 996 // We do not support connection migration when the self IP changed. | |
| 997 bool self_ip_changed_; | |
| 998 | |
| 999 // Set to true if the UDP packet headers are addressed to a different port. | |
| 1000 // We do not support connection migration when the self port changed. | |
| 1001 bool self_port_changed_; | |
| 1002 | |
| 1003 // Destination address of the last received packet. | 988 // Destination address of the last received packet. |
| 1004 IPEndPoint last_packet_destination_address_; | 989 IPEndPoint last_packet_destination_address_; |
| 1005 | 990 |
| 1006 // Source address of the last received packet. | 991 // Source address of the last received packet. |
| 1007 IPEndPoint last_packet_source_address_; | 992 IPEndPoint last_packet_source_address_; |
| 1008 | 993 |
| 1009 // Set to false if the connection should not send truncated connection IDs to | 994 // Set to false if the connection should not send truncated connection IDs to |
| 1010 // the peer, even if the peer supports it. | 995 // the peer, even if the peer supports it. |
| 1011 bool can_truncate_connection_ids_; | 996 bool can_truncate_connection_ids_; |
| 1012 | 997 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1038 | 1023 |
| 1039 // If true, multipath is enabled for this connection. | 1024 // If true, multipath is enabled for this connection. |
| 1040 bool multipath_enabled_; | 1025 bool multipath_enabled_; |
| 1041 | 1026 |
| 1042 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 1027 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
| 1043 }; | 1028 }; |
| 1044 | 1029 |
| 1045 } // namespace net | 1030 } // namespace net |
| 1046 | 1031 |
| 1047 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 1032 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
| OLD | NEW |