Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: net/quic/quic_connection.h

Issue 131743009: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use size_t instead of int to fix win_x64 compile error Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 virtual bool OnStreamFrames(const std::vector<QuicStreamFrame>& frames) = 0; 68 virtual bool OnStreamFrames(const std::vector<QuicStreamFrame>& frames) = 0;
69 69
70 // Called when the stream is reset by the peer. 70 // Called when the stream is reset by the peer.
71 virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0; 71 virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0;
72 72
73 // Called when the connection is going away according to the peer. 73 // Called when the connection is going away according to the peer.
74 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0; 74 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0;
75 75
76 // Called when the connection is closed either locally by the framer, or 76 // Called when the connection is closed either locally by the framer, or
77 // remotely by the peer. 77 // remotely by the peer.
78 virtual void OnConnectionClosed(QuicErrorCode error, 78 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) = 0;
79 bool from_peer) = 0; 79
80 // Called when the connection failed to write because the socket was blocked.
81 virtual void OnWriteBlocked() = 0;
80 82
81 // Called once a specific QUIC version is agreed by both endpoints. 83 // Called once a specific QUIC version is agreed by both endpoints.
82 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; 84 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0;
83 85
84 // Indicates a new QuicConfig has been negotiated. 86 // Indicates a new QuicConfig has been negotiated.
85 virtual void OnConfigNegotiated() = 0; 87 virtual void OnConfigNegotiated() = 0;
86 88
87 // Called when a blocked socket becomes writable. If all pending bytes for 89 // Called when a blocked socket becomes writable. If all pending bytes for
88 // this visitor are consumed by the connection successfully this should 90 // this visitor are consumed by the connection successfully this should
89 // return true, otherwise it should return false. 91 // return true, otherwise it should return false.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 const QuicEncryptedPacket& packet); 244 const QuicEncryptedPacket& packet);
243 245
244 // QuicBlockedWriterInterface 246 // QuicBlockedWriterInterface
245 // Called when the underlying connection becomes writable to allow queued 247 // Called when the underlying connection becomes writable to allow queued
246 // writes to happen. Returns false if the socket has become blocked. 248 // writes to happen. Returns false if the socket has become blocked.
247 virtual bool OnCanWrite() OVERRIDE; 249 virtual bool OnCanWrite() OVERRIDE;
248 250
249 // Called when a packet has been finally sent to the network. 251 // Called when a packet has been finally sent to the network.
250 bool OnPacketSent(WriteResult result); 252 bool OnPacketSent(WriteResult result);
251 253
252 // If the socket is not blocked, this allows queued writes to happen. Returns 254 // If the socket is not blocked, writes queued packets.
253 // false if the socket has become blocked. 255 void WriteIfNotBlocked();
254 bool WriteIfNotBlocked();
255 256
256 // Do any work which logically would be done in OnPacket but can not be 257 // Do any work which logically would be done in OnPacket but can not be
257 // safely done until the packet is validated. Returns true if the packet 258 // safely done until the packet is validated. Returns true if the packet
258 // can be handled, false otherwise. 259 // can be handled, false otherwise.
259 bool ProcessValidatedPacket(); 260 bool ProcessValidatedPacket();
260 261
261 // The version of the protocol this connection is using. 262 // The version of the protocol this connection is using.
262 QuicVersion version() const { return framer_.version(); } 263 QuicVersion version() const { return framer_.version(); }
263 264
264 // The versions of the protocol that this connection supports. 265 // The versions of the protocol that this connection supports.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 size_t NumQueuedPackets() const { return queued_packets_.size(); } 333 size_t NumQueuedPackets() const { return queued_packets_.size(); }
333 334
334 QuicEncryptedPacket* ReleaseConnectionClosePacket() { 335 QuicEncryptedPacket* ReleaseConnectionClosePacket() {
335 return connection_close_packet_.release(); 336 return connection_close_packet_.release();
336 } 337 }
337 338
338 // Flush any queued frames immediately. Preserves the batch write mode and 339 // Flush any queued frames immediately. Preserves the batch write mode and
339 // does nothing if there are no pending frames. 340 // does nothing if there are no pending frames.
340 void Flush(); 341 void Flush();
341 342
343 // Returns true if the underlying UDP socket is writable, there is
344 // no queued data and the connection is not congestion-control
345 // blocked.
346 bool CanWriteStreamData();
347
342 // Returns true if the connection has queued packets or frames. 348 // Returns true if the connection has queued packets or frames.
343 bool HasQueuedData() const; 349 bool HasQueuedData() const;
344 350
345 // 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
346 // out the connection if network timer has expired for |timeout|. 352 // out the connection if network timer has expired for |timeout|.
347 void SetIdleNetworkTimeout(QuicTime::Delta timeout); 353 void SetIdleNetworkTimeout(QuicTime::Delta timeout);
348 // 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.
349 // 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
350 // |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
351 // handshake finishes. 357 // handshake finishes.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 410 }
405 411
406 bool CanWrite(TransmissionType transmission_type, 412 bool CanWrite(TransmissionType transmission_type,
407 HasRetransmittableData retransmittable, 413 HasRetransmittableData retransmittable,
408 IsHandshake handshake); 414 IsHandshake handshake);
409 415
410 protected: 416 protected:
411 // Send a packet to the peer using encryption |level|. If |sequence_number| 417 // Send a packet to the peer using encryption |level|. If |sequence_number|
412 // is present in the |retransmission_map_|, then contents of this packet will 418 // is present in the |retransmission_map_|, then contents of this packet will
413 // be retransmitted with a new sequence number if it's not acked by the peer. 419 // be retransmitted with a new sequence number if it's not acked by the peer.
414 // Deletes |packet| via WritePacket call or transfers ownership to 420 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to
415 // QueuedPacket, ultimately deleted via WritePacket. Updates the 421 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the
416 // entropy map corresponding to |sequence_number| using |entropy_hash|. 422 // entropy map corresponding to |sequence_number| using |entropy_hash|.
417 // |transmission_type| and |retransmittable| are supplied to the congestion 423 // |transmission_type| and |retransmittable| are supplied to the congestion
418 // manager, and when |forced| is true, it bypasses the congestion manager. 424 // manager, and when |forced| is true, it bypasses the congestion manager.
419 // TODO(wtc): none of the callers check the return value. 425 // TODO(wtc): none of the callers check the return value.
420 virtual bool SendOrQueuePacket(EncryptionLevel level, 426 virtual bool SendOrQueuePacket(EncryptionLevel level,
421 const SerializedPacket& packet, 427 const SerializedPacket& packet,
422 TransmissionType transmission_type); 428 TransmissionType transmission_type);
423 429
424 // Writes the given packet to socket, encrypted with |level|, with the help 430 // Writes the given packet to socket, encrypted with |level|, with the help
425 // of helper. Returns true on successful write, false otherwise. However, 431 // of helper. Returns true on successful write, false otherwise. However,
426 // behavior is undefined if connection is not established or broken. In any 432 // behavior is undefined if connection is not established or broken. In any
427 // circumstances, a return value of true implies that |packet| has been 433 // circumstances, a return value of true implies that |packet| has been
428 // deleted and should not be accessed. If |sequence_number| is present in 434 // transmitted and may be destroyed. If |sequence_number| is present in
429 // |retransmission_map_| it also sets up retransmission of the given packet 435 // |retransmission_map_| it also sets up retransmission of the given packet
430 // in case of successful write. If |force| is FORCE, then the packet will be 436 // in case of successful write. If |force| is FORCE, then the packet will be
431 // sent immediately and the send scheduler will not be consulted. 437 // sent immediately and the send scheduler will not be consulted.
432 bool WritePacket(EncryptionLevel level, 438 bool WritePacket(EncryptionLevel level,
433 QuicPacketSequenceNumber sequence_number, 439 QuicPacketSequenceNumber sequence_number,
434 QuicPacket* packet, 440 QuicPacket* packet,
435 TransmissionType transmission_type, 441 TransmissionType transmission_type,
436 HasRetransmittableData retransmittable, 442 HasRetransmittableData retransmittable,
437 IsHandshake handshake, 443 IsHandshake handshake,
438 Force force); 444 Force force);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 531
526 typedef std::list<QueuedPacket> QueuedPacketList; 532 typedef std::list<QueuedPacket> QueuedPacketList;
527 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; 533 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap;
528 534
529 // Sends a version negotiation packet to the peer. 535 // Sends a version negotiation packet to the peer.
530 void SendVersionNegotiationPacket(); 536 void SendVersionNegotiationPacket();
531 537
532 // Clears any accumulated frames from the last received packet. 538 // Clears any accumulated frames from the last received packet.
533 void ClearLastFrames(); 539 void ClearLastFrames();
534 540
535 // Called from OnCanWrite and WriteIfNotBlocked to write queued packets.
536 // Returns false if the socket has become blocked.
537 bool DoWrite();
538
539 // Calculates the smallest sequence number length that can also represent four 541 // Calculates the smallest sequence number length that can also represent four
540 // times the maximum of the congestion window and the difference between the 542 // times the maximum of the congestion window and the difference between the
541 // least_packet_awaited_by_peer_ and |sequence_number|. 543 // least_packet_awaited_by_peer_ and |sequence_number|.
542 QuicSequenceNumberLength CalculateSequenceNumberLength( 544 QuicSequenceNumberLength CalculateSequenceNumberLength(
543 QuicPacketSequenceNumber sequence_number); 545 QuicPacketSequenceNumber sequence_number);
544 546
545 // Drop packet corresponding to |sequence_number| by deleting entries from 547 // Drop packet corresponding to |sequence_number| by deleting entries from
546 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop 548 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop
547 // all packets with encryption level NONE after the default level has been set 549 // all packets with encryption level NONE after the default level has been set
548 // to FORWARD_SECURE. 550 // to FORWARD_SECURE.
549 void DropPacket(QuicPacketSequenceNumber sequence_number); 551 void DropPacket(QuicPacketSequenceNumber sequence_number);
550 552
551 // Writes as many queued packets as possible. The connection must not be 553 // Writes as many queued packets as possible. The connection must not be
552 // blocked when this is called. 554 // blocked when this is called.
553 bool WriteQueuedPackets(); 555 void WriteQueuedPackets();
554 556
555 // Writes as many pending retransmissions as possible. 557 // Writes as many pending retransmissions as possible.
556 void WritePendingRetransmissions(); 558 void WritePendingRetransmissions();
557 559
558 // Returns true if the packet should be discarded and not sent. 560 // Returns true if the packet should be discarded and not sent.
559 bool ShouldDiscardPacket(EncryptionLevel level, 561 bool ShouldDiscardPacket(EncryptionLevel level,
560 QuicPacketSequenceNumber sequence_number, 562 QuicPacketSequenceNumber sequence_number,
561 HasRetransmittableData retransmittable); 563 HasRetransmittableData retransmittable);
562 564
563 // Queues |packet| in the hopes that it can be decrypted in the 565 // Queues |packet| in the hopes that it can be decrypted in the
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // they are added to this list. All corresponding frames are in 635 // they are added to this list. All corresponding frames are in
634 // unacked_packets_ if they are to be retransmitted. 636 // unacked_packets_ if they are to be retransmitted.
635 QueuedPacketList queued_packets_; 637 QueuedPacketList queued_packets_;
636 638
637 // Contains information about the current write in progress, if any. 639 // Contains information about the current write in progress, if any.
638 scoped_ptr<PendingWrite> pending_write_; 640 scoped_ptr<PendingWrite> pending_write_;
639 641
640 // Contains the connection close packet if the connection has been closed. 642 // Contains the connection close packet if the connection has been closed.
641 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; 643 scoped_ptr<QuicEncryptedPacket> connection_close_packet_;
642 644
643 // True when the socket becomes unwritable.
644 bool write_blocked_;
645
646 FecGroupMap group_map_; 645 FecGroupMap group_map_;
647 646
648 QuicReceivedPacketManager received_packet_manager_; 647 QuicReceivedPacketManager received_packet_manager_;
649 QuicSentEntropyManager sent_entropy_manager_; 648 QuicSentEntropyManager sent_entropy_manager_;
650 649
651 // An alarm that fires when an ACK should be sent to the peer. 650 // An alarm that fires when an ACK should be sent to the peer.
652 scoped_ptr<QuicAlarm> ack_alarm_; 651 scoped_ptr<QuicAlarm> ack_alarm_;
653 // An alarm that fires when a packet needs to be retransmitted. 652 // An alarm that fires when a packet needs to be retransmitted.
654 scoped_ptr<QuicAlarm> retransmission_alarm_; 653 scoped_ptr<QuicAlarm> retransmission_alarm_;
655 // An alarm that is scheduled when the sent scheduler requires a 654 // An alarm that is scheduled when the sent scheduler requires a
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 // If non-empty this contains the set of versions received in a 710 // If non-empty this contains the set of versions received in a
712 // version negotiation packet. 711 // version negotiation packet.
713 QuicVersionVector server_supported_versions_; 712 QuicVersionVector server_supported_versions_;
714 713
715 DISALLOW_COPY_AND_ASSIGN(QuicConnection); 714 DISALLOW_COPY_AND_ASSIGN(QuicConnection);
716 }; 715 };
717 716
718 } // namespace net 717 } // namespace net
719 718
720 #endif // NET_QUIC_QUIC_CONNECTION_H_ 719 #endif // NET_QUIC_QUIC_CONNECTION_H_
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698