Use extensions_path.h instead of chrome_path.h from extension_icon_image_unittest.cc
[chromium-blink-merge.git] / net / quic / quic_protocol.cc
blobc587c56f8dd22da51ce47fa3a758f9590dc6c100
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 default:
173 // This shold be an ERROR because we should never attempt to convert an
174 // invalid QuicVersion to be written to the wire.
175 LOG(ERROR) << "Unsupported QuicVersion: " << version;
176 return 0;
180 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) {
181 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
182 if (version_tag == QuicVersionToQuicTag(kSupportedQuicVersions[i])) {
183 return kSupportedQuicVersions[i];
186 // Reading from the client so this should not be considered an ERROR.
187 DVLOG(1) << "Unsupported QuicTag version: "
188 << QuicUtils::TagToString(version_tag);
189 return QUIC_VERSION_UNSUPPORTED;
192 #define RETURN_STRING_LITERAL(x) \
193 case x: \
194 return #x
196 string QuicVersionToString(const QuicVersion version) {
197 switch (version) {
198 RETURN_STRING_LITERAL(QUIC_VERSION_16);
199 RETURN_STRING_LITERAL(QUIC_VERSION_18);
200 RETURN_STRING_LITERAL(QUIC_VERSION_19);
201 RETURN_STRING_LITERAL(QUIC_VERSION_20);
202 RETURN_STRING_LITERAL(QUIC_VERSION_21);
203 default:
204 return "QUIC_VERSION_UNSUPPORTED";
208 string QuicVersionVectorToString(const QuicVersionVector& versions) {
209 string result = "";
210 for (size_t i = 0; i < versions.size(); ++i) {
211 if (i != 0) {
212 result.append(",");
214 result.append(QuicVersionToString(versions[i]));
216 return result;
219 ostream& operator<<(ostream& os, const QuicPacketHeader& header) {
220 os << "{ connection_id: " << header.public_header.connection_id
221 << ", connection_id_length:" << header.public_header.connection_id_length
222 << ", sequence_number_length:"
223 << header.public_header.sequence_number_length
224 << ", reset_flag: " << header.public_header.reset_flag
225 << ", version_flag: " << header.public_header.version_flag;
226 if (header.public_header.version_flag) {
227 os << " version: ";
228 for (size_t i = 0; i < header.public_header.versions.size(); ++i) {
229 os << header.public_header.versions[0] << " ";
232 os << ", fec_flag: " << header.fec_flag
233 << ", entropy_flag: " << header.entropy_flag
234 << ", entropy hash: " << static_cast<int>(header.entropy_hash)
235 << ", sequence_number: " << header.packet_sequence_number
236 << ", is_in_fec_group:" << header.is_in_fec_group
237 << ", fec_group: " << header.fec_group<< "}\n";
238 return os;
241 bool IsAwaitingPacket(const QuicAckFrame& ack_frame,
242 QuicPacketSequenceNumber sequence_number) {
243 return sequence_number > ack_frame.largest_observed ||
244 ContainsKey(ack_frame.missing_packets, sequence_number);
247 void InsertMissingPacketsBetween(QuicAckFrame* ack_frame,
248 QuicPacketSequenceNumber lower,
249 QuicPacketSequenceNumber higher) {
250 for (QuicPacketSequenceNumber i = lower; i < higher; ++i) {
251 ack_frame->missing_packets.insert(i);
255 QuicStopWaitingFrame::QuicStopWaitingFrame()
256 : entropy_hash(0),
257 least_unacked(0) {
260 QuicStopWaitingFrame::~QuicStopWaitingFrame() {}
262 QuicAckFrame::QuicAckFrame()
263 : entropy_hash(0),
264 largest_observed(0),
265 delta_time_largest_observed(QuicTime::Delta::Infinite()),
266 is_truncated(false) {}
268 QuicAckFrame::~QuicAckFrame() {}
270 CongestionFeedbackMessageTCP::CongestionFeedbackMessageTCP()
271 : receive_window(0) {
274 CongestionFeedbackMessageTimestamp::CongestionFeedbackMessageTimestamp() {
277 CongestionFeedbackMessageTimestamp::~CongestionFeedbackMessageTimestamp() {}
279 QuicCongestionFeedbackFrame::QuicCongestionFeedbackFrame() : type(kTCP) {}
281 QuicCongestionFeedbackFrame::~QuicCongestionFeedbackFrame() {}
283 QuicRstStreamErrorCode AdjustErrorForVersion(
284 QuicRstStreamErrorCode error_code,
285 QuicVersion version) {
286 switch (error_code) {
287 case QUIC_RST_FLOW_CONTROL_ACCOUNTING:
288 if (version < QUIC_VERSION_18) {
289 return QUIC_STREAM_NO_ERROR;
291 break;
292 default:
293 return error_code;
295 return error_code;
298 QuicRstStreamFrame::QuicRstStreamFrame()
299 : stream_id(0),
300 error_code(QUIC_STREAM_NO_ERROR) {
303 QuicRstStreamFrame::QuicRstStreamFrame(QuicStreamId stream_id,
304 QuicRstStreamErrorCode error_code,
305 QuicStreamOffset bytes_written)
306 : stream_id(stream_id),
307 error_code(error_code),
308 byte_offset(bytes_written) {
309 DCHECK_LE(error_code, numeric_limits<uint8>::max());
312 QuicConnectionCloseFrame::QuicConnectionCloseFrame()
313 : error_code(QUIC_NO_ERROR) {
316 QuicFrame::QuicFrame() {}
318 QuicFrame::QuicFrame(QuicPaddingFrame* padding_frame)
319 : type(PADDING_FRAME),
320 padding_frame(padding_frame) {
323 QuicFrame::QuicFrame(QuicStreamFrame* stream_frame)
324 : type(STREAM_FRAME),
325 stream_frame(stream_frame) {
328 QuicFrame::QuicFrame(QuicAckFrame* frame)
329 : type(ACK_FRAME),
330 ack_frame(frame) {
333 QuicFrame::QuicFrame(QuicCongestionFeedbackFrame* frame)
334 : type(CONGESTION_FEEDBACK_FRAME),
335 congestion_feedback_frame(frame) {
338 QuicFrame::QuicFrame(QuicStopWaitingFrame* frame)
339 : type(STOP_WAITING_FRAME),
340 stop_waiting_frame(frame) {
343 QuicFrame::QuicFrame(QuicPingFrame* frame)
344 : type(PING_FRAME),
345 ping_frame(frame) {
348 QuicFrame::QuicFrame(QuicRstStreamFrame* frame)
349 : type(RST_STREAM_FRAME),
350 rst_stream_frame(frame) {
353 QuicFrame::QuicFrame(QuicConnectionCloseFrame* frame)
354 : type(CONNECTION_CLOSE_FRAME),
355 connection_close_frame(frame) {
358 QuicFrame::QuicFrame(QuicGoAwayFrame* frame)
359 : type(GOAWAY_FRAME),
360 goaway_frame(frame) {
363 QuicFrame::QuicFrame(QuicWindowUpdateFrame* frame)
364 : type(WINDOW_UPDATE_FRAME),
365 window_update_frame(frame) {
368 QuicFrame::QuicFrame(QuicBlockedFrame* frame)
369 : type(BLOCKED_FRAME),
370 blocked_frame(frame) {
373 QuicFecData::QuicFecData() : fec_group(0) {}
375 ostream& operator<<(ostream& os, const QuicStopWaitingFrame& sent_info) {
376 os << "entropy_hash: " << static_cast<int>(sent_info.entropy_hash)
377 << " least_unacked: " << sent_info.least_unacked;
378 return os;
381 ostream& operator<<(ostream& os, const QuicAckFrame& ack_frame) {
382 os << "entropy_hash: " << static_cast<int>(ack_frame.entropy_hash)
383 << " is_truncated: " << ack_frame.is_truncated
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 << " ] revived_packets: [ ";
393 for (SequenceNumberSet::const_iterator it = ack_frame.revived_packets.begin();
394 it != ack_frame.revived_packets.end(); ++it) {
395 os << *it << " ";
397 os << " ]";
398 return os;
401 ostream& operator<<(ostream& os, const QuicFrame& frame) {
402 switch (frame.type) {
403 case PADDING_FRAME: {
404 os << "type { PADDING_FRAME } ";
405 break;
407 case RST_STREAM_FRAME: {
408 os << "type { " << RST_STREAM_FRAME << " } " << *(frame.rst_stream_frame);
409 break;
411 case CONNECTION_CLOSE_FRAME: {
412 os << "type { CONNECTION_CLOSE_FRAME } "
413 << *(frame.connection_close_frame);
414 break;
416 case GOAWAY_FRAME: {
417 os << "type { GOAWAY_FRAME } " << *(frame.goaway_frame);
418 break;
420 case WINDOW_UPDATE_FRAME: {
421 os << "type { WINDOW_UPDATE_FRAME } " << *(frame.window_update_frame);
422 break;
424 case BLOCKED_FRAME: {
425 os << "type { BLOCKED_FRAME } " << *(frame.blocked_frame);
426 break;
428 case STREAM_FRAME: {
429 os << "type { STREAM_FRAME } " << *(frame.stream_frame);
430 break;
432 case ACK_FRAME: {
433 os << "type { ACK_FRAME } " << *(frame.ack_frame);
434 break;
436 case CONGESTION_FEEDBACK_FRAME: {
437 os << "type { CONGESTION_FEEDBACK_FRAME } "
438 << *(frame.congestion_feedback_frame);
439 break;
441 case STOP_WAITING_FRAME: {
442 os << "type { STOP_WAITING_FRAME } " << *(frame.stop_waiting_frame);
443 break;
445 case PING_FRAME: {
446 os << "type { PING_FRAME } ";
447 break;
449 default: {
450 LOG(ERROR) << "Unknown frame type: " << frame.type;
451 break;
454 return os;
457 ostream& operator<<(ostream& os, const QuicRstStreamFrame& rst_frame) {
458 os << "stream_id { " << rst_frame.stream_id << " } "
459 << "error_code { " << rst_frame.error_code << " } "
460 << "error_details { " << rst_frame.error_details << " }\n";
461 return os;
464 ostream& operator<<(ostream& os,
465 const QuicConnectionCloseFrame& connection_close_frame) {
466 os << "error_code { " << connection_close_frame.error_code << " } "
467 << "error_details { " << connection_close_frame.error_details << " }\n";
468 return os;
471 ostream& operator<<(ostream& os, const QuicGoAwayFrame& goaway_frame) {
472 os << "error_code { " << goaway_frame.error_code << " } "
473 << "last_good_stream_id { " << goaway_frame.last_good_stream_id << " } "
474 << "reason_phrase { " << goaway_frame.reason_phrase << " }\n";
475 return os;
478 ostream& operator<<(ostream& os,
479 const QuicWindowUpdateFrame& window_update_frame) {
480 os << "stream_id { " << window_update_frame.stream_id << " } "
481 << "byte_offset { " << window_update_frame.byte_offset << " }\n";
482 return os;
485 ostream& operator<<(ostream& os, const QuicBlockedFrame& blocked_frame) {
486 os << "stream_id { " << blocked_frame.stream_id << " }\n";
487 return os;
490 ostream& operator<<(ostream& os, const QuicStreamFrame& stream_frame) {
491 os << "stream_id { " << stream_frame.stream_id << " } "
492 << "fin { " << stream_frame.fin << " } "
493 << "offset { " << stream_frame.offset << " } "
494 << "data { "
495 << QuicUtils::StringToHexASCIIDump(*(stream_frame.GetDataAsString()))
496 << " }\n";
497 return os;
500 ostream& operator<<(ostream& os,
501 const QuicCongestionFeedbackFrame& congestion_frame) {
502 os << "type: " << congestion_frame.type;
503 switch (congestion_frame.type) {
504 case kTimestamp: {
505 const CongestionFeedbackMessageTimestamp& timestamp =
506 congestion_frame.timestamp;
507 os << " received packets: [ ";
508 for (TimeMap::const_iterator it = timestamp.received_packet_times.begin();
509 it != timestamp.received_packet_times.end(); ++it) {
510 os << it->first << "@" << it->second.ToDebuggingValue() << " ";
512 os << "]";
513 break;
515 case kTCP: {
516 const CongestionFeedbackMessageTCP& tcp = congestion_frame.tcp;
517 os << " receive_window: " << tcp.receive_window;
518 break;
521 return os;
524 QuicGoAwayFrame::QuicGoAwayFrame()
525 : error_code(QUIC_NO_ERROR),
526 last_good_stream_id(0) {
529 QuicGoAwayFrame::QuicGoAwayFrame(QuicErrorCode error_code,
530 QuicStreamId last_good_stream_id,
531 const string& reason)
532 : error_code(error_code),
533 last_good_stream_id(last_good_stream_id),
534 reason_phrase(reason) {
535 DCHECK_LE(error_code, numeric_limits<uint8>::max());
538 QuicData::QuicData(const char* buffer,
539 size_t length)
540 : buffer_(buffer),
541 length_(length),
542 owns_buffer_(false) {
545 QuicData::QuicData(char* buffer,
546 size_t length,
547 bool owns_buffer)
548 : buffer_(buffer),
549 length_(length),
550 owns_buffer_(owns_buffer) {
553 QuicData::~QuicData() {
554 if (owns_buffer_) {
555 delete [] const_cast<char*>(buffer_);
559 QuicWindowUpdateFrame::QuicWindowUpdateFrame(QuicStreamId stream_id,
560 QuicStreamOffset byte_offset)
561 : stream_id(stream_id),
562 byte_offset(byte_offset) {}
564 QuicBlockedFrame::QuicBlockedFrame(QuicStreamId stream_id)
565 : stream_id(stream_id) {}
567 QuicPacket::QuicPacket(char* buffer,
568 size_t length,
569 bool owns_buffer,
570 QuicConnectionIdLength connection_id_length,
571 bool includes_version,
572 QuicSequenceNumberLength sequence_number_length,
573 bool is_fec_packet)
574 : QuicData(buffer, length, owns_buffer),
575 buffer_(buffer),
576 is_fec_packet_(is_fec_packet),
577 connection_id_length_(connection_id_length),
578 includes_version_(includes_version),
579 sequence_number_length_(sequence_number_length) {
582 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer,
583 size_t length)
584 : QuicData(buffer, length) {
587 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer,
588 size_t length,
589 bool owns_buffer)
590 : QuicData(buffer, length, owns_buffer) {
593 StringPiece QuicPacket::FecProtectedData() const {
594 const size_t start_of_fec = GetStartOfFecProtectedData(
595 connection_id_length_, includes_version_, sequence_number_length_);
596 return StringPiece(data() + start_of_fec, length() - start_of_fec);
599 StringPiece QuicPacket::AssociatedData() const {
600 return StringPiece(
601 data() + kStartOfHashData,
602 GetStartOfEncryptedData(
603 connection_id_length_, includes_version_, sequence_number_length_) -
604 kStartOfHashData);
607 StringPiece QuicPacket::BeforePlaintext() const {
608 return StringPiece(data(), GetStartOfEncryptedData(connection_id_length_,
609 includes_version_,
610 sequence_number_length_));
613 StringPiece QuicPacket::Plaintext() const {
614 const size_t start_of_encrypted_data =
615 GetStartOfEncryptedData(
616 connection_id_length_, includes_version_, sequence_number_length_);
617 return StringPiece(data() + start_of_encrypted_data,
618 length() - start_of_encrypted_data);
621 RetransmittableFrames::RetransmittableFrames()
622 : encryption_level_(NUM_ENCRYPTION_LEVELS) {
625 RetransmittableFrames::~RetransmittableFrames() {
626 for (QuicFrames::iterator it = frames_.begin(); it != frames_.end(); ++it) {
627 switch (it->type) {
628 case PADDING_FRAME:
629 delete it->padding_frame;
630 break;
631 case STREAM_FRAME:
632 delete it->stream_frame;
633 break;
634 case ACK_FRAME:
635 delete it->ack_frame;
636 break;
637 case CONGESTION_FEEDBACK_FRAME:
638 delete it->congestion_feedback_frame;
639 break;
640 case STOP_WAITING_FRAME:
641 delete it->stop_waiting_frame;
642 break;
643 case PING_FRAME:
644 delete it->ping_frame;
645 break;
646 case RST_STREAM_FRAME:
647 delete it->rst_stream_frame;
648 break;
649 case CONNECTION_CLOSE_FRAME:
650 delete it->connection_close_frame;
651 break;
652 case GOAWAY_FRAME:
653 delete it->goaway_frame;
654 break;
655 case WINDOW_UPDATE_FRAME:
656 delete it->window_update_frame;
657 break;
658 case BLOCKED_FRAME:
659 delete it->blocked_frame;
660 break;
661 case NUM_FRAME_TYPES:
662 DCHECK(false) << "Cannot delete type: " << it->type;
665 STLDeleteElements(&stream_data_);
668 const QuicFrame& RetransmittableFrames::AddStreamFrame(
669 QuicStreamFrame* stream_frame) {
670 // Make an owned copy of the stream frame's data.
671 stream_data_.push_back(stream_frame->GetDataAsString());
672 // Ensure the stream frame's IOVector points to the owned copy of the data.
673 stream_frame->data.Clear();
674 stream_frame->data.Append(const_cast<char*>(stream_data_.back()->data()),
675 stream_data_.back()->size());
676 frames_.push_back(QuicFrame(stream_frame));
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 IsHandshake RetransmittableFrames::HasCryptoHandshake() const {
688 for (size_t i = 0; i < frames().size(); ++i) {
689 if (frames()[i].type == STREAM_FRAME &&
690 frames()[i].stream_frame->stream_id == kCryptoStreamId) {
691 return IS_HANDSHAKE;
694 return NOT_HANDSHAKE;
697 void RetransmittableFrames::set_encryption_level(EncryptionLevel level) {
698 encryption_level_ = level;
701 SerializedPacket::SerializedPacket(
702 QuicPacketSequenceNumber sequence_number,
703 QuicSequenceNumberLength sequence_number_length,
704 QuicPacket* packet,
705 QuicPacketEntropyHash entropy_hash,
706 RetransmittableFrames* retransmittable_frames)
707 : sequence_number(sequence_number),
708 sequence_number_length(sequence_number_length),
709 packet(packet),
710 entropy_hash(entropy_hash),
711 retransmittable_frames(retransmittable_frames) {
714 SerializedPacket::~SerializedPacket() {}
716 QuicEncryptedPacket* QuicEncryptedPacket::Clone() const {
717 char* buffer = new char[this->length()];
718 memcpy(buffer, this->data(), this->length());
719 return new QuicEncryptedPacket(buffer, this->length(), true);
722 ostream& operator<<(ostream& os, const QuicEncryptedPacket& s) {
723 os << s.length() << "-byte data";
724 return os;
727 TransmissionInfo::TransmissionInfo()
728 : retransmittable_frames(NULL),
729 sequence_number_length(PACKET_1BYTE_SEQUENCE_NUMBER),
730 sent_time(QuicTime::Zero()),
731 bytes_sent(0),
732 nack_count(0),
733 transmission_type(NOT_RETRANSMISSION),
734 all_transmissions(NULL),
735 in_flight(false) {}
737 TransmissionInfo::TransmissionInfo(
738 RetransmittableFrames* retransmittable_frames,
739 QuicPacketSequenceNumber sequence_number,
740 QuicSequenceNumberLength sequence_number_length)
741 : retransmittable_frames(retransmittable_frames),
742 sequence_number_length(sequence_number_length),
743 sent_time(QuicTime::Zero()),
744 bytes_sent(0),
745 nack_count(0),
746 transmission_type(NOT_RETRANSMISSION),
747 all_transmissions(new SequenceNumberSet),
748 in_flight(false) {
749 all_transmissions->insert(sequence_number);
752 TransmissionInfo::TransmissionInfo(
753 RetransmittableFrames* retransmittable_frames,
754 QuicPacketSequenceNumber sequence_number,
755 QuicSequenceNumberLength sequence_number_length,
756 TransmissionType transmission_type,
757 SequenceNumberSet* all_transmissions)
758 : retransmittable_frames(retransmittable_frames),
759 sequence_number_length(sequence_number_length),
760 sent_time(QuicTime::Zero()),
761 bytes_sent(0),
762 nack_count(0),
763 transmission_type(transmission_type),
764 all_transmissions(all_transmissions),
765 in_flight(false) {
766 all_transmissions->insert(sequence_number);
769 } // namespace net