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

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

Issue 2544813002: Remove enum SpdyMajorVersion. (Closed)
Patch Set: Merge comment changes from 140661724. Created 4 years 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
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_protocol.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 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 5 // This file contains some protocol structures for use with SPDY 3 and HTTP 2
6 // The SPDY 3 spec can be found at: 6 // The SPDY 3 spec can be found at:
7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3
8 8
9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_
10 #define NET_SPDY_SPDY_PROTOCOL_H_ 10 #define NET_SPDY_SPDY_PROTOCOL_H_
(...skipping 13 matching lines...) Expand all
24 #include "base/strings/string_piece.h" 24 #include "base/strings/string_piece.h"
25 #include "base/sys_byteorder.h" 25 #include "base/sys_byteorder.h"
26 #include "net/base/net_export.h" 26 #include "net/base/net_export.h"
27 #include "net/spdy/spdy_alt_svc_wire_format.h" 27 #include "net/spdy/spdy_alt_svc_wire_format.h"
28 #include "net/spdy/spdy_bitmasks.h" 28 #include "net/spdy/spdy_bitmasks.h"
29 #include "net/spdy/spdy_bug_tracker.h" 29 #include "net/spdy/spdy_bug_tracker.h"
30 #include "net/spdy/spdy_header_block.h" 30 #include "net/spdy/spdy_header_block.h"
31 31
32 namespace net { 32 namespace net {
33 33
34 // The major versions of SPDY. Major version differences indicate 34 // A stream id is a 31 bit entity.
35 // framer-layer incompatibility, as opposed to minor version numbers
36 // which indicate application-layer incompatibility. It is NOT guaranteed
37 // that the enum value SPDYn maps to the integer n.
38 enum SpdyMajorVersion {
39 HTTP2 = 2,
40 };
41
42 // A SPDY stream id is a 31 bit entity.
43 typedef uint32_t SpdyStreamId; 35 typedef uint32_t SpdyStreamId;
44 36
45 // Specifies the stream ID used to denote the current session (for 37 // Specifies the stream ID used to denote the current session (for
46 // flow control). 38 // flow control).
47 const SpdyStreamId kSessionFlowControlStreamId = 0; 39 const SpdyStreamId kSessionFlowControlStreamId = 0;
48 40
49 // The maximum possible frame payload size allowed by the spec. 41 // The maximum possible frame payload size allowed by the spec.
50 const uint32_t kSpdyMaxFrameSizeLimit = (1 << 24) - 1; 42 const uint32_t kSpdyMaxFrameSizeLimit = (1 << 24) - 1;
51 43
52 // The initial value for the maximum frame payload size as per the spec. This is 44 // The initial value for the maximum frame payload size as per the spec. This is
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 typedef uint64_t SpdyPingId; 244 typedef uint64_t SpdyPingId;
253 245
254 typedef std::string SpdyProtocolId; 246 typedef std::string SpdyProtocolId;
255 247
256 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any, 248 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any,
257 // but is good to do anyway. 249 // but is good to do anyway.
258 class NET_EXPORT_PRIVATE SpdyConstants { 250 class NET_EXPORT_PRIVATE SpdyConstants {
259 public: 251 public:
260 // Returns true if a given on-the-wire enumeration of a frame type is valid 252 // Returns true if a given on-the-wire enumeration of a frame type is valid
261 // for a given protocol version, false otherwise. 253 // for a given protocol version, false otherwise.
262 static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field); 254 static bool IsValidFrameType(int frame_type_field);
263 255
264 // Parses a frame type from an on-the-wire enumeration of a given protocol 256 // Parses a frame type from an on-the-wire enumeration.
265 // version.
266 // Behavior is undefined for invalid frame type fields; consumers should first 257 // Behavior is undefined for invalid frame type fields; consumers should first
267 // use IsValidFrameType() to verify validity of frame type fields. 258 // use IsValidFrameType() to verify validity of frame type fields.
268 static SpdyFrameType ParseFrameType(SpdyMajorVersion version, 259 static SpdyFrameType ParseFrameType(int frame_type_field);
269 int frame_type_field);
270 260
271 // Serializes a given frame type to the on-the-wire enumeration value for the 261 // Serializes a given frame type to the on-the-wire enumeration value.
272 // given protocol version. 262 // Returns -1 on failure (I.E. Invalid frame type).
273 // Returns -1 on failure (I.E. Invalid frame type for the given version). 263 static int SerializeFrameType(SpdyFrameType frame_type);
274 static int SerializeFrameType(SpdyMajorVersion version,
275 SpdyFrameType frame_type);
276
277 // Returns the frame type for non-control (i.e. data) frames
278 // in the given SPDY version.
279 static int DataFrameType(SpdyMajorVersion version);
280 264
281 // (HTTP/2) All standard frame types except WINDOW_UPDATE are 265 // (HTTP/2) All standard frame types except WINDOW_UPDATE are
282 // (stream-specific xor connection-level). Returns false iff we know 266 // (stream-specific xor connection-level). Returns false iff we know
283 // the given frame type does not align with the given streamID. 267 // the given frame type does not align with the given streamID.
284 static bool IsValidHTTP2FrameStreamId(SpdyStreamId current_frame_stream_id, 268 static bool IsValidHTTP2FrameStreamId(SpdyStreamId current_frame_stream_id,
285 SpdyFrameType frame_type_field); 269 SpdyFrameType frame_type_field);
286 270
287 // Returns true if a given on-the-wire enumeration of a setting id is valid 271 // Returns true if a given on-the-wire enumeration of a setting id is valid
288 // for a given protocol version, false otherwise. 272 // false otherwise.
289 static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field); 273 static bool IsValidSettingId(int setting_id_field);
290 274
291 // Parses a setting id from an on-the-wire enumeration of a given protocol 275 // Parses a setting id from an on-the-wire enumeration
292 // version.
293 // Behavior is undefined for invalid setting id fields; consumers should first 276 // Behavior is undefined for invalid setting id fields; consumers should first
294 // use IsValidSettingId() to verify validity of setting id fields. 277 // use IsValidSettingId() to verify validity of setting id fields.
295 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version, 278 static SpdySettingsIds ParseSettingId(int setting_id_field);
296 int setting_id_field);
297 279
298 // Serializes a given setting id to the on-the-wire enumeration value for the 280 // Serializes a given setting id to the on-the-wire enumeration value.
299 // given protocol version. 281 // Returns -1 on failure (I.E. Invalid setting id).
300 // Returns -1 on failure (I.E. Invalid setting id for the given version). 282 static int SerializeSettingId(SpdySettingsIds id);
301 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id);
302 283
303 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code 284 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code
304 // is valid for a given protocol version, false otherwise. 285 // is valid, false otherwise.
305 static bool IsValidRstStreamStatus(SpdyMajorVersion version, 286 static bool IsValidRstStreamStatus(int rst_stream_status_field);
306 int rst_stream_status_field);
307 287
308 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given 288 // Parses a RST_STREAM status code from an on-the-wire enumeration.
309 // protocol version.
310 // Behavior is undefined for invalid RST_STREAM status code fields; consumers 289 // Behavior is undefined for invalid RST_STREAM status code fields; consumers
311 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM 290 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM
312 // status code fields.. 291 // status code fields..
313 static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version, 292 static SpdyRstStreamStatus ParseRstStreamStatus(int rst_stream_status_field);
314 int rst_stream_status_field);
315 293
316 // Serializes a given RST_STREAM status code to the on-the-wire enumeration 294 // Serializes a given RST_STREAM status code to the on-the-wire enumeration
317 // value for the given protocol version. 295 // value.
318 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given 296 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given
319 // version). 297 // version).
320 static int SerializeRstStreamStatus(SpdyMajorVersion version, 298 static int SerializeRstStreamStatus(SpdyRstStreamStatus rst_stream_status);
321 SpdyRstStreamStatus rst_stream_status);
322 299
323 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is 300 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is
324 // valid for the given protocol version, false otherwise. 301 // valid, false otherwise.
325 static bool IsValidGoAwayStatus(SpdyMajorVersion version, 302 static bool IsValidGoAwayStatus(int goaway_status_field);
326 int goaway_status_field);
327 303
328 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol 304 // Parses a GOAWAY status from an on-the-wire enumeration.
329 // version.
330 // Behavior is undefined for invalid GOAWAY status fields; consumers should 305 // Behavior is undefined for invalid GOAWAY status fields; consumers should
331 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields. 306 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields.
332 static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version, 307 static SpdyGoAwayStatus ParseGoAwayStatus(int goaway_status_field);
333 int goaway_status_field);
334 308
335 // Serializes a given GOAWAY status to the on-the-wire enumeration value for 309 // Serializes a given GOAWAY status to the on-the-wire enumeration value.
336 // the given protocol version.
337 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version). 310 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version).
338 static int SerializeGoAwayStatus(SpdyMajorVersion version, 311 static int SerializeGoAwayStatus(SpdyGoAwayStatus status);
339 SpdyGoAwayStatus status);
340 312
341 // Size, in bytes, of the data frame header. Future versions of SPDY 313 // Frame type for non-control (i.e. data) frames.
342 // will likely vary this, so we allow for the flexibility of a function call 314 static const int kDataFrameType;
343 // for this value as opposed to a constant. 315 // Size, in bytes, of the data frame header.
344 static size_t GetDataFrameMinimumSize(SpdyMajorVersion version); 316 static const size_t kDataFrameMinimumSize;
345
346 // Number of octets in the frame header. 317 // Number of octets in the frame header.
347 static size_t GetFrameHeaderSize(SpdyMajorVersion version); 318 static const size_t kFrameHeaderSize;
348
349 // Maximum possible configurable size of a frame in octets. 319 // Maximum possible configurable size of a frame in octets.
350 static size_t GetMaxFrameSizeLimit(SpdyMajorVersion version); 320 static const size_t kMaxFrameSizeLimit;
351 321 // Size of a header block size field. Valid only for SPDY 3.
352 // Returns the size of a header block size field. Valid only for SPDY 3. 322 static const size_t kSizeOfSizeField;
353 static size_t GetSizeOfSizeField(); 323 // Per-header overhead for block size accounting in bytes.
354 324 static const size_t kPerHeaderOverhead;
355 // Returns the per-header overhead for block size accounting in bytes.
356 static size_t GetPerHeaderOverhead(SpdyMajorVersion version);
357
358 // Returns the size (in bytes) of a wire setting ID and value.
359 static size_t GetSettingSize(SpdyMajorVersion version);
360
361 // Initial window size for a stream in bytes. 325 // Initial window size for a stream in bytes.
362 static int32_t GetInitialStreamWindowSize(SpdyMajorVersion version); 326 static const int32_t kInitialStreamWindowSize;
363
364 // Initial window size for a session in bytes. 327 // Initial window size for a session in bytes.
365 static int32_t GetInitialSessionWindowSize(SpdyMajorVersion version); 328 static const int32_t kInitialSessionWindowSize;
366 329 // The NPN string for HTTP2, "h2".
367 static std::string GetVersionString(SpdyMajorVersion version); 330 static const char kHttp2Npn[];
368 }; 331 };
369 332
370 // Variant type (i.e. tagged union) that is either a SPDY 3.x priority value, 333 // Variant type (i.e. tagged union) that is either a SPDY 3.x priority value,
371 // or else an HTTP/2 stream dependency tuple {parent stream ID, weight, 334 // or else an HTTP/2 stream dependency tuple {parent stream ID, weight,
372 // exclusive bit}. Templated to allow for use by QUIC code; SPDY and HTTP/2 335 // exclusive bit}. Templated to allow for use by QUIC code; SPDY and HTTP/2
373 // code should use the concrete type instantiation SpdyStreamPrecedence. 336 // code should use the concrete type instantiation SpdyStreamPrecedence.
374 template <typename StreamIdType> 337 template <typename StreamIdType>
375 class StreamPrecedence { 338 class StreamPrecedence {
376 public: 339 public:
377 // Constructs instance that is a SPDY 3.x priority. Clamps priority value to 340 // Constructs instance that is a SPDY 3.x priority. Clamps priority value to
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 union { 421 union {
459 SpdyPriority spdy3_priority_; 422 SpdyPriority spdy3_priority_;
460 Http2StreamDependency http2_stream_dependency_; 423 Http2StreamDependency http2_stream_dependency_;
461 }; 424 };
462 }; 425 };
463 426
464 typedef StreamPrecedence<SpdyStreamId> SpdyStreamPrecedence; 427 typedef StreamPrecedence<SpdyStreamId> SpdyStreamPrecedence;
465 428
466 class SpdyFrameVisitor; 429 class SpdyFrameVisitor;
467 430
468 // Intermediate representation for SPDY frames. 431 // Intermediate representation for HTTP2 frames.
469 class NET_EXPORT_PRIVATE SpdyFrameIR { 432 class NET_EXPORT_PRIVATE SpdyFrameIR {
470 public: 433 public:
471 virtual ~SpdyFrameIR() {} 434 virtual ~SpdyFrameIR() {}
472 435
473 virtual void Visit(SpdyFrameVisitor* visitor) const = 0; 436 virtual void Visit(SpdyFrameVisitor* visitor) const = 0;
474 437
475 protected: 438 protected:
476 SpdyFrameIR() {} 439 SpdyFrameIR() {}
477 440
478 private: 441 private:
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 bool is_ack_; 641 bool is_ack_;
679 642
680 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR); 643 DISALLOW_COPY_AND_ASSIGN(SpdySettingsIR);
681 }; 644 };
682 645
683 class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR { 646 class NET_EXPORT_PRIVATE SpdyPingIR : public SpdyFrameIR {
684 public: 647 public:
685 explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {} 648 explicit SpdyPingIR(SpdyPingId id) : id_(id), is_ack_(false) {}
686 SpdyPingId id() const { return id_; } 649 SpdyPingId id() const { return id_; }
687 650
688 // ACK logic is valid only for SPDY versions 4 and above.
689 bool is_ack() const { return is_ack_; } 651 bool is_ack() const { return is_ack_; }
690 void set_is_ack(bool is_ack) { is_ack_ = is_ack; } 652 void set_is_ack(bool is_ack) { is_ack_ = is_ack; }
691 653
692 void Visit(SpdyFrameVisitor* visitor) const override; 654 void Visit(SpdyFrameVisitor* visitor) const override;
693 655
694 private: 656 private:
695 SpdyPingId id_; 657 SpdyPingId id_;
696 bool is_ack_; 658 bool is_ack_;
697 659
698 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR); 660 DISALLOW_COPY_AND_ASSIGN(SpdyPingIR);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 SpdyFrameVisitor() {} 986 SpdyFrameVisitor() {}
1025 virtual ~SpdyFrameVisitor() {} 987 virtual ~SpdyFrameVisitor() {}
1026 988
1027 private: 989 private:
1028 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); 990 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor);
1029 }; 991 };
1030 992
1031 } // namespace net 993 } // namespace net
1032 994
1033 #endif // NET_SPDY_SPDY_PROTOCOL_H_ 995 #endif // NET_SPDY_SPDY_PROTOCOL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_protocol.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698