Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / quic_protocol.cc
blob314f0ff43b6d65c60400522b7d99ac9016c62d04
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
3 // found in the LICENSE file.
5 #include "net/quic/quic_protocol.h"
7 #include "base/stl_util.h"
8 #include "net/quic/quic_utils.h"
10 using base::StringPiece;
11 using std::map;
12 using std::numeric_limits;
13 using std::ostream;
14 using std::string;
16 namespace net {
18 size_t GetPacketHeaderSize(const QuicPacketHeader& header) {
19 return GetPacketHeaderSize(header.public_header.connection_id_length,
20 header.public_header.version_flag,
21 header.public_header.sequence_number_length,
22 header.is_in_fec_group);
25 size_t GetPacketHeaderSize(QuicConnectionIdLength connection_id_length,
26 bool include_version,
27 QuicSequenceNumberLength sequence_number_length,
28 InFecGroup is_in_fec_group) {
29 return kPublicFlagsSize + connection_id_length +
30 (include_version ? kQuicVersionSize : 0) + sequence_number_length +
31 kPrivateFlagsSize + (is_in_fec_group == IN_FEC_GROUP ? kFecGroupSize : 0);
34 size_t GetStartOfFecProtectedData(
35 QuicConnectionIdLength connection_id_length,
36 bool include_version,
37 QuicSequenceNumberLength sequence_number_length) {
38 return GetPacketHeaderSize(connection_id_length,
39 include_version,
40 sequence_number_length,
41 IN_FEC_GROUP);
44 size_t GetStartOfEncryptedData(
45 QuicConnectionIdLength connection_id_length,
46 bool include_version,
47 QuicSequenceNumberLength sequence_number_length) {
48 // Don't include the fec size, since encryption starts before private flags.
49 return GetPacketHeaderSize(connection_id_length,
50 include_version,
51 sequence_number_length,
52 NOT_IN_FEC_GROUP) - kPrivateFlagsSize;
55 QuicPacketPublicHeader::QuicPacketPublicHeader()
56 : connection_id(0),
57 connection_id_length(PACKET_8BYTE_CONNECTION_ID),
58 reset_flag(false),
59 version_flag(false),
60 sequence_number_length(PACKET_6BYTE_SEQUENCE_NUMBER) {
63 QuicPacketPublicHeader::QuicPacketPublicHeader(
64 const QuicPacketPublicHeader& other)
65 : connection_id(other.connection_id),
66 connection_id_length(other.connection_id_length),
67 reset_flag(other.reset_flag),
68 version_flag(other.version_flag),
69 sequence_number_length(other.sequence_number_length),
70 versions(other.versions) {
73 QuicPacketPublicHeader::~QuicPacketPublicHeader() {}
75 QuicPacketHeader::QuicPacketHeader()
76 : fec_flag(false),
77 entropy_flag(false),
78 entropy_hash(0),
79 packet_sequence_number(0),
80 is_in_fec_group(NOT_IN_FEC_GROUP),
81 fec_group(0) {
84 QuicPacketHeader::QuicPacketHeader(const QuicPacketPublicHeader& header)
85 : public_header(header),
86 fec_flag(false),
87 entropy_flag(false),
88 entropy_hash(0),
89 packet_sequence_number(0),
90 is_in_fec_group(NOT_IN_FEC_GROUP),
91 fec_group(0) {
94 QuicPublicResetPacket::QuicPublicResetPacket()
95 : nonce_proof(0),
96 rejected_sequence_number(0) {}
98 QuicPublicResetPacket::QuicPublicResetPacket(
99 const QuicPacketPublicHeader& header)
100 : public_header(header),
101 nonce_proof(0),
102 rejected_sequence_number(0) {}
104 QuicStreamFrame::QuicStreamFrame()
105 : stream_id(0),
106 fin(false),
107 offset(0),
108 notifier(NULL) {}
110 QuicStreamFrame::QuicStreamFrame(const QuicStreamFrame& frame)
111 : stream_id(frame.stream_id),
112 fin(frame.fin),
113 offset(frame.offset),
114 data(frame.data),
115 notifier(frame.notifier) {
118 QuicStreamFrame::QuicStreamFrame(QuicStreamId stream_id,
119 bool fin,
120 QuicStreamOffset offset,
121 IOVector data)
122 : stream_id(stream_id),
123 fin(fin),
124 offset(offset),
125 data(data),
126 notifier(NULL) {
129 string* QuicStreamFrame::GetDataAsString() const {
130 string* data_string = new string();
131 data_string->reserve(data.TotalBufferSize());
132 for (size_t i = 0; i < data.Size(); ++i) {
133 data_string->append(static_cast<char*>(data.iovec()[i].iov_base),
134 data.iovec()[i].iov_len);
136 DCHECK_EQ(data_string->size(), data.TotalBufferSize());
137 return data_string;
140 uint32 MakeQuicTag(char a, char b, char c, char d) {
141 return static_cast<uint32>(a) |
142 static_cast<uint32>(b) << 8 |
143 static_cast<uint32>(c) << 16 |
144 static_cast<uint32>(d) << 24;
147 bool ContainsQuicTag(const QuicTagVector& tag_vector, QuicTag tag) {
148 return std::find(tag_vector.begin(), tag_vector.end(), tag)
149 != tag_vector.end();
152 QuicVersionVector QuicSupportedVersions() {
153 QuicVersionVector supported_versions;
154 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
155 supported_versions.push_back(kSupportedQuicVersions[i]);
157 return supported_versions;
160 QuicTag QuicVersionToQuicTag(const QuicVersion version) {
161 switch (version) {
162 case QUIC_VERSION_16:
163 return MakeQuicTag('Q', '0', '1', '6');
164 case QUIC_VERSION_18:
165 return MakeQuicTag('Q', '0', '1', '8');
166 case QUIC_VERSION_19:
167 return MakeQuicTag('Q', '0', '1', '9');
168 case QUIC_VERSION_20:
169 return MakeQuicTag('Q', '0', '2', '0');
170 case QUIC_VERSION_21:
171 return MakeQuicTag('Q', '0', '2', '1');
172 case QUIC_VERSION_22:
173 return MakeQuicTag('Q', '0', '2', '2');
174 case QUIC_VERSION_23:
175 return MakeQuicTag('Q', '0', '2', '3');
176 default:
177 // This shold be an ERROR because we should never attempt to convert an
178 // invalid QuicVersion to be written to the wire.
179 LOG(ERROR) << "Unsupported QuicVersion: " << version;
180 return 0;
184 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) {
185 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
186 if (version_tag == QuicVersionToQuicTag(kSupportedQuicVersions[i])) {
187 return kSupportedQuicVersions[i];
190 // Reading from the client so this should not be considered an ERROR.
191 DVLOG(1) << "Unsupported QuicTag version: "
192 << QuicUtils::TagToString(version_tag);
193 return QUIC_VERSION_UNSUPPORTED;
196 #define RETURN_STRING_LITERAL(x) \
197 case x: \
198 return #x
200 string QuicVersionToString(const QuicVersion version) {
201 switch (version) {
202 RETURN_STRING_LITERAL(QUIC_VERSION_16);
203 RETURN_STRING_LITERAL(QUIC_VERSION_18);
204 RETURN_STRING_LITERAL(QUIC_VERSION_19);
205 RETURN_STRING_LITERAL(QUIC_VERSION_20);
206 RETURN_STRING_LITERAL(QUIC_VERSION_21);
207 RETURN_STRING_LITERAL(QUIC_VERSION_22);
208 RETURN_STRING_LITERAL(QUIC_VERSION_23);
209 default:
210 return "QUIC_VERSION_UNSUPPORTED";
214 string QuicVersionVectorToString(const QuicVersionVector& versions) {
215 string result = "";
216 for (size_t i = 0; i < versions.size(); ++i) {
217 if (i != 0) {
218 result.append(",");
220 result.append(QuicVersionToString(versions[i]));
222 return result;
225 ostream& operator<<(ostream& os, const QuicPacketHeader& header) {
226 os << "{ connection_id: " << header.public_header.connection_id
227 << ", connection_id_length:" << header.public_header.connection_id_length
228 << ", sequence_number_length:"
229 << header.public_header.sequence_number_length
230 << ", reset_flag: " << header.public_header.reset_flag
231 << ", version_flag: " << header.public_header.version_flag;
232 if (header.public_header.version_flag) {
233 os << " version: ";
234 for (size_t i = 0; i < header.public_header.versions.size(); ++i) {
235 os << header.public_header.versions[0] << " ";
238 os << ", fec_flag: " << header.fec_flag
239 << ", entropy_flag: " << header.entropy_flag
240 << ", entropy hash: " << static_cast<int>(header.entropy_hash)
241 << ", sequence_number: " << header.packet_sequence_number
242 << ", is_in_fec_group:" << header.is_in_fec_group
243 << ", fec_group: " << header.fec_group<< "}\n";
244 return os;
247 bool IsAwaitingPacket(const QuicAckFrame& ack_frame,
248 QuicPacketSequenceNumber sequence_number) {
249 return sequence_number > ack_frame.largest_observed ||
250 ContainsKey(ack_frame.missing_packets, sequence_number);
253 void InsertMissingPacketsBetween(QuicAckFrame* ack_frame,
254 QuicPacketSequenceNumber lower,
255 QuicPacketSequenceNumber higher) {
256 for (QuicPacketSequenceNumber i = lower; i < higher; ++i) {
257 ack_frame->missing_packets.insert(i);
261 QuicStopWaitingFrame::QuicStopWaitingFrame()
262 : entropy_hash(0),
263 least_unacked(0) {
266 QuicStopWaitingFrame::~QuicStopWaitingFrame() {}
268 QuicAckFrame::QuicAckFrame()
269 : entropy_hash(0),
270 largest_observed(0),
271 delta_time_largest_observed(QuicTime::Delta::Infinite()),
272 is_truncated(false) {}
274 QuicAckFrame::~QuicAckFrame() {}
276 CongestionFeedbackMessageTCP::CongestionFeedbackMessageTCP()
277 : receive_window(0) {
280 QuicCongestionFeedbackFrame::QuicCongestionFeedbackFrame() : type(kTCP) {}
282 QuicCongestionFeedbackFrame::~QuicCongestionFeedbackFrame() {}
284 QuicRstStreamErrorCode AdjustErrorForVersion(
285 QuicRstStreamErrorCode error_code,
286 QuicVersion version) {
287 switch (error_code) {
288 case QUIC_RST_FLOW_CONTROL_ACCOUNTING:
289 if (version < QUIC_VERSION_18) {
290 return QUIC_STREAM_NO_ERROR;
292 break;
293 default:
294 return error_code;
296 return error_code;
299 QuicRstStreamFrame::QuicRstStreamFrame()
300 : stream_id(0),
301 error_code(QUIC_STREAM_NO_ERROR) {
304 QuicRstStreamFrame::QuicRstStreamFrame(QuicStreamId stream_id,
305 QuicRstStreamErrorCode error_code,
306 QuicStreamOffset bytes_written)
307 : stream_id(stream_id),
308 error_code(error_code),
309 byte_offset(bytes_written) {
310 DCHECK_LE(error_code, numeric_limits<uint8>::max());
313 QuicConnectionCloseFrame::QuicConnectionCloseFrame()
314 : error_code(QUIC_NO_ERROR) {
317 QuicFrame::QuicFrame() {}
319 QuicFrame::QuicFrame(QuicPaddingFrame* padding_frame)
320 : type(PADDING_FRAME),
321 padding_frame(padding_frame) {
324 QuicFrame::QuicFrame(QuicStreamFrame* stream_frame)
325 : type(STREAM_FRAME),
326 stream_frame(stream_frame) {
329 QuicFrame::QuicFrame(QuicAckFrame* frame)
330 : type(ACK_FRAME),
331 ack_frame(frame) {
334 QuicFrame::QuicFrame(QuicCongestionFeedbackFrame* frame)
335 : type(CONGESTION_FEEDBACK_FRAME),
336 congestion_feedback_frame(frame) {
339 QuicFrame::QuicFrame(QuicStopWaitingFrame* frame)
340 : type(STOP_WAITING_FRAME),
341 stop_waiting_frame(frame) {
344 QuicFrame::QuicFrame(QuicPingFrame* frame)
345 : type(PING_FRAME),
346 ping_frame(frame) {
349 QuicFrame::QuicFrame(QuicRstStreamFrame* frame)
350 : type(RST_STREAM_FRAME),
351 rst_stream_frame(frame) {
354 QuicFrame::QuicFrame(QuicConnectionCloseFrame* frame)
355 : type(CONNECTION_CLOSE_FRAME),
356 connection_close_frame(frame) {
359 QuicFrame::QuicFrame(QuicGoAwayFrame* frame)
360 : type(GOAWAY_FRAME),
361 goaway_frame(frame) {
364 QuicFrame::QuicFrame(QuicWindowUpdateFrame* frame)
365 : type(WINDOW_UPDATE_FRAME),
366 window_update_frame(frame) {
369 QuicFrame::QuicFrame(QuicBlockedFrame* frame)
370 : type(BLOCKED_FRAME),
371 blocked_frame(frame) {
374 QuicFecData::QuicFecData() : fec_group(0) {}
376 ostream& operator<<(ostream& os, const QuicStopWaitingFrame& sent_info) {
377 os << "entropy_hash: " << static_cast<int>(sent_info.entropy_hash)
378 << " least_unacked: " << sent_info.least_unacked;
379 return os;
382 ostream& operator<<(ostream& os, const QuicAckFrame& ack_frame) {
383 os << "entropy_hash: " << static_cast<int>(ack_frame.entropy_hash)
384 << " largest_observed: " << ack_frame.largest_observed
385 << " delta_time_largest_observed: "
386 << ack_frame.delta_time_largest_observed.ToMicroseconds()
387 << " missing_packets: [ ";
388 for (SequenceNumberSet::const_iterator it = ack_frame.missing_packets.begin();
389 it != ack_frame.missing_packets.end(); ++it) {
390 os << *it << " ";
392 os << " ] is_truncated: " << ack_frame.is_truncated;
393 os << " revived_packets: [ ";
394 for (SequenceNumberSet::const_iterator it = ack_frame.revived_packets.begin();
395 it != ack_frame.revived_packets.end(); ++it) {
396 os << *it << " ";
398 os << " ] received_packets: [ ";
399 for (PacketTimeList::const_iterator it =
400 ack_frame.received_packet_times.begin();
401 it != ack_frame.received_packet_times.end(); ++it) {
402 os << it->first << " at " << it->second.ToDebuggingValue() << " ";
404 os << " ]";
405 return os;
408 ostream& operator<<(ostream& os, const QuicFrame& frame) {
409 switch (frame.type) {
410 case PADDING_FRAME: {
411 os << "type { PADDING_FRAME } ";
412 break;
414 case RST_STREAM_FRAME: {
415 os << "type { " << RST_STREAM_FRAME << " } " << *(frame.rst_stream_frame);
416 break;
418 case CONNECTION_CLOSE_FRAME: {
419 os << "type { CONNECTION_CLOSE_FRAME } "
420 << *(frame.connection_close_frame);
421 break;
423 case GOAWAY_FRAME: {
424 os << "type { GOAWAY_FRAME } " << *(frame.goaway_frame);
425 break;
427 case WINDOW_UPDATE_FRAME: {
428 os << "type { WINDOW_UPDATE_FRAME } " << *(frame.window_update_frame);
429 break;
431 case BLOCKED_FRAME: {
432 os << "type { BLOCKED_FRAME } " << *(frame.blocked_frame);
433 break;
435 case STREAM_FRAME: {
436 os << "type { STREAM_FRAME } " << *(frame.stream_frame);
437 break;
439 case ACK_FRAME: {
440 os << "type { ACK_FRAME } " << *(frame.ack_frame);
441 break;
443 case CONGESTION_FEEDBACK_FRAME: {
444 os << "type { CONGESTION_FEEDBACK_FRAME } "
445 << *(frame.congestion_feedback_frame);
446 break;
448 case STOP_WAITING_FRAME: {
449 os << "type { STOP_WAITING_FRAME } " << *(frame.stop_waiting_frame);
450 break;
452 case PING_FRAME: {
453 os << "type { PING_FRAME } ";
454 break;
456 default: {
457 LOG(ERROR) << "Unknown frame type: " << frame.type;
458 break;
461 return os;
464 ostream& operator<<(ostream& os, const QuicRstStreamFrame& rst_frame) {
465 os << "stream_id { " << rst_frame.stream_id << " } "
466 << "error_code { " << rst_frame.error_code << " } "
467 << "error_details { " << rst_frame.error_details << " }\n";
468 return os;
471 ostream& operator<<(ostream& os,
472 const QuicConnectionCloseFrame& connection_close_frame) {
473 os << "error_code { " << connection_close_frame.error_code << " } "
474 << "error_details { " << connection_close_frame.error_details << " }\n";
475 return os;
478 ostream& operator<<(ostream& os, const QuicGoAwayFrame& goaway_frame) {
479 os << "error_code { " << goaway_frame.error_code << " } "
480 << "last_good_stream_id { " << goaway_frame.last_good_stream_id << " } "
481 << "reason_phrase { " << goaway_frame.reason_phrase << " }\n";
482 return os;
485 ostream& operator<<(ostream& os,
486 const QuicWindowUpdateFrame& window_update_frame) {
487 os << "stream_id { " << window_update_frame.stream_id << " } "
488 << "byte_offset { " << window_update_frame.byte_offset << " }\n";
489 return os;
492 ostream& operator<<(ostream& os, const QuicBlockedFrame& blocked_frame) {
493 os << "stream_id { " << blocked_frame.stream_id << " }\n";
494 return os;
497 ostream& operator<<(ostream& os, const QuicStreamFrame& stream_frame) {
498 os << "stream_id { " << stream_frame.stream_id << " } "
499 << "fin { " << stream_frame.fin << " } "
500 << "offset { " << stream_frame.offset << " } "
501 << "data { "
502 << QuicUtils::StringToHexASCIIDump(*(stream_frame.GetDataAsString()))
503 << " }\n";
504 return os;
507 ostream& operator<<(ostream& os,
508 const QuicCongestionFeedbackFrame& congestion_frame) {
509 os << "type: " << congestion_frame.type;
510 switch (congestion_frame.type) {
511 case kTCP: {
512 const CongestionFeedbackMessageTCP& tcp = congestion_frame.tcp;
513 os << " receive_window: " << tcp.receive_window;
514 break;
517 return os;
520 QuicGoAwayFrame::QuicGoAwayFrame()
521 : error_code(QUIC_NO_ERROR),
522 last_good_stream_id(0) {
525 QuicGoAwayFrame::QuicGoAwayFrame(QuicErrorCode error_code,
526 QuicStreamId last_good_stream_id,
527 const string& reason)
528 : error_code(error_code),
529 last_good_stream_id(last_good_stream_id),
530 reason_phrase(reason) {
531 DCHECK_LE(error_code, numeric_limits<uint8>::max());
534 QuicData::QuicData(const char* buffer,
535 size_t length)
536 : buffer_(buffer),
537 length_(length),
538 owns_buffer_(false) {
541 QuicData::QuicData(char* buffer,
542 size_t length,
543 bool owns_buffer)
544 : buffer_(buffer),
545 length_(length),
546 owns_buffer_(owns_buffer) {
549 QuicData::~QuicData() {
550 if (owns_buffer_) {
551 delete [] const_cast<char*>(buffer_);
555 QuicWindowUpdateFrame::QuicWindowUpdateFrame(QuicStreamId stream_id,
556 QuicStreamOffset byte_offset)
557 : stream_id(stream_id),
558 byte_offset(byte_offset) {}
560 QuicBlockedFrame::QuicBlockedFrame(QuicStreamId stream_id)
561 : stream_id(stream_id) {}
563 QuicPacket::QuicPacket(char* buffer,
564 size_t length,
565 bool owns_buffer,
566 QuicConnectionIdLength connection_id_length,
567 bool includes_version,
568 QuicSequenceNumberLength sequence_number_length,
569 bool is_fec_packet)
570 : QuicData(buffer, length, owns_buffer),
571 buffer_(buffer),
572 is_fec_packet_(is_fec_packet),
573 connection_id_length_(connection_id_length),
574 includes_version_(includes_version),
575 sequence_number_length_(sequence_number_length) {
578 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer,
579 size_t length)
580 : QuicData(buffer, length) {
583 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer,
584 size_t length,
585 bool owns_buffer)
586 : QuicData(buffer, length, owns_buffer) {
589 StringPiece QuicPacket::FecProtectedData() const {
590 const size_t start_of_fec = GetStartOfFecProtectedData(
591 connection_id_length_, includes_version_, sequence_number_length_);
592 return StringPiece(data() + start_of_fec, length() - start_of_fec);
595 StringPiece QuicPacket::AssociatedData() const {
596 return StringPiece(
597 data() + kStartOfHashData,
598 GetStartOfEncryptedData(
599 connection_id_length_, includes_version_, sequence_number_length_) -
600 kStartOfHashData);
603 StringPiece QuicPacket::BeforePlaintext() const {
604 return StringPiece(data(), GetStartOfEncryptedData(connection_id_length_,
605 includes_version_,
606 sequence_number_length_));
609 StringPiece QuicPacket::Plaintext() const {
610 const size_t start_of_encrypted_data =
611 GetStartOfEncryptedData(
612 connection_id_length_, includes_version_, sequence_number_length_);
613 return StringPiece(data() + start_of_encrypted_data,
614 length() - start_of_encrypted_data);
617 RetransmittableFrames::RetransmittableFrames()
618 : encryption_level_(NUM_ENCRYPTION_LEVELS),
619 has_crypto_handshake_(NOT_HANDSHAKE) {
622 RetransmittableFrames::~RetransmittableFrames() {
623 for (QuicFrames::iterator it = frames_.begin(); it != frames_.end(); ++it) {
624 switch (it->type) {
625 case PADDING_FRAME:
626 delete it->padding_frame;
627 break;
628 case STREAM_FRAME:
629 delete it->stream_frame;
630 break;
631 case ACK_FRAME:
632 delete it->ack_frame;
633 break;
634 case CONGESTION_FEEDBACK_FRAME:
635 delete it->congestion_feedback_frame;
636 break;
637 case STOP_WAITING_FRAME:
638 delete it->stop_waiting_frame;
639 break;
640 case PING_FRAME:
641 delete it->ping_frame;
642 break;
643 case RST_STREAM_FRAME:
644 delete it->rst_stream_frame;
645 break;
646 case CONNECTION_CLOSE_FRAME:
647 delete it->connection_close_frame;
648 break;
649 case GOAWAY_FRAME:
650 delete it->goaway_frame;
651 break;
652 case WINDOW_UPDATE_FRAME:
653 delete it->window_update_frame;
654 break;
655 case BLOCKED_FRAME:
656 delete it->blocked_frame;
657 break;
658 case NUM_FRAME_TYPES:
659 DCHECK(false) << "Cannot delete type: " << it->type;
662 STLDeleteElements(&stream_data_);
665 const QuicFrame& RetransmittableFrames::AddStreamFrame(
666 QuicStreamFrame* stream_frame) {
667 // Make an owned copy of the stream frame's data.
668 stream_data_.push_back(stream_frame->GetDataAsString());
669 // Ensure the stream frame's IOVector points to the owned copy of the data.
670 stream_frame->data.Clear();
671 stream_frame->data.Append(const_cast<char*>(stream_data_.back()->data()),
672 stream_data_.back()->size());
673 frames_.push_back(QuicFrame(stream_frame));
674 if (stream_frame->stream_id == kCryptoStreamId) {
675 has_crypto_handshake_ = IS_HANDSHAKE;
677 return frames_.back();
680 const QuicFrame& RetransmittableFrames::AddNonStreamFrame(
681 const QuicFrame& frame) {
682 DCHECK_NE(frame.type, STREAM_FRAME);
683 frames_.push_back(frame);
684 return frames_.back();
687 void RetransmittableFrames::set_encryption_level(EncryptionLevel level) {
688 encryption_level_ = level;
691 SerializedPacket::SerializedPacket(
692 QuicPacketSequenceNumber sequence_number,
693 QuicSequenceNumberLength sequence_number_length,
694 QuicPacket* packet,
695 QuicPacketEntropyHash entropy_hash,
696 RetransmittableFrames* retransmittable_frames)
697 : sequence_number(sequence_number),
698 sequence_number_length(sequence_number_length),
699 packet(packet),
700 entropy_hash(entropy_hash),
701 retransmittable_frames(retransmittable_frames) {
704 SerializedPacket::~SerializedPacket() {}
706 QuicEncryptedPacket* QuicEncryptedPacket::Clone() const {
707 char* buffer = new char[this->length()];
708 memcpy(buffer, this->data(), this->length());
709 return new QuicEncryptedPacket(buffer, this->length(), true);
712 ostream& operator<<(ostream& os, const QuicEncryptedPacket& s) {
713 os << s.length() << "-byte data";
714 return os;
717 TransmissionInfo::TransmissionInfo()
718 : retransmittable_frames(NULL),
719 sequence_number_length(PACKET_1BYTE_SEQUENCE_NUMBER),
720 sent_time(QuicTime::Zero()),
721 bytes_sent(0),
722 nack_count(0),
723 transmission_type(NOT_RETRANSMISSION),
724 all_transmissions(NULL),
725 in_flight(false) {}
727 TransmissionInfo::TransmissionInfo(
728 RetransmittableFrames* retransmittable_frames,
729 QuicPacketSequenceNumber sequence_number,
730 QuicSequenceNumberLength sequence_number_length)
731 : retransmittable_frames(retransmittable_frames),
732 sequence_number_length(sequence_number_length),
733 sent_time(QuicTime::Zero()),
734 bytes_sent(0),
735 nack_count(0),
736 transmission_type(NOT_RETRANSMISSION),
737 all_transmissions(new SequenceNumberSet),
738 in_flight(false) {
739 all_transmissions->insert(sequence_number);
742 TransmissionInfo::TransmissionInfo(
743 RetransmittableFrames* retransmittable_frames,
744 QuicPacketSequenceNumber sequence_number,
745 QuicSequenceNumberLength sequence_number_length,
746 TransmissionType transmission_type,
747 SequenceNumberSet* all_transmissions)
748 : retransmittable_frames(retransmittable_frames),
749 sequence_number_length(sequence_number_length),
750 sent_time(QuicTime::Zero()),
751 bytes_sent(0),
752 nack_count(0),
753 transmission_type(transmission_type),
754 all_transmissions(all_transmissions),
755 in_flight(false) {
756 all_transmissions->insert(sequence_number);
759 } // namespace net