| 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 <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <ios> | 10 #include <ios> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 const size_t kPadLengthFieldSize = 1; | 112 const size_t kPadLengthFieldSize = 1; |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 const SpdyStreamId SpdyFramer::kInvalidStream = static_cast<SpdyStreamId>(-1); | 116 const SpdyStreamId SpdyFramer::kInvalidStream = static_cast<SpdyStreamId>(-1); |
| 117 const size_t SpdyFramer::kHeaderDataChunkMaxSize = 1024; | 117 const size_t SpdyFramer::kHeaderDataChunkMaxSize = 1024; |
| 118 // Even though the length field is 24 bits, we keep this 16 kB | 118 // Even though the length field is 24 bits, we keep this 16 kB |
| 119 // limit on control frame size for legacy reasons and to | 119 // limit on control frame size for legacy reasons and to |
| 120 // mitigate DOS attacks. | 120 // mitigate DOS attacks. |
| 121 const size_t SpdyFramer::kMaxControlFrameSize = (1 << 14) - 1; | 121 const size_t SpdyFramer::kMaxControlFrameSize = (1 << 14) - 1; |
| 122 const size_t SpdyFramer::kMaxDataPayloadSendSize = 1 << 14; |
| 122 // The size of the control frame buffer. Must be >= the minimum size of the | 123 // The size of the control frame buffer. Must be >= the minimum size of the |
| 123 // largest control frame, which is SYN_STREAM. See GetSynStreamMinimumSize() for | 124 // largest control frame, which is SYN_STREAM. See GetSynStreamMinimumSize() for |
| 124 // calculation details. | 125 // calculation details. |
| 125 const size_t SpdyFramer::kControlFrameBufferSize = 19; | 126 const size_t SpdyFramer::kControlFrameBufferSize = 19; |
| 126 | 127 |
| 127 #ifdef DEBUG_SPDY_STATE_CHANGES | 128 #ifdef DEBUG_SPDY_STATE_CHANGES |
| 128 #define CHANGE_STATE(newstate) \ | 129 #define CHANGE_STATE(newstate) \ |
| 129 do { \ | 130 do { \ |
| 130 DVLOG(1) << "Changing state from: " \ | 131 DVLOG(1) << "Changing state from: " \ |
| 131 << StateToString(state_) \ | 132 << StateToString(state_) \ |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 return GetControlFrameHeaderSize() + | 415 return GetControlFrameHeaderSize() + |
| 415 kPriorityDependencyPayloadSize + | 416 kPriorityDependencyPayloadSize + |
| 416 kPriorityWeightPayloadSize; | 417 kPriorityWeightPayloadSize; |
| 417 } | 418 } |
| 418 | 419 |
| 419 size_t SpdyFramer::GetFrameMinimumSize() const { | 420 size_t SpdyFramer::GetFrameMinimumSize() const { |
| 420 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize()); | 421 return std::min(GetDataFrameMinimumSize(), GetControlFrameHeaderSize()); |
| 421 } | 422 } |
| 422 | 423 |
| 423 size_t SpdyFramer::GetFrameMaximumSize() const { | 424 size_t SpdyFramer::GetFrameMaximumSize() const { |
| 424 return SpdyConstants::GetFrameMaximumSize(protocol_version_); | 425 if (protocol_version_ == HTTP2) { |
| 426 return send_frame_size_limit_ + |
| 427 SpdyConstants::GetFrameHeaderSize(protocol_version_); |
| 428 } else { |
| 429 return SpdyConstants::GetMaxFrameSizeLimit(protocol_version_); |
| 430 } |
| 425 } | 431 } |
| 426 | 432 |
| 427 size_t SpdyFramer::GetDataFrameMaximumPayload() const { | 433 size_t SpdyFramer::GetDataFrameMaximumPayload() const { |
| 428 return GetFrameMaximumSize() - GetDataFrameMinimumSize(); | 434 if (protocol_version_ == HTTP2) { |
| 435 return std::min(kMaxDataPayloadSendSize, |
| 436 GetFrameMaximumSize() - GetDataFrameMinimumSize()); |
| 437 } else { |
| 438 return GetFrameMaximumSize() - GetDataFrameMinimumSize(); |
| 439 } |
| 429 } | 440 } |
| 430 | 441 |
| 431 size_t SpdyFramer::GetPrefixLength(SpdyFrameType type) const { | 442 size_t SpdyFramer::GetPrefixLength(SpdyFrameType type) const { |
| 432 return SpdyConstants::GetPrefixLength(type, protocol_version_); | 443 return SpdyConstants::GetPrefixLength(type, protocol_version_); |
| 433 } | 444 } |
| 434 | 445 |
| 435 const char* SpdyFramer::StateToString(int state) { | 446 const char* SpdyFramer::StateToString(int state) { |
| 436 switch (state) { | 447 switch (state) { |
| 437 case SPDY_ERROR: | 448 case SPDY_ERROR: |
| 438 return "ERROR"; | 449 return "ERROR"; |
| (...skipping 2868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3307 #else | 3318 #else |
| 3308 WriteHeaderBlockToZ(&frame.header_block(), compressor); | 3319 WriteHeaderBlockToZ(&frame.header_block(), compressor); |
| 3309 #endif // defined(USE_SYSTEM_ZLIB) | 3320 #endif // defined(USE_SYSTEM_ZLIB) |
| 3310 | 3321 |
| 3311 int compressed_size = compressed_max_size - compressor->avail_out; | 3322 int compressed_size = compressed_max_size - compressor->avail_out; |
| 3312 builder->Seek(compressed_size); | 3323 builder->Seek(compressed_size); |
| 3313 builder->RewriteLength(*this); | 3324 builder->RewriteLength(*this); |
| 3314 } | 3325 } |
| 3315 | 3326 |
| 3316 } // namespace net | 3327 } // namespace net |
| OLD | NEW |