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 |
11 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 11 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
12 #define NET_SPDY_SPDY_PROTOCOL_H_ | 12 #define NET_SPDY_SPDY_PROTOCOL_H_ |
13 | 13 |
| 14 #include <stddef.h> |
| 15 #include <stdint.h> |
| 16 |
14 #include <limits> | 17 #include <limits> |
15 #include <map> | 18 #include <map> |
16 #include <string> | 19 #include <string> |
17 | 20 |
18 #include "base/basictypes.h" | |
19 #include "base/compiler_specific.h" | 21 #include "base/compiler_specific.h" |
20 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/macros.h" |
21 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
22 #include "base/strings/string_piece.h" | 25 #include "base/strings/string_piece.h" |
23 #include "base/sys_byteorder.h" | 26 #include "base/sys_byteorder.h" |
24 #include "net/base/net_export.h" | 27 #include "net/base/net_export.h" |
25 #include "net/spdy/spdy_alt_svc_wire_format.h" | 28 #include "net/spdy/spdy_alt_svc_wire_format.h" |
26 #include "net/spdy/spdy_bitmasks.h" | 29 #include "net/spdy/spdy_bitmasks.h" |
27 #include "net/spdy/spdy_header_block.h" | 30 #include "net/spdy/spdy_header_block.h" |
28 | 31 |
29 namespace net { | 32 namespace net { |
30 | 33 |
31 // The major versions of SPDY. Major version differences indicate | 34 // The major versions of SPDY. Major version differences indicate |
32 // framer-layer incompatibility, as opposed to minor version numbers | 35 // framer-layer incompatibility, as opposed to minor version numbers |
33 // which indicate application-layer incompatibility. Do not rely on | 36 // which indicate application-layer incompatibility. Do not rely on |
34 // the mapping from enum value SPDYn to the integer n. | 37 // the mapping from enum value SPDYn to the integer n. |
35 enum SpdyMajorVersion { | 38 enum SpdyMajorVersion { |
36 SPDY2 = 2, | 39 SPDY2 = 2, |
37 SPDY_MIN_VERSION = SPDY2, | 40 SPDY_MIN_VERSION = SPDY2, |
38 SPDY3 = 3, | 41 SPDY3 = 3, |
39 HTTP2 = 4, | 42 HTTP2 = 4, |
40 SPDY_MAX_VERSION = HTTP2 | 43 SPDY_MAX_VERSION = HTTP2 |
41 }; | 44 }; |
42 | 45 |
43 // A SPDY stream id is a 31 bit entity. | 46 // A SPDY stream id is a 31 bit entity. |
44 typedef uint32 SpdyStreamId; | 47 typedef uint32_t SpdyStreamId; |
45 | 48 |
46 // Specifies the stream ID used to denote the current session (for | 49 // Specifies the stream ID used to denote the current session (for |
47 // flow control). | 50 // flow control). |
48 const SpdyStreamId kSessionFlowControlStreamId = 0; | 51 const SpdyStreamId kSessionFlowControlStreamId = 0; |
49 | 52 |
50 // The maxmium possible control frame size allowed by the spec. | 53 // The maxmium possible control frame size allowed by the spec. |
51 const int32 kSpdyMaxControlFrameSize = (1 << 24) - 1; | 54 const int32_t kSpdyMaxControlFrameSize = (1 << 24) - 1; |
52 | 55 |
53 // The maximum control frame size we accept. | 56 // The maximum control frame size we accept. |
54 const int32 kControlFrameSizeLimit = 1 << 14; | 57 const int32_t kControlFrameSizeLimit = 1 << 14; |
55 | 58 |
56 // Maximum window size for a Spdy stream or session. | 59 // Maximum window size for a Spdy stream or session. |
57 const int32 kSpdyMaximumWindowSize = 0x7FFFFFFF; // Max signed 32bit int | 60 const int32_t kSpdyMaximumWindowSize = 0x7FFFFFFF; // Max signed 32bit int |
58 | 61 |
59 // Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame. | 62 // Maximum padding size in octets for one DATA or HEADERS or PUSH_PROMISE frame. |
60 const int32 kPaddingSizePerFrame = 256; | 63 const int32_t kPaddingSizePerFrame = 256; |
61 | 64 |
62 // SPDY 2 dictionary. | 65 // SPDY 2 dictionary. |
63 // This is just a hacked dictionary to use for shrinking HTTP-like headers. | 66 // This is just a hacked dictionary to use for shrinking HTTP-like headers. |
64 const char kV2Dictionary[] = | 67 const char kV2Dictionary[] = |
65 "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-" | 68 "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-" |
66 "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi" | 69 "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi" |
67 "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser" | 70 "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser" |
68 "-agent10010120020120220320420520630030130230330430530630740040140240340440" | 71 "-agent10010120020120220320420520630030130230330430530630740040140240340440" |
69 "5406407408409410411412413414415416417500501502503504505accept-rangesageeta" | 72 "5406407408409410411412413414415416417500501502503504505accept-rangesageeta" |
70 "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic" | 73 "glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 GOAWAY_COMPRESSION_ERROR = 9, | 413 GOAWAY_COMPRESSION_ERROR = 9, |
411 GOAWAY_CONNECT_ERROR = 10, | 414 GOAWAY_CONNECT_ERROR = 10, |
412 GOAWAY_ENHANCE_YOUR_CALM = 11, | 415 GOAWAY_ENHANCE_YOUR_CALM = 11, |
413 GOAWAY_INADEQUATE_SECURITY = 12, | 416 GOAWAY_INADEQUATE_SECURITY = 12, |
414 GOAWAY_HTTP_1_1_REQUIRED = 13 | 417 GOAWAY_HTTP_1_1_REQUIRED = 13 |
415 }; | 418 }; |
416 | 419 |
417 // A SPDY priority is a number between 0 and 7 (inclusive). | 420 // A SPDY priority is a number between 0 and 7 (inclusive). |
418 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a | 421 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a |
419 // number between 0 and 3. | 422 // number between 0 and 3. |
420 typedef uint8 SpdyPriority; | 423 typedef uint8_t SpdyPriority; |
421 | 424 |
422 // Lowest and Highest here refer to SPDY priorities as described in | 425 // Lowest and Highest here refer to SPDY priorities as described in |
423 | 426 |
424 // https://www.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3-1#TOC-2.3.3-
Stream-priority | 427 // https://www.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3-1#TOC-2.3.3-
Stream-priority |
425 const SpdyPriority kV3HighestPriority = 0; | 428 const SpdyPriority kV3HighestPriority = 0; |
426 const SpdyPriority kV3LowestPriority = 7; | 429 const SpdyPriority kV3LowestPriority = 7; |
427 | 430 |
428 typedef uint64 SpdyPingId; | 431 typedef uint64_t SpdyPingId; |
429 | 432 |
430 typedef std::string SpdyProtocolId; | 433 typedef std::string SpdyProtocolId; |
431 | 434 |
432 enum class SpdyHeaderValidatorType { | 435 enum class SpdyHeaderValidatorType { |
433 REQUEST, | 436 REQUEST, |
434 RESPONSE_HEADER, | 437 RESPONSE_HEADER, |
435 RESPONSE_TRAILER | 438 RESPONSE_TRAILER |
436 }; | 439 }; |
437 | 440 |
438 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any, | 441 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 static size_t GetFrameMaximumSize(SpdyMajorVersion version); | 530 static size_t GetFrameMaximumSize(SpdyMajorVersion version); |
528 | 531 |
529 // Returns the size of a header block size field. Valid only for SPDY | 532 // Returns the size of a header block size field. Valid only for SPDY |
530 // versions <= 3. | 533 // versions <= 3. |
531 static size_t GetSizeOfSizeField(SpdyMajorVersion version); | 534 static size_t GetSizeOfSizeField(SpdyMajorVersion version); |
532 | 535 |
533 // Returns the size (in bytes) of a wire setting ID and value. | 536 // Returns the size (in bytes) of a wire setting ID and value. |
534 static size_t GetSettingSize(SpdyMajorVersion version); | 537 static size_t GetSettingSize(SpdyMajorVersion version); |
535 | 538 |
536 // Initial window size for a stream in bytes. | 539 // Initial window size for a stream in bytes. |
537 static int32 GetInitialStreamWindowSize(SpdyMajorVersion version); | 540 static int32_t GetInitialStreamWindowSize(SpdyMajorVersion version); |
538 | 541 |
539 // Initial window size for a session in bytes. | 542 // Initial window size for a session in bytes. |
540 static int32 GetInitialSessionWindowSize(SpdyMajorVersion version); | 543 static int32_t GetInitialSessionWindowSize(SpdyMajorVersion version); |
541 | 544 |
542 static SpdyMajorVersion ParseMajorVersion(int version_number); | 545 static SpdyMajorVersion ParseMajorVersion(int version_number); |
543 | 546 |
544 static int SerializeMajorVersion(SpdyMajorVersion version); | 547 static int SerializeMajorVersion(SpdyMajorVersion version); |
545 | 548 |
546 static std::string GetVersionString(SpdyMajorVersion version); | 549 static std::string GetVersionString(SpdyMajorVersion version); |
547 }; | 550 }; |
548 | 551 |
549 class SpdyFrame; | 552 class SpdyFrame; |
550 typedef SpdyFrame SpdySerializedFrame; | 553 typedef SpdyFrame SpdySerializedFrame; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 752 |
750 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { | 753 class NET_EXPORT_PRIVATE SpdySettingsIR : public SpdyFrameIR { |
751 public: | 754 public: |
752 // Associates flags with a value. | 755 // Associates flags with a value. |
753 struct Value { | 756 struct Value { |
754 Value() : persist_value(false), | 757 Value() : persist_value(false), |
755 persisted(false), | 758 persisted(false), |
756 value(0) {} | 759 value(0) {} |
757 bool persist_value; | 760 bool persist_value; |
758 bool persisted; | 761 bool persisted; |
759 int32 value; | 762 int32_t value; |
760 }; | 763 }; |
761 typedef std::map<SpdySettingsIds, Value> ValueMap; | 764 typedef std::map<SpdySettingsIds, Value> ValueMap; |
762 | 765 |
763 SpdySettingsIR(); | 766 SpdySettingsIR(); |
764 | 767 |
765 ~SpdySettingsIR() override; | 768 ~SpdySettingsIR() override; |
766 | 769 |
767 // Overwrites as appropriate. | 770 // Overwrites as appropriate. |
768 const ValueMap& values() const { return values_; } | 771 const ValueMap& values() const { return values_; } |
769 void AddSetting(SpdySettingsIds id, | 772 void AddSetting(SpdySettingsIds id, |
770 bool persist_value, | 773 bool persist_value, |
771 bool persisted, | 774 bool persisted, |
772 int32 value) { | 775 int32_t value) { |
773 values_[id].persist_value = persist_value; | 776 values_[id].persist_value = persist_value; |
774 values_[id].persisted = persisted; | 777 values_[id].persisted = persisted; |
775 values_[id].value = value; | 778 values_[id].value = value; |
776 } | 779 } |
777 | 780 |
778 bool clear_settings() const { return clear_settings_; } | 781 bool clear_settings() const { return clear_settings_; } |
779 bool is_ack() const { return is_ack_; } | 782 bool is_ack() const { return is_ack_; } |
780 void set_is_ack(bool is_ack) { | 783 void set_is_ack(bool is_ack) { |
781 is_ack_ = is_ack; | 784 is_ack_ = is_ack; |
782 } | 785 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 | 844 |
842 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { | 845 class NET_EXPORT_PRIVATE SpdyHeadersIR : public SpdyFrameWithHeaderBlockIR { |
843 public: | 846 public: |
844 explicit SpdyHeadersIR(SpdyStreamId stream_id) | 847 explicit SpdyHeadersIR(SpdyStreamId stream_id) |
845 : SpdyFrameWithHeaderBlockIR(stream_id) {} | 848 : SpdyFrameWithHeaderBlockIR(stream_id) {} |
846 | 849 |
847 void Visit(SpdyFrameVisitor* visitor) const override; | 850 void Visit(SpdyFrameVisitor* visitor) const override; |
848 | 851 |
849 bool has_priority() const { return has_priority_; } | 852 bool has_priority() const { return has_priority_; } |
850 void set_has_priority(bool has_priority) { has_priority_ = has_priority; } | 853 void set_has_priority(bool has_priority) { has_priority_ = has_priority; } |
851 uint32 priority() const { return priority_; } | 854 uint32_t priority() const { return priority_; } |
852 void set_priority(SpdyPriority priority) { priority_ = priority; } | 855 void set_priority(SpdyPriority priority) { priority_ = priority; } |
853 SpdyStreamId parent_stream_id() const { return parent_stream_id_; } | 856 SpdyStreamId parent_stream_id() const { return parent_stream_id_; } |
854 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; } | 857 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; } |
855 bool exclusive() const { return exclusive_; } | 858 bool exclusive() const { return exclusive_; } |
856 void set_exclusive(bool exclusive) { exclusive_ = exclusive; } | 859 void set_exclusive(bool exclusive) { exclusive_ = exclusive; } |
857 bool padded() const { return padded_; } | 860 bool padded() const { return padded_; } |
858 int padding_payload_len() const { return padding_payload_len_; } | 861 int padding_payload_len() const { return padding_payload_len_; } |
859 void set_padding_len(int padding_len) { | 862 void set_padding_len(int padding_len) { |
860 DCHECK_GT(padding_len, 0); | 863 DCHECK_GT(padding_len, 0); |
861 DCHECK_LE(padding_len, kPaddingSizePerFrame); | 864 DCHECK_LE(padding_len, kPaddingSizePerFrame); |
862 padded_ = true; | 865 padded_ = true; |
863 // The pad field takes one octet on the wire. | 866 // The pad field takes one octet on the wire. |
864 padding_payload_len_ = padding_len - 1; | 867 padding_payload_len_ = padding_len - 1; |
865 } | 868 } |
866 | 869 |
867 private: | 870 private: |
868 bool has_priority_ = false; | 871 bool has_priority_ = false; |
869 // 31-bit priority. | 872 // 31-bit priority. |
870 uint32 priority_ = 0; | 873 uint32_t priority_ = 0; |
871 SpdyStreamId parent_stream_id_ = 0; | 874 SpdyStreamId parent_stream_id_ = 0; |
872 bool exclusive_ = false; | 875 bool exclusive_ = false; |
873 bool padded_ = false; | 876 bool padded_ = false; |
874 int padding_payload_len_ = 0; | 877 int padding_payload_len_ = 0; |
875 | 878 |
876 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR); | 879 DISALLOW_COPY_AND_ASSIGN(SpdyHeadersIR); |
877 }; | 880 }; |
878 | 881 |
879 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR { | 882 class NET_EXPORT_PRIVATE SpdyWindowUpdateIR : public SpdyFrameWithStreamIdIR { |
880 public: | 883 public: |
881 SpdyWindowUpdateIR(SpdyStreamId stream_id, int32 delta) | 884 SpdyWindowUpdateIR(SpdyStreamId stream_id, int32_t delta) |
882 : SpdyFrameWithStreamIdIR(stream_id) { | 885 : SpdyFrameWithStreamIdIR(stream_id) { |
883 set_delta(delta); | 886 set_delta(delta); |
884 } | 887 } |
885 int32 delta() const { return delta_; } | 888 int32_t delta() const { return delta_; } |
886 void set_delta(int32 delta) { | 889 void set_delta(int32_t delta) { |
887 DCHECK_LT(0, delta); | 890 DCHECK_LT(0, delta); |
888 DCHECK_LE(delta, kSpdyMaximumWindowSize); | 891 DCHECK_LE(delta, kSpdyMaximumWindowSize); |
889 delta_ = delta; | 892 delta_ = delta; |
890 } | 893 } |
891 | 894 |
892 void Visit(SpdyFrameVisitor* visitor) const override; | 895 void Visit(SpdyFrameVisitor* visitor) const override; |
893 | 896 |
894 private: | 897 private: |
895 int32 delta_; | 898 int32_t delta_; |
896 | 899 |
897 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR); | 900 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateIR); |
898 }; | 901 }; |
899 | 902 |
900 class NET_EXPORT_PRIVATE SpdyBlockedIR | 903 class NET_EXPORT_PRIVATE SpdyBlockedIR |
901 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) { | 904 : public NON_EXPORTED_BASE(SpdyFrameWithStreamIdIR) { |
902 public: | 905 public: |
903 explicit SpdyBlockedIR(SpdyStreamId stream_id) | 906 explicit SpdyBlockedIR(SpdyStreamId stream_id) |
904 : SpdyFrameWithStreamIdIR(stream_id) {} | 907 : SpdyFrameWithStreamIdIR(stream_id) {} |
905 | 908 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 985 |
983 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR { | 986 class NET_EXPORT_PRIVATE SpdyPriorityIR : public SpdyFrameWithStreamIdIR { |
984 public: | 987 public: |
985 explicit SpdyPriorityIR(SpdyStreamId stream_id) | 988 explicit SpdyPriorityIR(SpdyStreamId stream_id) |
986 : SpdyFrameWithStreamIdIR(stream_id), | 989 : SpdyFrameWithStreamIdIR(stream_id), |
987 parent_stream_id_(0), | 990 parent_stream_id_(0), |
988 weight_(1), | 991 weight_(1), |
989 exclusive_(false) {} | 992 exclusive_(false) {} |
990 SpdyPriorityIR(SpdyStreamId stream_id, | 993 SpdyPriorityIR(SpdyStreamId stream_id, |
991 SpdyStreamId parent_stream_id, | 994 SpdyStreamId parent_stream_id, |
992 uint8 weight, | 995 uint8_t weight, |
993 bool exclusive) | 996 bool exclusive) |
994 : SpdyFrameWithStreamIdIR(stream_id), | 997 : SpdyFrameWithStreamIdIR(stream_id), |
995 parent_stream_id_(parent_stream_id), | 998 parent_stream_id_(parent_stream_id), |
996 weight_(weight), | 999 weight_(weight), |
997 exclusive_(exclusive) {} | 1000 exclusive_(exclusive) {} |
998 SpdyStreamId parent_stream_id() const { return parent_stream_id_; } | 1001 SpdyStreamId parent_stream_id() const { return parent_stream_id_; } |
999 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; } | 1002 void set_parent_stream_id(SpdyStreamId id) { parent_stream_id_ = id; } |
1000 uint8 weight() const { return weight_; } | 1003 uint8_t weight() const { return weight_; } |
1001 void set_weight(uint8 weight) { weight_ = weight; } | 1004 void set_weight(uint8_t weight) { weight_ = weight; } |
1002 bool exclusive() const { return exclusive_; } | 1005 bool exclusive() const { return exclusive_; } |
1003 void set_exclusive(bool exclusive) { exclusive_ = exclusive; } | 1006 void set_exclusive(bool exclusive) { exclusive_ = exclusive; } |
1004 | 1007 |
1005 void Visit(SpdyFrameVisitor* visitor) const override; | 1008 void Visit(SpdyFrameVisitor* visitor) const override; |
1006 | 1009 |
1007 private: | 1010 private: |
1008 SpdyStreamId parent_stream_id_; | 1011 SpdyStreamId parent_stream_id_; |
1009 uint8 weight_; | 1012 uint8_t weight_; |
1010 bool exclusive_; | 1013 bool exclusive_; |
1011 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR); | 1014 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR); |
1012 }; | 1015 }; |
1013 | 1016 |
1014 // ------------------------------------------------------------------------- | 1017 // ------------------------------------------------------------------------- |
1015 // Wrapper classes for various SPDY frames. | 1018 // Wrapper classes for various SPDY frames. |
1016 | 1019 |
1017 // All Spdy Frame types derive from this SpdyFrame class. | 1020 // All Spdy Frame types derive from this SpdyFrame class. |
1018 class SpdyFrame { | 1021 class SpdyFrame { |
1019 public: | 1022 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 SpdyFrameVisitor() {} | 1082 SpdyFrameVisitor() {} |
1080 virtual ~SpdyFrameVisitor() {} | 1083 virtual ~SpdyFrameVisitor() {} |
1081 | 1084 |
1082 private: | 1085 private: |
1083 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 1086 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
1084 }; | 1087 }; |
1085 | 1088 |
1086 } // namespace net | 1089 } // namespace net |
1087 | 1090 |
1088 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 1091 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
OLD | NEW |