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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 // Called when the connection failed to write because the socket was blocked. | 88 // Called when the connection failed to write because the socket was blocked. |
89 virtual void OnWriteBlocked() = 0; | 89 virtual void OnWriteBlocked() = 0; |
90 | 90 |
91 // Called once a specific QUIC version is agreed by both endpoints. | 91 // Called once a specific QUIC version is agreed by both endpoints. |
92 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; | 92 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; |
93 | 93 |
94 // Called when a blocked socket becomes writable. | 94 // Called when a blocked socket becomes writable. |
95 virtual void OnCanWrite() = 0; | 95 virtual void OnCanWrite() = 0; |
96 | 96 |
| 97 // Called when the connection experiences a change in congestion window. |
| 98 virtual void OnCongestionWindowChange(QuicTime now) = 0; |
| 99 |
97 // Called to ask if the visitor wants to schedule write resumption as it both | 100 // Called to ask if the visitor wants to schedule write resumption as it both |
98 // has pending data to write, and is able to write (e.g. based on flow control | 101 // has pending data to write, and is able to write (e.g. based on flow control |
99 // limits). | 102 // limits). |
100 // Writes may be pending because they were write-blocked, congestion-throttled | 103 // Writes may be pending because they were write-blocked, congestion-throttled |
101 // or yielded to other connections. | 104 // or yielded to other connections. |
102 virtual bool WillingAndAbleToWrite() const = 0; | 105 virtual bool WillingAndAbleToWrite() const = 0; |
103 | 106 |
104 // Called to ask if any handshake messages are pending in this visitor. | 107 // Called to ask if any handshake messages are pending in this visitor. |
105 virtual bool HasPendingHandshake() const = 0; | 108 virtual bool HasPendingHandshake() const = 0; |
106 | 109 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 218 |
216 // Creates a new platform-specific alarm which will be configured to | 219 // Creates a new platform-specific alarm which will be configured to |
217 // notify |delegate| when the alarm fires. Caller takes ownership | 220 // notify |delegate| when the alarm fires. Caller takes ownership |
218 // of the new alarm, which will not yet be "set" to fire. | 221 // of the new alarm, which will not yet be "set" to fire. |
219 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; | 222 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) = 0; |
220 }; | 223 }; |
221 | 224 |
222 class NET_EXPORT_PRIVATE QuicConnection | 225 class NET_EXPORT_PRIVATE QuicConnection |
223 : public QuicFramerVisitorInterface, | 226 : public QuicFramerVisitorInterface, |
224 public QuicBlockedWriterInterface, | 227 public QuicBlockedWriterInterface, |
225 public QuicPacketGenerator::DelegateInterface { | 228 public QuicPacketGenerator::DelegateInterface, |
| 229 public QuicSentPacketManager::NetworkChangeVisitor { |
226 public: | 230 public: |
227 enum PacketType { | 231 enum PacketType { |
228 NORMAL, | 232 NORMAL, |
229 QUEUED, | 233 QUEUED, |
230 CONNECTION_CLOSE | 234 CONNECTION_CLOSE |
231 }; | 235 }; |
232 | 236 |
233 enum AckBundling { | 237 enum AckBundling { |
234 NO_ACK = 0, | 238 NO_ACK = 0, |
235 SEND_ACK = 1, | 239 SEND_ACK = 1, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // its FEC group that packet will be revived and processed. | 318 // its FEC group that packet will be revived and processed. |
315 virtual void ProcessUdpPacket(const IPEndPoint& self_address, | 319 virtual void ProcessUdpPacket(const IPEndPoint& self_address, |
316 const IPEndPoint& peer_address, | 320 const IPEndPoint& peer_address, |
317 const QuicEncryptedPacket& packet); | 321 const QuicEncryptedPacket& packet); |
318 | 322 |
319 // QuicBlockedWriterInterface | 323 // QuicBlockedWriterInterface |
320 // Called when the underlying connection becomes writable to allow queued | 324 // Called when the underlying connection becomes writable to allow queued |
321 // writes to happen. | 325 // writes to happen. |
322 virtual void OnCanWrite() OVERRIDE; | 326 virtual void OnCanWrite() OVERRIDE; |
323 | 327 |
324 // Called when a packet has been finally sent to the network. | 328 // Called when an error occurs while attempting to write a packet to the |
325 bool OnPacketSent(WriteResult result); | 329 // network. |
| 330 void OnWriteError(int error_code); |
326 | 331 |
327 // If the socket is not blocked, writes queued packets. | 332 // If the socket is not blocked, writes queued packets. |
328 void WriteIfNotBlocked(); | 333 void WriteIfNotBlocked(); |
329 | 334 |
330 // The version of the protocol this connection is using. | 335 // The version of the protocol this connection is using. |
331 QuicVersion version() const { return framer_.version(); } | 336 QuicVersion version() const { return framer_.version(); } |
332 | 337 |
333 // The versions of the protocol that this connection supports. | 338 // The versions of the protocol that this connection supports. |
334 const QuicVersionVector& supported_versions() const { | 339 const QuicVersionVector& supported_versions() const { |
335 return framer_.supported_versions(); | 340 return framer_.supported_versions(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 372 |
368 // QuicPacketGenerator::DelegateInterface | 373 // QuicPacketGenerator::DelegateInterface |
369 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, | 374 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, |
370 HasRetransmittableData retransmittable, | 375 HasRetransmittableData retransmittable, |
371 IsHandshake handshake) OVERRIDE; | 376 IsHandshake handshake) OVERRIDE; |
372 virtual QuicAckFrame* CreateAckFrame() OVERRIDE; | 377 virtual QuicAckFrame* CreateAckFrame() OVERRIDE; |
373 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE; | 378 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE; |
374 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() OVERRIDE; | 379 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() OVERRIDE; |
375 virtual bool OnSerializedPacket(const SerializedPacket& packet) OVERRIDE; | 380 virtual bool OnSerializedPacket(const SerializedPacket& packet) OVERRIDE; |
376 | 381 |
| 382 // QuicSentPacketManager::NetworkChangeVisitor |
| 383 virtual void OnCongestionWindowChange( |
| 384 QuicByteCount congestion_window) OVERRIDE; |
| 385 |
377 // Called by the crypto stream when the handshake completes. In the server's | 386 // 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 | 387 // case this is when the SHLO has been ACKed. Clients call this on receipt of |
379 // the SHLO. | 388 // the SHLO. |
380 void OnHandshakeComplete(); | 389 void OnHandshakeComplete(); |
381 | 390 |
382 // Accessors | 391 // Accessors |
383 void set_visitor(QuicConnectionVisitorInterface* visitor) { | 392 void set_visitor(QuicConnectionVisitorInterface* visitor) { |
384 visitor_ = visitor; | 393 visitor_ = visitor; |
385 } | 394 } |
386 // This method takes ownership of |debug_visitor|. | 395 // This method takes ownership of |debug_visitor|. |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 546 |
538 // Selects and updates the version of the protocol being used by selecting a | 547 // Selects and updates the version of the protocol being used by selecting a |
539 // version from |available_versions| which is also supported. Returns true if | 548 // version from |available_versions| which is also supported. Returns true if |
540 // such a version exists, false otherwise. | 549 // such a version exists, false otherwise. |
541 bool SelectMutualVersion(const QuicVersionVector& available_versions); | 550 bool SelectMutualVersion(const QuicVersionVector& available_versions); |
542 | 551 |
543 QuicPacketWriter* writer() { return writer_; } | 552 QuicPacketWriter* writer() { return writer_; } |
544 | 553 |
545 bool peer_port_changed() const { return peer_port_changed_; } | 554 bool peer_port_changed() const { return peer_port_changed_; } |
546 | 555 |
547 const QuicReceivedPacketManager& received_packet_manager() const { | |
548 return received_packet_manager_; | |
549 } | |
550 | |
551 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { | 556 QuicPacketSequenceNumber sequence_number_of_last_sent_packet() const { |
552 return sequence_number_of_last_sent_packet_; | 557 return sequence_number_of_last_sent_packet_; |
553 } | 558 } |
554 | 559 |
555 private: | 560 private: |
556 friend class test::QuicConnectionPeer; | 561 friend class test::QuicConnectionPeer; |
557 | 562 |
558 // Packets which have not been written to the wire. | 563 // Packets which have not been written to the wire. |
559 // Owns the QuicPacket* packet. | 564 // Owns the QuicPacket* packet. |
560 struct QueuedPacket { | 565 struct QueuedPacket { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 712 |
708 // When the version negotiation packet could not be sent because the socket | 713 // When the version negotiation packet could not be sent because the socket |
709 // was not writable, this is set to true. | 714 // was not writable, this is set to true. |
710 bool pending_version_negotiation_packet_; | 715 bool pending_version_negotiation_packet_; |
711 | 716 |
712 // When packets could not be sent because the socket was not writable, | 717 // When packets could not be sent because the socket was not writable, |
713 // they are added to this list. All corresponding frames are in | 718 // they are added to this list. All corresponding frames are in |
714 // unacked_packets_ if they are to be retransmitted. | 719 // unacked_packets_ if they are to be retransmitted. |
715 QueuedPacketList queued_packets_; | 720 QueuedPacketList queued_packets_; |
716 | 721 |
717 // Contains information about the current write in progress, if any. | |
718 scoped_ptr<QueuedPacket> pending_write_; | |
719 | |
720 // Contains the connection close packet if the connection has been closed. | 722 // Contains the connection close packet if the connection has been closed. |
721 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; | 723 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; |
722 | 724 |
723 FecGroupMap group_map_; | 725 FecGroupMap group_map_; |
724 | 726 |
725 QuicReceivedPacketManager received_packet_manager_; | 727 QuicReceivedPacketManager received_packet_manager_; |
726 QuicSentEntropyManager sent_entropy_manager_; | 728 QuicSentEntropyManager sent_entropy_manager_; |
727 | 729 |
728 // Indicates whether an ack should be sent the next time we try to write. | 730 // Indicates whether an ack should be sent the next time we try to write. |
729 bool ack_queued_; | 731 bool ack_queued_; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 // If non-empty this contains the set of versions received in a | 806 // If non-empty this contains the set of versions received in a |
805 // version negotiation packet. | 807 // version negotiation packet. |
806 QuicVersionVector server_supported_versions_; | 808 QuicVersionVector server_supported_versions_; |
807 | 809 |
808 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 810 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
809 }; | 811 }; |
810 | 812 |
811 } // namespace net | 813 } // namespace net |
812 | 814 |
813 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 815 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |