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 448 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, and takes ownership of the packet if the packet | 548 // Send a packet to the peer, and takes ownership of the packet if the packet |
530 // cannot be written immediately. | 549 // cannot be written immediately. |
531 virtual void SendOrQueuePacket(EncryptionLevel level, | 550 virtual void SendOrQueuePacket(QueuedPacket packet); |
532 const SerializedPacket& packet, | |
533 TransmissionType transmission_type); | |
534 | 551 |
535 QuicConnectionHelperInterface* helper() { return helper_; } | 552 QuicConnectionHelperInterface* helper() { return helper_; } |
536 | 553 |
537 // 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 |
538 // version from |available_versions| which is also supported. Returns true if | 555 // version from |available_versions| which is also supported. Returns true if |
539 // such a version exists, false otherwise. | 556 // such a version exists, false otherwise. |
540 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 557 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
541 | 558 |
542 QuicPacketWriter* writer() { return writer_; } | 559 QuicPacketWriter* writer() { return writer_; } |
543 | 560 |
544 bool peer_port_changed() const { return peer_port_changed_; } | 561 bool peer_port_changed() const { return peer_port_changed_; } |
545 | 562 |
546 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { | 563 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { |
547 return sequence_number_of_last_sent_packet_; | 564 return sequence_number_of_last_sent_packet_; |
548 } | 565 } |
549 | 566 |
550 private: | 567 private: |
551 friend class test::QuicConnectionPeer; | 568 friend class test::QuicConnectionPeer; |
552 | 569 friend class test::PacketSavingConnection; |
553 // Packets which have not been written to the wire. | |
554 // Owns the QuicPacket* packet. | |
555 struct QueuedPacket { | |
556 QueuedPacket(SerializedPacket packet, | |
557 EncryptionLevel level, | |
558 TransmissionType transmission_type); | |
559 | |
560 SerializedPacket serialized_packet; | |
561 const EncryptionLevel encryption_level; | |
562 TransmissionType transmission_type; | |
563 }; | |
564 | 570 |
565 typedef std::list<QueuedPacket> QueuedPacketList; | 571 typedef std::list<QueuedPacket> QueuedPacketList; |
566 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 572 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
567 | 573 |
568 // Writes the given packet to socket, encrypted with packet's | 574 // Writes the given packet to socket, encrypted with packet's |
569 // 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 |
570 // 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 |
571 // if connection is not established or broken. Notifies the SentPacketManager | 577 // SentPacketManager when the write is successful and sets |
572 // when the write is successful. | 578 // retransmittable frames to NULL. |
573 // Saves the connection close packet for later transmission, even if the | 579 // Saves the connection close packet for later transmission, even if the |
574 // writer is write blocked. | 580 // writer is write blocked. |
575 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); |
576 | 586 |
577 // Make sure an ack we got from our peer is sane. | 587 // Make sure an ack we got from our peer is sane. |
578 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); | 588 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); |
579 | 589 |
580 // 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. |
581 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); | 591 bool ValidateStopWaitingFrame(const QuicStopWaitingFrame& stop_waiting); |
582 | 592 |
583 // Sends a version negotiation packet to the peer. | 593 // Sends a version negotiation packet to the peer. |
584 void SendVersionNegotiationPacket(); | 594 void SendVersionNegotiationPacket(); |
585 | 595 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 // 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 |
796 // version negotiation packet. | 806 // version negotiation packet. |
797 QuicVersionVector server_supported_versions_; | 807 QuicVersionVector server_supported_versions_; |
798 | 808 |
799 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 809 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
800 }; | 810 }; |
801 | 811 |
802 } // namespace net | 812 } // namespace net |
803 | 813 |
804 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 814 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |