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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 const QuicEncryptedPacket& packet); | 244 const QuicEncryptedPacket& packet); |
245 | 245 |
246 // QuicBlockedWriterInterface | 246 // QuicBlockedWriterInterface |
247 // Called when the underlying connection becomes writable to allow queued | 247 // Called when the underlying connection becomes writable to allow queued |
248 // writes to happen. Returns false if the socket has become blocked. | 248 // writes to happen. Returns false if the socket has become blocked. |
249 virtual bool OnCanWrite() OVERRIDE; | 249 virtual bool OnCanWrite() OVERRIDE; |
250 | 250 |
251 // Called when a packet has been finally sent to the network. | 251 // Called when a packet has been finally sent to the network. |
252 bool OnPacketSent(WriteResult result); | 252 bool OnPacketSent(WriteResult result); |
253 | 253 |
254 // If the socket is not blocked, this allows queued writes to happen. Returns | 254 // If the socket is not blocked, writes queued packets. |
255 // false if the socket has become blocked. | 255 void WriteIfNotBlocked(); |
256 bool WriteIfNotBlocked(); | |
257 | 256 |
258 // 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 |
259 // 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 |
260 // can be handled, false otherwise. | 259 // can be handled, false otherwise. |
261 bool ProcessValidatedPacket(); | 260 bool ProcessValidatedPacket(); |
262 | 261 |
263 // The version of the protocol this connection is using. | 262 // The version of the protocol this connection is using. |
264 QuicVersion version() const { return framer_.version(); } | 263 QuicVersion version() const { return framer_.version(); } |
265 | 264 |
266 // The versions of the protocol that this connection supports. | 265 // The versions of the protocol that this connection supports. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 410 } |
412 | 411 |
413 bool CanWrite(TransmissionType transmission_type, | 412 bool CanWrite(TransmissionType transmission_type, |
414 HasRetransmittableData retransmittable, | 413 HasRetransmittableData retransmittable, |
415 IsHandshake handshake); | 414 IsHandshake handshake); |
416 | 415 |
417 protected: | 416 protected: |
418 // 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| |
419 // 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 |
420 // 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. |
421 // Deletes |packet| via WritePacket call or transfers ownership to | 420 // Deletes |packet| if WritePacket call succeeds, or transfers ownership to |
422 // QueuedPacket, ultimately deleted via WritePacket. Updates the | 421 // QueuedPacket, ultimately deleted in WriteQueuedPackets. Updates the |
423 // entropy map corresponding to |sequence_number| using |entropy_hash|. | 422 // entropy map corresponding to |sequence_number| using |entropy_hash|. |
424 // |transmission_type| and |retransmittable| are supplied to the congestion | 423 // |transmission_type| and |retransmittable| are supplied to the congestion |
425 // manager, and when |forced| is true, it bypasses the congestion manager. | 424 // manager, and when |forced| is true, it bypasses the congestion manager. |
426 // TODO(wtc): none of the callers check the return value. | 425 // TODO(wtc): none of the callers check the return value. |
427 virtual bool SendOrQueuePacket(EncryptionLevel level, | 426 virtual bool SendOrQueuePacket(EncryptionLevel level, |
428 const SerializedPacket& packet, | 427 const SerializedPacket& packet, |
429 TransmissionType transmission_type); | 428 TransmissionType transmission_type); |
430 | 429 |
431 // 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 |
432 // of helper. Returns true on successful write, false otherwise. However, | 431 // of helper. Returns true on successful write, false otherwise. However, |
433 // 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 |
434 // circumstances, a return value of true implies that |packet| has been | 433 // circumstances, a return value of true implies that |packet| has been |
435 // deleted and should not be accessed. If |sequence_number| is present in | 434 // transmitted and may be destroyed. If |sequence_number| is present in |
436 // |retransmission_map_| it also sets up retransmission of the given packet | 435 // |retransmission_map_| it also sets up retransmission of the given packet |
437 // 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 |
438 // sent immediately and the send scheduler will not be consulted. | 437 // sent immediately and the send scheduler will not be consulted. |
439 bool WritePacket(EncryptionLevel level, | 438 bool WritePacket(EncryptionLevel level, |
440 QuicPacketSequenceNumber sequence_number, | 439 QuicPacketSequenceNumber sequence_number, |
441 QuicPacket* packet, | 440 QuicPacket* packet, |
442 TransmissionType transmission_type, | 441 TransmissionType transmission_type, |
443 HasRetransmittableData retransmittable, | 442 HasRetransmittableData retransmittable, |
444 IsHandshake handshake, | 443 IsHandshake handshake, |
445 Force force); | 444 Force force); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 531 |
533 typedef std::list<QueuedPacket> QueuedPacketList; | 532 typedef std::list<QueuedPacket> QueuedPacketList; |
534 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 533 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
535 | 534 |
536 // Sends a version negotiation packet to the peer. | 535 // Sends a version negotiation packet to the peer. |
537 void SendVersionNegotiationPacket(); | 536 void SendVersionNegotiationPacket(); |
538 | 537 |
539 // Clears any accumulated frames from the last received packet. | 538 // Clears any accumulated frames from the last received packet. |
540 void ClearLastFrames(); | 539 void ClearLastFrames(); |
541 | 540 |
542 // Called from OnCanWrite and WriteIfNotBlocked to write queued packets. | |
543 // Returns false if the socket has become blocked. | |
544 bool DoWrite(); | |
545 | |
546 // Calculates the smallest sequence number length that can also represent four | 541 // Calculates the smallest sequence number length that can also represent four |
547 // 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 |
548 // least_packet_awaited_by_peer_ and |sequence_number|. | 543 // least_packet_awaited_by_peer_ and |sequence_number|. |
549 QuicSequenceNumberLength CalculateSequenceNumberLength( | 544 QuicSequenceNumberLength CalculateSequenceNumberLength( |
550 QuicPacketSequenceNumber sequence_number); | 545 QuicPacketSequenceNumber sequence_number); |
551 | 546 |
552 // Drop packet corresponding to |sequence_number| by deleting entries from | 547 // Drop packet corresponding to |sequence_number| by deleting entries from |
553 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop | 548 // |unacked_packets_| and |retransmission_map_|, if present. We need to drop |
554 // 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 |
555 // to FORWARD_SECURE. | 550 // to FORWARD_SECURE. |
556 void DropPacket(QuicPacketSequenceNumber sequence_number); | 551 void DropPacket(QuicPacketSequenceNumber sequence_number); |
557 | 552 |
558 // 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 |
559 // blocked when this is called. | 554 // blocked when this is called. |
560 bool WriteQueuedPackets(); | 555 void WriteQueuedPackets(); |
561 | 556 |
562 // Writes as many pending retransmissions as possible. | 557 // Writes as many pending retransmissions as possible. |
563 void WritePendingRetransmissions(); | 558 void WritePendingRetransmissions(); |
564 | 559 |
565 // Returns true if the packet should be discarded and not sent. | 560 // Returns true if the packet should be discarded and not sent. |
566 bool ShouldDiscardPacket(EncryptionLevel level, | 561 bool ShouldDiscardPacket(EncryptionLevel level, |
567 QuicPacketSequenceNumber sequence_number, | 562 QuicPacketSequenceNumber sequence_number, |
568 HasRetransmittableData retransmittable); | 563 HasRetransmittableData retransmittable); |
569 | 564 |
570 // 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 Loading... |
640 // they are added to this list. All corresponding frames are in | 635 // they are added to this list. All corresponding frames are in |
641 // unacked_packets_ if they are to be retransmitted. | 636 // unacked_packets_ if they are to be retransmitted. |
642 QueuedPacketList queued_packets_; | 637 QueuedPacketList queued_packets_; |
643 | 638 |
644 // Contains information about the current write in progress, if any. | 639 // Contains information about the current write in progress, if any. |
645 scoped_ptr<PendingWrite> pending_write_; | 640 scoped_ptr<PendingWrite> pending_write_; |
646 | 641 |
647 // Contains the connection close packet if the connection has been closed. | 642 // Contains the connection close packet if the connection has been closed. |
648 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; | 643 scoped_ptr<QuicEncryptedPacket> connection_close_packet_; |
649 | 644 |
650 // True when the socket becomes unwritable. | |
651 bool write_blocked_; | |
652 | |
653 FecGroupMap group_map_; | 645 FecGroupMap group_map_; |
654 | 646 |
655 QuicReceivedPacketManager received_packet_manager_; | 647 QuicReceivedPacketManager received_packet_manager_; |
656 QuicSentEntropyManager sent_entropy_manager_; | 648 QuicSentEntropyManager sent_entropy_manager_; |
657 | 649 |
658 // 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. |
659 scoped_ptr<QuicAlarm> ack_alarm_; | 651 scoped_ptr<QuicAlarm> ack_alarm_; |
660 // An alarm that fires when a packet needs to be retransmitted. | 652 // An alarm that fires when a packet needs to be retransmitted. |
661 scoped_ptr<QuicAlarm> retransmission_alarm_; | 653 scoped_ptr<QuicAlarm> retransmission_alarm_; |
662 // 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 Loading... |
718 // 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 |
719 // version negotiation packet. | 711 // version negotiation packet. |
720 QuicVersionVector server_supported_versions_; | 712 QuicVersionVector server_supported_versions_; |
721 | 713 |
722 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 714 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
723 }; | 715 }; |
724 | 716 |
725 } // namespace net | 717 } // namespace net |
726 | 718 |
727 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 719 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |