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 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 const QuicVersionVector& server_supported_versions() const { | 472 const QuicVersionVector& server_supported_versions() const { |
473 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); | 473 DCHECK_EQ(Perspective::IS_CLIENT, perspective_); |
474 return server_supported_versions_; | 474 return server_supported_versions_; |
475 } | 475 } |
476 | 476 |
477 size_t NumFecGroups() const { return group_map_.size(); } | 477 size_t NumFecGroups() const { return group_map_.size(); } |
478 | 478 |
479 // Testing only. | 479 // Testing only. |
480 size_t NumQueuedPackets() const { return queued_packets_.size(); } | 480 size_t NumQueuedPackets() const { return queued_packets_.size(); } |
481 | 481 |
482 QuicEncryptedPacket* ReleaseConnectionClosePacket() { | 482 // Once called, any sent crypto packets to be saved as the |
483 return connection_close_packet_.release(); | 483 // termination packet, for use with stateless rejections. |
484 } | 484 void EnableSavingCryptoPackets(); |
485 | 485 |
486 // Returns true if the underlying UDP socket is writable, there is | 486 // Returns true if the underlying UDP socket is writable, there is |
487 // no queued data and the connection is not congestion-control | 487 // no queued data and the connection is not congestion-control |
488 // blocked. | 488 // blocked. |
489 bool CanWriteStreamData(); | 489 bool CanWriteStreamData(); |
490 | 490 |
491 // Returns true if the connection has queued packets or frames. | 491 // Returns true if the connection has queued packets or frames. |
492 bool HasQueuedData() const; | 492 bool HasQueuedData() const; |
493 | 493 |
494 // Sets the overall and idle state connection timeouts. | 494 // Sets the overall and idle state connection timeouts. |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 | 615 |
616 // Sends an MTU discovery packet of size |mtu_discovery_target_| and updates | 616 // Sends an MTU discovery packet of size |mtu_discovery_target_| and updates |
617 // the MTU discovery alarm. | 617 // the MTU discovery alarm. |
618 void DiscoverMtu(); | 618 void DiscoverMtu(); |
619 | 619 |
620 // Return the name of the cipher of the primary decrypter of the framer. | 620 // Return the name of the cipher of the primary decrypter of the framer. |
621 const char* cipher_name() const { return framer_.decrypter()->cipher_name(); } | 621 const char* cipher_name() const { return framer_.decrypter()->cipher_name(); } |
622 // Return the id of the cipher of the primary decrypter of the framer. | 622 // Return the id of the cipher of the primary decrypter of the framer. |
623 uint32 cipher_id() const { return framer_.decrypter()->cipher_id(); } | 623 uint32 cipher_id() const { return framer_.decrypter()->cipher_id(); } |
624 | 624 |
| 625 std::vector<QuicEncryptedPacket*>* termination_packets() { |
| 626 return termination_packets_.get(); |
| 627 } |
| 628 |
625 protected: | 629 protected: |
626 // Packets which have not been written to the wire. | 630 // Packets which have not been written to the wire. |
627 // Owns the QuicPacket* packet. | 631 // Owns the QuicPacket* packet. |
628 struct QueuedPacket { | 632 struct QueuedPacket { |
629 QueuedPacket(SerializedPacket packet, | 633 QueuedPacket(SerializedPacket packet, |
630 EncryptionLevel level); | 634 EncryptionLevel level); |
631 QueuedPacket(SerializedPacket packet, | 635 QueuedPacket(SerializedPacket packet, |
632 EncryptionLevel level, | 636 EncryptionLevel level, |
633 TransmissionType transmission_type, | 637 TransmissionType transmission_type, |
634 QuicPacketNumber original_packet_number); | 638 QuicPacketNumber original_packet_number); |
(...skipping 10 matching lines...) Expand all Loading... |
645 // safely done until the packet is validated. Returns true if the packet | 649 // safely done until the packet is validated. Returns true if the packet |
646 // can be handled, false otherwise. | 650 // can be handled, false otherwise. |
647 virtual bool ProcessValidatedPacket(); | 651 virtual bool ProcessValidatedPacket(); |
648 | 652 |
649 // Send a packet to the peer, and takes ownership of the packet if the packet | 653 // Send a packet to the peer, and takes ownership of the packet if the packet |
650 // cannot be written immediately. | 654 // cannot be written immediately. |
651 virtual void SendOrQueuePacket(QueuedPacket packet); | 655 virtual void SendOrQueuePacket(QueuedPacket packet); |
652 | 656 |
653 QuicConnectionHelperInterface* helper() { return helper_; } | 657 QuicConnectionHelperInterface* helper() { return helper_; } |
654 | 658 |
| 659 // On peer address changes, determine and return the change type. |
| 660 virtual PeerAddressChangeType DeterminePeerAddressChangeType(); |
| 661 |
655 // Selects and updates the version of the protocol being used by selecting a | 662 // Selects and updates the version of the protocol being used by selecting a |
656 // version from |available_versions| which is also supported. Returns true if | 663 // version from |available_versions| which is also supported. Returns true if |
657 // such a version exists, false otherwise. | 664 // such a version exists, false otherwise. |
658 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 665 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
659 | 666 |
660 bool peer_ip_changed() const { return peer_ip_changed_; } | 667 bool peer_ip_changed() const { return peer_ip_changed_; } |
661 | 668 |
662 bool peer_port_changed() const { return peer_port_changed_; } | 669 bool peer_port_changed() const { return peer_port_changed_; } |
663 | 670 |
| 671 const IPAddressNumber& migrating_peer_ip() const { |
| 672 return migrating_peer_ip_; |
| 673 } |
| 674 |
664 private: | 675 private: |
665 friend class test::QuicConnectionPeer; | 676 friend class test::QuicConnectionPeer; |
666 friend class test::PacketSavingConnection; | 677 friend class test::PacketSavingConnection; |
667 | 678 |
668 typedef std::list<QueuedPacket> QueuedPacketList; | 679 typedef std::list<QueuedPacket> QueuedPacketList; |
669 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 680 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
670 | 681 |
671 // Writes the given packet to socket, encrypted with packet's | 682 // Writes the given packet to socket, encrypted with packet's |
672 // encryption_level. Returns true on successful write, and false if the writer | 683 // encryption_level. Returns true on successful write, and false if the writer |
673 // was blocked and the write needs to be tried again. Notifies the | 684 // was blocked and the write needs to be tried again. Notifies the |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 | 769 |
759 // Sets the MTU discovery alarm if necessary. | 770 // Sets the MTU discovery alarm if necessary. |
760 void MaybeSetMtuAlarm(); | 771 void MaybeSetMtuAlarm(); |
761 | 772 |
762 // On arrival of a new packet, checks to see if the socket addresses have | 773 // On arrival of a new packet, checks to see if the socket addresses have |
763 // changed since the last packet we saw on this connection. | 774 // changed since the last packet we saw on this connection. |
764 void CheckForAddressMigration(const IPEndPoint& self_address, | 775 void CheckForAddressMigration(const IPEndPoint& self_address, |
765 const IPEndPoint& peer_address); | 776 const IPEndPoint& peer_address); |
766 | 777 |
767 HasRetransmittableData IsRetransmittable(const QueuedPacket& packet); | 778 HasRetransmittableData IsRetransmittable(const QueuedPacket& packet); |
768 bool IsConnectionClose(const QueuedPacket& packet); | 779 bool IsTerminationPacket(const QueuedPacket& packet); |
769 | 780 |
770 // Set the size of the packet we are targeting while doing path MTU discovery. | 781 // Set the size of the packet we are targeting while doing path MTU discovery. |
771 void SetMtuDiscoveryTarget(QuicByteCount target); | 782 void SetMtuDiscoveryTarget(QuicByteCount target); |
772 | 783 |
773 // Validates the potential maximum packet size, and reduces it if it exceeds | 784 // Validates the potential maximum packet size, and reduces it if it exceeds |
774 // the largest supported by the protocol or the packet writer. | 785 // the largest supported by the protocol or the packet writer. |
775 QuicByteCount LimitMaxPacketSize(QuicByteCount suggested_max_packet_size); | 786 QuicByteCount LimitMaxPacketSize(QuicByteCount suggested_max_packet_size); |
776 | 787 |
777 QuicFramer framer_; | 788 QuicFramer framer_; |
778 QuicConnectionHelperInterface* helper_; // Not owned. | 789 QuicConnectionHelperInterface* helper_; // Not owned. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 839 |
829 // When the version negotiation packet could not be sent because the socket | 840 // When the version negotiation packet could not be sent because the socket |
830 // was not writable, this is set to true. | 841 // was not writable, this is set to true. |
831 bool pending_version_negotiation_packet_; | 842 bool pending_version_negotiation_packet_; |
832 | 843 |
833 // When packets could not be sent because the socket was not writable, | 844 // When packets could not be sent because the socket was not writable, |
834 // they are added to this list. All corresponding frames are in | 845 // they are added to this list. All corresponding frames are in |
835 // unacked_packets_ if they are to be retransmitted. | 846 // unacked_packets_ if they are to be retransmitted. |
836 QueuedPacketList queued_packets_; | 847 QueuedPacketList queued_packets_; |
837 | 848 |
838 // Contains the connection close packet if the connection has been closed. | 849 // If true, then crypto packets will be saved as termination packets. |
839 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; | 850 bool save_crypto_packets_as_termination_packets_; |
| 851 |
| 852 // Contains the connection close packets if the connection has been closed. |
| 853 scoped_ptr<std::vector<QuicEncryptedPacket*>> termination_packets_; |
840 | 854 |
841 // When true, the connection does not send a close packet on timeout. | 855 // When true, the connection does not send a close packet on timeout. |
842 bool silent_close_enabled_; | 856 bool silent_close_enabled_; |
843 | 857 |
844 FecGroupMap group_map_; | 858 FecGroupMap group_map_; |
845 | 859 |
846 QuicReceivedPacketManager received_packet_manager_; | 860 QuicReceivedPacketManager received_packet_manager_; |
847 QuicSentEntropyManager sent_entropy_manager_; | 861 QuicSentEntropyManager sent_entropy_manager_; |
848 | 862 |
849 // Indicates whether an ack should be sent the next time we try to write. | 863 // Indicates whether an ack should be sent the next time we try to write. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 | 978 |
965 // Whether a GoAway has been received. | 979 // Whether a GoAway has been received. |
966 bool goaway_received_; | 980 bool goaway_received_; |
967 | 981 |
968 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 982 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
969 }; | 983 }; |
970 | 984 |
971 } // namespace net | 985 } // namespace net |
972 | 986 |
973 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 987 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |