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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Constructs a new QuicConnection for |connection_id| and |address|. Invokes | 244 // Constructs a new QuicConnection for |connection_id| and |address|. Invokes |
245 // writer_factory->Create() to get a writer; |owns_writer| specifies whether | 245 // writer_factory->Create() to get a writer; |owns_writer| specifies whether |
246 // the connection takes ownership of the returned writer. |helper| must | 246 // the connection takes ownership of the returned writer. |helper| must |
247 // outlive this connection. | 247 // outlive this connection. |
248 QuicConnection(QuicConnectionId connection_id, | 248 QuicConnection(QuicConnectionId connection_id, |
249 IPEndPoint address, | 249 IPEndPoint address, |
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 bool is_secure, |
254 const QuicVersionVector& supported_versions); | 255 const QuicVersionVector& supported_versions); |
255 ~QuicConnection() override; | 256 ~QuicConnection() override; |
256 | 257 |
257 // Sets connection parameters from the supplied |config|. | 258 // Sets connection parameters from the supplied |config|. |
258 void SetFromConfig(const QuicConfig& config); | 259 void SetFromConfig(const QuicConfig& config); |
259 | 260 |
260 // Sets the number of active streams on the connection for congestion control. | 261 // Sets the number of active streams on the connection for congestion control. |
261 void SetNumOpenStreams(size_t num_streams); | 262 void SetNumOpenStreams(size_t num_streams); |
262 | 263 |
263 // Send the data in |data| to the peer in as few packets as possible. | 264 // Send the data in |data| to the peer in as few packets as possible. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 void set_debug_visitor(QuicConnectionDebugVisitor* debug_visitor) { | 391 void set_debug_visitor(QuicConnectionDebugVisitor* debug_visitor) { |
391 debug_visitor_.reset(debug_visitor); | 392 debug_visitor_.reset(debug_visitor); |
392 packet_generator_.set_debug_delegate(debug_visitor); | 393 packet_generator_.set_debug_delegate(debug_visitor); |
393 sent_packet_manager_.set_debug_delegate(debug_visitor); | 394 sent_packet_manager_.set_debug_delegate(debug_visitor); |
394 } | 395 } |
395 const IPEndPoint& self_address() const { return self_address_; } | 396 const IPEndPoint& self_address() const { return self_address_; } |
396 const IPEndPoint& peer_address() const { return peer_address_; } | 397 const IPEndPoint& peer_address() const { return peer_address_; } |
397 QuicConnectionId connection_id() const { return connection_id_; } | 398 QuicConnectionId connection_id() const { return connection_id_; } |
398 const QuicClock* clock() const { return clock_; } | 399 const QuicClock* clock() const { return clock_; } |
399 QuicRandom* random_generator() const { return random_generator_; } | 400 QuicRandom* random_generator() const { return random_generator_; } |
400 size_t max_packet_length() const; | 401 QuicByteCount max_packet_length() const; |
401 void set_max_packet_length(size_t length); | 402 void set_max_packet_length(QuicByteCount length); |
402 | 403 |
403 bool connected() const { return connected_; } | 404 bool connected() const { return connected_; } |
404 | 405 |
405 // Must only be called on client connections. | 406 // Must only be called on client connections. |
406 const QuicVersionVector& server_supported_versions() const { | 407 const QuicVersionVector& server_supported_versions() const { |
407 DCHECK(!is_server_); | 408 DCHECK(!is_server_); |
408 return server_supported_versions_; | 409 return server_supported_versions_; |
409 } | 410 } |
410 | 411 |
411 size_t NumFecGroups() const { return group_map_.size(); } | 412 size_t NumFecGroups() const { return group_map_.size(); } |
412 | 413 |
413 // Testing only. | 414 // Testing only. |
414 size_t NumQueuedPackets() const { return queued_packets_.size(); } | 415 size_t NumQueuedPackets() const { return queued_packets_.size(); } |
415 | 416 |
416 QuicEncryptedPacket* ReleaseConnectionClosePacket() { | 417 QuicEncryptedPacket* ReleaseConnectionClosePacket() { |
417 return connection_close_packet_.release(); | 418 return connection_close_packet_.release(); |
418 } | 419 } |
419 | 420 |
420 // Returns true if the underlying UDP socket is writable, there is | 421 // Returns true if the underlying UDP socket is writable, there is |
421 // no queued data and the connection is not congestion-control | 422 // no queued data and the connection is not congestion-control |
422 // blocked. | 423 // blocked. |
423 bool CanWriteStreamData(); | 424 bool CanWriteStreamData(); |
424 | 425 |
425 // Returns true if the connection has queued packets or frames. | 426 // Returns true if the connection has queued packets or frames. |
426 bool HasQueuedData() const; | 427 bool HasQueuedData() const; |
427 | 428 |
428 // TODO(ianswett): Remove when quic_unified_timeouts is removed. | |
429 // Sets (or resets) the idle state connection timeout. Also, checks and times | |
430 // out the connection if network timer has expired for |timeout|. | |
431 void SetIdleNetworkTimeout(QuicTime::Delta timeout); | |
432 | |
433 // Sets (or resets) the total time delta the connection can be alive for. | |
434 // Used to limit the time a connection can be alive before crypto handshake | |
435 // finishes. | |
436 void SetOverallConnectionTimeout(QuicTime::Delta timeout); | |
437 | |
438 // Sets the overall and idle state connection timeouts. | 429 // Sets the overall and idle state connection timeouts. |
439 void SetNetworkTimeouts(QuicTime::Delta overall_timeout, | 430 void SetNetworkTimeouts(QuicTime::Delta overall_timeout, |
440 QuicTime::Delta idle_timeout); | 431 QuicTime::Delta idle_timeout); |
441 | 432 |
442 // If the connection has timed out, this will close the connection. | 433 // If the connection has timed out, this will close the connection. |
443 // Otherwise, it will reschedule the timeout alarm. | 434 // Otherwise, it will reschedule the timeout alarm. |
444 void CheckForTimeout(); | 435 void CheckForTimeout(); |
445 | 436 |
446 // Sends a ping, and resets the ping alarm. | 437 // Sends a ping, and resets the ping alarm. |
447 void SendPing(); | 438 void SendPing(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 ~ScopedPacketBundler(); | 514 ~ScopedPacketBundler(); |
524 | 515 |
525 private: | 516 private: |
526 QuicConnection* connection_; | 517 QuicConnection* connection_; |
527 bool already_in_batch_mode_; | 518 bool already_in_batch_mode_; |
528 }; | 519 }; |
529 | 520 |
530 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { | 521 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { |
531 return sequence_number_of_last_sent_packet_; | 522 return sequence_number_of_last_sent_packet_; |
532 } | 523 } |
| 524 const QuicPacketWriter* writer() const { return writer_; } |
| 525 |
| 526 bool is_secure() const { return is_secure_; } |
533 | 527 |
534 protected: | 528 protected: |
535 // Packets which have not been written to the wire. | 529 // Packets which have not been written to the wire. |
536 // Owns the QuicPacket* packet. | 530 // Owns the QuicPacket* packet. |
537 struct QueuedPacket { | 531 struct QueuedPacket { |
538 QueuedPacket(SerializedPacket packet, | 532 QueuedPacket(SerializedPacket packet, |
539 EncryptionLevel level); | 533 EncryptionLevel level); |
540 QueuedPacket(SerializedPacket packet, | 534 QueuedPacket(SerializedPacket packet, |
541 EncryptionLevel level, | 535 EncryptionLevel level, |
542 TransmissionType transmission_type, | 536 TransmissionType transmission_type, |
(...skipping 17 matching lines...) Expand all Loading... |
560 virtual void SendOrQueuePacket(QueuedPacket packet); | 554 virtual void SendOrQueuePacket(QueuedPacket packet); |
561 | 555 |
562 QuicConnectionHelperInterface* helper() { return helper_; } | 556 QuicConnectionHelperInterface* helper() { return helper_; } |
563 | 557 |
564 // Selects and updates the version of the protocol being used by selecting a | 558 // Selects and updates the version of the protocol being used by selecting a |
565 // version from |available_versions| which is also supported. Returns true if | 559 // version from |available_versions| which is also supported. Returns true if |
566 // such a version exists, false otherwise. | 560 // such a version exists, false otherwise. |
567 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 561 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
568 | 562 |
569 QuicPacketWriter* writer() { return writer_; } | 563 QuicPacketWriter* writer() { return writer_; } |
570 const QuicPacketWriter* writer() const { return writer_; } | |
571 | 564 |
572 bool peer_port_changed() const { return peer_port_changed_; } | 565 bool peer_port_changed() const { return peer_port_changed_; } |
573 | 566 |
574 private: | 567 private: |
575 friend class test::QuicConnectionPeer; | 568 friend class test::QuicConnectionPeer; |
576 friend class test::PacketSavingConnection; | 569 friend class test::PacketSavingConnection; |
577 | 570 |
578 typedef std::list<QueuedPacket> QueuedPacketList; | 571 typedef std::list<QueuedPacket> QueuedPacketList; |
579 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 572 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
580 | 573 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // client. | 688 // client. |
696 IPEndPoint self_address_; | 689 IPEndPoint self_address_; |
697 IPEndPoint peer_address_; | 690 IPEndPoint peer_address_; |
698 // Used to store latest peer port to possibly migrate to later. | 691 // Used to store latest peer port to possibly migrate to later. |
699 int migrating_peer_port_; | 692 int migrating_peer_port_; |
700 | 693 |
701 // True if the last packet has gotten far enough in the framer to be | 694 // True if the last packet has gotten far enough in the framer to be |
702 // decrypted. | 695 // decrypted. |
703 bool last_packet_decrypted_; | 696 bool last_packet_decrypted_; |
704 bool last_packet_revived_; // True if the last packet was revived from FEC. | 697 bool last_packet_revived_; // True if the last packet was revived from FEC. |
705 size_t last_size_; // Size of the last received packet. | 698 QuicByteCount last_size_; // Size of the last received packet. |
706 EncryptionLevel last_decrypted_packet_level_; | 699 EncryptionLevel last_decrypted_packet_level_; |
707 QuicPacketHeader last_header_; | 700 QuicPacketHeader last_header_; |
708 std::vector<QuicStreamFrame> last_stream_frames_; | 701 std::vector<QuicStreamFrame> last_stream_frames_; |
709 std::vector<QuicAckFrame> last_ack_frames_; | 702 std::vector<QuicAckFrame> last_ack_frames_; |
710 std::vector<QuicCongestionFeedbackFrame> last_congestion_frames_; | 703 std::vector<QuicCongestionFeedbackFrame> last_congestion_frames_; |
711 std::vector<QuicStopWaitingFrame> last_stop_waiting_frames_; | 704 std::vector<QuicStopWaitingFrame> last_stop_waiting_frames_; |
712 std::vector<QuicRstStreamFrame> last_rst_frames_; | 705 std::vector<QuicRstStreamFrame> last_rst_frames_; |
713 std::vector<QuicGoAwayFrame> last_goaway_frames_; | 706 std::vector<QuicGoAwayFrame> last_goaway_frames_; |
714 std::vector<QuicWindowUpdateFrame> last_window_update_frames_; | 707 std::vector<QuicWindowUpdateFrame> last_window_update_frames_; |
715 std::vector<QuicBlockedFrame> last_blocked_frames_; | 708 std::vector<QuicBlockedFrame> last_blocked_frames_; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 bool self_port_changed_; | 823 bool self_port_changed_; |
831 | 824 |
832 // Set to false if the connection should not send truncated connection IDs to | 825 // Set to false if the connection should not send truncated connection IDs to |
833 // the peer, even if the peer supports it. | 826 // the peer, even if the peer supports it. |
834 bool can_truncate_connection_ids_; | 827 bool can_truncate_connection_ids_; |
835 | 828 |
836 // If non-empty this contains the set of versions received in a | 829 // If non-empty this contains the set of versions received in a |
837 // version negotiation packet. | 830 // version negotiation packet. |
838 QuicVersionVector server_supported_versions_; | 831 QuicVersionVector server_supported_versions_; |
839 | 832 |
| 833 // True if this is a secure QUIC connection. |
| 834 bool is_secure_; |
| 835 |
840 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 836 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
841 }; | 837 }; |
842 | 838 |
843 } // namespace net | 839 } // namespace net |
844 | 840 |
845 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 841 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |