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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 virtual bool HasOpenDataStreams() const = 0; | 114 virtual bool HasOpenDataStreams() const = 0; |
115 }; | 115 }; |
116 | 116 |
117 // Interface which gets callbacks from the QuicConnection at interesting | 117 // Interface which gets callbacks from the QuicConnection at interesting |
118 // points. Implementations must not mutate the state of the connection | 118 // points. Implementations must not mutate the state of the connection |
119 // as a result of these callbacks. | 119 // as a result of these callbacks. |
120 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitor | 120 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitor |
121 : public QuicPacketGenerator::DebugDelegate, | 121 : public QuicPacketGenerator::DebugDelegate, |
122 public QuicSentPacketManager::DebugDelegate { | 122 public QuicSentPacketManager::DebugDelegate { |
123 public: | 123 public: |
124 virtual ~QuicConnectionDebugVisitor() {} | 124 ~QuicConnectionDebugVisitor() override {} |
125 | 125 |
126 // Called when a packet has been sent. | 126 // Called when a packet has been sent. |
127 virtual void OnPacketSent(const SerializedPacket& serialized_packet, | 127 virtual void OnPacketSent(const SerializedPacket& serialized_packet, |
128 QuicPacketSequenceNumber original_sequence_number, | 128 QuicPacketSequenceNumber original_sequence_number, |
129 EncryptionLevel level, | 129 EncryptionLevel level, |
130 TransmissionType transmission_type, | 130 TransmissionType transmission_type, |
131 const QuicEncryptedPacket& packet, | 131 const QuicEncryptedPacket& packet, |
132 QuicTime sent_time) {} | 132 QuicTime sent_time) {} |
133 | 133 |
134 // Called when a packet has been received, but before it is | 134 // Called when a packet has been received, but before it is |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // writer_factory->Create() to get a writer; |owns_writer| specifies whether | 245 // writer_factory->Create() to get a writer; |owns_writer| specifies whether |
246 // the connection takes ownership of the returned writer. |helper| must | 246 // the connection takes ownership of the returned writer. |helper| must |
247 // outlive this connection. | 247 // outlive this connection. |
248 QuicConnection(QuicConnectionId connection_id, | 248 QuicConnection(QuicConnectionId connection_id, |
249 IPEndPoint address, | 249 IPEndPoint address, |
250 QuicConnectionHelperInterface* helper, | 250 QuicConnectionHelperInterface* helper, |
251 const PacketWriterFactory& writer_factory, | 251 const PacketWriterFactory& writer_factory, |
252 bool owns_writer, | 252 bool owns_writer, |
253 bool is_server, | 253 bool is_server, |
254 const QuicVersionVector& supported_versions); | 254 const QuicVersionVector& supported_versions); |
255 virtual ~QuicConnection(); | 255 ~QuicConnection() override; |
256 | 256 |
257 // Sets connection parameters from the supplied |config|. | 257 // Sets connection parameters from the supplied |config|. |
258 void SetFromConfig(const QuicConfig& config); | 258 void SetFromConfig(const QuicConfig& config); |
259 | 259 |
260 // Send the data in |data| to the peer in as few packets as possible. | 260 // Send the data in |data| to the peer in as few packets as possible. |
261 // Returns a pair with the number of bytes consumed from data, and a boolean | 261 // Returns a pair with the number of bytes consumed from data, and a boolean |
262 // indicating if the fin bit was consumed. This does not indicate the data | 262 // indicating if the fin bit was consumed. This does not indicate the data |
263 // has been sent on the wire: it may have been turned into a packet and queued | 263 // has been sent on the wire: it may have been turned into a packet and queued |
264 // if the socket was unexpectedly blocked. |fec_protection| indicates if | 264 // if the socket was unexpectedly blocked. |fec_protection| indicates if |
265 // data is to be FEC protected. Note that data that is sent immediately | 265 // data is to be FEC protected. Note that data that is sent immediately |
(...skipping 26 matching lines...) Expand all Loading... |
292 // destroyed: otherwise call SendConnectionCloseWithDetails instead. | 292 // destroyed: otherwise call SendConnectionCloseWithDetails instead. |
293 virtual void SendConnectionClosePacket(QuicErrorCode error, | 293 virtual void SendConnectionClosePacket(QuicErrorCode error, |
294 const std::string& details); | 294 const std::string& details); |
295 | 295 |
296 // Sends a connection close frame to the peer, and closes the connection by | 296 // Sends a connection close frame to the peer, and closes the connection by |
297 // calling CloseConnection(notifying the visitor as it does so). | 297 // calling CloseConnection(notifying the visitor as it does so). |
298 virtual void SendConnectionClose(QuicErrorCode error); | 298 virtual void SendConnectionClose(QuicErrorCode error); |
299 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, | 299 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, |
300 const std::string& details); | 300 const std::string& details); |
301 // Notifies the visitor of the close and marks the connection as disconnected. | 301 // Notifies the visitor of the close and marks the connection as disconnected. |
302 virtual void CloseConnection(QuicErrorCode error, bool from_peer) override; | 302 void CloseConnection(QuicErrorCode error, bool from_peer) override; |
303 virtual void SendGoAway(QuicErrorCode error, | 303 virtual void SendGoAway(QuicErrorCode error, |
304 QuicStreamId last_good_stream_id, | 304 QuicStreamId last_good_stream_id, |
305 const std::string& reason); | 305 const std::string& reason); |
306 | 306 |
307 // Returns statistics tracked for this connection. | 307 // Returns statistics tracked for this connection. |
308 const QuicConnectionStats& GetStats(); | 308 const QuicConnectionStats& GetStats(); |
309 | 309 |
310 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from | 310 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from |
311 // the peer. If processing this packet permits a packet to be revived from | 311 // the peer. If processing this packet permits a packet to be revived from |
312 // its FEC group that packet will be revived and processed. | 312 // its FEC group that packet will be revived and processed. |
313 virtual void ProcessUdpPacket(const IPEndPoint& self_address, | 313 virtual void ProcessUdpPacket(const IPEndPoint& self_address, |
314 const IPEndPoint& peer_address, | 314 const IPEndPoint& peer_address, |
315 const QuicEncryptedPacket& packet); | 315 const QuicEncryptedPacket& packet); |
316 | 316 |
317 // QuicBlockedWriterInterface | 317 // QuicBlockedWriterInterface |
318 // Called when the underlying connection becomes writable to allow queued | 318 // Called when the underlying connection becomes writable to allow queued |
319 // writes to happen. | 319 // writes to happen. |
320 virtual void OnCanWrite() override; | 320 void OnCanWrite() override; |
321 | 321 |
322 // Called when an error occurs while attempting to write a packet to the | 322 // Called when an error occurs while attempting to write a packet to the |
323 // network. | 323 // network. |
324 void OnWriteError(int error_code); | 324 void OnWriteError(int error_code); |
325 | 325 |
326 // If the socket is not blocked, writes queued packets. | 326 // If the socket is not blocked, writes queued packets. |
327 void WriteIfNotBlocked(); | 327 void WriteIfNotBlocked(); |
328 | 328 |
329 // The version of the protocol this connection is using. | 329 // The version of the protocol this connection is using. |
330 QuicVersion version() const { return framer_.version(); } | 330 QuicVersion version() const { return framer_.version(); } |
331 | 331 |
332 // The versions of the protocol that this connection supports. | 332 // The versions of the protocol that this connection supports. |
333 const QuicVersionVector& supported_versions() const { | 333 const QuicVersionVector& supported_versions() const { |
334 return framer_.supported_versions(); | 334 return framer_.supported_versions(); |
335 } | 335 } |
336 | 336 |
337 // From QuicFramerVisitorInterface | 337 // From QuicFramerVisitorInterface |
338 virtual void OnError(QuicFramer* framer) override; | 338 void OnError(QuicFramer* framer) override; |
339 virtual bool OnProtocolVersionMismatch(QuicVersion received_version) override; | 339 bool OnProtocolVersionMismatch(QuicVersion received_version) override; |
340 virtual void OnPacket() override; | 340 void OnPacket() override; |
341 virtual void OnPublicResetPacket( | 341 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override; |
342 const QuicPublicResetPacket& packet) override; | 342 void OnVersionNegotiationPacket( |
343 virtual void OnVersionNegotiationPacket( | |
344 const QuicVersionNegotiationPacket& packet) override; | 343 const QuicVersionNegotiationPacket& packet) override; |
345 virtual void OnRevivedPacket() override; | 344 void OnRevivedPacket() override; |
346 virtual bool OnUnauthenticatedPublicHeader( | 345 bool OnUnauthenticatedPublicHeader( |
347 const QuicPacketPublicHeader& header) override; | 346 const QuicPacketPublicHeader& header) override; |
348 virtual bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; | 347 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override; |
349 virtual void OnDecryptedPacket(EncryptionLevel level) override; | 348 void OnDecryptedPacket(EncryptionLevel level) override; |
350 virtual bool OnPacketHeader(const QuicPacketHeader& header) override; | 349 bool OnPacketHeader(const QuicPacketHeader& header) override; |
351 virtual void OnFecProtectedPayload(base::StringPiece payload) override; | 350 void OnFecProtectedPayload(base::StringPiece payload) override; |
352 virtual bool OnStreamFrame(const QuicStreamFrame& frame) override; | 351 bool OnStreamFrame(const QuicStreamFrame& frame) override; |
353 virtual bool OnAckFrame(const QuicAckFrame& frame) override; | 352 bool OnAckFrame(const QuicAckFrame& frame) override; |
354 virtual bool OnCongestionFeedbackFrame( | 353 bool OnCongestionFeedbackFrame( |
355 const QuicCongestionFeedbackFrame& frame) override; | 354 const QuicCongestionFeedbackFrame& frame) override; |
356 virtual bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; | 355 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override; |
357 virtual bool OnPingFrame(const QuicPingFrame& frame) override; | 356 bool OnPingFrame(const QuicPingFrame& frame) override; |
358 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; | 357 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override; |
359 virtual bool OnConnectionCloseFrame( | 358 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override; |
360 const QuicConnectionCloseFrame& frame) override; | 359 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; |
361 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override; | 360 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; |
362 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override; | 361 bool OnBlockedFrame(const QuicBlockedFrame& frame) override; |
363 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) override; | 362 void OnFecData(const QuicFecData& fec) override; |
364 virtual void OnFecData(const QuicFecData& fec) override; | 363 void OnPacketComplete() override; |
365 virtual void OnPacketComplete() override; | |
366 | 364 |
367 // QuicPacketGenerator::DelegateInterface | 365 // QuicPacketGenerator::DelegateInterface |
368 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, | 366 bool ShouldGeneratePacket(TransmissionType transmission_type, |
369 HasRetransmittableData retransmittable, | 367 HasRetransmittableData retransmittable, |
370 IsHandshake handshake) override; | 368 IsHandshake handshake) override; |
371 virtual QuicAckFrame* CreateAckFrame() override; | 369 QuicAckFrame* CreateAckFrame() override; |
372 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() override; | 370 QuicCongestionFeedbackFrame* CreateFeedbackFrame() override; |
373 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() override; | 371 QuicStopWaitingFrame* CreateStopWaitingFrame() override; |
374 virtual void OnSerializedPacket(const SerializedPacket& packet) override; | 372 void OnSerializedPacket(const SerializedPacket& packet) override; |
375 | 373 |
376 // QuicSentPacketManager::NetworkChangeVisitor | 374 // QuicSentPacketManager::NetworkChangeVisitor |
377 virtual void OnCongestionWindowChange( | 375 void OnCongestionWindowChange(QuicByteCount congestion_window) override; |
378 QuicByteCount congestion_window) override; | |
379 | 376 |
380 // Called by the crypto stream when the handshake completes. In the server's | 377 // Called by the crypto stream when the handshake completes. In the server's |
381 // case this is when the SHLO has been ACKed. Clients call this on receipt of | 378 // case this is when the SHLO has been ACKed. Clients call this on receipt of |
382 // the SHLO. | 379 // the SHLO. |
383 void OnHandshakeComplete(); | 380 void OnHandshakeComplete(); |
384 | 381 |
385 // Accessors | 382 // Accessors |
386 void set_visitor(QuicConnectionVisitorInterface* visitor) { | 383 void set_visitor(QuicConnectionVisitorInterface* visitor) { |
387 visitor_ = visitor; | 384 visitor_ = visitor; |
388 } | 385 } |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 // If non-empty this contains the set of versions received in a | 814 // If non-empty this contains the set of versions received in a |
818 // version negotiation packet. | 815 // version negotiation packet. |
819 QuicVersionVector server_supported_versions_; | 816 QuicVersionVector server_supported_versions_; |
820 | 817 |
821 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 818 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
822 }; | 819 }; |
823 | 820 |
824 } // namespace net | 821 } // namespace net |
825 | 822 |
826 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 823 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |