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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 CONNECTION_CLOSE | 216 CONNECTION_CLOSE |
217 }; | 217 }; |
218 | 218 |
219 enum AckBundling { | 219 enum AckBundling { |
220 NO_ACK = 0, | 220 NO_ACK = 0, |
221 SEND_ACK = 1, | 221 SEND_ACK = 1, |
222 BUNDLE_PENDING_ACK = 2, | 222 BUNDLE_PENDING_ACK = 2, |
223 }; | 223 }; |
224 | 224 |
225 // Constructs a new QuicConnection for |connection_id| and |address|. | 225 // Constructs a new QuicConnection for |connection_id| and |address|. |
226 // |helper| and |writer| must outlive this connection. | 226 // |helper| must outlive this connection, and if |owns_writer| is false, so |
| 227 // must |writer|. |
227 QuicConnection(QuicConnectionId connection_id, | 228 QuicConnection(QuicConnectionId connection_id, |
228 IPEndPoint address, | 229 IPEndPoint address, |
229 QuicConnectionHelperInterface* helper, | 230 QuicConnectionHelperInterface* helper, |
230 QuicPacketWriter* writer, | 231 QuicPacketWriter* writer, |
| 232 bool owns_writer, |
231 bool is_server, | 233 bool is_server, |
232 const QuicVersionVector& supported_versions); | 234 const QuicVersionVector& supported_versions); |
233 virtual ~QuicConnection(); | 235 virtual ~QuicConnection(); |
234 | 236 |
235 // Sets connection parameters from the supplied |config|. | 237 // Sets connection parameters from the supplied |config|. |
236 void SetFromConfig(const QuicConfig& config); | 238 void SetFromConfig(const QuicConfig& config); |
237 | 239 |
238 // Send the data in |data| to the peer in as few packets as possible. | 240 // Send the data in |data| to the peer in as few packets as possible. |
239 // Returns a pair with the number of bytes consumed from data, and a boolean | 241 // Returns a pair with the number of bytes consumed from data, and a boolean |
240 // indicating if the fin bit was consumed. This does not indicate the data | 242 // indicating if the fin bit was consumed. This does not indicate the data |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // Called when the underlying connection becomes writable to allow queued | 298 // Called when the underlying connection becomes writable to allow queued |
297 // writes to happen. | 299 // writes to happen. |
298 virtual void OnCanWrite() OVERRIDE; | 300 virtual void OnCanWrite() OVERRIDE; |
299 | 301 |
300 // Called when a packet has been finally sent to the network. | 302 // Called when a packet has been finally sent to the network. |
301 bool OnPacketSent(WriteResult result); | 303 bool OnPacketSent(WriteResult result); |
302 | 304 |
303 // If the socket is not blocked, writes queued packets. | 305 // If the socket is not blocked, writes queued packets. |
304 void WriteIfNotBlocked(); | 306 void WriteIfNotBlocked(); |
305 | 307 |
306 // Do any work which logically would be done in OnPacket but can not be | |
307 // safely done until the packet is validated. Returns true if the packet | |
308 // can be handled, false otherwise. | |
309 virtual bool ProcessValidatedPacket(); | |
310 | |
311 // The version of the protocol this connection is using. | 308 // The version of the protocol this connection is using. |
312 QuicVersion version() const { return framer_.version(); } | 309 QuicVersion version() const { return framer_.version(); } |
313 | 310 |
314 // The versions of the protocol that this connection supports. | 311 // The versions of the protocol that this connection supports. |
315 const QuicVersionVector& supported_versions() const { | 312 const QuicVersionVector& supported_versions() const { |
316 return framer_.supported_versions(); | 313 return framer_.supported_versions(); |
317 } | 314 } |
318 | 315 |
319 // From QuicFramerVisitorInterface | 316 // From QuicFramerVisitorInterface |
320 virtual void OnError(QuicFramer* framer) OVERRIDE; | 317 virtual void OnError(QuicFramer* framer) OVERRIDE; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 // outgoing packet. | 480 // outgoing packet. |
484 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); | 481 ScopedPacketBundler(QuicConnection* connection, AckBundling send_ack); |
485 ~ScopedPacketBundler(); | 482 ~ScopedPacketBundler(); |
486 | 483 |
487 private: | 484 private: |
488 QuicConnection* connection_; | 485 QuicConnection* connection_; |
489 bool already_in_batch_mode_; | 486 bool already_in_batch_mode_; |
490 }; | 487 }; |
491 | 488 |
492 protected: | 489 protected: |
| 490 // Do any work which logically would be done in OnPacket but can not be |
| 491 // safely done until the packet is validated. Returns true if the packet |
| 492 // can be handled, false otherwise. |
| 493 virtual bool ProcessValidatedPacket(); |
| 494 |
493 // Send a packet to the peer using encryption |level|. If |sequence_number| | 495 // Send a packet to the peer using encryption |level|. If |sequence_number| |
494 // is present in the |retransmission_map_|, then contents of this packet will | 496 // is present in the |retransmission_map_|, then contents of this packet will |
495 // be retransmitted with a new sequence number if it's not acked by the peer. | 497 // be retransmitted with a new sequence number if it's not acked by the peer. |
496 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to | 498 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to |
497 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the | 499 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the |
498 // entropy map corresponding to |sequence_number| using |entropy_hash|. | 500 // entropy map corresponding to |sequence_number| using |entropy_hash|. |
499 // |transmission_type| and |retransmittable| are supplied to the congestion | 501 // |transmission_type| and |retransmittable| are supplied to the congestion |
500 // manager, and when |forced| is true, it bypasses the congestion manager. | 502 // manager, and when |forced| is true, it bypasses the congestion manager. |
501 // TODO(wtc): none of the callers check the return value. | 503 // TODO(wtc): none of the callers check the return value. |
502 virtual bool SendOrQueuePacket(EncryptionLevel level, | 504 virtual bool SendOrQueuePacket(EncryptionLevel level, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // Sets the ping alarm to the appropriate value, if any. | 627 // Sets the ping alarm to the appropriate value, if any. |
626 void SetPingAlarm(); | 628 void SetPingAlarm(); |
627 | 629 |
628 // On arrival of a new packet, checks to see if the socket addresses have | 630 // On arrival of a new packet, checks to see if the socket addresses have |
629 // changed since the last packet we saw on this connection. | 631 // changed since the last packet we saw on this connection. |
630 void CheckForAddressMigration(const IPEndPoint& self_address, | 632 void CheckForAddressMigration(const IPEndPoint& self_address, |
631 const IPEndPoint& peer_address); | 633 const IPEndPoint& peer_address); |
632 | 634 |
633 QuicFramer framer_; | 635 QuicFramer framer_; |
634 QuicConnectionHelperInterface* helper_; // Not owned. | 636 QuicConnectionHelperInterface* helper_; // Not owned. |
635 QuicPacketWriter* writer_; // Not owned. | 637 QuicPacketWriter* writer_; // Owned or not depending on |owns_writer_|. |
| 638 bool owns_writer_; |
636 EncryptionLevel encryption_level_; | 639 EncryptionLevel encryption_level_; |
637 const QuicClock* clock_; | 640 const QuicClock* clock_; |
638 QuicRandom* random_generator_; | 641 QuicRandom* random_generator_; |
639 | 642 |
640 const QuicConnectionId connection_id_; | 643 const QuicConnectionId connection_id_; |
641 // Address on the last successfully processed packet received from the | 644 // Address on the last successfully processed packet received from the |
642 // client. | 645 // client. |
643 IPEndPoint self_address_; | 646 IPEndPoint self_address_; |
644 IPEndPoint peer_address_; | 647 IPEndPoint peer_address_; |
645 // Used to store latest peer port to possibly migrate to later. | 648 // Used to store latest peer port to possibly migrate to later. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 // If non-empty this contains the set of versions received in a | 776 // If non-empty this contains the set of versions received in a |
774 // version negotiation packet. | 777 // version negotiation packet. |
775 QuicVersionVector server_supported_versions_; | 778 QuicVersionVector server_supported_versions_; |
776 | 779 |
777 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 780 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
778 }; | 781 }; |
779 | 782 |
780 } // namespace net | 783 } // namespace net |
781 | 784 |
782 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 785 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |