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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 class QuicClock; | 47 class QuicClock; |
48 class QuicConfig; | 48 class QuicConfig; |
49 class QuicConnection; | 49 class QuicConnection; |
50 class QuicDecrypter; | 50 class QuicDecrypter; |
51 class QuicEncrypter; | 51 class QuicEncrypter; |
52 class QuicFecGroup; | 52 class QuicFecGroup; |
53 class QuicRandom; | 53 class QuicRandom; |
54 | 54 |
55 namespace test { | 55 namespace test { |
| 56 class PacketSavingConnection; |
56 class QuicConnectionPeer; | 57 class QuicConnectionPeer; |
57 } // namespace test | 58 } // namespace test |
58 | 59 |
59 // Class that receives callbacks from the connection when frames are received | 60 // Class that receives callbacks from the connection when frames are received |
60 // and when other interesting events happen. | 61 // and when other interesting events happen. |
61 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface { | 62 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface { |
62 public: | 63 public: |
63 virtual ~QuicConnectionVisitorInterface() {} | 64 virtual ~QuicConnectionVisitorInterface() {} |
64 | 65 |
65 // A simple visitor interface for dealing with data frames. | 66 // A simple visitor interface for dealing with data frames. |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 virtual void OnFecData(const QuicFecData& fec) OVERRIDE; | 368 virtual void OnFecData(const QuicFecData& fec) OVERRIDE; |
368 virtual void OnPacketComplete() OVERRIDE; | 369 virtual void OnPacketComplete() OVERRIDE; |
369 | 370 |
370 // QuicPacketGenerator::DelegateInterface | 371 // QuicPacketGenerator::DelegateInterface |
371 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, | 372 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, |
372 HasRetransmittableData retransmittable, | 373 HasRetransmittableData retransmittable, |
373 IsHandshake handshake) OVERRIDE; | 374 IsHandshake handshake) OVERRIDE; |
374 virtual QuicAckFrame* CreateAckFrame() OVERRIDE; | 375 virtual QuicAckFrame* CreateAckFrame() OVERRIDE; |
375 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE; | 376 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE; |
376 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() OVERRIDE; | 377 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() OVERRIDE; |
377 virtual bool OnSerializedPacket(const SerializedPacket& packet) OVERRIDE; | 378 virtual void OnSerializedPacket(const SerializedPacket& packet) OVERRIDE; |
378 | 379 |
379 // QuicSentPacketManager::NetworkChangeVisitor | 380 // QuicSentPacketManager::NetworkChangeVisitor |
380 virtual void OnCongestionWindowChange( | 381 virtual void OnCongestionWindowChange( |
381 QuicByteCount congestion_window) OVERRIDE; | 382 QuicByteCount congestion_window) OVERRIDE; |
382 | 383 |
383 // Called by the crypto stream when the handshake completes. In the server's | 384 // Called by the crypto stream when the handshake completes. In the server's |
384 // case this is when the SHLO has been ACKed. Clients call this on receipt of | 385 // case this is when the SHLO has been ACKed. Clients call this on receipt of |
385 // the SHLO. | 386 // the SHLO. |
386 void OnHandshakeComplete(); | 387 void OnHandshakeComplete(); |
387 | 388 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 void SendPing(); | 446 void SendPing(); |
446 | 447 |
447 // Sets up a packet with an QuicAckFrame and sends it out. | 448 // Sets up a packet with an QuicAckFrame and sends it out. |
448 void SendAck(); | 449 void SendAck(); |
449 | 450 |
450 // Called when an RTO fires. Resets the retransmission alarm if there are | 451 // Called when an RTO fires. Resets the retransmission alarm if there are |
451 // remaining unacked packets. | 452 // remaining unacked packets. |
452 void OnRetransmissionTimeout(); | 453 void OnRetransmissionTimeout(); |
453 | 454 |
454 // Retransmits all unacked packets with retransmittable frames if | 455 // Retransmits all unacked packets with retransmittable frames if |
455 // |retransmission_type| is ALL_PACKETS, otherwise retransmits only initially | 456 // |retransmission_type| is ALL_UNACKED_PACKETS, otherwise retransmits only |
456 // encrypted packets. Used when the negotiated protocol version is different | 457 // initially encrypted packets. Used when the negotiated protocol version is |
457 // from what was initially assumed and when the visitor wants to re-transmit | 458 // different from what was initially assumed and when the initial encryption |
458 // initially encrypted packets when the initial encrypter changes. | 459 // changes. |
459 void RetransmitUnackedPackets(RetransmissionType retransmission_type); | 460 void RetransmitUnackedPackets(TransmissionType retransmission_type); |
460 | 461 |
461 // Calls |sent_packet_manager_|'s NeuterUnencryptedPackets. Used when the | 462 // Calls |sent_packet_manager_|'s NeuterUnencryptedPackets. Used when the |
462 // connection becomes forward secure and hasn't received acks for all packets. | 463 // connection becomes forward secure and hasn't received acks for all packets. |
463 void NeuterUnencryptedPackets(); | 464 void NeuterUnencryptedPackets(); |
464 | 465 |
465 // Changes the encrypter used for level |level| to |encrypter|. The function | 466 // Changes the encrypter used for level |level| to |encrypter|. The function |
466 // takes ownership of |encrypter|. | 467 // takes ownership of |encrypter|. |
467 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); | 468 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); |
468 const QuicEncrypter* encrypter(EncryptionLevel level) const; | 469 const QuicEncrypter* encrypter(EncryptionLevel level) const; |
469 | 470 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // outgoing packet. | 515 // outgoing packet. |
515 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); | 516 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); |
516 ~ScopedPacketBundler(); | 517 ~ScopedPacketBundler(); |
517 | 518 |
518 private: | 519 private: |
519 QuicConnection* connection_; | 520 QuicConnection* connection_; |
520 bool already_in_batch_mode_; | 521 bool already_in_batch_mode_; |
521 }; | 522 }; |
522 | 523 |
523 protected: | 524 protected: |
| 525 // Packets which have not been written to the wire. |
| 526 // Owns the QuicPacket* packet. |
| 527 struct QueuedPacket { |
| 528 QueuedPacket(SerializedPacket packet, |
| 529 EncryptionLevel level); |
| 530 QueuedPacket(SerializedPacket packet, |
| 531 EncryptionLevel level, |
| 532 TransmissionType transmission_type, |
| 533 QuicPacketSequenceNumber original_sequence_number); |
| 534 |
| 535 SerializedPacket serialized_packet; |
| 536 const EncryptionLevel encryption_level; |
| 537 TransmissionType transmission_type; |
| 538 // The packet's original sequence number if it is a retransmission. |
| 539 // Otherwise it must be 0. |
| 540 QuicPacketSequenceNumber original_sequence_number; |
| 541 }; |
| 542 |
524 // Do any work which logically would be done in OnPacket but can not be | 543 // Do any work which logically would be done in OnPacket but can not be |
525 // safely done until the packet is validated. Returns true if the packet | 544 // safely done until the packet is validated. Returns true if the packet |
526 // can be handled, false otherwise. | 545 // can be handled, false otherwise. |
527 virtual bool ProcessValidatedPacket(); | 546 virtual bool ProcessValidatedPacket(); |
528 | 547 |
529 // Send a packet to the peer using encryption |level|. If |sequence_number| | 548 // Send a packet to the peer, and takes ownership of the packet if the packet |
530 // is present in the |retransmission_map_|, then contents of this packet will | 549 // cannot be written immediately. |
531 // be retransmitted with a new sequence number if it's not acked by the peer. | 550 virtual void SendOrQueuePacket(QueuedPacket packet); |
532 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to | |
533 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the | |
534 // entropy map corresponding to |sequence_number| using |entropy_hash|. | |
535 // |transmission_type| and |retransmittable| are supplied to the congestion | |
536 // manager, and when |forced| is true, it bypasses the congestion manager. | |
537 // TODO(wtc): none of the callers check the return value. | |
538 virtual bool SendOrQueuePacket(EncryptionLevel level, | |
539 const SerializedPacket& packet, | |
540 TransmissionType transmission_type); | |
541 | 551 |
542 QuicConnectionHelperInterface* helper() { return helper_; } | 552 QuicConnectionHelperInterface* helper() { return helper_; } |
543 | 553 |
544 // Selects and updates the version of the protocol being used by selecting a | 554 // Selects and updates the version of the protocol being used by selecting a |
545 // version from |available_versions| which is also supported. Returns true if | 555 // version from |available_versions| which is also supported. Returns true if |
546 // such a version exists, false otherwise. | 556 // such a version exists, false otherwise. |
547 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 557 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
548 | 558 |
549 QuicPacketWriter* writer() { return writer_; } | 559 QuicPacketWriter* writer() { return writer_; } |
550 | 560 |
551 bool peer_port_changed() const { return peer_port_changed_; } | 561 bool peer_port_changed() const { return peer_port_changed_; } |
552 | 562 |
553 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { | 563 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { |
554 return sequence_number_of_last_sent_packet_; | 564 return sequence_number_of_last_sent_packet_; |
555 } | 565 } |
556 | 566 |
557 private: | 567 private: |
558 friend class test::QuicConnectionPeer; | 568 friend class test::QuicConnectionPeer; |
559 | 569 friend class test::PacketSavingConnection; |
560 // Packets which have not been written to the wire. | |
561 // Owns the QuicPacket* packet. | |
562 struct QueuedPacket { | |
563 QueuedPacket(SerializedPacket packet, | |
564 EncryptionLevel level, | |
565 TransmissionType transmission_type); | |
566 | |
567 SerializedPacket serialized_packet; | |
568 const EncryptionLevel encryption_level; | |
569 TransmissionType transmission_type; | |
570 }; | |
571 | 570 |
572 typedef std::list<QueuedPacket> QueuedPacketList; | 571 typedef std::list<QueuedPacket> QueuedPacketList; |
573 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 572 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
574 | 573 |
575 // Writes the given packet to socket, encrypted with packet's | 574 // Writes the given packet to socket, encrypted with packet's |
576 // encryption_level. Returns true on successful write, and false if the writer | 575 // encryption_level. Returns true on successful write, and false if the writer |
577 // was blocked and the write needs to be tried again. Behavior is undefined | 576 // was blocked and the write needs to be tried again. Notifies the |
578 // if connection is not established or broken. Notifies the SentPacketManager | 577 // SentPacketManager when the write is successful and sets |
579 // when the write is successful. | 578 // retransmittable frames to NULL. |
580 // Saves the connection close packet for later transmission, even if the | 579 // Saves the connection close packet for later transmission, even if the |
581 // writer is write blocked. | 580 // writer is write blocked. |
582 bool WritePacket(const QueuedPacket& packet); | 581 bool WritePacket(QueuedPacket* packet); |
| 582 |
| 583 // Does the main work of WritePacket, but does not delete the packet or |
| 584 // retransmittable frames upon success. |
| 585 bool WritePacketInner(QueuedPacket* packet); |
583 | 586 |
584 // Make sure an ack we got from our peer is sane. | 587 // Make sure an ack we got from our peer is sane. |
585 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); | 588 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); |
586 | 589 |
587 // Make sure a stop waiting we got from our peer is sane. | 590 // Make sure a stop waiting we got from our peer is sane. |
588 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); | 591 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); |
589 | 592 |
590 // Sends a version negotiation packet to the peer. | 593 // Sends a version negotiation packet to the peer. |
591 void SendVersionNegotiationPacket(); | 594 void SendVersionNegotiationPacket(); |
592 | 595 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 // If non-empty this contains the set of versions received in a | 805 // If non-empty this contains the set of versions received in a |
803 // version negotiation packet. | 806 // version negotiation packet. |
804 QuicVersionVector server_supported_versions_; | 807 QuicVersionVector server_supported_versions_; |
805 | 808 |
806 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 809 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
807 }; | 810 }; |
808 | 811 |
809 } // namespace net | 812 } // namespace net |
810 | 813 |
811 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 814 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |