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

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

Issue 288373004: Add handling + parsing for HTTP/2 ALTSVC frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Non-static initializer fixes. Created 6 years, 7 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/mock_spdy_framer_visitor.h ('k') | net/spdy/spdy_framer.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 #ifndef NET_SPDY_SPDY_FRAMER_H_ 5 #ifndef NET_SPDY_SPDY_FRAMER_H_
6 #define NET_SPDY_SPDY_FRAMER_H_ 6 #define NET_SPDY_SPDY_FRAMER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <memory>
10 #include <string> 11 #include <string>
11 #include <utility> 12 #include <utility>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/basictypes.h" 15 #include "base/basictypes.h"
15 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/string_piece.h"
17 #include "base/sys_byteorder.h" 19 #include "base/sys_byteorder.h"
18 #include "net/base/net_export.h" 20 #include "net/base/net_export.h"
19 #include "net/spdy/hpack_decoder.h" 21 #include "net/spdy/hpack_decoder.h"
20 #include "net/spdy/hpack_encoder.h" 22 #include "net/spdy/hpack_encoder.h"
21 #include "net/spdy/spdy_header_block.h" 23 #include "net/spdy/spdy_header_block.h"
22 #include "net/spdy/spdy_protocol.h" 24 #include "net/spdy/spdy_protocol.h"
23 25
24 // TODO(akalin): Remove support for CREDENTIAL frames. 26 // TODO(akalin): Remove support for CREDENTIAL frames.
25 27
26 typedef struct z_stream_s z_stream; // Forward declaration for zlib. 28 typedef struct z_stream_s z_stream; // Forward declaration for zlib.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 96
95 // The amount of the buffer that is filled with valid data. 97 // The amount of the buffer that is filled with valid data.
96 size_t setting_buf_len; 98 size_t setting_buf_len;
97 99
98 // The ID of the last setting that was processed in the current SETTINGS 100 // The ID of the last setting that was processed in the current SETTINGS
99 // frame. Used for detecting out-of-order or duplicate keys within a settings 101 // frame. Used for detecting out-of-order or duplicate keys within a settings
100 // frame. Set to -1 before first key/value pair is processed. 102 // frame. Set to -1 before first key/value pair is processed.
101 int last_setting_id; 103 int last_setting_id;
102 }; 104 };
103 105
106 // Scratch space necessary for processing ALTSVC frames.
107 struct NET_EXPORT_PRIVATE SpdyAltSvcScratch {
108 SpdyAltSvcScratch();
109 ~SpdyAltSvcScratch();
110
111 void Reset() {
112 max_age = 0;
113 port = 0;
114 pid_len = 0;
115 host_len = 0;
116 origin_len = 0;
117 pid_buf_len = 0;
118 host_buf_len = 0;
119 origin_buf_len = 0;
120 protocol_id.reset();
121 host.reset();
122 origin.reset();
123 }
124
125 uint32 max_age;
126 uint16 port;
127 uint8 pid_len;
128 uint8 host_len;
129 size_t origin_len;
130 size_t pid_buf_len;
131 size_t host_buf_len;
132 size_t origin_buf_len;
133 scoped_ptr<char[]> protocol_id;
134 scoped_ptr<char[]> host;
135 scoped_ptr<char[]> origin;
136 };
137
104 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer. 138 // SpdyFramerVisitorInterface is a set of callbacks for the SpdyFramer.
105 // Implement this interface to receive event callbacks as frames are 139 // Implement this interface to receive event callbacks as frames are
106 // decoded from the framer. 140 // decoded from the framer.
107 // 141 //
108 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY, 142 // Control frames that contain SPDY header blocks (SYN_STREAM, SYN_REPLY,
109 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the 143 // HEADER, and PUSH_PROMISE) are processed in fashion that allows the
110 // decompressed header block to be delivered in chunks to the visitor. 144 // decompressed header block to be delivered in chunks to the visitor.
111 // The following steps are followed: 145 // The following steps are followed:
112 // 1. OnSynStream, OnSynReply, OnHeaders, or OnPushPromise is called. 146 // 1. OnSynStream, OnSynReply, OnHeaders, or OnPushPromise is called.
113 // 2. Repeated: OnControlFrameHeaderData is called with chunks of the 147 // 2. Repeated: OnControlFrameHeaderData is called with chunks of the
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 // Note that header block data is not included. See 269 // Note that header block data is not included. See
236 // OnControlFrameHeaderData(). 270 // OnControlFrameHeaderData().
237 virtual void OnPushPromise(SpdyStreamId stream_id, 271 virtual void OnPushPromise(SpdyStreamId stream_id,
238 SpdyStreamId promised_stream_id, 272 SpdyStreamId promised_stream_id,
239 bool end) = 0; 273 bool end) = 0;
240 274
241 // Called when a CONTINUATION frame is received. 275 // Called when a CONTINUATION frame is received.
242 // Note that header block data is not included. See 276 // Note that header block data is not included. See
243 // OnControlFrameHeaderData(). 277 // OnControlFrameHeaderData().
244 virtual void OnContinuation(SpdyStreamId stream_id, bool end) = 0; 278 virtual void OnContinuation(SpdyStreamId stream_id, bool end) = 0;
279
280 // Called when an ALTSVC frame has been parsed.
281 virtual void OnAltSvc(SpdyStreamId stream_id,
282 uint32 max_age,
283 uint16 port,
284 base::StringPiece protocol_id,
285 base::StringPiece host,
286 base::StringPiece origin) {}
245 }; 287 };
246 288
247 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting 289 // Optionally, and in addition to SpdyFramerVisitorInterface, a class supporting
248 // SpdyFramerDebugVisitorInterface may be used in conjunction with SpdyFramer in 290 // SpdyFramerDebugVisitorInterface may be used in conjunction with SpdyFramer in
249 // order to extract debug/internal information about the SpdyFramer as it 291 // order to extract debug/internal information about the SpdyFramer as it
250 // operates. 292 // operates.
251 // 293 //
252 // Most SPDY implementations need not bother with this interface at all. 294 // Most SPDY implementations need not bother with this interface at all.
253 class NET_EXPORT_PRIVATE SpdyFramerDebugVisitorInterface { 295 class NET_EXPORT_PRIVATE SpdyFramerDebugVisitorInterface {
254 public: 296 public:
(...skipping 29 matching lines...) Expand all
284 SPDY_CONTROL_FRAME_PAYLOAD, 326 SPDY_CONTROL_FRAME_PAYLOAD,
285 SPDY_READ_PADDING_LENGTH, 327 SPDY_READ_PADDING_LENGTH,
286 SPDY_CONSUME_PADDING, 328 SPDY_CONSUME_PADDING,
287 SPDY_IGNORE_REMAINING_PAYLOAD, 329 SPDY_IGNORE_REMAINING_PAYLOAD,
288 SPDY_FORWARD_STREAM_FRAME, 330 SPDY_FORWARD_STREAM_FRAME,
289 SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK, 331 SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK,
290 SPDY_CONTROL_FRAME_HEADER_BLOCK, 332 SPDY_CONTROL_FRAME_HEADER_BLOCK,
291 SPDY_GOAWAY_FRAME_PAYLOAD, 333 SPDY_GOAWAY_FRAME_PAYLOAD,
292 SPDY_RST_STREAM_FRAME_PAYLOAD, 334 SPDY_RST_STREAM_FRAME_PAYLOAD,
293 SPDY_SETTINGS_FRAME_PAYLOAD, 335 SPDY_SETTINGS_FRAME_PAYLOAD,
336 SPDY_ALTSVC_FRAME_PAYLOAD,
294 }; 337 };
295 338
296 // SPDY error codes. 339 // SPDY error codes.
297 enum SpdyError { 340 enum SpdyError {
298 SPDY_NO_ERROR, 341 SPDY_NO_ERROR,
299 SPDY_INVALID_CONTROL_FRAME, // Control frame is mal-formatted. 342 SPDY_INVALID_CONTROL_FRAME, // Control frame is mal-formatted.
300 SPDY_CONTROL_PAYLOAD_TOO_LARGE, // Control frame payload was too large. 343 SPDY_CONTROL_PAYLOAD_TOO_LARGE, // Control frame payload was too large.
301 SPDY_ZLIB_INIT_FAILURE, // The Zlib library could not initialize. 344 SPDY_ZLIB_INIT_FAILURE, // The Zlib library could not initialize.
302 SPDY_UNSUPPORTED_VERSION, // Control frame has unsupported version. 345 SPDY_UNSUPPORTED_VERSION, // Control frame has unsupported version.
303 SPDY_DECOMPRESS_FAILURE, // There was an error decompressing. 346 SPDY_DECOMPRESS_FAILURE, // There was an error decompressing.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 const SpdyPushPromiseIR& push_promise); 467 const SpdyPushPromiseIR& push_promise);
425 468
426 // Serializes a CONTINUATION frame. The CONTINUATION frame is used 469 // Serializes a CONTINUATION frame. The CONTINUATION frame is used
427 // to continue a sequence of header block fragments. 470 // to continue a sequence of header block fragments.
428 // TODO(jgraettinger): This implementation is incorrect. The continuation 471 // TODO(jgraettinger): This implementation is incorrect. The continuation
429 // frame continues a previously-begun HPACK encoding; it doesn't begin a 472 // frame continues a previously-begun HPACK encoding; it doesn't begin a
430 // new one. Figure out whether it makes sense to keep SerializeContinuation(). 473 // new one. Figure out whether it makes sense to keep SerializeContinuation().
431 SpdySerializedFrame* SerializeContinuation( 474 SpdySerializedFrame* SerializeContinuation(
432 const SpdyContinuationIR& continuation); 475 const SpdyContinuationIR& continuation);
433 476
477 // Serializes an ALTSVC frame. The ALTSVC frame advertises the
478 // availability of an alternative service to the client.
479 SpdySerializedFrame* SerializeAltSvc(const SpdyAltSvcIR& altsvc);
480
434 // Serialize a frame of unknown type. 481 // Serialize a frame of unknown type.
435 SpdySerializedFrame* SerializeFrame(const SpdyFrameIR& frame); 482 SpdySerializedFrame* SerializeFrame(const SpdyFrameIR& frame);
436 483
437 // NOTES about frame compression. 484 // NOTES about frame compression.
438 // We want spdy to compress headers across the entire session. As long as 485 // We want spdy to compress headers across the entire session. As long as
439 // the session is over TCP, frames are sent serially. The client & server 486 // the session is over TCP, frames are sent serially. The client & server
440 // can each compress frames in the same order and then compress them in that 487 // can each compress frames in the same order and then compress them in that
441 // order, and the remote can do the reverse. However, we ultimately want 488 // order, and the remote can do the reverse. However, we ultimately want
442 // the creation of frames to be less sensitive to order so that they can be 489 // the creation of frames to be less sensitive to order so that they can be
443 // placed over a UDP based protocol and yet still benefit from some 490 // placed over a UDP based protocol and yet still benefit from some
(...skipping 25 matching lines...) Expand all
469 size_t GetSynReplyMinimumSize() const; 516 size_t GetSynReplyMinimumSize() const;
470 size_t GetRstStreamMinimumSize() const; 517 size_t GetRstStreamMinimumSize() const;
471 size_t GetSettingsMinimumSize() const; 518 size_t GetSettingsMinimumSize() const;
472 size_t GetPingSize() const; 519 size_t GetPingSize() const;
473 size_t GetGoAwayMinimumSize() const; 520 size_t GetGoAwayMinimumSize() const;
474 size_t GetHeadersMinimumSize() const; 521 size_t GetHeadersMinimumSize() const;
475 size_t GetWindowUpdateSize() const; 522 size_t GetWindowUpdateSize() const;
476 size_t GetBlockedSize() const; 523 size_t GetBlockedSize() const;
477 size_t GetPushPromiseMinimumSize() const; 524 size_t GetPushPromiseMinimumSize() const;
478 size_t GetContinuationMinimumSize() const; 525 size_t GetContinuationMinimumSize() const;
526 size_t GetAltSvcMinimumSize() const;
479 527
480 // Returns the minimum size a frame can be (data or control). 528 // Returns the minimum size a frame can be (data or control).
481 size_t GetFrameMinimumSize() const; 529 size_t GetFrameMinimumSize() const;
482 530
483 // Returns the maximum size a frame can be (data or control). 531 // Returns the maximum size a frame can be (data or control).
484 size_t GetFrameMaximumSize() const; 532 size_t GetFrameMaximumSize() const;
485 533
486 // Returns the maximum size that a control frame can be. 534 // Returns the maximum size that a control frame can be.
487 size_t GetControlFrameMaximumSize() const; 535 size_t GetControlFrameMaximumSize() const;
488 536
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 // whether data is treated as HPACK- vs SPDY3-encoded. 611 // whether data is treated as HPACK- vs SPDY3-encoded.
564 size_t ProcessControlFrameHeaderBlock(const char* data, 612 size_t ProcessControlFrameHeaderBlock(const char* data,
565 size_t len, 613 size_t len,
566 bool is_hpack_header_block); 614 bool is_hpack_header_block);
567 size_t ProcessFramePaddingLength(const char* data, size_t len); 615 size_t ProcessFramePaddingLength(const char* data, size_t len);
568 size_t ProcessFramePadding(const char* data, size_t len); 616 size_t ProcessFramePadding(const char* data, size_t len);
569 size_t ProcessDataFramePayload(const char* data, size_t len); 617 size_t ProcessDataFramePayload(const char* data, size_t len);
570 size_t ProcessGoAwayFramePayload(const char* data, size_t len); 618 size_t ProcessGoAwayFramePayload(const char* data, size_t len);
571 size_t ProcessRstStreamFramePayload(const char* data, size_t len); 619 size_t ProcessRstStreamFramePayload(const char* data, size_t len);
572 size_t ProcessSettingsFramePayload(const char* data, size_t len); 620 size_t ProcessSettingsFramePayload(const char* data, size_t len);
621 size_t ProcessAltSvcFramePayload(const char* data, size_t len);
573 size_t ProcessIgnoredControlFramePayload(/*const char* data,*/ size_t len); 622 size_t ProcessIgnoredControlFramePayload(/*const char* data,*/ size_t len);
574 623
575 // TODO(jgraettinger): To be removed with migration to 624 // TODO(jgraettinger): To be removed with migration to
576 // SpdyHeadersHandlerInterface. 625 // SpdyHeadersHandlerInterface.
577 // Serializes the last-processed header block of |hpack_decoder_| as 626 // Serializes the last-processed header block of |hpack_decoder_| as
578 // a SPDY3 format block, and delivers it to the visitor via reentrant 627 // a SPDY3 format block, and delivers it to the visitor via reentrant
579 // call to ProcessControlFrameHeaderBlock(). 628 // call to ProcessControlFrameHeaderBlock().
580 void DeliverHpackBlockAsSpdy3Block(); 629 void DeliverHpackBlockAsSpdy3Block();
581 630
582 // Helpers for above internal breakouts from ProcessInput. 631 // Helpers for above internal breakouts from ProcessInput.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 uint32 current_frame_length_; 742 uint32 current_frame_length_;
694 743
695 // The stream ID field of the frame currently being read, if applicable. 744 // The stream ID field of the frame currently being read, if applicable.
696 SpdyStreamId current_frame_stream_id_; 745 SpdyStreamId current_frame_stream_id_;
697 746
698 // Scratch space for handling SETTINGS frames. 747 // Scratch space for handling SETTINGS frames.
699 // TODO(hkhalil): Unify memory for this scratch space with 748 // TODO(hkhalil): Unify memory for this scratch space with
700 // current_frame_buffer_. 749 // current_frame_buffer_.
701 SpdySettingsScratch settings_scratch_; 750 SpdySettingsScratch settings_scratch_;
702 751
752 SpdyAltSvcScratch altsvc_scratch_;
753
703 bool enable_compression_; // Controls all compression 754 bool enable_compression_; // Controls all compression
704 // SPDY header compressors. 755 // SPDY header compressors.
705 scoped_ptr<z_stream> header_compressor_; 756 scoped_ptr<z_stream> header_compressor_;
706 scoped_ptr<z_stream> header_decompressor_; 757 scoped_ptr<z_stream> header_decompressor_;
707 758
708 scoped_ptr<HpackEncoder> hpack_encoder_; 759 scoped_ptr<HpackEncoder> hpack_encoder_;
709 scoped_ptr<HpackDecoder> hpack_decoder_; 760 scoped_ptr<HpackDecoder> hpack_decoder_;
710 761
711 SpdyFramerVisitorInterface* visitor_; 762 SpdyFramerVisitorInterface* visitor_;
712 SpdyFramerDebugVisitorInterface* debug_visitor_; 763 SpdyFramerDebugVisitorInterface* debug_visitor_;
(...skipping 27 matching lines...) Expand all
740 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM 791 // If a HEADERS frame is followed by a CONTINUATION frame, the FIN/END_STREAM
741 // flag is still carried in the HEADERS frame. If it's set, flip this so that 792 // flag is still carried in the HEADERS frame. If it's set, flip this so that
742 // we know to terminate the stream when the entire header block has been 793 // we know to terminate the stream when the entire header block has been
743 // processed. 794 // processed.
744 bool end_stream_when_done_; 795 bool end_stream_when_done_;
745 }; 796 };
746 797
747 } // namespace net 798 } // namespace net
748 799
749 #endif // NET_SPDY_SPDY_FRAMER_H_ 800 #endif // NET_SPDY_SPDY_FRAMER_H_
OLDNEW
« no previous file with comments | « net/spdy/mock_spdy_framer_visitor.h ('k') | net/spdy/spdy_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698