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 #include "net/quic/quic_framer.h" | 5 #include "net/quic/quic_framer.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 uint32_t time_delta_us; | 1588 uint32_t time_delta_us; |
1589 if (!reader->ReadBytes(&time_delta_us, sizeof(time_delta_us))) { | 1589 if (!reader->ReadBytes(&time_delta_us, sizeof(time_delta_us))) { |
1590 set_detailed_error("Unable to read time delta in received packets."); | 1590 set_detailed_error("Unable to read time delta in received packets."); |
1591 return false; | 1591 return false; |
1592 } | 1592 } |
1593 | 1593 |
1594 last_timestamp_ = CalculateTimestampFromWire(time_delta_us); | 1594 last_timestamp_ = CalculateTimestampFromWire(time_delta_us); |
1595 | 1595 |
1596 ack_frame->received_packet_times.reserve(num_received_packets); | 1596 ack_frame->received_packet_times.reserve(num_received_packets); |
1597 ack_frame->received_packet_times.push_back( | 1597 ack_frame->received_packet_times.push_back( |
1598 std::make_pair(seq_num, creation_time_.Add(last_timestamp_))); | 1598 std::make_pair(seq_num, creation_time_ + last_timestamp_)); |
1599 | 1599 |
1600 for (uint8_t i = 1; i < num_received_packets; ++i) { | 1600 for (uint8_t i = 1; i < num_received_packets; ++i) { |
1601 if (!reader->ReadBytes(&delta_from_largest_observed, | 1601 if (!reader->ReadBytes(&delta_from_largest_observed, |
1602 PACKET_1BYTE_PACKET_NUMBER)) { | 1602 PACKET_1BYTE_PACKET_NUMBER)) { |
1603 set_detailed_error( | 1603 set_detailed_error( |
1604 "Unable to read sequence delta in received packets."); | 1604 "Unable to read sequence delta in received packets."); |
1605 return false; | 1605 return false; |
1606 } | 1606 } |
1607 seq_num = ack_frame->largest_observed - delta_from_largest_observed; | 1607 seq_num = ack_frame->largest_observed - delta_from_largest_observed; |
1608 | 1608 |
1609 // Time delta from the previous timestamp. | 1609 // Time delta from the previous timestamp. |
1610 uint64_t incremental_time_delta_us; | 1610 uint64_t incremental_time_delta_us; |
1611 if (!reader->ReadUFloat16(&incremental_time_delta_us)) { | 1611 if (!reader->ReadUFloat16(&incremental_time_delta_us)) { |
1612 set_detailed_error( | 1612 set_detailed_error( |
1613 "Unable to read incremental time delta in received packets."); | 1613 "Unable to read incremental time delta in received packets."); |
1614 return false; | 1614 return false; |
1615 } | 1615 } |
1616 | 1616 |
1617 last_timestamp_ = last_timestamp_.Add( | 1617 last_timestamp_ = last_timestamp_ + QuicTime::Delta::FromMicroseconds( |
1618 QuicTime::Delta::FromMicroseconds(incremental_time_delta_us)); | 1618 incremental_time_delta_us); |
1619 ack_frame->received_packet_times.push_back( | 1619 ack_frame->received_packet_times.push_back( |
1620 std::make_pair(seq_num, creation_time_.Add(last_timestamp_))); | 1620 std::make_pair(seq_num, creation_time_ + last_timestamp_)); |
1621 } | 1621 } |
1622 } | 1622 } |
1623 return true; | 1623 return true; |
1624 } | 1624 } |
1625 | 1625 |
1626 bool QuicFramer::ProcessStopWaitingFrame(QuicDataReader* reader, | 1626 bool QuicFramer::ProcessStopWaitingFrame(QuicDataReader* reader, |
1627 const QuicPacketHeader& header, | 1627 const QuicPacketHeader& header, |
1628 QuicStopWaitingFrame* stop_waiting) { | 1628 QuicStopWaitingFrame* stop_waiting) { |
1629 if (quic_version_ <= QUIC_VERSION_33) { | 1629 if (quic_version_ <= QUIC_VERSION_33) { |
1630 if (!reader->ReadBytes(&stop_waiting->entropy_hash, 1)) { | 1630 if (!reader->ReadBytes(&stop_waiting->entropy_hash, 1)) { |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 return false; | 2440 return false; |
2441 } | 2441 } |
2442 | 2442 |
2443 if (!writer->WriteUInt8(delta_from_largest_observed & | 2443 if (!writer->WriteUInt8(delta_from_largest_observed & |
2444 k1ByteSequenceNumberMask)) { | 2444 k1ByteSequenceNumberMask)) { |
2445 return false; | 2445 return false; |
2446 } | 2446 } |
2447 | 2447 |
2448 // Use the lowest 4 bytes of the time delta from the creation_time_. | 2448 // Use the lowest 4 bytes of the time delta from the creation_time_. |
2449 const uint64_t time_epoch_delta_us = UINT64_C(1) << 32; | 2449 const uint64_t time_epoch_delta_us = UINT64_C(1) << 32; |
2450 uint32_t time_delta_us = static_cast<uint32_t>( | 2450 uint32_t time_delta_us = |
2451 it->second.Subtract(creation_time_).ToMicroseconds() & | 2451 static_cast<uint32_t>((it->second - creation_time_).ToMicroseconds() & |
2452 (time_epoch_delta_us - 1)); | 2452 (time_epoch_delta_us - 1)); |
2453 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) { | 2453 if (!writer->WriteBytes(&time_delta_us, sizeof(time_delta_us))) { |
2454 return false; | 2454 return false; |
2455 } | 2455 } |
2456 | 2456 |
2457 QuicTime prev_time = it->second; | 2457 QuicTime prev_time = it->second; |
2458 | 2458 |
2459 for (++it; it != frame.received_packet_times.end(); ++it) { | 2459 for (++it; it != frame.received_packet_times.end(); ++it) { |
2460 packet_number = it->first; | 2460 packet_number = it->first; |
2461 delta_from_largest_observed = frame.largest_observed - packet_number; | 2461 delta_from_largest_observed = frame.largest_observed - packet_number; |
2462 | 2462 |
2463 if (delta_from_largest_observed > numeric_limits<uint8_t>::max()) { | 2463 if (delta_from_largest_observed > numeric_limits<uint8_t>::max()) { |
2464 return false; | 2464 return false; |
2465 } | 2465 } |
2466 | 2466 |
2467 if (!writer->WriteUInt8(delta_from_largest_observed & | 2467 if (!writer->WriteUInt8(delta_from_largest_observed & |
2468 k1ByteSequenceNumberMask)) { | 2468 k1ByteSequenceNumberMask)) { |
2469 return false; | 2469 return false; |
2470 } | 2470 } |
2471 | 2471 |
2472 uint64_t frame_time_delta_us = | 2472 uint64_t frame_time_delta_us = (it->second - prev_time).ToMicroseconds(); |
2473 it->second.Subtract(prev_time).ToMicroseconds(); | |
2474 prev_time = it->second; | 2473 prev_time = it->second; |
2475 if (!writer->WriteUFloat16(frame_time_delta_us)) { | 2474 if (!writer->WriteUFloat16(frame_time_delta_us)) { |
2476 return false; | 2475 return false; |
2477 } | 2476 } |
2478 } | 2477 } |
2479 return true; | 2478 return true; |
2480 } | 2479 } |
2481 | 2480 |
2482 bool QuicFramer::AppendStopWaitingFrame(const QuicPacketHeader& header, | 2481 bool QuicFramer::AppendStopWaitingFrame(const QuicPacketHeader& header, |
2483 const QuicStopWaitingFrame& frame, | 2482 const QuicStopWaitingFrame& frame, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2591 | 2590 |
2592 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2591 bool QuicFramer::RaiseError(QuicErrorCode error) { |
2593 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) | 2592 DVLOG(1) << "Error: " << QuicUtils::ErrorToString(error) |
2594 << " detail: " << detailed_error_; | 2593 << " detail: " << detailed_error_; |
2595 set_error(error); | 2594 set_error(error); |
2596 visitor_->OnError(this); | 2595 visitor_->OnError(this); |
2597 return false; | 2596 return false; |
2598 } | 2597 } |
2599 | 2598 |
2600 } // namespace net | 2599 } // namespace net |
OLD | NEW |