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/core/quic_framer.h" | 5 #include "net/quic/core/quic_framer.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 size_t QuicFramer::GetWindowUpdateFrameSize() { | 200 size_t QuicFramer::GetWindowUpdateFrameSize() { |
201 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; | 201 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; |
202 } | 202 } |
203 | 203 |
204 // static | 204 // static |
205 size_t QuicFramer::GetBlockedFrameSize() { | 205 size_t QuicFramer::GetBlockedFrameSize() { |
206 return kQuicFrameTypeSize + kQuicMaxStreamIdSize; | 206 return kQuicFrameTypeSize + kQuicMaxStreamIdSize; |
207 } | 207 } |
208 | 208 |
209 // static | 209 // static |
210 size_t QuicFramer::GetPathCloseFrameSize() { | |
211 return kQuicFrameTypeSize + kQuicPathIdSize; | |
212 } | |
213 | |
214 // static | |
215 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) { | 210 size_t QuicFramer::GetStreamIdSize(QuicStreamId stream_id) { |
216 // Sizes are 1 through 4 bytes. | 211 // Sizes are 1 through 4 bytes. |
217 for (int i = 1; i <= 4; ++i) { | 212 for (int i = 1; i <= 4; ++i) { |
218 stream_id >>= 8; | 213 stream_id >>= 8; |
219 if (stream_id == 0) { | 214 if (stream_id == 0) { |
220 return i; | 215 return i; |
221 } | 216 } |
222 } | 217 } |
223 QUIC_BUG << "Failed to determine StreamIDSize."; | 218 QUIC_BUG << "Failed to determine StreamIDSize."; |
224 return 4; | 219 return 4; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 QUIC_BUG << "AppendWindowUpdateFrame failed"; | 386 QUIC_BUG << "AppendWindowUpdateFrame failed"; |
392 return 0; | 387 return 0; |
393 } | 388 } |
394 break; | 389 break; |
395 case BLOCKED_FRAME: | 390 case BLOCKED_FRAME: |
396 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) { | 391 if (!AppendBlockedFrame(*frame.blocked_frame, &writer)) { |
397 QUIC_BUG << "AppendBlockedFrame failed"; | 392 QUIC_BUG << "AppendBlockedFrame failed"; |
398 return 0; | 393 return 0; |
399 } | 394 } |
400 break; | 395 break; |
401 case PATH_CLOSE_FRAME: | |
402 if (!AppendPathCloseFrame(*frame.path_close_frame, &writer)) { | |
403 QUIC_BUG << "AppendPathCloseFrame failed"; | |
404 return 0; | |
405 } | |
406 break; | |
407 default: | 396 default: |
408 RaiseError(QUIC_INVALID_FRAME_DATA); | 397 RaiseError(QUIC_INVALID_FRAME_DATA); |
409 QUIC_BUG << "QUIC_INVALID_FRAME_DATA"; | 398 QUIC_BUG << "QUIC_INVALID_FRAME_DATA"; |
410 return 0; | 399 return 0; |
411 } | 400 } |
412 ++i; | 401 ++i; |
413 } | 402 } |
414 | 403 |
415 return writer.length(); | 404 return writer.length(); |
416 } | 405 } |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 // Ping has no payload. | 1100 // Ping has no payload. |
1112 QuicPingFrame ping_frame; | 1101 QuicPingFrame ping_frame; |
1113 if (!visitor_->OnPingFrame(ping_frame)) { | 1102 if (!visitor_->OnPingFrame(ping_frame)) { |
1114 QUIC_DVLOG(1) << ENDPOINT | 1103 QUIC_DVLOG(1) << ENDPOINT |
1115 << "Visitor asked to stop further processing."; | 1104 << "Visitor asked to stop further processing."; |
1116 // Returning true since there was no parsing error. | 1105 // Returning true since there was no parsing error. |
1117 return true; | 1106 return true; |
1118 } | 1107 } |
1119 continue; | 1108 continue; |
1120 } | 1109 } |
1121 case PATH_CLOSE_FRAME: { | |
1122 QuicPathCloseFrame path_close_frame; | |
1123 if (!ProcessPathCloseFrame(reader, &path_close_frame)) { | |
1124 return RaiseError(QUIC_INVALID_PATH_CLOSE_DATA); | |
1125 } | |
1126 if (!visitor_->OnPathCloseFrame(path_close_frame)) { | |
1127 QUIC_DVLOG(1) << ENDPOINT | |
1128 << "Visitor asked to stop further processing."; | |
1129 // Returning true since there was no parsing error. | |
1130 return true; | |
1131 } | |
1132 continue; | |
1133 } | |
1134 | 1110 |
1135 default: | 1111 default: |
1136 set_detailed_error("Illegal frame type."); | 1112 set_detailed_error("Illegal frame type."); |
1137 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " | 1113 QUIC_DLOG(WARNING) << ENDPOINT << "Illegal frame type: " |
1138 << static_cast<int>(frame_type); | 1114 << static_cast<int>(frame_type); |
1139 return RaiseError(QUIC_INVALID_FRAME_DATA); | 1115 return RaiseError(QUIC_INVALID_FRAME_DATA); |
1140 } | 1116 } |
1141 } | 1117 } |
1142 | 1118 |
1143 return true; | 1119 return true; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader, | 1423 bool QuicFramer::ProcessBlockedFrame(QuicDataReader* reader, |
1448 QuicBlockedFrame* frame) { | 1424 QuicBlockedFrame* frame) { |
1449 if (!reader->ReadUInt32(&frame->stream_id)) { | 1425 if (!reader->ReadUInt32(&frame->stream_id)) { |
1450 set_detailed_error("Unable to read stream_id."); | 1426 set_detailed_error("Unable to read stream_id."); |
1451 return false; | 1427 return false; |
1452 } | 1428 } |
1453 | 1429 |
1454 return true; | 1430 return true; |
1455 } | 1431 } |
1456 | 1432 |
1457 bool QuicFramer::ProcessPathCloseFrame(QuicDataReader* reader, | |
1458 QuicPathCloseFrame* frame) { | |
1459 if (!reader->ReadBytes(&frame->path_id, 1)) { | |
1460 set_detailed_error("Unable to read path_id."); | |
1461 return false; | |
1462 } | |
1463 | |
1464 return true; | |
1465 } | |
1466 | |
1467 // static | 1433 // static |
1468 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket( | 1434 QuicStringPiece QuicFramer::GetAssociatedDataFromEncryptedPacket( |
1469 QuicVersion version, | 1435 QuicVersion version, |
1470 const QuicEncryptedPacket& encrypted, | 1436 const QuicEncryptedPacket& encrypted, |
1471 QuicConnectionIdLength connection_id_length, | 1437 QuicConnectionIdLength connection_id_length, |
1472 bool includes_version, | 1438 bool includes_version, |
1473 bool includes_diversification_nonce, | 1439 bool includes_diversification_nonce, |
1474 QuicPacketNumberLength packet_number_length) { | 1440 QuicPacketNumberLength packet_number_length) { |
1475 // TODO(ianswett): This is identical to QuicData::AssociatedData. | 1441 // TODO(ianswett): This is identical to QuicData::AssociatedData. |
1476 return QuicStringPiece( | 1442 return QuicStringPiece( |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1697 return GetRstStreamFrameSize(); | 1663 return GetRstStreamFrameSize(); |
1698 case CONNECTION_CLOSE_FRAME: | 1664 case CONNECTION_CLOSE_FRAME: |
1699 return GetMinConnectionCloseFrameSize() + | 1665 return GetMinConnectionCloseFrameSize() + |
1700 frame.connection_close_frame->error_details.size(); | 1666 frame.connection_close_frame->error_details.size(); |
1701 case GOAWAY_FRAME: | 1667 case GOAWAY_FRAME: |
1702 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); | 1668 return GetMinGoAwayFrameSize() + frame.goaway_frame->reason_phrase.size(); |
1703 case WINDOW_UPDATE_FRAME: | 1669 case WINDOW_UPDATE_FRAME: |
1704 return GetWindowUpdateFrameSize(); | 1670 return GetWindowUpdateFrameSize(); |
1705 case BLOCKED_FRAME: | 1671 case BLOCKED_FRAME: |
1706 return GetBlockedFrameSize(); | 1672 return GetBlockedFrameSize(); |
1707 case PATH_CLOSE_FRAME: | |
1708 return GetPathCloseFrameSize(); | |
1709 case PADDING_FRAME: | 1673 case PADDING_FRAME: |
1710 DCHECK(false); | 1674 DCHECK(false); |
1711 return 0; | 1675 return 0; |
1712 case NUM_FRAME_TYPES: | 1676 case NUM_FRAME_TYPES: |
1713 DCHECK(false); | 1677 DCHECK(false); |
1714 return 0; | 1678 return 0; |
1715 } | 1679 } |
1716 | 1680 |
1717 // Not reachable, but some Chrome compilers can't figure that out. *sigh* | 1681 // Not reachable, but some Chrome compilers can't figure that out. *sigh* |
1718 DCHECK(false); | 1682 DCHECK(false); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 | 2096 |
2133 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame, | 2097 bool QuicFramer::AppendBlockedFrame(const QuicBlockedFrame& frame, |
2134 QuicDataWriter* writer) { | 2098 QuicDataWriter* writer) { |
2135 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id); | 2099 uint32_t stream_id = static_cast<uint32_t>(frame.stream_id); |
2136 if (!writer->WriteUInt32(stream_id)) { | 2100 if (!writer->WriteUInt32(stream_id)) { |
2137 return false; | 2101 return false; |
2138 } | 2102 } |
2139 return true; | 2103 return true; |
2140 } | 2104 } |
2141 | 2105 |
2142 bool QuicFramer::AppendPathCloseFrame(const QuicPathCloseFrame& frame, | |
2143 QuicDataWriter* writer) { | |
2144 uint8_t path_id = static_cast<uint8_t>(frame.path_id); | |
2145 if (!writer->WriteUInt8(path_id)) { | |
2146 return false; | |
2147 } | |
2148 return true; | |
2149 } | |
2150 | |
2151 bool QuicFramer::RaiseError(QuicErrorCode error) { | 2106 bool QuicFramer::RaiseError(QuicErrorCode error) { |
2152 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) | 2107 QUIC_DLOG(INFO) << ENDPOINT << "Error: " << QuicErrorCodeToString(error) |
2153 << " detail: " << detailed_error_; | 2108 << " detail: " << detailed_error_; |
2154 set_error(error); | 2109 set_error(error); |
2155 visitor_->OnError(this); | 2110 visitor_->OnError(this); |
2156 return false; | 2111 return false; |
2157 } | 2112 } |
2158 | 2113 |
2159 } // namespace net | 2114 } // namespace net |
OLD | NEW |