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/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/third_party/valgrind/memcheck.h" | 10 #include "base/third_party/valgrind/memcheck.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 return GetControlFrameHeaderSize(); | 298 return GetControlFrameHeaderSize(); |
299 } | 299 } |
300 | 300 |
301 size_t SpdyFramer::GetPushPromiseMinimumSize() const { | 301 size_t SpdyFramer::GetPushPromiseMinimumSize() const { |
302 DCHECK_LT(SPDY3, protocol_version()); | 302 DCHECK_LT(SPDY3, protocol_version()); |
303 // Size, in bytes, of a PUSH_PROMISE frame, sans the embedded header block. | 303 // Size, in bytes, of a PUSH_PROMISE frame, sans the embedded header block. |
304 // Calculated as frame prefix + 4 (promised stream id). | 304 // Calculated as frame prefix + 4 (promised stream id). |
305 return GetControlFrameHeaderSize() + 4; | 305 return GetControlFrameHeaderSize() + 4; |
306 } | 306 } |
307 | 307 |
308 size_t SpdyFramer::GetContinuationMinimumSize() const { | 308 size_t SpdyFramer::GetContinuationMinimumSize() const { |
309 // Size, in bytes, of a CONTINUATION frame not including the variable-length | 309 // Size, in bytes, of a CONTINUATION frame not including the variable-length |
310 // headers fragments. | 310 // headers fragments. |
311 return GetControlFrameHeaderSize(); | 311 return GetControlFrameHeaderSize(); |
312 } | 312 } |
313 | 313 |
314 size_t SpdyFramer::GetAltSvcMinimumSize() const { | 314 size_t SpdyFramer::GetAltSvcMinimumSize() const { |
315 // Size, in bytes, of an ALTSVC frame not including the Protocol-ID, Host, and | 315 // Size, in bytes, of an ALTSVC frame not including the Protocol-ID, Host, and |
316 // (optional) Origin fields, all of which can vary in length. | 316 // (optional) Origin fields, all of which can vary in length. |
317 // Note that this gives a lower bound on the frame size rather than a true | 317 // Note that this gives a lower bound on the frame size rather than a true |
318 // minimum; the actual frame should always be larger than this. | 318 // minimum; the actual frame should always be larger than this. |
319 // Calculated as frame prefix + 4 (max-age) + 2 (port) + 1 (reserved byte) | 319 // Calculated as frame prefix + 4 (max-age) + 2 (port) + 1 (reserved byte) |
320 // + 1 (pid_len) + 1 (host_len). | 320 // + 1 (pid_len) + 1 (host_len). |
321 return GetControlFrameHeaderSize() + 9; | 321 return GetControlFrameHeaderSize() + 9; |
322 } | 322 } |
323 | 323 |
| 324 size_t SpdyFramer::GetPrioritySize() const { |
| 325 // Size, in bytes, of a PRIORITY frame. |
| 326 // Calculated as frame prefix + 4 (stream dependency) + 1 (weight) |
| 327 return GetControlFrameHeaderSize() + 5; |
| 328 } |
| 329 |
324 size_t SpdyFramer::GetFrameMinimumSize() const { | 330 size_t SpdyFramer::GetFrameMinimumSize() const { |
325 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize()); | 331 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize()); |
326 } | 332 } |
327 | 333 |
328 size_t SpdyFramer::GetFrameMaximumSize() const { | 334 size_t SpdyFramer::GetFrameMaximumSize() const { |
329 return SpdyConstants::GetFrameMaximumSize(protocol_version()); | 335 return SpdyConstants::GetFrameMaximumSize(protocol_version()); |
330 } | 336 } |
331 | 337 |
332 size_t SpdyFramer::GetDataFrameMaximumPayload() const { | 338 size_t SpdyFramer::GetDataFrameMaximumPayload() const { |
333 return GetFrameMaximumSize() - GetDataFrameMinimumSize(); | 339 return GetFrameMaximumSize() - GetDataFrameMinimumSize(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 case CREDENTIAL: | 477 case CREDENTIAL: |
472 return "CREDENTIAL"; | 478 return "CREDENTIAL"; |
473 case BLOCKED: | 479 case BLOCKED: |
474 return "BLOCKED"; | 480 return "BLOCKED"; |
475 case PUSH_PROMISE: | 481 case PUSH_PROMISE: |
476 return "PUSH_PROMISE"; | 482 return "PUSH_PROMISE"; |
477 case CONTINUATION: | 483 case CONTINUATION: |
478 return "CONTINUATION"; | 484 return "CONTINUATION"; |
479 case ALTSVC: | 485 case ALTSVC: |
480 return "ALTSVC"; | 486 return "ALTSVC"; |
| 487 case PRIORITY: |
| 488 return "PRIORITY"; |
481 } | 489 } |
482 return "UNKNOWN_CONTROL_TYPE"; | 490 return "UNKNOWN_CONTROL_TYPE"; |
483 } | 491 } |
484 | 492 |
485 size_t SpdyFramer::ProcessInput(const char* data, size_t len) { | 493 size_t SpdyFramer::ProcessInput(const char* data, size_t len) { |
486 DCHECK(visitor_); | 494 DCHECK(visitor_); |
487 DCHECK(data); | 495 DCHECK(data); |
488 | 496 |
489 size_t original_len = len; | 497 size_t original_len = len; |
490 do { | 498 do { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | 970 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
963 } | 971 } |
964 break; | 972 break; |
965 case ALTSVC: | 973 case ALTSVC: |
966 if (current_frame_length_ <= GetAltSvcMinimumSize()) { | 974 if (current_frame_length_ <= GetAltSvcMinimumSize()) { |
967 set_error(SPDY_INVALID_CONTROL_FRAME); | 975 set_error(SPDY_INVALID_CONTROL_FRAME); |
968 } else if (current_frame_flags_ != 0) { | 976 } else if (current_frame_flags_ != 0) { |
969 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); | 977 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
970 } | 978 } |
971 break; | 979 break; |
| 980 case PRIORITY: |
| 981 if (current_frame_length_ != GetPrioritySize() || |
| 982 protocol_version() <= SPDY3) { |
| 983 set_error(SPDY_INVALID_CONTROL_FRAME); |
| 984 } else if (current_frame_flags_ != 0) { |
| 985 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); |
| 986 } |
| 987 break; |
972 default: | 988 default: |
973 LOG(WARNING) << "Valid " << display_protocol_ | 989 LOG(WARNING) << "Valid " << display_protocol_ |
974 << " control frame with unhandled type: " | 990 << " control frame with unhandled type: " |
975 << current_frame_type_; | 991 << current_frame_type_; |
976 // This branch should be unreachable because of the frame type bounds | 992 // This branch should be unreachable because of the frame type bounds |
977 // check above. However, we DLOG(FATAL) here in an effort to painfully | 993 // check above. However, we DLOG(FATAL) here in an effort to painfully |
978 // club the head of the developer who failed to keep this file in sync | 994 // club the head of the developer who failed to keep this file in sync |
979 // with spdy_protocol.h. | 995 // with spdy_protocol.h. |
980 DLOG(FATAL); | 996 DLOG(FATAL); |
981 set_error(SPDY_INVALID_CONTROL_FRAME); | 997 set_error(SPDY_INVALID_CONTROL_FRAME); |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 visitor_->OnWindowUpdate(current_frame_stream_id_, | 1757 visitor_->OnWindowUpdate(current_frame_stream_id_, |
1742 delta_window_size); | 1758 delta_window_size); |
1743 } | 1759 } |
1744 break; | 1760 break; |
1745 case BLOCKED: { | 1761 case BLOCKED: { |
1746 DCHECK_LT(SPDY3, protocol_version()); | 1762 DCHECK_LT(SPDY3, protocol_version()); |
1747 DCHECK(reader.IsDoneReading()); | 1763 DCHECK(reader.IsDoneReading()); |
1748 visitor_->OnBlocked(current_frame_stream_id_); | 1764 visitor_->OnBlocked(current_frame_stream_id_); |
1749 } | 1765 } |
1750 break; | 1766 break; |
| 1767 case PRIORITY: { |
| 1768 DCHECK_LT(SPDY3, protocol_version()); |
| 1769 // TODO(hkhalil): Process PRIORITY frames rather than ignore them. |
| 1770 reader.Seek(5); |
| 1771 DCHECK(reader.IsDoneReading()); |
| 1772 } |
| 1773 break; |
1751 default: | 1774 default: |
1752 // Unreachable. | 1775 // Unreachable. |
1753 LOG(FATAL) << "Unhandled control frame " << current_frame_type_; | 1776 LOG(FATAL) << "Unhandled control frame " << current_frame_type_; |
1754 } | 1777 } |
1755 | 1778 |
1756 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD); | 1779 CHANGE_STATE(SPDY_IGNORE_REMAINING_PAYLOAD); |
1757 } | 1780 } |
1758 return original_len - len; | 1781 return original_len - len; |
1759 } | 1782 } |
1760 | 1783 |
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3187 builder->Seek(compressed_size); | 3210 builder->Seek(compressed_size); |
3188 builder->RewriteLength(*this); | 3211 builder->RewriteLength(*this); |
3189 | 3212 |
3190 pre_compress_bytes.Add(uncompressed_len); | 3213 pre_compress_bytes.Add(uncompressed_len); |
3191 post_compress_bytes.Add(compressed_size); | 3214 post_compress_bytes.Add(compressed_size); |
3192 | 3215 |
3193 compressed_frames.Increment(); | 3216 compressed_frames.Increment(); |
3194 } | 3217 } |
3195 | 3218 |
3196 } // namespace net | 3219 } // namespace net |
OLD | NEW |