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

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

Issue 12334063: Land recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more EXPECT_FALSE Created 7 years, 9 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_clock_test.cc ('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 //
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 <list> 19 #include <list>
20 #include <map>
20 #include <queue> 21 #include <queue>
21 #include <set> 22 #include <set>
22 #include <vector> 23 #include <vector>
23 24
24 #include "base/hash_tables.h" 25 #include "base/hash_tables.h"
25 #include "net/base/ip_endpoint.h" 26 #include "net/base/ip_endpoint.h"
27 #include "net/base/linked_hash_map.h"
26 #include "net/quic/congestion_control/quic_congestion_manager.h" 28 #include "net/quic/congestion_control/quic_congestion_manager.h"
27 #include "net/quic/quic_blocked_writer_interface.h" 29 #include "net/quic/quic_blocked_writer_interface.h"
28 #include "net/quic/quic_fec_group.h" 30 #include "net/quic/quic_fec_group.h"
29 #include "net/quic/quic_framer.h" 31 #include "net/quic/quic_framer.h"
30 #include "net/quic/quic_packet_creator.h" 32 #include "net/quic/quic_packet_creator.h"
33 #include "net/quic/quic_packet_entropy_manager.h"
34 #include "net/quic/quic_packet_generator.h"
31 #include "net/quic/quic_protocol.h" 35 #include "net/quic/quic_protocol.h"
32 36
33 namespace net { 37 namespace net {
34 38
35 class QuicClock; 39 class QuicClock;
36 class QuicConnection; 40 class QuicConnection;
37 class QuicEncrypter; 41 class QuicEncrypter;
38 class QuicFecGroup; 42 class QuicFecGroup;
39 class QuicRandom; 43 class QuicRandom;
40 44
41 namespace test { 45 namespace test {
42 class QuicConnectionPeer; 46 class QuicConnectionPeer;
43 } // namespace test 47 } // namespace test
44 48
45 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface { 49 class NET_EXPORT_PRIVATE QuicConnectionVisitorInterface {
46 public: 50 public:
47 typedef std::set<QuicPacketSequenceNumber> AckedPackets;
48
49 virtual ~QuicConnectionVisitorInterface() {} 51 virtual ~QuicConnectionVisitorInterface() {}
50 52
51 // A simple visitor interface for dealing with data frames. The session 53 // A simple visitor interface for dealing with data frames. The session
52 // should determine if all frames will be accepted, and return true if so. 54 // should determine if all frames will be accepted, and return true if so.
53 // If any frames can't be processed or buffered, none of the data should 55 // If any frames can't be processed or buffered, none of the data should
54 // be used, and the callee should return false. 56 // be used, and the callee should return false.
55 virtual bool OnPacket(const IPEndPoint& self_address, 57 virtual bool OnPacket(const IPEndPoint& self_address,
56 const IPEndPoint& peer_address, 58 const IPEndPoint& peer_address,
57 const QuicPacketHeader& header, 59 const QuicPacketHeader& header,
58 const std::vector<QuicStreamFrame>& frame) = 0; 60 const std::vector<QuicStreamFrame>& frame) = 0;
59 61
60 // Called when the stream is reset by the peer. 62 // Called when the stream is reset by the peer.
61 virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0; 63 virtual void OnRstStream(const QuicRstStreamFrame& frame) = 0;
62 64
65 // Called when the connection is going away according to the peer.
66 virtual void OnGoAway(const QuicGoAwayFrame& frame) = 0;
67
63 // Called when the connection is closed either locally by the framer, or 68 // Called when the connection is closed either locally by the framer, or
64 // remotely by the peer. 69 // remotely by the peer.
65 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) = 0; 70 virtual void ConnectionClose(QuicErrorCode error, bool from_peer) = 0;
66 71
67 // Called when packets are acked by the peer. 72 // Called when packets are acked by the peer.
68 virtual void OnAck(AckedPackets acked_packets) = 0; 73 virtual void OnAck(const SequenceNumberSet& acked_packets) = 0;
69 74
70 // Called when a blocked socket becomes writable. If all pending bytes for 75 // Called when a blocked socket becomes writable. If all pending bytes for
71 // this visitor are consumed by the connection successfully this should 76 // this visitor are consumed by the connection successfully this should
72 // return true, otherwise it should return false. 77 // return true, otherwise it should return false.
73 virtual bool OnCanWrite() = 0; 78 virtual bool OnCanWrite() = 0;
74 }; 79 };
75 80
76 // Interface which gets callbacks from the QuicConnection at interesting 81 // Interface which gets callbacks from the QuicConnection at interesting
77 // points. Implementations must not mutate the state of the connection 82 // points. Implementations must not mutate the state of the connection
78 // as a result of these callbacks. 83 // as a result of these callbacks.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Sets an alarm which fires when an Ack may need to be sent. 168 // Sets an alarm which fires when an Ack may need to be sent.
164 // Implementations must call SendAck() when the alarm fires. 169 // Implementations must call SendAck() when the alarm fires.
165 // If the alarm is already registered for a shorter timeout, this call is a 170 // If the alarm is already registered for a shorter timeout, this call is a
166 // no-op. 171 // no-op.
167 virtual void SetAckAlarm(QuicTime::Delta delay) = 0; 172 virtual void SetAckAlarm(QuicTime::Delta delay) = 0;
168 173
169 // Clears the ack alarm if it was set. If it was not set, this is a no-op. 174 // Clears the ack alarm if it was set. If it was not set, this is a no-op.
170 virtual void ClearAckAlarm() = 0; 175 virtual void ClearAckAlarm() = 0;
171 }; 176 };
172 177
173 class NET_EXPORT_PRIVATE QuicConnection : public QuicFramerVisitorInterface, 178 class NET_EXPORT_PRIVATE QuicConnection
174 public QuicBlockedWriterInterface { 179 : public QuicFramerVisitorInterface,
180 public QuicBlockedWriterInterface,
181 public QuicPacketGenerator::DelegateInterface {
175 public: 182 public:
176 // Constructs a new QuicConnection for the specified |guid| and |address|. 183 // Constructs a new QuicConnection for the specified |guid| and |address|.
177 // |helper| will be owned by this connection. 184 // |helper| will be owned by this connection.
178 QuicConnection(QuicGuid guid, 185 QuicConnection(QuicGuid guid,
179 IPEndPoint address, 186 IPEndPoint address,
180 QuicConnectionHelperInterface* helper); 187 QuicConnectionHelperInterface* helper);
181 virtual ~QuicConnection(); 188 virtual ~QuicConnection();
182 189
183 static void DeleteEnclosedFrame(QuicFrame* frame); 190 static void DeleteEnclosedFrame(QuicFrame* frame);
184 191
185 // Send the data payload to the peer. 192 // Send the data payload to the peer.
186 // Returns a pair with the number of bytes consumed from data, and a boolean 193 // Returns a pair with the number of bytes consumed from data, and a boolean
187 // indicating if the fin bit was consumed. This does not indicate the data 194 // indicating if the fin bit was consumed. This does not indicate the data
188 // has been sent on the wire: it may have been turned into a packet and queued 195 // has been sent on the wire: it may have been turned into a packet and queued
189 // if the socket was unexpectedly blocked. 196 // if the socket was unexpectedly blocked.
190 QuicConsumedData SendStreamData(QuicStreamId id, 197 QuicConsumedData SendStreamData(QuicStreamId id,
191 base::StringPiece data, 198 base::StringPiece data,
192 QuicStreamOffset offset, 199 QuicStreamOffset offset,
193 bool fin); 200 bool fin);
194 // Send a stream reset frame to the peer. 201 // Send a stream reset frame to the peer.
195 virtual void SendRstStream(QuicStreamId id, 202 virtual void SendRstStream(QuicStreamId id,
196 QuicErrorCode error, 203 QuicErrorCode error);
197 QuicStreamOffset offset); 204
205 // Sends the connection close packet without affecting the state of the
206 // connection. This should only be called if the session is actively being
207 // destroyed: otherwise call SendConnectionCloseWithDetails instead.
208 virtual void SendConnectionClosePacket(QuicErrorCode error,
209 const std::string& details);
210
198 // Sends a connection close frame to the peer, and closes the connection by 211 // Sends a connection close frame to the peer, and closes the connection by
199 // calling CloseConnection(notifying the visitor as it does so). 212 // calling CloseConnection(notifying the visitor as it does so).
200 virtual void SendConnectionClose(QuicErrorCode error); 213 virtual void SendConnectionClose(QuicErrorCode error);
201 virtual void SendConnectionCloseWithDetails(QuicErrorCode error, 214 virtual void SendConnectionCloseWithDetails(QuicErrorCode error,
202 const std::string& details); 215 const std::string& details);
203 // Notifies the visitor of the close and marks the connection as disconnected. 216 // Notifies the visitor of the close and marks the connection as disconnected.
204 void CloseConnection(QuicErrorCode error, bool from_peer); 217 void CloseConnection(QuicErrorCode error, bool from_peer);
218 virtual void SendGoAway(QuicErrorCode error,
219 QuicStreamId last_good_stream_id,
220 const std::string& reason);
205 221
206 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from 222 // Processes an incoming UDP packet (consisting of a QuicEncryptedPacket) from
207 // the peer. If processing this packet permits a packet to be revived from 223 // the peer. If processing this packet permits a packet to be revived from
208 // its FEC group that packet will be revived and processed. 224 // its FEC group that packet will be revived and processed.
209 virtual void ProcessUdpPacket(const IPEndPoint& self_address, 225 virtual void ProcessUdpPacket(const IPEndPoint& self_address,
210 const IPEndPoint& peer_address, 226 const IPEndPoint& peer_address,
211 const QuicEncryptedPacket& packet); 227 const QuicEncryptedPacket& packet);
212 228
213 // QuicBlockedWriterInterface 229 // QuicBlockedWriterInterface
214 // Called when the underlying connection becomes writable to allow 230 // Called when the underlying connection becomes writable to allow
215 // queued writes to happen. Returns false if the socket has become blocked. 231 // queued writes to happen. Returns false if the socket has become blocked.
216 virtual bool OnCanWrite() OVERRIDE; 232 virtual bool OnCanWrite() OVERRIDE;
217 233
218 // From QuicFramerVisitorInterface 234 // From QuicFramerVisitorInterface
219 virtual void OnError(QuicFramer* framer) OVERRIDE; 235 virtual void OnError(QuicFramer* framer) OVERRIDE;
220 virtual void OnPacket() OVERRIDE; 236 virtual void OnPacket() OVERRIDE;
221 virtual void OnPublicResetPacket( 237 virtual void OnPublicResetPacket(
222 const QuicPublicResetPacket& packet) OVERRIDE; 238 const QuicPublicResetPacket& packet) OVERRIDE;
223 virtual void OnRevivedPacket() OVERRIDE; 239 virtual void OnRevivedPacket() OVERRIDE;
224 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; 240 virtual bool OnPacketHeader(const QuicPacketHeader& header) OVERRIDE;
225 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE; 241 virtual void OnFecProtectedPayload(base::StringPiece payload) OVERRIDE;
226 virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; 242 virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE;
227 virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE; 243 virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE;
228 virtual void OnCongestionFeedbackFrame( 244 virtual void OnCongestionFeedbackFrame(
229 const QuicCongestionFeedbackFrame& frame) OVERRIDE; 245 const QuicCongestionFeedbackFrame& frame) OVERRIDE;
230 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; 246 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE;
247 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE;
231 virtual void OnConnectionCloseFrame( 248 virtual void OnConnectionCloseFrame(
232 const QuicConnectionCloseFrame& frame) OVERRIDE; 249 const QuicConnectionCloseFrame& frame) OVERRIDE;
233 virtual void OnFecData(const QuicFecData& fec) OVERRIDE; 250 virtual void OnFecData(const QuicFecData& fec) OVERRIDE;
234 virtual void OnPacketComplete() OVERRIDE; 251 virtual void OnPacketComplete() OVERRIDE;
235 252
253 // QuicPacketGenerator::DelegateInterface
254 virtual QuicAckFrame* CreateAckFrame() OVERRIDE;
255 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() OVERRIDE;
256 virtual bool OnSerializedPacket(const SerializedPacket& packet) OVERRIDE;
257
236 // Accessors 258 // Accessors
237 void set_visitor(QuicConnectionVisitorInterface* visitor) { 259 void set_visitor(QuicConnectionVisitorInterface* visitor) {
238 visitor_ = visitor; 260 visitor_ = visitor;
239 } 261 }
240 void set_debug_visitor(QuicConnectionDebugVisitorInterface* debug_visitor) { 262 void set_debug_visitor(QuicConnectionDebugVisitorInterface* debug_visitor) {
241 debug_visitor_ = debug_visitor; 263 debug_visitor_ = debug_visitor;
242 } 264 }
243 const IPEndPoint& self_address() const { return self_address_; } 265 const IPEndPoint& self_address() const { return self_address_; }
244 const IPEndPoint& peer_address() const { return peer_address_; } 266 const IPEndPoint& peer_address() const { return peer_address_; }
245 QuicGuid guid() const { return guid_; } 267 QuicGuid guid() const { return guid_; }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 bool ShouldSimulateLostPacket(); 301 bool ShouldSimulateLostPacket();
280 302
281 // Sets up a packet with an QuicAckFrame and sends it out. 303 // Sets up a packet with an QuicAckFrame and sends it out.
282 void SendAck(); 304 void SendAck();
283 305
284 // Called when an RTO fires. Returns the time when this alarm 306 // Called when an RTO fires. Returns the time when this alarm
285 // should next fire, or 0 if no retransmission alarm should be set. 307 // should next fire, or 0 if no retransmission alarm should be set.
286 QuicTime OnRetransmissionTimeout(); 308 QuicTime OnRetransmissionTimeout();
287 309
288 protected: 310 protected:
289 // Serializes then sends or queues the packet currently open. 311 // Deletes all missing packets before least unacked. The connection won't
290 void SendOrQueueCurrentPacket(); 312 // process any packets with sequence number before |least_unacked| that it
313 // received after this call. Returns true if there were missing packets before
314 // |least_unacked| unacked, false otherwise.
315 bool DontWaitForPacketsBefore(QuicPacketSequenceNumber least_unacked);
291 316
292 // Send a packet to the peer. If |sequence_number| is present in the 317 // Send a packet to the peer. If |sequence_number| is present in the
293 // |retransmission_map_|, then contents of this packet will be retransmitted 318 // |retransmission_map_|, then contents of this packet will be retransmitted
294 // with a new sequence number if it's not acked by the peer. Deletes 319 // with a new sequence number if it's not acked by the peer. Deletes
295 // |packet| via WritePacket call or transfers ownership to QueuedPacket, 320 // |packet| via WritePacket call or transfers ownership to QueuedPacket,
296 // ultimately deleted via WritePacket. If |force| is true, then the packet 321 // ultimately deleted via WritePacket. Also, it updates the entropy map
297 // will be sent immediately and the send scheduler will not be consulted. 322 // corresponding to |sequence_number| using |entropy_hash|.
298 // TODO(wtc): none of the callers check the return value. 323 // TODO(wtc): none of the callers check the return value.
299 virtual bool SendOrQueuePacket(QuicPacketSequenceNumber sequence_number, 324 virtual bool SendOrQueuePacket(QuicPacketSequenceNumber sequence_number,
300 QuicPacket* packet, 325 QuicPacket* packet,
301 bool force); 326 QuicPacketEntropyHash entropy_hash);
302 327
303 // Writes the given packet to socket with the help of helper. Returns true on 328 // Writes the given packet to socket with the help of helper. Returns true on
304 // successful write, false otherwise. However, behavior is undefined if 329 // successful write, false otherwise. However, behavior is undefined if
305 // connection is not established or broken. In any circumstances, a return 330 // connection is not established or broken. In any circumstances, a return
306 // value of true implies that |packet| has been deleted and should not be 331 // value of true implies that |packet| has been deleted and should not be
307 // accessed. If |sequence_number| is present in |retransmission_map_| it also 332 // accessed. If |sequence_number| is present in |retransmission_map_| it also
308 // sets up retransmission of the given packet in case of successful write. If 333 // sets up retransmission of the given packet in case of successful write. If
309 // |force| is true, then the packet will be sent immediately and the send 334 // |force| is true, then the packet will be sent immediately and the send
310 // scheduler will not be consulted. 335 // scheduler will not be consulted.
311 bool WritePacket(QuicPacketSequenceNumber sequence_number, 336 bool WritePacket(QuicPacketSequenceNumber sequence_number,
312 QuicPacket* packet, 337 QuicPacket* packet,
313 bool force); 338 bool force);
314 339
315 // Make sure an ack we got from our peer is sane. 340 // Make sure an ack we got from our peer is sane.
316 bool ValidateAckFrame(const QuicAckFrame& incoming_ack); 341 bool ValidateAckFrame(const QuicAckFrame& incoming_ack);
317 342
318 // These two are called by OnAckFrame to update the appropriate internal 343 // These two are called by OnAckFrame to update the appropriate internal
319 // state. 344 // state.
320 // 345 //
321 // Updates internal state based on incoming_ack.received_info 346 // Updates internal state based on incoming_ack.received_info
322 void UpdatePacketInformationReceivedByPeer( 347 void UpdatePacketInformationReceivedByPeer(
323 const QuicAckFrame& incoming_ack); 348 const QuicAckFrame& incoming_ack);
324 // Updates internal state based in incoming_ack.sent_info 349 // Updates internal state based in incoming_ack.sent_info
325 void UpdatePacketInformationSentByPeer(const QuicAckFrame& incoming_ack); 350 void UpdatePacketInformationSentByPeer(const QuicAckFrame& incoming_ack);
326 351
327 // Utility which sets SetLeastUnacked to least_unacked, and updates the list
328 // of non-retransmitting packets accordingly.
329 void SetLeastUnacked(QuicPacketSequenceNumber least_unacked);
330
331 // Helper to update least unacked. If acked_sequence_number was not the least
332 // unacked packet, this is a no-op. If it was the least unacked packet,
333 // this finds the new least unacked packet and updates the outgoing ack frame.
334 void UpdateLeastUnacked(QuicPacketSequenceNumber acked_sequence_number);
335
336 QuicConnectionHelperInterface* helper() { return helper_; } 352 QuicConnectionHelperInterface* helper() { return helper_; }
337 353
338 private: 354 private:
339 friend class test::QuicConnectionPeer; 355 friend class test::QuicConnectionPeer;
340 356
341 // Packets which have not been written to the wire. 357 // Packets which have not been written to the wire.
342 // Owns the QuicPacket* packet. 358 // Owns the QuicPacket* packet.
343 struct QueuedPacket { 359 struct QueuedPacket {
344 QueuedPacket(QuicPacketSequenceNumber sequence_number, 360 QueuedPacket(QuicPacketSequenceNumber sequence_number,
345 QuicPacket* packet) 361 QuicPacket* packet)
346 : sequence_number(sequence_number), 362 : sequence_number(sequence_number),
347 packet(packet) { 363 packet(packet) {
348 } 364 }
349 365
350 QuicPacketSequenceNumber sequence_number; 366 QuicPacketSequenceNumber sequence_number;
351 QuicPacket* packet; 367 QuicPacket* packet;
352 }; 368 };
353 369
354 struct UnackedPacket {
355 explicit UnackedPacket(QuicFrames unacked_frames);
356 UnackedPacket(QuicFrames unacked_frames, std::string data);
357 ~UnackedPacket();
358
359 QuicFrames frames;
360 // Data referenced by the StringPiece of a QuicStreamFrame.
361 std::string data;
362 };
363
364 struct RetransmissionInfo { 370 struct RetransmissionInfo {
365 explicit RetransmissionInfo(QuicPacketSequenceNumber sequence_number) 371 explicit RetransmissionInfo(QuicPacketSequenceNumber sequence_number)
366 : sequence_number(sequence_number), 372 : sequence_number(sequence_number),
367 scheduled_time(QuicTime::Zero()), 373 scheduled_time(QuicTime::Zero()),
368 number_nacks(0), 374 number_nacks(0),
369 number_retransmissions(0) { 375 number_retransmissions(0) {
370 } 376 }
371 377
372 QuicPacketSequenceNumber sequence_number; 378 QuicPacketSequenceNumber sequence_number;
373 QuicTime scheduled_time; 379 QuicTime scheduled_time;
374 size_t number_nacks; 380 size_t number_nacks;
375 size_t number_retransmissions; 381 size_t number_retransmissions;
376 }; 382 };
377 383
378 class RetransmissionInfoComparator { 384 class RetransmissionInfoComparator {
379 public: 385 public:
380 bool operator()(const RetransmissionInfo& lhs, 386 bool operator()(const RetransmissionInfo& lhs,
381 const RetransmissionInfo& rhs) const { 387 const RetransmissionInfo& rhs) const {
382 DCHECK(lhs.scheduled_time.IsInitialized() && 388 DCHECK(lhs.scheduled_time.IsInitialized() &&
383 rhs.scheduled_time.IsInitialized()); 389 rhs.scheduled_time.IsInitialized());
384 return lhs.scheduled_time > rhs.scheduled_time; 390 return lhs.scheduled_time > rhs.scheduled_time;
385 } 391 }
386 }; 392 };
387 393
388 typedef std::list<QueuedPacket> QueuedPacketList; 394 typedef std::list<QueuedPacket> QueuedPacketList;
389 typedef base::hash_map<QuicPacketSequenceNumber, 395 typedef linked_hash_map<QuicPacketSequenceNumber,
390 UnackedPacket*> UnackedPacketMap; 396 RetransmittableFrames*> UnackedPacketMap;
391 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap; 397 typedef std::map<QuicFecGroupNumber, QuicFecGroup*> FecGroupMap;
392 typedef base::hash_map<QuicPacketSequenceNumber, 398 typedef base::hash_map<QuicPacketSequenceNumber,
393 RetransmissionInfo> RetransmissionMap; 399 RetransmissionInfo> RetransmissionMap;
394 typedef std::priority_queue<RetransmissionInfo, 400 typedef std::priority_queue<RetransmissionInfo,
395 std::vector<RetransmissionInfo>, 401 std::vector<RetransmissionInfo>,
396 RetransmissionInfoComparator> 402 RetransmissionInfoComparator>
397 RetransmissionTimeouts; 403 RetransmissionTimeouts;
398 404
399 static void DeleteEnclosedFrames(UnackedPacket* unacked);
400
401 // Checks if a packet can be written now, and sets the timer if necessary. 405 // Checks if a packet can be written now, and sets the timer if necessary.
402 bool CanWrite(bool is_retransmission); 406 virtual bool CanWrite(bool is_retransmission) OVERRIDE;
403 407
404 void MaybeSetupRetransmission(QuicPacketSequenceNumber sequence_number); 408 void MaybeSetupRetransmission(QuicPacketSequenceNumber sequence_number);
405 bool IsRetransmission(QuicPacketSequenceNumber sequence_number); 409 bool IsRetransmission(QuicPacketSequenceNumber sequence_number);
406 410
407 // Writes as much queued data as possible. The connection must not be 411 // Writes as many queued packets as possible. The connection must not be
408 // blocked when this is called. Will leave queued frames in the PacketCreator 412 // blocked when this is called.
409 // if the queued data was not enough to fill a packet and |force_send| is 413 bool WriteQueuedPackets();
410 // false.
411 bool WriteQueuedData(bool flush);
412 414
413 // If a packet can be revived from the current FEC group, then 415 // If a packet can be revived from the current FEC group, then
414 // revive and process the packet. 416 // revive and process the packet.
415 void MaybeProcessRevivedPacket(); 417 void MaybeProcessRevivedPacket();
416 418
419 void UpdateOutgoingAck();
420
417 void MaybeSendAckInResponseToPacket(); 421 void MaybeSendAckInResponseToPacket();
418 422
419 // Get the FEC group associate with the last processed packet. 423 // Get the FEC group associate with the last processed packet.
420 QuicFecGroup* GetFecGroup(); 424 QuicFecGroup* GetFecGroup();
421 425
422 // Closes any FEC groups protecting packets before |sequence_number|. 426 // Closes any FEC groups protecting packets before |sequence_number|.
423 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number); 427 void CloseFecGroupsBefore(QuicPacketSequenceNumber sequence_number);
424 428
425 QuicConnectionHelperInterface* helper_; 429 QuicConnectionHelperInterface* helper_;
426 QuicFramer framer_; 430 QuicFramer framer_;
427 const QuicClock* clock_; 431 const QuicClock* clock_;
428 QuicRandom* random_generator_; 432 QuicRandom* random_generator_;
429 433
430 const QuicGuid guid_; 434 const QuicGuid guid_;
431 // Address on the last successfully processed packet received from the 435 // Address on the last successfully processed packet received from the
432 // client. 436 // client.
433 IPEndPoint self_address_; 437 IPEndPoint self_address_;
434 IPEndPoint peer_address_; 438 IPEndPoint peer_address_;
435 // Address on the last(currently being processed) packet received. Not 439 // Address on the last(currently being processed) packet received. Not
436 // verified/authenticated. 440 // verified/authenticated.
437 IPEndPoint last_self_address_; 441 IPEndPoint last_self_address_;
438 IPEndPoint last_peer_address_; 442 IPEndPoint last_peer_address_;
439 443
440 bool last_packet_revived_; // True if the last packet was revived from FEC. 444 bool last_packet_revived_; // True if the last packet was revived from FEC.
441 size_t last_size_; // Size of the last received packet. 445 size_t last_size_; // Size of the last received packet.
442 QuicPacketHeader last_header_; 446 QuicPacketHeader last_header_;
443 std::vector<QuicStreamFrame> last_stream_frames_; 447 std::vector<QuicStreamFrame> last_stream_frames_;
444 448
445 bool should_send_ack_;
446 bool should_send_congestion_feedback_;
447 QuicAckFrame outgoing_ack_; 449 QuicAckFrame outgoing_ack_;
448 QuicCongestionFeedbackFrame outgoing_congestion_feedback_; 450 QuicCongestionFeedbackFrame outgoing_congestion_feedback_;
449 451
450 // Track some client state so we can do less bookkeeping 452 // Track some peer state so we can do less bookkeeping
453 // Largest sequence sent by the peer which had an ack frame (latest ack info).
451 QuicPacketSequenceNumber largest_seen_packet_with_ack_; 454 QuicPacketSequenceNumber largest_seen_packet_with_ack_;
455 // Largest sequence number that the peer has observed. Mostly received,
456 // missing in case of truncated acks.
452 QuicPacketSequenceNumber peer_largest_observed_packet_; 457 QuicPacketSequenceNumber peer_largest_observed_packet_;
458 // Least sequence number which the peer is still waiting for.
459 QuicPacketSequenceNumber least_packet_awaited_by_peer_;
460 // Least sequence number of the the packet sent by the peer for which it
461 // hasn't received an ack.
453 QuicPacketSequenceNumber peer_least_packet_awaiting_ack_; 462 QuicPacketSequenceNumber peer_least_packet_awaiting_ack_;
454 463
455 // When new packets are created which may be retransmitted, they are added 464 // When new packets are created which may be retransmitted, they are added
456 // to this map, which contains owning pointers to the contained frames. 465 // to this map, which contains owning pointers to the contained frames.
457 UnackedPacketMap unacked_packets_; 466 UnackedPacketMap unacked_packets_;
458 467
459 // Heap of packets that we might need to retransmit, and the time at 468 // Heap of packets that we might need to retransmit, and the time at
460 // which we should retransmit them. Every time a packet is sent it is added 469 // which we should retransmit them. Every time a packet is sent it is added
461 // to this heap which is O(log(number of pending packets to be retransmitted)) 470 // to this heap which is O(log(number of pending packets to be retransmitted))
462 // which might be costly. This should be optimized to O(1) by maintaining a 471 // which might be costly. This should be optimized to O(1) by maintaining a
463 // priority queue of lists of packets to be retransmitted, where list x 472 // priority queue of lists of packets to be retransmitted, where list x
464 // contains all packets that have been retransmitted x times. 473 // contains all packets that have been retransmitted x times.
465 RetransmissionTimeouts retransmission_timeouts_; 474 RetransmissionTimeouts retransmission_timeouts_;
466 475
467 // Map from sequence number to the retransmission info. 476 // Map from sequence number to the retransmission info.
468 RetransmissionMap retransmission_map_; 477 RetransmissionMap retransmission_map_;
469 478
470 // True while OnRetransmissionTimeout is running to prevent 479 // True while OnRetransmissionTimeout is running to prevent
471 // SetRetransmissionAlarm from being called erroneously. 480 // SetRetransmissionAlarm from being called erroneously.
472 bool handling_retransmission_timeout_; 481 bool handling_retransmission_timeout_;
473 482
474 // When packets could not be sent because the socket was not writable, 483 // When packets could not be sent because the socket was not writable,
475 // they are added to this list. All corresponding frames are in 484 // they are added to this list. All corresponding frames are in
476 // unacked_packets_ if they are to be retransmitted. 485 // unacked_packets_ if they are to be retransmitted.
477 QueuedPacketList queued_packets_; 486 QueuedPacketList queued_packets_;
478 487
479 // Pending control frames, besides the ack and congestion control frames.
480 QuicFrames queued_control_frames_;
481
482 // True when the socket becomes unwritable. 488 // True when the socket becomes unwritable.
483 bool write_blocked_; 489 bool write_blocked_;
484 490
485 FecGroupMap group_map_; 491 FecGroupMap group_map_;
486 492
493 QuicPacketEntropyManager entropy_manager_;
494
487 QuicConnectionVisitorInterface* visitor_; 495 QuicConnectionVisitorInterface* visitor_;
488 QuicConnectionDebugVisitorInterface* debug_visitor_; 496 QuicConnectionDebugVisitorInterface* debug_visitor_;
489 QuicPacketCreator packet_creator_; 497 QuicPacketCreator packet_creator_;
498 QuicPacketGenerator packet_generator_;
490 499
491 // Network idle time before we kill of this connection. 500 // Network idle time before we kill of this connection.
492 const QuicTime::Delta timeout_; 501 const QuicTime::Delta timeout_;
493 // The time that we got or tried to send a packet for this connection. 502
494 QuicTime time_of_last_packet_; 503 // The time that we got a packet for this connection.
504 QuicTime time_of_last_received_packet_;
505
506 // The time that we last sent a packet for this connection.
507 QuicTime time_of_last_sent_packet_;
495 508
496 // Congestion manager which controls the rate the connection sends packets 509 // Congestion manager which controls the rate the connection sends packets
497 // as well as collecting and generating congestion feedback. 510 // as well as collecting and generating congestion feedback.
498 QuicCongestionManager congestion_manager_; 511 QuicCongestionManager congestion_manager_;
499 512
500 // True by default. False if we've received or sent an explicit connection 513 // True by default. False if we've received or sent an explicit connection
501 // close. 514 // close.
502 bool connected_; 515 bool connected_;
503 516
504 // True if the last ack received from the peer may have been truncated. False 517 // True if the last ack received from the peer may have been truncated. False
505 // otherwise. 518 // otherwise.
506 bool received_truncated_ack_; 519 bool received_truncated_ack_;
507 520
508 bool send_ack_in_response_to_packet_; 521 bool send_ack_in_response_to_packet_;
509 522
510 DISALLOW_COPY_AND_ASSIGN(QuicConnection); 523 DISALLOW_COPY_AND_ASSIGN(QuicConnection);
511 }; 524 };
512 525
513 } // namespace net 526 } // namespace net
514 527
515 #endif // NET_QUIC_QUIC_CONNECTION_H_ 528 #endif // NET_QUIC_QUIC_CONNECTION_H_
OLDNEW
« no previous file with comments | « net/quic/quic_clock_test.cc ('k') | net/quic/quic_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698