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 14 matching lines...) Expand all Loading... |
25 #include "base/hash_tables.h" | 25 #include "base/hash_tables.h" |
26 #include "net/base/ip_endpoint.h" | 26 #include "net/base/ip_endpoint.h" |
27 #include "net/base/linked_hash_map.h" | 27 #include "net/base/linked_hash_map.h" |
28 #include "net/quic/congestion_control/quic_congestion_manager.h" | 28 #include "net/quic/congestion_control/quic_congestion_manager.h" |
29 #include "net/quic/quic_blocked_writer_interface.h" | 29 #include "net/quic/quic_blocked_writer_interface.h" |
30 #include "net/quic/quic_framer.h" | 30 #include "net/quic/quic_framer.h" |
31 #include "net/quic/quic_packet_creator.h" | 31 #include "net/quic/quic_packet_creator.h" |
32 #include "net/quic/quic_packet_entropy_manager.h" | 32 #include "net/quic/quic_packet_entropy_manager.h" |
33 #include "net/quic/quic_packet_generator.h" | 33 #include "net/quic/quic_packet_generator.h" |
34 #include "net/quic/quic_protocol.h" | 34 #include "net/quic/quic_protocol.h" |
| 35 #include "net/quic/quic_stats.h" |
35 | 36 |
36 namespace net { | 37 namespace net { |
37 | 38 |
38 class QuicClock; | 39 class QuicClock; |
39 class QuicConnection; | 40 class QuicConnection; |
40 class QuicFecGroup; | 41 class QuicFecGroup; |
41 class QuicRandom; | 42 class QuicRandom; |
42 | 43 |
43 namespace test { | 44 namespace test { |
44 class QuicConnectionPeer; | 45 class QuicConnectionPeer; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface { | 83 class NET_EXPORT_PRIVATE QuicConnectionDebugVisitorInterface { |
83 public: | 84 public: |
84 virtual ~QuicConnectionDebugVisitorInterface() {} | 85 virtual ~QuicConnectionDebugVisitorInterface() {} |
85 | 86 |
86 // Called when a packet has been received, but before it is | 87 // Called when a packet has been received, but before it is |
87 // validated or parsed. | 88 // validated or parsed. |
88 virtual void OnPacketReceived(const IPEndPoint& self_address, | 89 virtual void OnPacketReceived(const IPEndPoint& self_address, |
89 const IPEndPoint& peer_address, | 90 const IPEndPoint& peer_address, |
90 const QuicEncryptedPacket& packet) = 0; | 91 const QuicEncryptedPacket& packet) = 0; |
91 | 92 |
92 // Called when the header of a packet has been parsed. | 93 // Called when the protocol version on the received packet doensn't match |
| 94 // current protocol version of the connection. |
| 95 virtual void OnProtocolVersionMismatch( |
| 96 QuicVersionTag version) = 0; |
| 97 |
| 98 // Called when the complete header of a packet has been parsed. |
93 virtual void OnPacketHeader(const QuicPacketHeader& header) = 0; | 99 virtual void OnPacketHeader(const QuicPacketHeader& header) = 0; |
94 | 100 |
95 // Called when a StreamFrame has been parsed. | 101 // Called when a StreamFrame has been parsed. |
96 virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; | 102 virtual void OnStreamFrame(const QuicStreamFrame& frame) = 0; |
97 | 103 |
98 // Called when a AckFrame has been parsed. | 104 // Called when a AckFrame has been parsed. |
99 virtual void OnAckFrame(const QuicAckFrame& frame) = 0; | 105 virtual void OnAckFrame(const QuicAckFrame& frame) = 0; |
100 | 106 |
101 // Called when a CongestionFeedbackFrame has been parsed. | 107 // Called when a CongestionFeedbackFrame has been parsed. |
102 virtual void OnCongestionFeedbackFrame( | 108 virtual void OnCongestionFeedbackFrame( |
103 const QuicCongestionFeedbackFrame& frame) = 0; | 109 const QuicCongestionFeedbackFrame& frame) = 0; |
104 | 110 |
105 // Called when a RstStreamFrame has been parsed. | 111 // Called when a RstStreamFrame has been parsed. |
106 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0; | 112 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) = 0; |
107 | 113 |
108 // Called when a ConnectionCloseFrame has been parsed. | 114 // Called when a ConnectionCloseFrame has been parsed. |
109 virtual void OnConnectionCloseFrame( | 115 virtual void OnConnectionCloseFrame( |
110 const QuicConnectionCloseFrame& frame) = 0; | 116 const QuicConnectionCloseFrame& frame) = 0; |
111 | 117 |
112 // Called when a public reset packet has been received. | 118 // Called when a public reset packet has been received. |
113 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0; | 119 virtual void OnPublicResetPacket(const QuicPublicResetPacket& packet) = 0; |
114 | 120 |
| 121 // Called when a version negotiation packet has been received. |
| 122 virtual void OnVersionNegotiationPacket( |
| 123 const QuicVersionNegotiationPacket& packet) = 0; |
| 124 |
115 // Called after a packet has been successfully parsed which results | 125 // Called after a packet has been successfully parsed which results |
116 // in the revival of a packet via FEC. | 126 // in the revival of a packet via FEC. |
117 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header, | 127 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header, |
118 base::StringPiece payload) = 0; | 128 base::StringPiece payload) = 0; |
119 }; | 129 }; |
120 | 130 |
121 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { | 131 class NET_EXPORT_PRIVATE QuicConnectionHelperInterface { |
122 public: | 132 public: |
123 virtual ~QuicConnectionHelperInterface() {} | 133 virtual ~QuicConnectionHelperInterface() {} |
124 | 134 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 185 |
176 class NET_EXPORT_PRIVATE QuicConnection | 186 class NET_EXPORT_PRIVATE QuicConnection |
177 : public QuicFramerVisitorInterface, | 187 : public QuicFramerVisitorInterface, |
178 public QuicBlockedWriterInterface, | 188 public QuicBlockedWriterInterface, |
179 public QuicPacketGenerator::DelegateInterface { | 189 public QuicPacketGenerator::DelegateInterface { |
180 public: | 190 public: |
181 // Constructs a new QuicConnection for the specified |guid| and |address|. | 191 // Constructs a new QuicConnection for the specified |guid| and |address|. |
182 // |helper| will be owned by this connection. | 192 // |helper| will be owned by this connection. |
183 QuicConnection(QuicGuid guid, | 193 QuicConnection(QuicGuid guid, |
184 IPEndPoint address, | 194 IPEndPoint address, |
185 QuicConnectionHelperInterface* helper); | 195 QuicConnectionHelperInterface* helper, |
| 196 bool is_server); |
186 virtual ~QuicConnection(); | 197 virtual ~QuicConnection(); |
187 | 198 |
188 static void DeleteEnclosedFrame(QuicFrame* frame); | 199 static void DeleteEnclosedFrame(QuicFrame* frame); |
189 | 200 |
190 // Send the data payload to the peer. | 201 // Send the data payload to the peer. |
191 // Returns a pair with the number of bytes consumed from data, and a boolean | 202 // Returns a pair with the number of bytes consumed from data, and a boolean |
192 // indicating if the fin bit was consumed. This does not indicate the data | 203 // indicating if the fin bit was consumed. This does not indicate the data |
193 // has been sent on the wire: it may have been turned into a packet and queued | 204 // has been sent on the wire: it may have been turned into a packet and queued |
194 // if the socket was unexpectedly blocked. | 205 // if the socket was unexpectedly blocked. |
195 QuicConsumedData SendStreamData(QuicStreamId id, | 206 QuicConsumedData SendStreamData(QuicStreamId id, |
(...skipping 14 matching lines...) Expand all Loading... |
210 // calling CloseConnection(notifying the visitor as it does so). | 221 // calling CloseConnection(notifying the visitor as it does so). |
211 virtual void SendConnectionClose(QuicErrorCode error); | 222 virtual void SendConnectionClose(QuicErrorCode error); |
212 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, | 223 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, |
213 const std::string& details); | 224 const std::string& details); |
214 // Notifies the visitor of the close and marks the connection as disconnected. | 225 // Notifies the visitor of the close and marks the connection as disconnected. |
215 void CloseConnection(QuicErrorCode error, bool from_peer); | 226 void CloseConnection(QuicErrorCode error, bool from_peer); |
216 virtual void SendGoAway(QuicErrorCode error, | 227 virtual void SendGoAway(QuicErrorCode error, |
217 QuicStreamId last_good_stream_id, | 228 QuicStreamId last_good_stream_id, |
218 const std::string& reason); | 229 const std::string& reason); |
219 | 230 |
| 231 // Returns statistics tracked for this connection. |
| 232 const QuicConnectionStats& GetStats(); |
| 233 |
220 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from | 234 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from |
221 // the peer. If processing this packet permits a packet to be revived from | 235 // the peer. If processing this packet permits a packet to be revived from |
222 // its FEC group that packet will be revived and processed. | 236 // its FEC group that packet will be revived and processed. |
223 virtual void ProcessUdpPacket(const IPEndPoint& self_address, | 237 virtual void ProcessUdpPacket(const IPEndPoint& self_address, |
224 const IPEndPoint& peer_address, | 238 const IPEndPoint& peer_address, |
225 const QuicEncryptedPacket& packet); | 239 const QuicEncryptedPacket& packet); |
226 | 240 |
227 // QuicBlockedWriterInterface | 241 // QuicBlockedWriterInterface |
228 // Called when the underlying connection becomes writable to allow | 242 // Called when the underlying connection becomes writable to allow |
229 // queued writes to happen. Returns false if the socket has become blocked. | 243 // queued writes to happen. Returns false if the socket has become blocked. |
230 virtual bool OnCanWrite() OVERRIDE; | 244 virtual bool OnCanWrite() OVERRIDE; |
231 | 245 |
| 246 QuicVersionTag version() const { |
| 247 return quic_version_; |
| 248 } |
| 249 |
232 // From QuicFramerVisitorInterface | 250 // From QuicFramerVisitorInterface |
233 virtual void OnError(QuicFramer* framer) OVERRIDE; | 251 virtual void OnError(QuicFramer* framer) OVERRIDE; |
| 252 virtual bool OnProtocolVersionMismatch( |
| 253 QuicVersionTag received_version) OVERRIDE; |
234 virtual void OnPacket() OVERRIDE; | 254 virtual void OnPacket() OVERRIDE; |
235 virtual void OnPublicResetPacket( | 255 virtual void OnPublicResetPacket( |
236 const QuicPublicResetPacket& packet) OVERRIDE; | 256 const QuicPublicResetPacket& packet) OVERRIDE; |
| 257 virtual void OnVersionNegotiationPacket( |
| 258 const QuicVersionNegotiationPacket& packet) OVERRIDE; |
237 virtual void OnRevivedPacket() OVERRIDE; | 259 virtual void OnRevivedPacket() OVERRIDE; |
238 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; | 260 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; |
239 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE; | 261 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE; |
240 virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; | 262 virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; |
241 virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE; | 263 virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE; |
242 virtual void OnCongestionFeedbackFrame( | 264 virtual void OnCongestionFeedbackFrame( |
243 const QuicCongestionFeedbackFrame& frame) OVERRIDE; | 265 const QuicCongestionFeedbackFrame& frame) OVERRIDE; |
244 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; | 266 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; |
245 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; | 267 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; |
246 virtual void OnConnectionCloseFrame( | 268 virtual void OnConnectionCloseFrame( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 373 |
352 QuicConnectionHelperInterface* helper() { return helper_; } | 374 QuicConnectionHelperInterface* helper() { return helper_; } |
353 | 375 |
354 private: | 376 private: |
355 friend class test::QuicConnectionPeer; | 377 friend class test::QuicConnectionPeer; |
356 | 378 |
357 // Packets which have not been written to the wire. | 379 // Packets which have not been written to the wire. |
358 // Owns the QuicPacket* packet. | 380 // Owns the QuicPacket* packet. |
359 struct QueuedPacket { | 381 struct QueuedPacket { |
360 QueuedPacket(QuicPacketSequenceNumber sequence_number, | 382 QueuedPacket(QuicPacketSequenceNumber sequence_number, |
361 QuicPacket* packet) | 383 QuicPacket* packet, |
| 384 bool has_retransmittable_data) |
362 : sequence_number(sequence_number), | 385 : sequence_number(sequence_number), |
363 packet(packet) { | 386 packet(packet), |
| 387 has_retransmittable_data(has_retransmittable_data) { |
364 } | 388 } |
365 | 389 |
366 QuicPacketSequenceNumber sequence_number; | 390 QuicPacketSequenceNumber sequence_number; |
367 QuicPacket* packet; | 391 QuicPacket* packet; |
| 392 bool has_retransmittable_data; |
368 }; | 393 }; |
369 | 394 |
370 struct RetransmissionInfo { | 395 struct RetransmissionInfo { |
371 explicit RetransmissionInfo(QuicPacketSequenceNumber sequence_number) | 396 explicit RetransmissionInfo(QuicPacketSequenceNumber sequence_number) |
372 : sequence_number(sequence_number), | 397 : sequence_number(sequence_number), |
373 scheduled_time(QuicTime::Zero()), | 398 scheduled_time(QuicTime::Zero()), |
374 number_nacks(0), | 399 number_nacks(0), |
375 number_retransmissions(0) { | 400 number_retransmissions(0) { |
376 } | 401 } |
377 | 402 |
(...skipping 17 matching lines...) Expand all Loading... |
395 typedef linked_hash_map<QuicPacketSequenceNumber, | 420 typedef linked_hash_map<QuicPacketSequenceNumber, |
396 RetransmittableFrames*> UnackedPacketMap; | 421 RetransmittableFrames*> UnackedPacketMap; |
397 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; | 422 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; |
398 typedef base::hash_map<QuicPacketSequenceNumber, | 423 typedef base::hash_map<QuicPacketSequenceNumber, |
399 RetransmissionInfo> RetransmissionMap; | 424 RetransmissionInfo> RetransmissionMap; |
400 typedef std::priority_queue<RetransmissionInfo, | 425 typedef std::priority_queue<RetransmissionInfo, |
401 std::vector<RetransmissionInfo>, | 426 std::vector<RetransmissionInfo>, |
402 RetransmissionInfoComparator> | 427 RetransmissionInfoComparator> |
403 RetransmissionTimeouts; | 428 RetransmissionTimeouts; |
404 | 429 |
| 430 // Selects and updates the version of the protocol being used by selecting a |
| 431 // version from |available_versions| which is also supported. Returns true if |
| 432 // such a version exists, false otherwise. |
| 433 bool SelectMutualVersion( |
| 434 const QuicVersionTagList& available_versions); |
| 435 // Sends a version negotiation packet to the peer. |
| 436 void SendVersionNegotiationPacket(); |
| 437 |
405 // Checks if a packet can be written now, and sets the timer if necessary. | 438 // Checks if a packet can be written now, and sets the timer if necessary. |
406 virtual bool CanWrite(bool is_retransmission) OVERRIDE; | 439 virtual bool CanWrite(bool is_retransmission, |
| 440 bool has_retransmittable_data) OVERRIDE; |
407 | 441 |
408 void MaybeSetupRetransmission(QuicPacketSequenceNumber sequence_number); | 442 void MaybeSetupRetransmission(QuicPacketSequenceNumber sequence_number); |
409 bool IsRetransmission(QuicPacketSequenceNumber sequence_number); | 443 bool IsRetransmission(QuicPacketSequenceNumber sequence_number); |
| 444 void RetransmitAllUnackedPackets(); |
410 | 445 |
411 // Writes as many queued packets as possible. The connection must not be | 446 // Writes as many queued packets as possible. The connection must not be |
412 // blocked when this is called. | 447 // blocked when this is called. |
413 bool WriteQueuedPackets(); | 448 bool WriteQueuedPackets(); |
414 | 449 |
415 // If a packet can be revived from the current FEC group, then | 450 // If a packet can be revived from the current FEC group, then |
416 // revive and process the packet. | 451 // revive and process the packet. |
417 void MaybeProcessRevivedPacket(); | 452 void MaybeProcessRevivedPacket(); |
418 | 453 |
419 void UpdateOutgoingAck(); | 454 void UpdateOutgoingAck(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 QuicPacketEntropyManager entropy_manager_; | 528 QuicPacketEntropyManager entropy_manager_; |
494 | 529 |
495 QuicConnectionVisitorInterface* visitor_; | 530 QuicConnectionVisitorInterface* visitor_; |
496 QuicConnectionDebugVisitorInterface* debug_visitor_; | 531 QuicConnectionDebugVisitorInterface* debug_visitor_; |
497 QuicPacketCreator packet_creator_; | 532 QuicPacketCreator packet_creator_; |
498 QuicPacketGenerator packet_generator_; | 533 QuicPacketGenerator packet_generator_; |
499 | 534 |
500 // Network idle time before we kill of this connection. | 535 // Network idle time before we kill of this connection. |
501 const QuicTime::Delta timeout_; | 536 const QuicTime::Delta timeout_; |
502 | 537 |
| 538 // Statistics for this session. |
| 539 QuicConnectionStats stats_; |
| 540 |
503 // The time that we got a packet for this connection. | 541 // The time that we got a packet for this connection. |
504 QuicTime time_of_last_received_packet_; | 542 QuicTime time_of_last_received_packet_; |
505 | 543 |
506 // The time that we last sent a packet for this connection. | 544 // The time that we last sent a packet for this connection. |
507 QuicTime time_of_last_sent_packet_; | 545 QuicTime time_of_last_sent_packet_; |
508 | 546 |
509 // Congestion manager which controls the rate the connection sends packets | 547 // Congestion manager which controls the rate the connection sends packets |
510 // as well as collecting and generating congestion feedback. | 548 // as well as collecting and generating congestion feedback. |
511 QuicCongestionManager congestion_manager_; | 549 QuicCongestionManager congestion_manager_; |
512 | 550 |
| 551 // The state of connection in version negotiation finite state machine. |
| 552 QuicVersionNegotiationState version_negotiation_state_; |
| 553 |
| 554 // The version of the protocol this connection is using. |
| 555 QuicVersionTag quic_version_; |
| 556 |
| 557 // Tracks if the connection was created by the server. |
| 558 bool is_server_; |
| 559 |
513 // True by default. False if we've received or sent an explicit connection | 560 // True by default. False if we've received or sent an explicit connection |
514 // close. | 561 // close. |
515 bool connected_; | 562 bool connected_; |
516 | 563 |
517 // True if the last ack received from the peer may have been truncated. False | 564 // True if the last ack received from the peer may have been truncated. False |
518 // otherwise. | 565 // otherwise. |
519 bool received_truncated_ack_; | 566 bool received_truncated_ack_; |
520 | 567 |
521 bool send_ack_in_response_to_packet_; | 568 bool send_ack_in_response_to_packet_; |
522 | 569 |
523 DISALLOW_COPY_AND_ASSIGN(QuicConnection); | 570 DISALLOW_COPY_AND_ASSIGN(QuicConnection); |
524 }; | 571 }; |
525 | 572 |
526 } // namespace net | 573 } // namespace net |
527 | 574 |
528 #endif // NET_QUIC_QUIC_CONNECTION_H_ | 575 #endif // NET_QUIC_QUIC_CONNECTION_H_ |
OLD | NEW |