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/buffered_spdy_framer.h" | 5 #include "net/spdy/buffered_spdy_framer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
| 11 namespace { |
| 12 |
| 13 // GOAWAY frame debug data is only buffered up to this many bytes. |
| 14 size_t kGoAwayDebugDataMaxSize = 1024; |
| 15 |
| 16 } // namespace |
| 17 |
11 SpdyMajorVersion NextProtoToSpdyMajorVersion(NextProto next_proto) { | 18 SpdyMajorVersion NextProtoToSpdyMajorVersion(NextProto next_proto) { |
12 switch (next_proto) { | 19 switch (next_proto) { |
13 case kProtoDeprecatedSPDY2: | 20 case kProtoDeprecatedSPDY2: |
14 return SPDY2; | 21 return SPDY2; |
15 case kProtoSPDY3: | 22 case kProtoSPDY3: |
16 case kProtoSPDY31: | 23 case kProtoSPDY31: |
17 return SPDY3; | 24 return SPDY3; |
18 case kProtoHTTP2: | 25 case kProtoHTTP2: |
19 return HTTP2; | 26 return HTTP2; |
20 case kProtoUnknown: | 27 case kProtoUnknown: |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 void BufferedSpdyFramer::OnPing(SpdyPingId unique_id, bool is_ack) { | 226 void BufferedSpdyFramer::OnPing(SpdyPingId unique_id, bool is_ack) { |
220 visitor_->OnPing(unique_id, is_ack); | 227 visitor_->OnPing(unique_id, is_ack); |
221 } | 228 } |
222 | 229 |
223 void BufferedSpdyFramer::OnRstStream(SpdyStreamId stream_id, | 230 void BufferedSpdyFramer::OnRstStream(SpdyStreamId stream_id, |
224 SpdyRstStreamStatus status) { | 231 SpdyRstStreamStatus status) { |
225 visitor_->OnRstStream(stream_id, status); | 232 visitor_->OnRstStream(stream_id, status); |
226 } | 233 } |
227 void BufferedSpdyFramer::OnGoAway(SpdyStreamId last_accepted_stream_id, | 234 void BufferedSpdyFramer::OnGoAway(SpdyStreamId last_accepted_stream_id, |
228 SpdyGoAwayStatus status) { | 235 SpdyGoAwayStatus status) { |
229 visitor_->OnGoAway(last_accepted_stream_id, status); | 236 DCHECK(!goaway_fields_); |
| 237 goaway_fields_.reset(new GoAwayFields()); |
| 238 goaway_fields_->last_accepted_stream_id = last_accepted_stream_id; |
| 239 goaway_fields_->status = status; |
| 240 } |
| 241 |
| 242 bool BufferedSpdyFramer::OnGoAwayFrameData(const char* goaway_data, |
| 243 size_t len) { |
| 244 if (len > 0) { |
| 245 if (goaway_fields_->debug_data.size() < kGoAwayDebugDataMaxSize) { |
| 246 goaway_fields_->debug_data.append( |
| 247 goaway_data, std::min(len, kGoAwayDebugDataMaxSize - |
| 248 goaway_fields_->debug_data.size())); |
| 249 } |
| 250 return true; |
| 251 } |
| 252 visitor_->OnGoAway(goaway_fields_->last_accepted_stream_id, |
| 253 goaway_fields_->status, goaway_fields_->debug_data); |
| 254 goaway_fields_.reset(); |
| 255 return true; |
230 } | 256 } |
231 | 257 |
232 void BufferedSpdyFramer::OnWindowUpdate(SpdyStreamId stream_id, | 258 void BufferedSpdyFramer::OnWindowUpdate(SpdyStreamId stream_id, |
233 int delta_window_size) { | 259 int delta_window_size) { |
234 visitor_->OnWindowUpdate(stream_id, delta_window_size); | 260 visitor_->OnWindowUpdate(stream_id, delta_window_size); |
235 } | 261 } |
236 | 262 |
237 void BufferedSpdyFramer::OnPushPromise(SpdyStreamId stream_id, | 263 void BufferedSpdyFramer::OnPushPromise(SpdyStreamId stream_id, |
238 SpdyStreamId promised_stream_id, | 264 SpdyStreamId promised_stream_id, |
239 bool end) { | 265 bool end) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 SpdyFrame* BufferedSpdyFramer::CreatePingFrame(SpdyPingId unique_id, | 373 SpdyFrame* BufferedSpdyFramer::CreatePingFrame(SpdyPingId unique_id, |
348 bool is_ack) const { | 374 bool is_ack) const { |
349 SpdyPingIR ping_ir(unique_id); | 375 SpdyPingIR ping_ir(unique_id); |
350 ping_ir.set_is_ack(is_ack); | 376 ping_ir.set_is_ack(is_ack); |
351 return spdy_framer_.SerializePing(ping_ir); | 377 return spdy_framer_.SerializePing(ping_ir); |
352 } | 378 } |
353 | 379 |
354 // TODO(jgraettinger): Eliminate uses of this method (prefer SpdyGoAwayIR). | 380 // TODO(jgraettinger): Eliminate uses of this method (prefer SpdyGoAwayIR). |
355 SpdyFrame* BufferedSpdyFramer::CreateGoAway( | 381 SpdyFrame* BufferedSpdyFramer::CreateGoAway( |
356 SpdyStreamId last_accepted_stream_id, | 382 SpdyStreamId last_accepted_stream_id, |
357 SpdyGoAwayStatus status) const { | 383 SpdyGoAwayStatus status, |
358 SpdyGoAwayIR go_ir(last_accepted_stream_id, status, ""); | 384 base::StringPiece debug_data) const { |
| 385 SpdyGoAwayIR go_ir(last_accepted_stream_id, status, debug_data); |
359 return spdy_framer_.SerializeGoAway(go_ir); | 386 return spdy_framer_.SerializeGoAway(go_ir); |
360 } | 387 } |
361 | 388 |
362 // TODO(jgraettinger): Eliminate uses of this method (prefer SpdyHeadersIR). | 389 // TODO(jgraettinger): Eliminate uses of this method (prefer SpdyHeadersIR). |
363 SpdyFrame* BufferedSpdyFramer::CreateHeaders( | 390 SpdyFrame* BufferedSpdyFramer::CreateHeaders( |
364 SpdyStreamId stream_id, | 391 SpdyStreamId stream_id, |
365 SpdyControlFlags flags, | 392 SpdyControlFlags flags, |
366 SpdyPriority priority, | 393 SpdyPriority priority, |
367 const SpdyHeaderBlock* headers) { | 394 const SpdyHeaderBlock* headers) { |
368 SpdyHeadersIR headers_ir(stream_id); | 395 SpdyHeadersIR headers_ir(stream_id); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 438 |
412 void BufferedSpdyFramer::InitHeaderStreaming(SpdyStreamId stream_id) { | 439 void BufferedSpdyFramer::InitHeaderStreaming(SpdyStreamId stream_id) { |
413 memset(header_buffer_, 0, kHeaderBufferSize); | 440 memset(header_buffer_, 0, kHeaderBufferSize); |
414 header_buffer_used_ = 0; | 441 header_buffer_used_ = 0; |
415 header_buffer_valid_ = true; | 442 header_buffer_valid_ = true; |
416 header_stream_id_ = stream_id; | 443 header_stream_id_ = stream_id; |
417 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 444 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
418 } | 445 } |
419 | 446 |
420 } // namespace net | 447 } // namespace net |
OLD | NEW |