| 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 // 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 LOG(DFATAL) << "Unhandled SPDY version."; | 177 LOG(DFATAL) << "Unhandled SPDY version."; |
| 178 return 0; | 178 return 0; |
| 179 } | 179 } |
| 180 | 180 |
| 181 size_t SpdyFramer::GetSynStreamMinimumSize() const { | 181 size_t SpdyFramer::GetSynStreamMinimumSize() const { |
| 182 // Size, in bytes, of a SYN_STREAM frame not including the variable-length | 182 // Size, in bytes, of a SYN_STREAM frame not including the variable-length |
| 183 // name-value block. | 183 // name-value block. |
| 184 if (spdy_version_ < 4) { | 184 if (spdy_version_ < 4) { |
| 185 // Calculated as: | 185 // Calculated as: |
| 186 // control frame header + 2 * 4 (stream IDs) + 1 (priority) + 1 (slot) | 186 // control frame header + 2 * 4 (stream IDs) + 1 (priority) |
| 187 // + 1 (unused, was credential slot) |
| 187 return GetControlFrameHeaderSize() + 10; | 188 return GetControlFrameHeaderSize() + 10; |
| 188 } else { | 189 } else { |
| 189 // Calculated as: | 190 // Calculated as: |
| 190 // frame prefix + 4 (priority) | 191 // frame prefix + 4 (priority) |
| 191 return GetControlFrameHeaderSize() + 4; | 192 return GetControlFrameHeaderSize() + 4; |
| 192 } | 193 } |
| 193 } | 194 } |
| 194 | 195 |
| 195 size_t SpdyFramer::GetSynReplyMinimumSize() const { | 196 size_t SpdyFramer::GetSynReplyMinimumSize() const { |
| 196 // Size, in bytes, of a SYN_REPLY frame not including the variable-length | 197 // Size, in bytes, of a SYN_REPLY frame not including the variable-length |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 | 1156 |
| 1156 SpdyPriority priority = 0; | 1157 SpdyPriority priority = 0; |
| 1157 successful_read = reader.ReadUInt8(&priority); | 1158 successful_read = reader.ReadUInt8(&priority); |
| 1158 DCHECK(successful_read); | 1159 DCHECK(successful_read); |
| 1159 if (protocol_version() < 3) { | 1160 if (protocol_version() < 3) { |
| 1160 priority = priority >> 6; | 1161 priority = priority >> 6; |
| 1161 } else { | 1162 } else { |
| 1162 priority = priority >> 5; | 1163 priority = priority >> 5; |
| 1163 } | 1164 } |
| 1164 | 1165 |
| 1165 uint8 slot = 0; | 1166 // Seek past unused byte; used to be credential slot in SPDY 3. |
| 1166 if (protocol_version() < 3) { | 1167 reader.Seek(1); |
| 1167 // SPDY 2 had an unused byte here. Seek past it. | |
| 1168 reader.Seek(1); | |
| 1169 } else { | |
| 1170 successful_read = reader.ReadUInt8(&slot); | |
| 1171 DCHECK(successful_read); | |
| 1172 } | |
| 1173 | 1168 |
| 1174 DCHECK(reader.IsDoneReading()); | 1169 DCHECK(reader.IsDoneReading()); |
| 1175 if (debug_visitor_) { | 1170 if (debug_visitor_) { |
| 1176 debug_visitor_->OnReceiveCompressedFrame( | 1171 debug_visitor_->OnReceiveCompressedFrame( |
| 1177 current_frame_stream_id_, | 1172 current_frame_stream_id_, |
| 1178 current_frame_type_, | 1173 current_frame_type_, |
| 1179 current_frame_length_); | 1174 current_frame_length_); |
| 1180 } | 1175 } |
| 1181 visitor_->OnSynStream( | 1176 visitor_->OnSynStream( |
| 1182 current_frame_stream_id_, | 1177 current_frame_stream_id_, |
| 1183 associated_to_stream_id, | 1178 associated_to_stream_id, |
| 1184 priority, | 1179 priority, |
| 1185 slot, | |
| 1186 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0, | 1180 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0, |
| 1187 (current_frame_flags_ & CONTROL_FLAG_UNIDIRECTIONAL) != 0); | 1181 (current_frame_flags_ & CONTROL_FLAG_UNIDIRECTIONAL) != 0); |
| 1188 } | 1182 } |
| 1189 CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK); | 1183 CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK); |
| 1190 break; | 1184 break; |
| 1191 case SETTINGS: | 1185 case SETTINGS: |
| 1192 visitor_->OnSettings(current_frame_flags_ & | 1186 visitor_->OnSettings(current_frame_flags_ & |
| 1193 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS); | 1187 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS); |
| 1194 CHANGE_STATE(SPDY_SETTINGS_FRAME_PAYLOAD); | 1188 CHANGE_STATE(SPDY_SETTINGS_FRAME_PAYLOAD); |
| 1195 break; | 1189 break; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 current_frame_stream_id_, | 1231 current_frame_stream_id_, |
| 1238 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0); | 1232 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0); |
| 1239 } else if (spdy_version_ > 3 && | 1233 } else if (spdy_version_ > 3 && |
| 1240 current_frame_flags_ & HEADERS_FLAG_PRIORITY) { | 1234 current_frame_flags_ & HEADERS_FLAG_PRIORITY) { |
| 1241 // SPDY 4+ is missing SYN_STREAM. Simulate it so that API changes | 1235 // SPDY 4+ is missing SYN_STREAM. Simulate it so that API changes |
| 1242 // can be made independent of wire changes. | 1236 // can be made independent of wire changes. |
| 1243 visitor_->OnSynStream( | 1237 visitor_->OnSynStream( |
| 1244 current_frame_stream_id_, | 1238 current_frame_stream_id_, |
| 1245 0, // associated_to_stream_id | 1239 0, // associated_to_stream_id |
| 1246 priority, | 1240 priority, |
| 1247 0, // TODO(hkhalil): handle slot for SPDY 4+? | |
| 1248 current_frame_flags_ & CONTROL_FLAG_FIN, | 1241 current_frame_flags_ & CONTROL_FLAG_FIN, |
| 1249 false); // unidirectional | 1242 false); // unidirectional |
| 1250 } else { | 1243 } else { |
| 1251 visitor_->OnHeaders( | 1244 visitor_->OnHeaders( |
| 1252 current_frame_stream_id_, | 1245 current_frame_stream_id_, |
| 1253 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0); | 1246 (current_frame_flags_ & CONTROL_FLAG_FIN) != 0); |
| 1254 } | 1247 } |
| 1255 } | 1248 } |
| 1256 CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK); | 1249 CHANGE_STATE(SPDY_CONTROL_FRAME_HEADER_BLOCK); |
| 1257 break; | 1250 break; |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 // The size of this frame, including variable-length name-value block. | 1784 // The size of this frame, including variable-length name-value block. |
| 1792 const size_t size = GetSynStreamMinimumSize() | 1785 const size_t size = GetSynStreamMinimumSize() |
| 1793 + GetSerializedLength(syn_stream.name_value_block()); | 1786 + GetSerializedLength(syn_stream.name_value_block()); |
| 1794 | 1787 |
| 1795 SpdyFrameBuilder builder(size); | 1788 SpdyFrameBuilder builder(size); |
| 1796 if (spdy_version_ < 4) { | 1789 if (spdy_version_ < 4) { |
| 1797 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags); | 1790 builder.WriteControlFrameHeader(*this, SYN_STREAM, flags); |
| 1798 builder.WriteUInt32(syn_stream.stream_id()); | 1791 builder.WriteUInt32(syn_stream.stream_id()); |
| 1799 builder.WriteUInt32(syn_stream.associated_to_stream_id()); | 1792 builder.WriteUInt32(syn_stream.associated_to_stream_id()); |
| 1800 builder.WriteUInt8(priority << ((spdy_version_ < 3) ? 6 : 5)); | 1793 builder.WriteUInt8(priority << ((spdy_version_ < 3) ? 6 : 5)); |
| 1801 builder.WriteUInt8(syn_stream.slot()); | 1794 builder.WriteUInt8(0); // Unused byte where credential slot used to be. |
| 1802 } else { | 1795 } else { |
| 1803 builder.WriteFramePrefix(*this, | 1796 builder.WriteFramePrefix(*this, |
| 1804 HEADERS, | 1797 HEADERS, |
| 1805 flags, | 1798 flags, |
| 1806 syn_stream.stream_id()); | 1799 syn_stream.stream_id()); |
| 1807 builder.WriteUInt32(priority); | 1800 builder.WriteUInt32(priority); |
| 1808 } | 1801 } |
| 1809 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); | 1802 DCHECK_EQ(GetSynStreamMinimumSize(), builder.length()); |
| 1810 SerializeNameValueBlock(&builder, syn_stream); | 1803 SerializeNameValueBlock(&builder, syn_stream); |
| 1811 | 1804 |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 builder->Seek(compressed_size); | 2371 builder->Seek(compressed_size); |
| 2379 builder->RewriteLength(*this); | 2372 builder->RewriteLength(*this); |
| 2380 | 2373 |
| 2381 pre_compress_bytes.Add(uncompressed_len); | 2374 pre_compress_bytes.Add(uncompressed_len); |
| 2382 post_compress_bytes.Add(compressed_size); | 2375 post_compress_bytes.Add(compressed_size); |
| 2383 | 2376 |
| 2384 compressed_frames.Increment(); | 2377 compressed_frames.Increment(); |
| 2385 } | 2378 } |
| 2386 | 2379 |
| 2387 } // namespace net | 2380 } // namespace net |
| OLD | NEW |