| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 QuicConnectionHelperInterface* helper, | 250 QuicConnectionHelperInterface* helper, |
| 251 const PacketWriterFactory& writer_factory, | 251 const PacketWriterFactory& writer_factory, |
| 252 bool owns_writer, | 252 bool owns_writer, |
| 253 bool is_server, | 253 bool is_server, |
| 254 const QuicVersionVector& supported_versions); | 254 const QuicVersionVector& supported_versions); |
| 255 ~QuicConnection() override; | 255 ~QuicConnection() override; |
| 256 | 256 |
| 257 // Sets connection parameters from the supplied |config|. | 257 // Sets connection parameters from the supplied |config|. |
| 258 void SetFromConfig(const QuicConfig& config); | 258 void SetFromConfig(const QuicConfig& config); |
| 259 | 259 |
| 260 // Sets the number of active streams on the connection for congestion control. |
| 261 void SetNumOpenStreams(size_t num_streams); |
| 262 |
| 260 // Send the data in |data| to the peer in as few packets as possible. | 263 // Send the data in |data| to the peer in as few packets as possible. |
| 261 // Returns a pair with the number of bytes consumed from data, and a boolean | 264 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 262 // indicating if the fin bit was consumed. This does not indicate the data | 265 // indicating if the fin bit was consumed. This does not indicate the data |
| 263 // has been sent on the wire: it may have been turned into a packet and queued | 266 // has been sent on the wire: it may have been turned into a packet and queued |
| 264 // if the socket was unexpectedly blocked. |fec_protection| indicates if | 267 // if the socket was unexpectedly blocked. |fec_protection| indicates if |
| 265 // data is to be FEC protected. Note that data that is sent immediately | 268 // data is to be FEC protected. Note that data that is sent immediately |
| 266 // following MUST_FEC_PROTECT data may get protected by falling within the | 269 // following MUST_FEC_PROTECT data may get protected by falling within the |
| 267 // same FEC group. | 270 // same FEC group. |
| 268 // If |delegate| is provided, then it will be informed once ACKs have been | 271 // If |delegate| is provided, then it will be informed once ACKs have been |
| 269 // received for all the packets written in this call. | 272 // received for all the packets written in this call. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // QuicPacketGenerator::DelegateInterface | 368 // QuicPacketGenerator::DelegateInterface |
| 366 bool ShouldGeneratePacket(TransmissionType transmission_type, | 369 bool ShouldGeneratePacket(TransmissionType transmission_type, |
| 367 HasRetransmittableData retransmittable, | 370 HasRetransmittableData retransmittable, |
| 368 IsHandshake handshake) override; | 371 IsHandshake handshake) override; |
| 369 QuicAckFrame* CreateAckFrame() override; | 372 QuicAckFrame* CreateAckFrame() override; |
| 370 QuicCongestionFeedbackFrame* CreateFeedbackFrame() override; | 373 QuicCongestionFeedbackFrame* CreateFeedbackFrame() override; |
| 371 QuicStopWaitingFrame* CreateStopWaitingFrame() override; | 374 QuicStopWaitingFrame* CreateStopWaitingFrame() override; |
| 372 void OnSerializedPacket(const SerializedPacket& packet) override; | 375 void OnSerializedPacket(const SerializedPacket& packet) override; |
| 373 | 376 |
| 374 // QuicSentPacketManager::NetworkChangeVisitor | 377 // QuicSentPacketManager::NetworkChangeVisitor |
| 375 void OnCongestionWindowChange(QuicByteCount congestion_window) override; | 378 void OnCongestionWindowChange() override; |
| 376 | 379 |
| 377 // Called by the crypto stream when the handshake completes. In the server's | 380 // Called by the crypto stream when the handshake completes. In the server's |
| 378 // case this is when the SHLO has been ACKed. Clients call this on receipt of | 381 // case this is when the SHLO has been ACKed. Clients call this on receipt of |
| 379 // the SHLO. | 382 // the SHLO. |
| 380 void OnHandshakeComplete(); | 383 void OnHandshakeComplete(); |
| 381 | 384 |
| 382 // Accessors | 385 // Accessors |
| 383 void set_visitor(QuicConnectionVisitorInterface* visitor) { | 386 void set_visitor(QuicConnectionVisitorInterface* visitor) { |
| 384 visitor_ = visitor; | 387 visitor_ = visitor; |
| 385 } | 388 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 // blocked. | 422 // blocked. |
| 420 bool CanWriteStreamData(); | 423 bool CanWriteStreamData(); |
| 421 | 424 |
| 422 // Returns true if the connection has queued packets or frames. | 425 // Returns true if the connection has queued packets or frames. |
| 423 bool HasQueuedData() const; | 426 bool HasQueuedData() const; |
| 424 | 427 |
| 425 // TODO(ianswett): Remove when quic_unified_timeouts is removed. | 428 // TODO(ianswett): Remove when quic_unified_timeouts is removed. |
| 426 // Sets (or resets) the idle state connection timeout. Also, checks and times | 429 // Sets (or resets) the idle state connection timeout. Also, checks and times |
| 427 // out the connection if network timer has expired for |timeout|. | 430 // out the connection if network timer has expired for |timeout|. |
| 428 void SetIdleNetworkTimeout(QuicTime::Delta timeout); | 431 void SetIdleNetworkTimeout(QuicTime::Delta timeout); |
| 432 |
| 429 // Sets (or resets) the total time delta the connection can be alive for. | 433 // Sets (or resets) the total time delta the connection can be alive for. |
| 430 // Also, checks and times out the connection if timer has expired for | 434 // Also, checks and times out the connection if timer has expired for |
| 431 // |timeout|. Used to limit the time a connection can be alive before crypto | 435 // |timeout|. Used to limit the time a connection can be alive before crypto |
| 432 // handshake finishes. | 436 // handshake finishes. |
| 433 void SetOverallConnectionTimeout(QuicTime::Delta timeout); | 437 void SetOverallConnectionTimeout(QuicTime::Delta timeout); |
| 434 | 438 |
| 435 // Sets the overall and idle state connection timeouts. | 439 // Sets the overall and idle state connection timeouts. |
| 436 // Times out the connection if the timeout has been reached and | 440 // Times out the connection if the timeout has been reached and |
| 437 // the quic_timeouts_only_from_alarms flag is false. | 441 // the quic_timeouts_only_from_alarms flag is false. |
| 438 void SetNetworkTimeouts(QuicTime::Delta overall_timeout, | 442 void SetNetworkTimeouts(QuicTime::Delta overall_timeout, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 // an ACK frame is opportunistically bundled with the first | 523 // an ACK frame is opportunistically bundled with the first |
| 520 // outgoing packet. | 524 // outgoing packet. |
| 521 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); | 525 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); |
| 522 ~ScopedPacketBundler(); | 526 ~ScopedPacketBundler(); |
| 523 | 527 |
| 524 private: | 528 private: |
| 525 QuicConnection* connection_; | 529 QuicConnection* connection_; |
| 526 bool already_in_batch_mode_; | 530 bool already_in_batch_mode_; |
| 527 }; | 531 }; |
| 528 | 532 |
| 533 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { |
| 534 return sequence_number_of_last_sent_packet_; |
| 535 } |
| 536 |
| 529 protected: | 537 protected: |
| 530 // Packets which have not been written to the wire. | 538 // Packets which have not been written to the wire. |
| 531 // Owns the QuicPacket* packet. | 539 // Owns the QuicPacket* packet. |
| 532 struct QueuedPacket { | 540 struct QueuedPacket { |
| 533 QueuedPacket(SerializedPacket packet, | 541 QueuedPacket(SerializedPacket packet, |
| 534 EncryptionLevel level); | 542 EncryptionLevel level); |
| 535 QueuedPacket(SerializedPacket packet, | 543 QueuedPacket(SerializedPacket packet, |
| 536 EncryptionLevel level, | 544 EncryptionLevel level, |
| 537 TransmissionType transmission_type, | 545 TransmissionType transmission_type, |
| 538 QuicPacketSequenceNumber original_sequence_number); | 546 QuicPacketSequenceNumber original_sequence_number); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 559 // Selects and updates the version of the protocol being used by selecting a | 567 // Selects and updates the version of the protocol being used by selecting a |
| 560 // version from |available_versions| which is also supported. Returns true if | 568 // version from |available_versions| which is also supported. Returns true if |
| 561 // such a version exists, false otherwise. | 569 // such a version exists, false otherwise. |
| 562 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 570 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
| 563 | 571 |
| 564 QuicPacketWriter* writer() { return writer_; } | 572 QuicPacketWriter* writer() { return writer_; } |
| 565 const QuicPacketWriter* writer() const { return writer_; } | 573 const QuicPacketWriter* writer() const { return writer_; } |
| 566 | 574 |
| 567 bool peer_port_changed() const { return peer_port_changed_; } | 575 bool peer_port_changed() const { return peer_port_changed_; } |
| 568 | 576 |
| 569 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { | |
| 570 return sequence_number_of_last_sent_packet_; | |
| 571 } | |
| 572 | |
| 573 private: | 577 private: |
| 574 friend class test::QuicConnectionPeer; | 578 friend class test::QuicConnectionPeer; |
| 575 friend class test::PacketSavingConnection; | 579 friend class test::PacketSavingConnection; |
| 576 | 580 |
| 577 typedef std::list<QueuedPacket> QueuedPacketList; | 581 typedef std::list<QueuedPacket> QueuedPacketList; |
| 578 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 582 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
| 579 | 583 |
| 580 // Writes the given packet to socket, encrypted with packet's | 584 // Writes the given packet to socket, encrypted with packet's |
| 581 // encryption_level. Returns true on successful write, and false if the writer | 585 // encryption_level. Returns true on successful write, and false if the writer |
| 582 // was blocked and the write needs to be tried again. Notifies the | 586 // was blocked and the write needs to be tried again. Notifies the |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 void CheckForAddressMigration(const IPEndPoint& self_address, | 675 void CheckForAddressMigration(const IPEndPoint& self_address, |
| 672 const IPEndPoint& peer_address); | 676 const IPEndPoint& peer_address); |
| 673 | 677 |
| 674 HasRetransmittableData IsRetransmittable(const QueuedPacket& packet); | 678 HasRetransmittableData IsRetransmittable(const QueuedPacket& packet); |
| 675 bool IsConnectionClose(QueuedPacket packet); | 679 bool IsConnectionClose(QueuedPacket packet); |
| 676 | 680 |
| 677 QuicFramer framer_; | 681 QuicFramer framer_; |
| 678 QuicConnectionHelperInterface* helper_; // Not owned. | 682 QuicConnectionHelperInterface* helper_; // Not owned. |
| 679 QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. | 683 QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. |
| 680 bool owns_writer_; | 684 bool owns_writer_; |
| 685 // Encryption level for new packets. Should only be changed via |
| 686 // SetDefaultEncryptionLevel(). |
| 681 EncryptionLevel encryption_level_; | 687 EncryptionLevel encryption_level_; |
| 688 bool has_forward_secure_encrypter_; |
| 689 // The sequence number of the first packet which will be encrypted with the |
| 690 // foward-secure encrypter, even if the peer has not started sending |
| 691 // forward-secure packets. |
| 692 QuicPacketSequenceNumber first_required_forward_secure_packet_; |
| 682 const QuicClock* clock_; | 693 const QuicClock* clock_; |
| 683 QuicRandom* random_generator_; | 694 QuicRandom* random_generator_; |
| 684 | 695 |
| 685 const QuicConnectionId connection_id_; | 696 const QuicConnectionId connection_id_; |
| 686 // Address on the last successfully processed packet received from the | 697 // Address on the last successfully processed packet received from the |
| 687 // client. | 698 // client. |
| 688 IPEndPoint self_address_; | 699 IPEndPoint self_address_; |
| 689 IPEndPoint peer_address_; | 700 IPEndPoint peer_address_; |
| 690 // Used to store latest peer port to possibly migrate to later. | 701 // Used to store latest peer port to possibly migrate to later. |
| 691 int migrating_peer_port_; | 702 int migrating_peer_port_; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 // If non-empty this contains the set of versions received in a | 839 // If non-empty this contains the set of versions received in a |
| 829 // version negotiation packet. | 840 // version negotiation packet. |
| 830 QuicVersionVector server_supported_versions_; | 841 QuicVersionVector server_supported_versions_; |
| 831 | 842 |
| 832 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 843 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
| 833 }; | 844 }; |
| 834 | 845 |
| 835 } // namespace net | 846 } // namespace net |
| 836 | 847 |
| 837 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 848 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
| OLD | NEW |