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 // This file contains some protocol structures for use with SPDY 2 and 3 | 5 // This file contains some protocol structures for use with SPDY 2 and 3 |
6 // The SPDY 2 spec can be found at: | 6 // The SPDY 2 spec can be found at: |
7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft2 | 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft2 |
8 // The SPDY 3 spec can be found at: | 8 // The SPDY 3 spec can be found at: |
9 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 | 9 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
22 #include "base/strings/string_piece.h" | 22 #include "base/strings/string_piece.h" |
23 #include "base/sys_byteorder.h" | 23 #include "base/sys_byteorder.h" |
24 #include "net/base/net_export.h" | 24 #include "net/base/net_export.h" |
25 #include "net/spdy/spdy_bitmasks.h" | 25 #include "net/spdy/spdy_bitmasks.h" |
26 | 26 |
27 namespace net { | 27 namespace net { |
28 | 28 |
29 // The major versions of SPDY. Major version differences indicate | 29 // The major versions of SPDY. Major version differences indicate |
30 // framer-layer incompatibility, as opposed to minor version numbers | 30 // framer-layer incompatibility, as opposed to minor version numbers |
31 // which indicate application-layer incompatibility. It is guaranteed | 31 // which indicate application-layer incompatibility. Do not rely on |
32 // that the enum value SPDYn maps to the integer n. | 32 // the mapping from enum value SPDYn to the integer n. |
33 enum SpdyMajorVersion { | 33 enum SpdyMajorVersion { |
34 SPDY2 = 2, | 34 SPDY2 = 2, |
35 SPDY_MIN_VERSION = SPDY2, | 35 SPDY_MIN_VERSION = SPDY2, |
36 SPDY3 = 3, | 36 SPDY3 = 3, |
37 SPDY4 = 4, | 37 SPDY4 = 4, |
38 SPDY_MAX_VERSION = SPDY4 | 38 SPDY5 = 5, |
| 39 SPDY_MAX_VERSION = SPDY5 |
39 }; | 40 }; |
40 | 41 |
41 // A SPDY stream id is a 31 bit entity. | 42 // A SPDY stream id is a 31 bit entity. |
42 typedef uint32 SpdyStreamId; | 43 typedef uint32 SpdyStreamId; |
43 | 44 |
44 // Specifies the stream ID used to denote the current session (for | 45 // Specifies the stream ID used to denote the current session (for |
45 // flow control). | 46 // flow control). |
46 const SpdyStreamId kSessionFlowControlStreamId = 0; | 47 const SpdyStreamId kSessionFlowControlStreamId = 0; |
47 | 48 |
48 // Initial window size for a Spdy stream in bytes. | 49 // Initial window size for a Spdy stream in bytes. |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 SETTINGS_HEADER_TABLE_SIZE = 0x8, | 354 SETTINGS_HEADER_TABLE_SIZE = 0x8, |
354 // Whether or not server push (PUSH_PROMISE) is enabled. | 355 // Whether or not server push (PUSH_PROMISE) is enabled. |
355 SETTINGS_ENABLE_PUSH = 0x9, | 356 SETTINGS_ENABLE_PUSH = 0x9, |
356 }; | 357 }; |
357 | 358 |
358 // Status codes for RST_STREAM frames. | 359 // Status codes for RST_STREAM frames. |
359 enum SpdyRstStreamStatus { | 360 enum SpdyRstStreamStatus { |
360 RST_STREAM_INVALID = 0, | 361 RST_STREAM_INVALID = 0, |
361 RST_STREAM_PROTOCOL_ERROR = 1, | 362 RST_STREAM_PROTOCOL_ERROR = 1, |
362 RST_STREAM_INVALID_STREAM = 2, | 363 RST_STREAM_INVALID_STREAM = 2, |
| 364 RST_STREAM_STREAM_CLOSED = 2, // Equivalent to INVALID_STREAM |
363 RST_STREAM_REFUSED_STREAM = 3, | 365 RST_STREAM_REFUSED_STREAM = 3, |
364 RST_STREAM_UNSUPPORTED_VERSION = 4, | 366 RST_STREAM_UNSUPPORTED_VERSION = 4, |
365 RST_STREAM_CANCEL = 5, | 367 RST_STREAM_CANCEL = 5, |
366 RST_STREAM_INTERNAL_ERROR = 6, | 368 RST_STREAM_INTERNAL_ERROR = 6, |
367 RST_STREAM_FLOW_CONTROL_ERROR = 7, | 369 RST_STREAM_FLOW_CONTROL_ERROR = 7, |
368 RST_STREAM_STREAM_IN_USE = 8, | 370 RST_STREAM_STREAM_IN_USE = 8, |
369 RST_STREAM_STREAM_ALREADY_CLOSED = 9, | 371 RST_STREAM_STREAM_ALREADY_CLOSED = 9, |
370 RST_STREAM_INVALID_CREDENTIALS = 10, | 372 RST_STREAM_INVALID_CREDENTIALS = 10, |
| 373 // FRAME_TOO_LARGE (defined by SPDY versions 3.1 and below), and |
| 374 // FRAME_SIZE_ERROR (defined by HTTP/2) are mapped to the same internal |
| 375 // reset status. |
371 RST_STREAM_FRAME_TOO_LARGE = 11, | 376 RST_STREAM_FRAME_TOO_LARGE = 11, |
372 RST_STREAM_NUM_STATUS_CODES = 12 | 377 RST_STREAM_FRAME_SIZE_ERROR = 11, |
| 378 RST_STREAM_SETTINGS_TIMEOUT = 12, |
| 379 RST_STREAM_CONNECT_ERROR = 13, |
| 380 RST_STREAM_ENHANCE_YOUR_CALM = 14, |
| 381 RST_STREAM_NUM_STATUS_CODES = 15 |
373 }; | 382 }; |
374 | 383 |
375 // Status codes for GOAWAY frames. | 384 // Status codes for GOAWAY frames. |
376 enum SpdyGoAwayStatus { | 385 enum SpdyGoAwayStatus { |
377 GOAWAY_INVALID = -1, | |
378 GOAWAY_OK = 0, | 386 GOAWAY_OK = 0, |
| 387 GOAWAY_NO_ERROR = GOAWAY_OK, |
379 GOAWAY_PROTOCOL_ERROR = 1, | 388 GOAWAY_PROTOCOL_ERROR = 1, |
380 GOAWAY_INTERNAL_ERROR = 2, | 389 GOAWAY_INTERNAL_ERROR = 2, |
381 GOAWAY_NUM_STATUS_CODES = 3 // Must be last. | 390 GOAWAY_FLOW_CONTROL_ERROR = 3, |
| 391 GOAWAY_SETTINGS_TIMEOUT = 4, |
| 392 GOAWAY_STREAM_CLOSED = 5, |
| 393 GOAWAY_FRAME_SIZE_ERROR = 6, |
| 394 GOAWAY_REFUSED_STREAM = 7, |
| 395 GOAWAY_CANCEL = 8, |
| 396 GOAWAY_COMPRESSION_ERROR = 9, |
| 397 GOAWAY_CONNECT_ERROR = 10, |
| 398 GOAWAY_ENHANCE_YOUR_CALM = 11, |
| 399 GOAWAY_INADEQUATE_SECURITY = 12 |
382 }; | 400 }; |
383 | 401 |
384 // A SPDY priority is a number between 0 and 7 (inclusive). | 402 // A SPDY priority is a number between 0 and 7 (inclusive). |
385 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a | 403 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a |
386 // number between 0 and 3. | 404 // number between 0 and 3. |
387 typedef uint8 SpdyPriority; | 405 typedef uint8 SpdyPriority; |
388 | 406 |
389 typedef std::map<std::string, std::string> SpdyNameValueBlock; | 407 typedef std::map<std::string, std::string> SpdyNameValueBlock; |
390 | 408 |
391 typedef uint64 SpdyPingId; | 409 typedef uint64 SpdyPingId; |
(...skipping 27 matching lines...) Expand all Loading... |
419 // version. | 437 // version. |
420 // Behavior is undefined for invalid setting id fields; consumers should first | 438 // Behavior is undefined for invalid setting id fields; consumers should first |
421 // use IsValidSettingId() to verify validity of setting id fields. | 439 // use IsValidSettingId() to verify validity of setting id fields. |
422 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version, | 440 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version, |
423 int setting_id_field); | 441 int setting_id_field); |
424 | 442 |
425 // Serializes a given setting id to the on-the-wire enumeration value for the | 443 // Serializes a given setting id to the on-the-wire enumeration value for the |
426 // given protocol version. | 444 // given protocol version. |
427 // Returns -1 on failure (I.E. Invalid setting id for the given version). | 445 // Returns -1 on failure (I.E. Invalid setting id for the given version). |
428 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id); | 446 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id); |
| 447 |
| 448 // Returns true if a given on-the-wire enumeration of a RST_STREAM status code |
| 449 // is valid for a given protocol version, false otherwise. |
| 450 static bool IsValidRstStreamStatus(SpdyMajorVersion version, |
| 451 int rst_stream_status_field); |
| 452 |
| 453 // Parses a RST_STREAM status code from an on-the-wire enumeration of a given |
| 454 // protocol version. |
| 455 // Behavior is undefined for invalid RST_STREAM status code fields; consumers |
| 456 // should first use IsValidRstStreamStatus() to verify validity of RST_STREAM |
| 457 // status code fields.. |
| 458 static SpdyRstStreamStatus ParseRstStreamStatus(SpdyMajorVersion version, |
| 459 int rst_stream_status_field); |
| 460 |
| 461 // Serializes a given RST_STREAM status code to the on-the-wire enumeration |
| 462 // value for the given protocol version. |
| 463 // Returns -1 on failure (I.E. Invalid RST_STREAM status code for the given |
| 464 // version). |
| 465 static int SerializeRstStreamStatus(SpdyMajorVersion version, |
| 466 SpdyRstStreamStatus rst_stream_status); |
| 467 |
| 468 // Returns true if a given on-the-wire enumeration of a GOAWAY status code is |
| 469 // valid for the given protocol version, false otherwise. |
| 470 static bool IsValidGoAwayStatus(SpdyMajorVersion version, |
| 471 int goaway_status_field); |
| 472 |
| 473 // Parses a GOAWAY status from an on-the-wire enumeration of a given protocol |
| 474 // version. |
| 475 // Behavior is undefined for invalid GOAWAY status fields; consumers should |
| 476 // first use IsValidGoAwayStatus() to verify validity of GOAWAY status fields. |
| 477 static SpdyGoAwayStatus ParseGoAwayStatus(SpdyMajorVersion version, |
| 478 int goaway_status_field); |
| 479 |
| 480 // Serializes a given GOAWAY status to the on-the-wire enumeration value for |
| 481 // the given protocol version. |
| 482 // Returns -1 on failure (I.E. Invalid GOAWAY status for the given version). |
| 483 static int SerializeGoAwayStatus(SpdyMajorVersion version, |
| 484 SpdyGoAwayStatus status); |
| 485 |
| 486 // Size, in bytes, of the data frame header. Future versions of SPDY |
| 487 // will likely vary this, so we allow for the flexibility of a function call |
| 488 // for this value as opposed to a constant. |
| 489 static size_t GetDataFrameMinimumSize(); |
| 490 |
| 491 // Size, in bytes, of the control frame header. |
| 492 static size_t GetControlFrameHeaderSize(SpdyMajorVersion version); |
| 493 |
| 494 static size_t GetPrefixLength(SpdyFrameType type, SpdyMajorVersion version); |
| 495 |
| 496 static size_t GetFrameMaximumSize(SpdyMajorVersion version); |
| 497 |
| 498 static SpdyMajorVersion ParseMajorVersion(int version_number); |
| 499 |
| 500 static int SerializeMajorVersion(SpdyMajorVersion version); |
| 501 |
| 502 static std::string GetVersionString(SpdyMajorVersion version); |
429 }; | 503 }; |
430 | 504 |
431 class SpdyFrame; | 505 class SpdyFrame; |
432 typedef SpdyFrame SpdySerializedFrame; | 506 typedef SpdyFrame SpdySerializedFrame; |
433 | 507 |
434 class SpdyFrameVisitor; | 508 class SpdyFrameVisitor; |
435 | 509 |
436 // Intermediate representation for SPDY frames. | 510 // Intermediate representation for SPDY frames. |
437 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is | 511 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is |
438 // gone. | 512 // gone. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 public: | 703 public: |
630 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status, | 704 SpdyRstStreamIR(SpdyStreamId stream_id, SpdyRstStreamStatus status, |
631 base::StringPiece description); | 705 base::StringPiece description); |
632 | 706 |
633 virtual ~SpdyRstStreamIR(); | 707 virtual ~SpdyRstStreamIR(); |
634 | 708 |
635 SpdyRstStreamStatus status() const { | 709 SpdyRstStreamStatus status() const { |
636 return status_; | 710 return status_; |
637 } | 711 } |
638 void set_status(SpdyRstStreamStatus status) { | 712 void set_status(SpdyRstStreamStatus status) { |
639 DCHECK_NE(status, RST_STREAM_INVALID); | |
640 DCHECK_LT(status, RST_STREAM_NUM_STATUS_CODES); | |
641 status_ = status; | 713 status_ = status; |
642 } | 714 } |
643 | 715 |
644 base::StringPiece description() const { return description_; } | 716 base::StringPiece description() const { return description_; } |
645 | 717 |
646 void set_description(base::StringPiece description) { | 718 void set_description(base::StringPiece description) { |
647 description_ = description; | 719 description_ = description; |
648 } | 720 } |
649 | 721 |
650 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE; | 722 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 SpdyFrameVisitor() {} | 987 SpdyFrameVisitor() {} |
916 virtual ~SpdyFrameVisitor() {} | 988 virtual ~SpdyFrameVisitor() {} |
917 | 989 |
918 private: | 990 private: |
919 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 991 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
920 }; | 992 }; |
921 | 993 |
922 } // namespace net | 994 } // namespace net |
923 | 995 |
924 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 996 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
OLD | NEW |