| 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 // |
| 11 // On the client side, the Connection handles the raw reads, as well as the | 11 // On the client side, the Connection handles the raw reads, as well as the |
| 12 // processing. | 12 // processing. |
| 13 // | 13 // |
| 14 // Note: this class is not thread-safe. | 14 // Note: this class is not thread-safe. |
| 15 | 15 |
| 16 #ifndef NET_QUIC_QUIC_CONNECTION_H_ | 16 #ifndef NET_QUIC_QUIC_CONNECTION_H_ |
| 17 #define NET_QUIC_QUIC_CONNECTION_H_ | 17 #define NET_QUIC_QUIC_CONNECTION_H_ |
| 18 | 18 |
| 19 #include <deque> | 19 #include <deque> |
| 20 #include <list> | 20 #include <list> |
| 21 #include <map> | 21 #include <map> |
| 22 #include <queue> | 22 #include <queue> |
| 23 #include <set> | 23 #include <set> |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/containers/hash_tables.h" | 26 #include "base/containers/hash_tables.h" |
| 27 #include "net/base/iovec.h" |
| 27 #include "net/base/ip_endpoint.h" | 28 #include "net/base/ip_endpoint.h" |
| 28 #include "net/base/linked_hash_map.h" | 29 #include "net/base/linked_hash_map.h" |
| 29 #include "net/quic/congestion_control/quic_congestion_manager.h" | 30 #include "net/quic/congestion_control/quic_congestion_manager.h" |
| 30 #include "net/quic/quic_ack_notifier.h" | 31 #include "net/quic/quic_ack_notifier.h" |
| 31 #include "net/quic/quic_alarm.h" | 32 #include "net/quic/quic_alarm.h" |
| 32 #include "net/quic/quic_blocked_writer_interface.h" | 33 #include "net/quic/quic_blocked_writer_interface.h" |
| 33 #include "net/quic/quic_connection_stats.h" | 34 #include "net/quic/quic_connection_stats.h" |
| 34 #include "net/quic/quic_framer.h" | 35 #include "net/quic/quic_framer.h" |
| 35 #include "net/quic/quic_packet_creator.h" | 36 #include "net/quic/quic_packet_creator.h" |
| 36 #include "net/quic/quic_packet_generator.h" | 37 #include "net/quic/quic_packet_generator.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0; | 70 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0; |
| 70 | 71 |
| 71 // Called when the connection is closed either locally by the framer, or | 72 // Called when the connection is closed either locally by the framer, or |
| 72 // remotely by the peer. | 73 // remotely by the peer. |
| 73 virtual void ConnectionClose(QuicErrorCode error, | 74 virtual void ConnectionClose(QuicErrorCode error, |
| 74 bool from_peer) = 0; | 75 bool from_peer) = 0; |
| 75 | 76 |
| 76 // Called when packets are acked by the peer. | 77 // Called when packets are acked by the peer. |
| 77 virtual void OnAck(const SequenceNumberSet& acked_packets) = 0; | 78 virtual void OnAck(const SequenceNumberSet& acked_packets) = 0; |
| 78 | 79 |
| 80 // Called once a specific QUIC version is agreed by both endpoints. |
| 81 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; |
| 82 |
| 79 // Called when a blocked socket becomes writable. If all pending bytes for | 83 // Called when a blocked socket becomes writable. If all pending bytes for |
| 80 // this visitor are consumed by the connection successfully this should | 84 // this visitor are consumed by the connection successfully this should |
| 81 // return true, otherwise it should return false. | 85 // return true, otherwise it should return false. |
| 82 virtual bool OnCanWrite() = 0; | 86 virtual bool OnCanWrite() = 0; |
| 83 }; | 87 }; |
| 84 | 88 |
| 85 // Interface which gets callbacks from the QuicConnection at interesting | 89 // Interface which gets callbacks from the QuicConnection at interesting |
| 86 // points. Implementations must not mutate the state of the connection | 90 // points. Implementations must not mutate the state of the connection |
| 87 // as a result of these callbacks. | 91 // as a result of these callbacks. |
| 88 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface | 92 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 202 |
| 199 // Constructs a new QuicConnection for the specified |guid| and |address|. | 203 // Constructs a new QuicConnection for the specified |guid| and |address|. |
| 200 // |helper| will be owned by this connection. | 204 // |helper| will be owned by this connection. |
| 201 QuicConnection(QuicGuid guid, | 205 QuicConnection(QuicGuid guid, |
| 202 IPEndPoint address, | 206 IPEndPoint address, |
| 203 QuicConnectionHelperInterface* helper, | 207 QuicConnectionHelperInterface* helper, |
| 204 bool is_server, | 208 bool is_server, |
| 205 QuicVersion version); | 209 QuicVersion version); |
| 206 virtual ~QuicConnection(); | 210 virtual ~QuicConnection(); |
| 207 | 211 |
| 208 // Send the data payload to the peer. | 212 // Send the data in |iov| to the peer in as few packets as possible. |
| 209 // Returns a pair with the number of bytes consumed from data, and a boolean | 213 // Returns a pair with the number of bytes consumed from data, and a boolean |
| 210 // indicating if the fin bit was consumed. This does not indicate the data | 214 // indicating if the fin bit was consumed. This does not indicate the data |
| 211 // has been sent on the wire: it may have been turned into a packet and queued | 215 // has been sent on the wire: it may have been turned into a packet and queued |
| 212 // if the socket was unexpectedly blocked. | 216 // if the socket was unexpectedly blocked. |
| 213 QuicConsumedData SendStreamData(QuicStreamId id, | 217 QuicConsumedData SendvStreamData(QuicStreamId id, |
| 214 base::StringPiece data, | 218 const struct iovec* iov, |
| 215 QuicStreamOffset offset, | 219 int count, |
| 216 bool fin); | 220 QuicStreamOffset offset, |
| 221 bool fin); |
| 222 |
| 217 // Same as above, except that the provided delegate will be informed once ACKs | 223 // Same as above, except that the provided delegate will be informed once ACKs |
| 218 // have been received for all the packets written. | 224 // have been received for all the packets written. |
| 219 // The |delegate| is not owned by the QuicConnection and must outlive it. | 225 // The |delegate| is not owned by the QuicConnection and must outlive it. |
| 220 QuicConsumedData SendStreamDataAndNotifyWhenAcked( | 226 QuicConsumedData SendStreamDataAndNotifyWhenAcked( |
| 221 QuicStreamId id, | 227 QuicStreamId id, |
| 222 base::StringPiece data, | 228 base::StringPiece data, |
| 223 QuicStreamOffset offset, | 229 QuicStreamOffset offset, |
| 224 bool fin, | 230 bool fin, |
| 225 QuicAckNotifier::DelegateInterface* delegate); | 231 QuicAckNotifier::DelegateInterface* delegate); |
| 226 | 232 |
| 227 // Send a stream reset frame to the peer. | 233 // Send a stream reset frame to the peer. |
| 228 virtual void SendRstStream(QuicStreamId id, | 234 virtual void SendRstStream(QuicStreamId id, |
| 229 QuicRstStreamErrorCode error); | 235 QuicRstStreamErrorCode error); |
| 230 | 236 |
| 231 // Sends the connection close packet without affecting the state of the | 237 // Sends the connection close packet without affecting the state of the |
| 232 // connection. This should only be called if the session is actively being | 238 // connection. This should only be called if the session is actively being |
| 233 // destroyed: otherwise call SendConnectionCloseWithDetails instead. | 239 // destroyed: otherwise call SendConnectionCloseWithDetails instead. |
| 234 virtual void SendConnectionClosePacket(QuicErrorCode error, | 240 virtual void SendConnectionClosePacket(QuicErrorCode error, |
| 235 const std::string& details); | 241 const std::string& details); |
| 236 | 242 |
| 237 // Sends a connection close frame to the peer, and closes the connection by | 243 // Sends a connection close frame to the peer, and closes the connection by |
| 238 // calling CloseConnection(notifying the visitor as it does so). | 244 // calling CloseConnection(notifying the visitor as it does so). |
| 239 virtual void SendConnectionClose(QuicErrorCode error); | 245 virtual void SendConnectionClose(QuicErrorCode error); |
| 240 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, | 246 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, |
| 241 const std::string& details); | 247 const std::string& details); |
| 242 // Notifies the visitor of the close and marks the connection as disconnected. | 248 // Notifies the visitor of the close and marks the connection as disconnected. |
| 243 void CloseConnection(QuicErrorCode error, bool from_peer); | 249 virtual void CloseConnection(QuicErrorCode error, bool from_peer) OVERRIDE; |
| 244 virtual void SendGoAway(QuicErrorCode error, | 250 virtual void SendGoAway(QuicErrorCode error, |
| 245 QuicStreamId last_good_stream_id, | 251 QuicStreamId last_good_stream_id, |
| 246 const std::string& reason); | 252 const std::string& reason); |
| 247 | 253 |
| 248 // Returns statistics tracked for this connection. | 254 // Returns statistics tracked for this connection. |
| 249 const QuicConnectionStats& GetStats(); | 255 const QuicConnectionStats& GetStats(); |
| 250 | 256 |
| 251 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from | 257 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from |
| 252 // the peer. If processing this packet permits a packet to be revived from | 258 // the peer. If processing this packet permits a packet to be revived from |
| 253 // its FEC group that packet will be revived and processed. | 259 // its FEC group that packet will be revived and processed. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 334 |
| 329 QuicPacketCreator::Options* options() { return packet_creator_.options(); } | 335 QuicPacketCreator::Options* options() { return packet_creator_.options(); } |
| 330 | 336 |
| 331 bool connected() { return connected_; } | 337 bool connected() { return connected_; } |
| 332 | 338 |
| 333 size_t NumFecGroups() const { return group_map_.size(); } | 339 size_t NumFecGroups() const { return group_map_.size(); } |
| 334 | 340 |
| 335 // Testing only. | 341 // Testing only. |
| 336 size_t NumQueuedPackets() const { return queued_packets_.size(); } | 342 size_t NumQueuedPackets() const { return queued_packets_.size(); } |
| 337 | 343 |
| 344 // Flush any queued frames immediately. Preserves the batch write mode and |
| 345 // does nothing if there are no pending frames. |
| 346 void Flush(); |
| 347 |
| 338 // Returns true if the connection has queued packets or frames. | 348 // Returns true if the connection has queued packets or frames. |
| 339 bool HasQueuedData() const; | 349 bool HasQueuedData() const; |
| 340 | 350 |
| 341 // Sets (or resets) the idle state connection timeout. Also, checks and times | 351 // Sets (or resets) the idle state connection timeout. Also, checks and times |
| 342 // out the connection if network timer has expired for |timeout|. | 352 // out the connection if network timer has expired for |timeout|. |
| 343 void SetIdleNetworkTimeout(QuicTime::Delta timeout); | 353 void SetIdleNetworkTimeout(QuicTime::Delta timeout); |
| 344 // Sets (or resets) the total time delta the connection can be alive for. | 354 // Sets (or resets) the total time delta the connection can be alive for. |
| 345 // Also, checks and times out the connection if timer has expired for | 355 // Also, checks and times out the connection if timer has expired for |
| 346 // |timeout|. Used to limit the time a connection can be alive before crypto | 356 // |timeout|. Used to limit the time a connection can be alive before crypto |
| 347 // handshake finishes. | 357 // handshake finishes. |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 // Once a given QuicAckNotifier has seen all the sequence numbers it is | 728 // Once a given QuicAckNotifier has seen all the sequence numbers it is |
| 719 // interested in, it will be deleted, and removed from this list. | 729 // interested in, it will be deleted, and removed from this list. |
| 720 AckNotifierList ack_notifiers_; | 730 AckNotifierList ack_notifiers_; |
| 721 | 731 |
| 722 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 732 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
| 723 }; | 733 }; |
| 724 | 734 |
| 725 } // namespace net | 735 } // namespace net |
| 726 | 736 |
| 727 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 737 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
| OLD | NEW |