Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: net/spdy/spdy_framer.cc

Issue 352383002: Update SPDY4 settings ID to 16 bits (from 8). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extract SpdyConstants::GetSettingSize() Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 } else if (current_frame_flags_ != 0) { 868 } else if (current_frame_flags_ != 0) {
869 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); 869 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
870 } 870 }
871 break; 871 break;
872 case SETTINGS: 872 case SETTINGS:
873 { 873 {
874 // Make sure that we have an integral number of 8-byte key/value pairs, 874 // Make sure that we have an integral number of 8-byte key/value pairs,
875 // plus a 4-byte length field in SPDY3 and below. 875 // plus a 4-byte length field in SPDY3 and below.
876 size_t values_prefix_size = (protocol_version() <= SPDY3 ? 4 : 0); 876 size_t values_prefix_size = (protocol_version() <= SPDY3 ? 4 : 0);
877 // Size of each key/value pair in bytes. 877 // Size of each key/value pair in bytes.
878 size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5); 878 size_t setting_size = SpdyConstants::GetSettingSize(protocol_version());
879 if (current_frame_length_ < GetSettingsMinimumSize() || 879 if (current_frame_length_ < GetSettingsMinimumSize() ||
880 (current_frame_length_ - GetControlFrameHeaderSize()) 880 (current_frame_length_ - GetControlFrameHeaderSize())
881 % setting_size != values_prefix_size) { 881 % setting_size != values_prefix_size) {
882 DLOG(WARNING) << "Invalid length for SETTINGS frame: " 882 DLOG(WARNING) << "Invalid length for SETTINGS frame: "
883 << current_frame_length_; 883 << current_frame_length_;
884 set_error(SPDY_INVALID_CONTROL_FRAME); 884 set_error(SPDY_INVALID_CONTROL_FRAME);
885 } else if (protocol_version() <= SPDY3 && 885 } else if (protocol_version() <= SPDY3 &&
886 current_frame_flags_ & 886 current_frame_flags_ &
887 ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { 887 ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) {
888 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS); 888 set_error(SPDY_INVALID_CONTROL_FRAME_FLAGS);
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1598 return process_bytes; 1598 return process_bytes;
1599 } 1599 }
1600 1600
1601 size_t SpdyFramer::ProcessSettingsFramePayload(const char* data, 1601 size_t SpdyFramer::ProcessSettingsFramePayload(const char* data,
1602 size_t data_len) { 1602 size_t data_len) {
1603 DCHECK_EQ(SPDY_SETTINGS_FRAME_PAYLOAD, state_); 1603 DCHECK_EQ(SPDY_SETTINGS_FRAME_PAYLOAD, state_);
1604 DCHECK_EQ(SETTINGS, current_frame_type_); 1604 DCHECK_EQ(SETTINGS, current_frame_type_);
1605 size_t unprocessed_bytes = std::min(data_len, remaining_data_length_); 1605 size_t unprocessed_bytes = std::min(data_len, remaining_data_length_);
1606 size_t processed_bytes = 0; 1606 size_t processed_bytes = 0;
1607 1607
1608 size_t setting_size = protocol_version() <= SPDY3 ? 8 : 5; 1608 size_t setting_size = SpdyConstants::GetSettingSize(protocol_version());
1609 1609
1610 // Loop over our incoming data. 1610 // Loop over our incoming data.
1611 while (unprocessed_bytes > 0) { 1611 while (unprocessed_bytes > 0) {
1612 // Process up to one setting at a time. 1612 // Process up to one setting at a time.
1613 size_t processing = std::min( 1613 size_t processing = std::min(
1614 unprocessed_bytes, 1614 unprocessed_bytes,
1615 static_cast<size_t>(setting_size - settings_scratch_.setting_buf_len)); 1615 static_cast<size_t>(setting_size - settings_scratch_.setting_buf_len));
1616 1616
1617 // Check if we have a complete setting in our input. 1617 // Check if we have a complete setting in our input.
1618 if (processing == setting_size) { 1618 if (processing == setting_size) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1692 // Extract fields. 1692 // Extract fields.
1693 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id. 1693 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id.
1694 if (protocol_version() <= SPDY3) { 1694 if (protocol_version() <= SPDY3) {
1695 const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data)); 1695 const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data));
1696 SettingsFlagsAndId id_and_flags = 1696 SettingsFlagsAndId id_and_flags =
1697 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire); 1697 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire);
1698 id_field = id_and_flags.id(); 1698 id_field = id_and_flags.id();
1699 flags = id_and_flags.flags(); 1699 flags = id_and_flags.flags();
1700 value = ntohl(*(reinterpret_cast<const uint32*>(data + 4))); 1700 value = ntohl(*(reinterpret_cast<const uint32*>(data + 4)));
1701 } else { 1701 } else {
1702 id_field = *(reinterpret_cast<const uint8*>(data)); 1702 id_field = ntohs(*(reinterpret_cast<const uint16*>(data)));
1703 value = ntohl(*(reinterpret_cast<const uint32*>(data + 1))); 1703 value = ntohl(*(reinterpret_cast<const uint32*>(data + 2)));
1704 } 1704 }
1705 1705
1706 // Validate id. 1706 // Validate id.
1707 if (!SpdyConstants::IsValidSettingId(protocol_version(), id_field)) { 1707 if (!SpdyConstants::IsValidSettingId(protocol_version(), id_field)) {
1708 DLOG(WARNING) << "Unknown SETTINGS ID: " << id_field; 1708 DLOG(WARNING) << "Unknown SETTINGS ID: " << id_field;
1709 return false; 1709 return false;
1710 } 1710 }
1711 id = SpdyConstants::ParseSettingId(protocol_version(), id_field); 1711 id = SpdyConstants::ParseSettingId(protocol_version(), id_field);
1712 1712
1713 if (protocol_version() <= SPDY3) { 1713 if (protocol_version() <= SPDY3) {
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
2444 if (settings.clear_settings()) { 2444 if (settings.clear_settings()) {
2445 flags |= SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS; 2445 flags |= SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS;
2446 } 2446 }
2447 } else { 2447 } else {
2448 if (settings.is_ack()) { 2448 if (settings.is_ack()) {
2449 flags |= SETTINGS_FLAG_ACK; 2449 flags |= SETTINGS_FLAG_ACK;
2450 } 2450 }
2451 } 2451 }
2452 const SpdySettingsIR::ValueMap* values = &(settings.values()); 2452 const SpdySettingsIR::ValueMap* values = &(settings.values());
2453 2453
2454 size_t setting_size = (protocol_version() <= SPDY3 ? 8 : 5); 2454 size_t setting_size = SpdyConstants::GetSettingSize(protocol_version());
2455 // Size, in bytes, of this SETTINGS frame. 2455 // Size, in bytes, of this SETTINGS frame.
2456 const size_t size = GetSettingsMinimumSize() + 2456 const size_t size = GetSettingsMinimumSize() +
2457 (values->size() * setting_size); 2457 (values->size() * setting_size);
2458 SpdyFrameBuilder builder(size, protocol_version()); 2458 SpdyFrameBuilder builder(size, protocol_version());
2459 if (protocol_version() <= SPDY3) { 2459 if (protocol_version() <= SPDY3) {
2460 builder.WriteControlFrameHeader(*this, SETTINGS, flags); 2460 builder.WriteControlFrameHeader(*this, SETTINGS, flags);
2461 } else { 2461 } else {
2462 builder.BeginNewFrame(*this, SETTINGS, flags, 0); 2462 builder.BeginNewFrame(*this, SETTINGS, flags, 0);
2463 } 2463 }
2464 2464
(...skipping 16 matching lines...) Expand all
2481 } 2481 }
2482 if (it->second.persisted) { 2482 if (it->second.persisted) {
2483 setting_flags |= SETTINGS_FLAG_PERSISTED; 2483 setting_flags |= SETTINGS_FLAG_PERSISTED;
2484 } 2484 }
2485 SettingsFlagsAndId flags_and_id( 2485 SettingsFlagsAndId flags_and_id(
2486 setting_flags, 2486 setting_flags,
2487 SpdyConstants::SerializeSettingId(protocol_version(), it->first)); 2487 SpdyConstants::SerializeSettingId(protocol_version(), it->first));
2488 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version()); 2488 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version());
2489 builder.WriteBytes(&id_and_flags_wire, 4); 2489 builder.WriteBytes(&id_and_flags_wire, 4);
2490 } else { 2490 } else {
2491 builder.WriteUInt8(SpdyConstants::SerializeSettingId(protocol_version(), 2491 builder.WriteUInt16(SpdyConstants::SerializeSettingId(protocol_version(),
2492 it->first)); 2492 it->first));
2493 } 2493 }
2494 builder.WriteUInt32(it->second.value); 2494 builder.WriteUInt32(it->second.value);
2495 } 2495 }
2496 DCHECK_EQ(size, builder.length()); 2496 DCHECK_EQ(size, builder.length());
2497 return builder.take(); 2497 return builder.take();
2498 } 2498 }
2499 2499
2500 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const { 2500 SpdySerializedFrame* SpdyFramer::SerializePing(const SpdyPingIR& ping) const {
2501 SpdyFrameBuilder builder(GetPingSize(), protocol_version()); 2501 SpdyFrameBuilder builder(GetPingSize(), protocol_version());
2502 if (protocol_version() <= SPDY3) { 2502 if (protocol_version() <= SPDY3) {
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 builder->Seek(compressed_size); 3197 builder->Seek(compressed_size);
3198 builder->RewriteLength(*this); 3198 builder->RewriteLength(*this);
3199 3199
3200 pre_compress_bytes.Add(uncompressed_len); 3200 pre_compress_bytes.Add(uncompressed_len);
3201 post_compress_bytes.Add(compressed_size); 3201 post_compress_bytes.Add(compressed_size);
3202 3202
3203 compressed_frames.Increment(); 3203 compressed_frames.Increment();
3204 } 3204 }
3205 3205
3206 } // namespace net 3206 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698