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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 // Return the id of the cipher of the primary decrypter of the framer. | 629 // Return the id of the cipher of the primary decrypter of the framer. |
630 uint32_t cipher_id() const { return framer_.decrypter()->cipher_id(); } | 630 uint32_t cipher_id() const { return framer_.decrypter()->cipher_id(); } |
631 | 631 |
632 std::vector<QuicEncryptedPacket*>* termination_packets() { | 632 std::vector<QuicEncryptedPacket*>* termination_packets() { |
633 return termination_packets_.get(); | 633 return termination_packets_.get(); |
634 } | 634 } |
635 | 635 |
636 bool ack_frame_updated() const; | 636 bool ack_frame_updated() const; |
637 | 637 |
638 protected: | 638 protected: |
639 // Packets which have not been written to the wire. | |
640 struct QueuedPacket { | |
641 explicit QueuedPacket(SerializedPacket packet); | |
642 QueuedPacket(SerializedPacket packet, | |
643 TransmissionType transmission_type, | |
644 QuicPacketNumber original_packet_number); | |
645 | |
646 SerializedPacket serialized_packet; | |
647 TransmissionType transmission_type; | |
648 // The packet's original packet number if it is a retransmission. | |
649 // Otherwise it must be 0. | |
650 QuicPacketNumber original_packet_number; | |
651 }; | |
652 | |
653 // Do any work which logically would be done in OnPacket but can not be | 639 // Do any work which logically would be done in OnPacket but can not be |
654 // safely done until the packet is validated. Returns true if the packet | 640 // safely done until the packet is validated. Returns true if the packet |
655 // can be handled, false otherwise. Also migrates the connection if the packet | 641 // can be handled, false otherwise. Also migrates the connection if the packet |
656 // can be handled and peer address changes. | 642 // can be handled and peer address changes. |
657 virtual bool ProcessValidatedPacket(const QuicPacketHeader& header); | 643 virtual bool ProcessValidatedPacket(const QuicPacketHeader& header); |
658 | 644 |
659 // Send a packet to the peer, and takes ownership of the packet if the packet | 645 // Send a packet to the peer, and takes ownership of the packet if the packet |
660 // cannot be written immediately. | 646 // cannot be written immediately. |
661 virtual void SendOrQueuePacket(QueuedPacket packet); | 647 virtual void SendOrQueuePacket(SerializedPacket* packet); |
662 | 648 |
663 QuicConnectionHelperInterface* helper() { return helper_; } | 649 QuicConnectionHelperInterface* helper() { return helper_; } |
664 | 650 |
665 // On peer address changes, determine and return the change type. | 651 // On peer address changes, determine and return the change type. |
666 virtual PeerAddressChangeType DeterminePeerAddressChangeType(); | 652 virtual PeerAddressChangeType DeterminePeerAddressChangeType(); |
667 | 653 |
668 // Selects and updates the version of the protocol being used by selecting a | 654 // Selects and updates the version of the protocol being used by selecting a |
669 // version from |available_versions| which is also supported. Returns true if | 655 // version from |available_versions| which is also supported. Returns true if |
670 // such a version exists, false otherwise. | 656 // such a version exists, false otherwise. |
671 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 657 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
672 | 658 |
673 bool peer_ip_changed() const { return peer_ip_changed_; } | 659 bool peer_ip_changed() const { return peer_ip_changed_; } |
674 | 660 |
675 bool peer_port_changed() const { return peer_port_changed_; } | 661 bool peer_port_changed() const { return peer_port_changed_; } |
676 | 662 |
677 const IPAddressNumber& migrating_peer_ip() const { | 663 const IPAddressNumber& migrating_peer_ip() const { |
678 return migrating_peer_ip_; | 664 return migrating_peer_ip_; |
679 } | 665 } |
680 | 666 |
681 private: | 667 private: |
682 friend class test::QuicConnectionPeer; | 668 friend class test::QuicConnectionPeer; |
683 friend class test::PacketSavingConnection; | 669 friend class test::PacketSavingConnection; |
684 | 670 |
685 typedef std::list<QueuedPacket> QueuedPacketList; | 671 typedef std::list<SerializedPacket> QueuedPacketList; |
686 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 672 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
687 | 673 |
688 // Writes the given packet to socket, encrypted with packet's | 674 // Writes the given packet to socket, encrypted with packet's |
689 // encryption_level. Returns true on successful write, and false if the writer | 675 // encryption_level. Returns true on successful write, and false if the writer |
690 // was blocked and the write needs to be tried again. Notifies the | 676 // was blocked and the write needs to be tried again. Notifies the |
691 // SentPacketManager when the write is successful and sets | 677 // SentPacketManager when the write is successful and sets |
692 // retransmittable frames to nullptr. | 678 // retransmittable frames to nullptr. |
693 // Saves the connection close packet for later transmission, even if the | 679 // Saves the connection close packet for later transmission, even if the |
694 // writer is write blocked. | 680 // writer is write blocked. |
695 bool WritePacket(QueuedPacket* packet); | 681 bool WritePacket(SerializedPacket* packet); |
696 | 682 |
697 // Does the main work of WritePacket, but does not delete the packet or | 683 // Does the main work of WritePacket, but does not delete the packet or |
698 // retransmittable frames upon success. | 684 // retransmittable frames upon success. |
699 bool WritePacketInner(QueuedPacket* packet); | 685 bool WritePacketInner(SerializedPacket* packet); |
700 | 686 |
701 // Make sure an ack we got from our peer is sane. | 687 // Make sure an ack we got from our peer is sane. |
702 // Returns nullptr for valid acks or an error std::string if it was invalid. | 688 // Returns nullptr for valid acks or an error std::string if it was invalid. |
703 const char* ValidateAckFrame(const QuicAckFrame& incoming_ack); | 689 const char* ValidateAckFrame(const QuicAckFrame& incoming_ack); |
704 | 690 |
705 // Make sure a stop waiting we got from our peer is sane. | 691 // Make sure a stop waiting we got from our peer is sane. |
706 // Returns nullptr if the frame is valid or an error std::string if it was | 692 // Returns nullptr if the frame is valid or an error std::string if it was |
707 // invalid. | 693 // invalid. |
708 const char* ValidateStopWaitingFrame( | 694 const char* ValidateStopWaitingFrame( |
709 const QuicStopWaitingFrame& stop_waiting); | 695 const QuicStopWaitingFrame& stop_waiting); |
710 | 696 |
711 // Sends a version negotiation packet to the peer. | 697 // Sends a version negotiation packet to the peer. |
712 void SendVersionNegotiationPacket(); | 698 void SendVersionNegotiationPacket(); |
713 | 699 |
714 // Clears any accumulated frames from the last received packet. | 700 // Clears any accumulated frames from the last received packet. |
715 void ClearLastFrames(); | 701 void ClearLastFrames(); |
716 | 702 |
717 // Deletes and clears any QueuedPackets. | 703 // Deletes and clears any queued packets. |
718 void ClearQueuedPackets(); | 704 void ClearQueuedPackets(); |
719 | 705 |
720 // Closes the connection if the sent or received packet manager are tracking | 706 // Closes the connection if the sent or received packet manager are tracking |
721 // too many outstanding packets. | 707 // too many outstanding packets. |
722 void MaybeCloseIfTooManyOutstandingPackets(); | 708 void MaybeCloseIfTooManyOutstandingPackets(); |
723 | 709 |
724 // Writes as many queued packets as possible. The connection must not be | 710 // Writes as many queued packets as possible. The connection must not be |
725 // blocked when this is called. | 711 // blocked when this is called. |
726 void WriteQueuedPackets(); | 712 void WriteQueuedPackets(); |
727 | 713 |
728 // Writes as many pending retransmissions as possible. | 714 // Writes as many pending retransmissions as possible. |
729 void WritePendingRetransmissions(); | 715 void WritePendingRetransmissions(); |
730 | 716 |
731 // Returns true if the packet should be discarded and not sent. | 717 // Returns true if the packet should be discarded and not sent. |
732 bool ShouldDiscardPacket(const QueuedPacket& packet); | 718 bool ShouldDiscardPacket(const SerializedPacket& packet); |
733 | 719 |
734 // Queues |packet| in the hopes that it can be decrypted in the | 720 // Queues |packet| in the hopes that it can be decrypted in the |
735 // future, when a new key is installed. | 721 // future, when a new key is installed. |
736 void QueueUndecryptablePacket(const QuicEncryptedPacket& packet); | 722 void QueueUndecryptablePacket(const QuicEncryptedPacket& packet); |
737 | 723 |
738 // Attempts to process any queued undecryptable packets. | 724 // Attempts to process any queued undecryptable packets. |
739 void MaybeProcessUndecryptablePackets(); | 725 void MaybeProcessUndecryptablePackets(); |
740 | 726 |
741 // If a packet can be revived from the current FEC group, then | 727 // If a packet can be revived from the current FEC group, then |
742 // revive and process the packet. | 728 // revive and process the packet. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 void SetRetransmissionAlarm(); | 761 void SetRetransmissionAlarm(); |
776 | 762 |
777 // Sets the MTU discovery alarm if necessary. | 763 // Sets the MTU discovery alarm if necessary. |
778 void MaybeSetMtuAlarm(); | 764 void MaybeSetMtuAlarm(); |
779 | 765 |
780 // On arrival of a new packet, checks to see if the socket addresses have | 766 // On arrival of a new packet, checks to see if the socket addresses have |
781 // changed since the last packet we saw on this connection. | 767 // changed since the last packet we saw on this connection. |
782 void CheckForAddressMigration(const IPEndPoint& self_address, | 768 void CheckForAddressMigration(const IPEndPoint& self_address, |
783 const IPEndPoint& peer_address); | 769 const IPEndPoint& peer_address); |
784 | 770 |
785 HasRetransmittableData IsRetransmittable(const QueuedPacket& packet); | 771 HasRetransmittableData IsRetransmittable(const SerializedPacket& packet); |
786 bool IsTerminationPacket(const QueuedPacket& packet); | 772 bool IsTerminationPacket(const SerializedPacket& packet); |
787 | 773 |
788 // Set the size of the packet we are targeting while doing path MTU discovery. | 774 // Set the size of the packet we are targeting while doing path MTU discovery. |
789 void SetMtuDiscoveryTarget(QuicByteCount target); | 775 void SetMtuDiscoveryTarget(QuicByteCount target); |
790 | 776 |
791 // Validates the potential maximum packet size, and reduces it if it exceeds | 777 // Validates the potential maximum packet size, and reduces it if it exceeds |
792 // the largest supported by the protocol or the packet writer. | 778 // the largest supported by the protocol or the packet writer. |
793 QuicByteCount LimitMaxPacketSize(QuicByteCount suggested_max_packet_size); | 779 QuicByteCount LimitMaxPacketSize(QuicByteCount suggested_max_packet_size); |
794 | 780 |
795 QuicFramer framer_; | 781 QuicFramer framer_; |
796 QuicConnectionHelperInterface* helper_; // Not owned. | 782 QuicConnectionHelperInterface* helper_; // Not owned. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 | 979 |
994 // Whether a GoAway has been received. | 980 // Whether a GoAway has been received. |
995 bool goaway_received_; | 981 bool goaway_received_; |
996 | 982 |
997 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 983 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
998 }; | 984 }; |
999 | 985 |
1000 } // namespace net | 986 } // namespace net |
1001 | 987 |
1002 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 988 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |