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

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

Issue 202383002: Add settings IDs to SpdyConstants. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test fix. Created 6 years, 9 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 | « net/spdy/spdy_framer.h ('k') | 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 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't 5 // TODO(rtenhove) clean up frame buffer size calculations so that we aren't
6 // constantly adding and subtracting header sizes; this is ugly and error- 6 // constantly adding and subtracting header sizes; this is ugly and error-
7 // prone. 7 // prone.
8 8
9 #include "net/spdy/spdy_framer.h" 9 #include "net/spdy/spdy_framer.h"
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(int version, 83 SettingsFlagsAndId SettingsFlagsAndId::FromWireFormat(int version,
84 uint32 wire) { 84 uint32 wire) {
85 if (version < 3) { 85 if (version < 3) {
86 ConvertFlagsAndIdForSpdy2(&wire); 86 ConvertFlagsAndIdForSpdy2(&wire);
87 } 87 }
88 return SettingsFlagsAndId(ntohl(wire) >> 24, ntohl(wire) & 0x00ffffff); 88 return SettingsFlagsAndId(ntohl(wire) >> 24, ntohl(wire) & 0x00ffffff);
89 } 89 }
90 90
91 SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id) 91 SettingsFlagsAndId::SettingsFlagsAndId(uint8 flags, uint32 id)
92 : flags_(flags), id_(id & 0x00ffffff) { 92 : flags_(flags), id_(id & 0x00ffffff) {
93 LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large."; 93 LOG_IF(DFATAL, id > (1u << 24)) << "SPDY setting ID too large: " << id;
94 } 94 }
95 95
96 uint32 SettingsFlagsAndId::GetWireFormat(int version) const { 96 uint32 SettingsFlagsAndId::GetWireFormat(int version) const {
97 uint32 wire = htonl(id_ & 0x00ffffff) | htonl(flags_ << 24); 97 uint32 wire = htonl(id_ & 0x00ffffff) | htonl(flags_ << 24);
98 if (version < 3) { 98 if (version < 3) {
99 ConvertFlagsAndIdForSpdy2(&wire); 99 ConvertFlagsAndIdForSpdy2(&wire);
100 } 100 }
101 return wire; 101 return wire;
102 } 102 }
103 103
(...skipping 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 GetSerializedLength(protocol_version(), &block)); 1600 GetSerializedLength(protocol_version(), &block));
1601 1601
1602 SerializeNameValueBlockWithoutCompression(&builder, block); 1602 SerializeNameValueBlockWithoutCompression(&builder, block);
1603 scoped_ptr<SpdyFrame> frame(builder.take()); 1603 scoped_ptr<SpdyFrame> frame(builder.take());
1604 1604
1605 remaining_data_length_ = frame->size(); 1605 remaining_data_length_ = frame->size();
1606 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false); 1606 ProcessControlFrameHeaderBlock(frame->data(), frame->size(), false);
1607 } 1607 }
1608 1608
1609 bool SpdyFramer::ProcessSetting(const char* data) { 1609 bool SpdyFramer::ProcessSetting(const char* data) {
1610 int id_field;
1610 SpdySettingsIds id; 1611 SpdySettingsIds id;
1611 uint8 flags = 0; 1612 uint8 flags = 0;
1612 uint32 value; 1613 uint32 value;
1613 1614
1614 // Extract fields. 1615 // Extract fields.
1615 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id. 1616 // Maintain behavior of old SPDY 2 bug with byte ordering of flags/id.
1616 if (protocol_version() <= SPDY3) { 1617 if (protocol_version() <= SPDY3) {
1617 const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data)); 1618 const uint32 id_and_flags_wire = *(reinterpret_cast<const uint32*>(data));
1618 SettingsFlagsAndId id_and_flags = 1619 SettingsFlagsAndId id_and_flags =
1619 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire); 1620 SettingsFlagsAndId::FromWireFormat(protocol_version(), id_and_flags_wire);
1620 id = static_cast<SpdySettingsIds>(id_and_flags.id()); 1621 id_field = id_and_flags.id();
1621 flags = id_and_flags.flags(); 1622 flags = id_and_flags.flags();
1622 value = ntohl(*(reinterpret_cast<const uint32*>(data + 4))); 1623 value = ntohl(*(reinterpret_cast<const uint32*>(data + 4)));
1623 } else { 1624 } else {
1624 id = static_cast<SpdySettingsIds>(*(reinterpret_cast<const uint8*>(data))); 1625 id_field = *(reinterpret_cast<const uint8*>(data));
1625 value = ntohl(*(reinterpret_cast<const uint32*>(data + 1))); 1626 value = ntohl(*(reinterpret_cast<const uint32*>(data + 1)));
1626 } 1627 }
1627 1628
1628 // Validate id. 1629 // Validate id.
1629 switch (id) { 1630 if (!SpdyConstants::IsValidSettingId(protocol_version(), id_field)) {
1630 case SETTINGS_UPLOAD_BANDWIDTH: 1631 DLOG(WARNING) << "Unknown SETTINGS ID: " << id_field;
1631 case SETTINGS_DOWNLOAD_BANDWIDTH: 1632 return false;
1632 case SETTINGS_ROUND_TRIP_TIME:
1633 case SETTINGS_MAX_CONCURRENT_STREAMS:
1634 case SETTINGS_CURRENT_CWND:
1635 case SETTINGS_DOWNLOAD_RETRANS_RATE:
1636 case SETTINGS_INITIAL_WINDOW_SIZE:
1637 // Valid values.
1638 break;
1639 default:
1640 DLOG(WARNING) << "Unknown SETTINGS ID: " << id;
1641 return false;
1642 } 1633 }
1634 id = SpdyConstants::ParseSettingId(protocol_version(), id_field);
1643 1635
1644 if (protocol_version() <= SPDY3) { 1636 if (protocol_version() <= SPDY3) {
1645 // Detect duplicates. 1637 // Detect duplicates.
1646 if (static_cast<uint32>(id) <= settings_scratch_.last_setting_id) { 1638 if (id <= settings_scratch_.last_setting_id) {
1647 DLOG(WARNING) << "Duplicate entry or invalid ordering for id " << id 1639 DLOG(WARNING) << "Duplicate entry or invalid ordering for id " << id
1648 << " in " << display_protocol_ << " SETTINGS frame " 1640 << " in " << display_protocol_ << " SETTINGS frame "
1649 << "(last setting id was " 1641 << "(last setting id was "
1650 << settings_scratch_.last_setting_id << ")."; 1642 << settings_scratch_.last_setting_id << ").";
1651 return false; 1643 return false;
1652 } 1644 }
1653 settings_scratch_.last_setting_id = id; 1645 settings_scratch_.last_setting_id = id;
1654 1646
1655 // Validate flags. 1647 // Validate flags.
1656 uint8 kFlagsMask = SETTINGS_FLAG_PLEASE_PERSIST | SETTINGS_FLAG_PERSISTED; 1648 uint8 kFlagsMask = SETTINGS_FLAG_PLEASE_PERSIST | SETTINGS_FLAG_PERSISTED;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
2287 it != values->end(); 2279 it != values->end();
2288 ++it) { 2280 ++it) {
2289 if (protocol_version() <= SPDY3) { 2281 if (protocol_version() <= SPDY3) {
2290 uint8 setting_flags = 0; 2282 uint8 setting_flags = 0;
2291 if (it->second.persist_value) { 2283 if (it->second.persist_value) {
2292 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST; 2284 setting_flags |= SETTINGS_FLAG_PLEASE_PERSIST;
2293 } 2285 }
2294 if (it->second.persisted) { 2286 if (it->second.persisted) {
2295 setting_flags |= SETTINGS_FLAG_PERSISTED; 2287 setting_flags |= SETTINGS_FLAG_PERSISTED;
2296 } 2288 }
2297 SettingsFlagsAndId flags_and_id(setting_flags, it->first); 2289 SettingsFlagsAndId flags_and_id(
2290 setting_flags,
2291 SpdyConstants::SerializeSettingId(protocol_version(), it->first));
2298 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version()); 2292 uint32 id_and_flags_wire = flags_and_id.GetWireFormat(protocol_version());
2299 builder.WriteBytes(&id_and_flags_wire, 4); 2293 builder.WriteBytes(&id_and_flags_wire, 4);
2300 } else { 2294 } else {
2301 builder.WriteUInt8(static_cast<uint8>(it->first)); 2295 builder.WriteUInt8(SpdyConstants::SerializeSettingId(protocol_version(),
2296 it->first));
2302 } 2297 }
2303 builder.WriteUInt32(it->second.value); 2298 builder.WriteUInt32(it->second.value);
2304 } 2299 }
2305 DCHECK_EQ(size, builder.length()); 2300 DCHECK_EQ(size, builder.length());
2306 return builder.take(); 2301 return builder.take();
2307 } 2302 }
2308 2303
2309 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const { 2304 SpdyFrame* SpdyFramer::SerializeBlocked(const SpdyBlockedIR& blocked) const {
2310 DCHECK_LT(SPDY3, protocol_version()); 2305 DCHECK_LT(SPDY3, protocol_version());
2311 SpdyFrameBuilder builder(GetBlockedSize()); 2306 SpdyFrameBuilder builder(GetBlockedSize());
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2846 builder->Seek(compressed_size); 2841 builder->Seek(compressed_size);
2847 builder->RewriteLength(*this); 2842 builder->RewriteLength(*this);
2848 2843
2849 pre_compress_bytes.Add(uncompressed_len); 2844 pre_compress_bytes.Add(uncompressed_len);
2850 post_compress_bytes.Add(compressed_size); 2845 post_compress_bytes.Add(compressed_size);
2851 2846
2852 compressed_frames.Increment(); 2847 compressed_frames.Increment();
2853 } 2848 }
2854 2849
2855 } // namespace net 2850 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.h ('k') | net/spdy/spdy_framer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698