| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. | 5 // This file contains some protocol structures for use with Spdy. |
| 6 | 6 |
| 7 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 7 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
| 8 #define NET_SPDY_SPDY_PROTOCOL_H_ | 8 #define NET_SPDY_SPDY_PROTOCOL_H_ |
| 9 #pragma once | 9 #pragma once |
| 10 | 10 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 // Flags for settings within a SETTINGS frame. | 184 // Flags for settings within a SETTINGS frame. |
| 185 enum SpdySettingsFlags { | 185 enum SpdySettingsFlags { |
| 186 SETTINGS_FLAG_PLEASE_PERSIST = 0x1, | 186 SETTINGS_FLAG_PLEASE_PERSIST = 0x1, |
| 187 SETTINGS_FLAG_PERSISTED = 0x2 | 187 SETTINGS_FLAG_PERSISTED = 0x2 |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 // List of known settings. | 190 // List of known settings. |
| 191 enum SpdySettingsIds { | 191 enum SpdySettingsIds { |
| 192 SETTINGS_UPLOAD_BANDWIDTH = 0x1, | 192 SETTINGS_UPLOAD_BANDWIDTH = 0x1, |
| 193 SETTINGS_DOWNLOAD_BANDWIDTH = 0x2, | 193 SETTINGS_DOWNLOAD_BANDWIDTH = 0x2, |
| 194 // Network round trip time in milliseconds. |
| 194 SETTINGS_ROUND_TRIP_TIME = 0x3, | 195 SETTINGS_ROUND_TRIP_TIME = 0x3, |
| 195 SETTINGS_MAX_CONCURRENT_STREAMS = 0x4, | 196 SETTINGS_MAX_CONCURRENT_STREAMS = 0x4, |
| 197 // TCP congestion window in packets. |
| 196 SETTINGS_CURRENT_CWND = 0x5, | 198 SETTINGS_CURRENT_CWND = 0x5, |
| 197 // Downstream byte retransmission rate in percentage. | 199 // Downstream byte retransmission rate in percentage. |
| 198 SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6, | 200 SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6, |
| 199 // Initial window size in bytes | 201 // Initial window size in bytes |
| 200 SETTINGS_INITIAL_WINDOW_SIZE = 0x7 | 202 SETTINGS_INITIAL_WINDOW_SIZE = 0x7 |
| 201 }; | 203 }; |
| 202 | 204 |
| 203 // Status codes, as used in control frames (primarily RST_STREAM). | 205 // Status codes, as used in control frames (primarily RST_STREAM). |
| 204 enum SpdyStatusCodes { | 206 enum SpdyStatusCodes { |
| 205 INVALID = 0, | 207 INVALID = 0, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 SpdyStreamId stream_id_; | 273 SpdyStreamId stream_id_; |
| 272 uint32 status_; | 274 uint32 status_; |
| 273 }; | 275 }; |
| 274 | 276 |
| 275 // A SETTINGS Control Frame structure. | 277 // A SETTINGS Control Frame structure. |
| 276 struct SpdySettingsControlFrameBlock : SpdyFrameBlock { | 278 struct SpdySettingsControlFrameBlock : SpdyFrameBlock { |
| 277 uint32 num_entries_; | 279 uint32 num_entries_; |
| 278 // Variable data here. | 280 // Variable data here. |
| 279 }; | 281 }; |
| 280 | 282 |
| 283 // A NOOP Control Frame structure. |
| 284 struct SpdyNoopControlFrameBlock : SpdyFrameBlock { |
| 285 }; |
| 286 |
| 287 // A PING Control Frame structure. |
| 288 struct SpdyPingControlFrameBlock : SpdyFrameBlock { |
| 289 uint32 unique_id_; |
| 290 }; |
| 291 |
| 281 // A GOAWAY Control Frame structure. | 292 // A GOAWAY Control Frame structure. |
| 282 struct SpdyGoAwayControlFrameBlock : SpdyFrameBlock { | 293 struct SpdyGoAwayControlFrameBlock : SpdyFrameBlock { |
| 283 SpdyStreamId last_accepted_stream_id_; | 294 SpdyStreamId last_accepted_stream_id_; |
| 284 }; | 295 }; |
| 285 | 296 |
| 286 // A HEADERS Control Frame structure. | 297 // A HEADERS Control Frame structure. |
| 287 struct SpdyHeadersControlFrameBlock : SpdyFrameBlock { | 298 struct SpdyHeadersControlFrameBlock : SpdyFrameBlock { |
| 288 SpdyStreamId stream_id_; | 299 SpdyStreamId stream_id_; |
| 289 uint16 unused_; | 300 uint16 unused_; |
| 290 }; | 301 }; |
| 291 | 302 |
| 292 // A WINDOW_UPDATE Control Frame structure | 303 // A WINDOW_UPDATE Control Frame structure |
| 293 struct SpdyWindowUpdateControlFrameBlock : SpdyFrameBlock { | 304 struct SpdyWindowUpdateControlFrameBlock : SpdyFrameBlock { |
| 294 SpdyStreamId stream_id_; | 305 SpdyStreamId stream_id_; |
| 295 uint32 delta_window_size_; | 306 uint32 delta_window_size_; |
| 296 }; | 307 }; |
| 297 | 308 |
| 298 // A structure for the 8 bit flags and 24 bit ID fields. | 309 // A structure for the 8 bit flags and 24 bit ID fields. |
| 299 union SettingsFlagsAndId { | 310 union SettingsFlagsAndId { |
| 311 // Sets both flags and id to the value for flags-and-id as sent over the wire |
| 300 SettingsFlagsAndId(uint32 val) : id_(val) {} | 312 SettingsFlagsAndId(uint32 val) : id_(val) {} |
| 301 uint8 flags() const { return flags_[0]; } | 313 uint8 flags() const { return flags_[0]; } |
| 302 void set_flags(uint8 flags) { flags_[0] = flags; } | 314 void set_flags(uint8 flags) { flags_[0] = flags; } |
| 303 uint32 id() const { return (ntohl(id_) & kSettingsIdMask); } | 315 uint32 id() const { return (ntohl(id_) & kSettingsIdMask); } |
| 304 void set_id(uint32 id) { | 316 void set_id(uint32 id) { |
| 305 DCHECK_EQ(0u, (id & ~kSettingsIdMask)); | 317 DCHECK_EQ(0u, (id & ~kSettingsIdMask)); |
| 306 id_ = htonl((flags() << 24) | (id & kSettingsIdMask)); | 318 id_ = htonl((flags() << 24) | (id & kSettingsIdMask)); |
| 307 } | 319 } |
| 308 | 320 |
| 309 uint8 flags_[4]; // 8 bits | 321 uint8 flags_[4]; // 8 bits |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 uint16 type = ntohs(block()->control_.type_); | 455 uint16 type = ntohs(block()->control_.type_); |
| 444 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); | 456 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); |
| 445 return static_cast<SpdyControlType>(type); | 457 return static_cast<SpdyControlType>(type); |
| 446 } | 458 } |
| 447 | 459 |
| 448 void set_type(SpdyControlType type) { | 460 void set_type(SpdyControlType type) { |
| 449 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); | 461 DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES); |
| 450 mutable_block()->control_.type_ = htons(type); | 462 mutable_block()->control_.type_ = htons(type); |
| 451 } | 463 } |
| 452 | 464 |
| 465 // Returns true if this control frame is of a type that has a header block, |
| 466 // otherwise it returns false. |
| 467 bool has_header_block() const { |
| 468 return type() == SYN_STREAM || type() == SYN_REPLY || type() == HEADERS; |
| 469 } |
| 470 |
| 453 // Returns the size of the SpdyFrameBlock structure. | 471 // Returns the size of the SpdyFrameBlock structure. |
| 454 // Note: this is not the size of the SpdyControlFrame class. | 472 // Note: this is not the size of the SpdyControlFrame class. |
| 455 static size_t size() { return sizeof(SpdyFrameBlock); } | 473 static size_t size() { return sizeof(SpdyFrameBlock); } |
| 456 | 474 |
| 475 // The size of the 'Number of Name/Value pairs' field in a Name/Value block. |
| 476 static const size_t kNumNameValuePairsSize = 2; |
| 477 |
| 478 // The size of the 'Length of a name' field in a Name/Value block. |
| 479 static const size_t kLengthOfNameSize = 2; |
| 480 |
| 481 // The size of the 'Length of a value' field in a Name/Value block. |
| 482 static const size_t kLengthOfValueSize = 2; |
| 483 |
| 457 private: | 484 private: |
| 458 const struct SpdyFrameBlock* block() const { | 485 const struct SpdyFrameBlock* block() const { |
| 459 return frame_; | 486 return frame_; |
| 460 } | 487 } |
| 461 struct SpdyFrameBlock* mutable_block() { | 488 struct SpdyFrameBlock* mutable_block() { |
| 462 return frame_; | 489 return frame_; |
| 463 } | 490 } |
| 464 DISALLOW_COPY_AND_ASSIGN(SpdyControlFrame); | 491 DISALLOW_COPY_AND_ASSIGN(SpdyControlFrame); |
| 465 }; | 492 }; |
| 466 | 493 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 | 587 |
| 561 SpdyStreamId stream_id() const { | 588 SpdyStreamId stream_id() const { |
| 562 return ntohl(block()->stream_id_) & kStreamIdMask; | 589 return ntohl(block()->stream_id_) & kStreamIdMask; |
| 563 } | 590 } |
| 564 | 591 |
| 565 void set_stream_id(SpdyStreamId id) { | 592 void set_stream_id(SpdyStreamId id) { |
| 566 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); | 593 mutable_block()->stream_id_ = htonl(id & kStreamIdMask); |
| 567 } | 594 } |
| 568 | 595 |
| 569 SpdyStatusCodes status() const { | 596 SpdyStatusCodes status() const { |
| 570 return static_cast<SpdyStatusCodes>(ntohl(block()->status_)); | 597 SpdyStatusCodes status = |
| 598 static_cast<SpdyStatusCodes>(ntohl(block()->status_)); |
| 599 if (status < INVALID || status >= NUM_STATUS_CODES) { |
| 600 status = INVALID; |
| 601 } |
| 602 return status; |
| 571 } | 603 } |
| 572 void set_status(SpdyStatusCodes status) { | 604 void set_status(SpdyStatusCodes status) { |
| 573 mutable_block()->status_ = htonl(static_cast<uint32>(status)); | 605 mutable_block()->status_ = htonl(static_cast<uint32>(status)); |
| 574 } | 606 } |
| 575 | 607 |
| 576 // Returns the size of the SpdyRstStreamControlFrameBlock structure. | 608 // Returns the size of the SpdyRstStreamControlFrameBlock structure. |
| 577 // Note: this is not the size of the SpdyRstStreamControlFrame class. | 609 // Note: this is not the size of the SpdyRstStreamControlFrame class. |
| 578 static size_t size() { return sizeof(SpdyRstStreamControlFrameBlock); } | 610 static size_t size() { return sizeof(SpdyRstStreamControlFrameBlock); } |
| 579 | 611 |
| 580 private: | 612 private: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 private: | 648 private: |
| 617 const struct SpdySettingsControlFrameBlock* block() const { | 649 const struct SpdySettingsControlFrameBlock* block() const { |
| 618 return static_cast<SpdySettingsControlFrameBlock*>(frame_); | 650 return static_cast<SpdySettingsControlFrameBlock*>(frame_); |
| 619 } | 651 } |
| 620 struct SpdySettingsControlFrameBlock* mutable_block() { | 652 struct SpdySettingsControlFrameBlock* mutable_block() { |
| 621 return static_cast<SpdySettingsControlFrameBlock*>(frame_); | 653 return static_cast<SpdySettingsControlFrameBlock*>(frame_); |
| 622 } | 654 } |
| 623 DISALLOW_COPY_AND_ASSIGN(SpdySettingsControlFrame); | 655 DISALLOW_COPY_AND_ASSIGN(SpdySettingsControlFrame); |
| 624 }; | 656 }; |
| 625 | 657 |
| 658 class SpdyNoOpControlFrame : public SpdyControlFrame { |
| 659 public: |
| 660 SpdyNoOpControlFrame() : SpdyControlFrame(size()) {} |
| 661 SpdyNoOpControlFrame(char* data, bool owns_buffer) |
| 662 : SpdyControlFrame(data, owns_buffer) {} |
| 663 |
| 664 static size_t size() { return sizeof(SpdyNoopControlFrameBlock); } |
| 665 }; |
| 666 |
| 667 class SpdyPingControlFrame : public SpdyControlFrame { |
| 668 public: |
| 669 SpdyPingControlFrame() : SpdyControlFrame(size()) {} |
| 670 SpdyPingControlFrame(char* data, bool owns_buffer) |
| 671 : SpdyControlFrame(data, owns_buffer) {} |
| 672 |
| 673 uint32 unique_id() const { |
| 674 return ntohl(block()->unique_id_); |
| 675 } |
| 676 |
| 677 void set_unique_id(uint32 unique_id) { |
| 678 mutable_block()->unique_id_ = htonl(unique_id); |
| 679 } |
| 680 |
| 681 static size_t size() { return sizeof(SpdyPingControlFrameBlock); } |
| 682 |
| 683 private: |
| 684 const struct SpdyPingControlFrameBlock* block() const { |
| 685 return static_cast<SpdyPingControlFrameBlock*>(frame_); |
| 686 } |
| 687 struct SpdyPingControlFrameBlock* mutable_block() { |
| 688 return static_cast<SpdyPingControlFrameBlock*>(frame_); |
| 689 } |
| 690 }; |
| 691 |
| 626 class SpdyGoAwayControlFrame : public SpdyControlFrame { | 692 class SpdyGoAwayControlFrame : public SpdyControlFrame { |
| 627 public: | 693 public: |
| 628 SpdyGoAwayControlFrame() : SpdyControlFrame(size()) {} | 694 SpdyGoAwayControlFrame() : SpdyControlFrame(size()) {} |
| 629 SpdyGoAwayControlFrame(char* data, bool owns_buffer) | 695 SpdyGoAwayControlFrame(char* data, bool owns_buffer) |
| 630 : SpdyControlFrame(data, owns_buffer) {} | 696 : SpdyControlFrame(data, owns_buffer) {} |
| 631 | 697 |
| 632 SpdyStreamId last_accepted_stream_id() const { | 698 SpdyStreamId last_accepted_stream_id() const { |
| 633 return ntohl(block()->last_accepted_stream_id_) & kStreamIdMask; | 699 return ntohl(block()->last_accepted_stream_id_) & kStreamIdMask; |
| 634 } | 700 } |
| 635 | 701 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { | 787 struct SpdyWindowUpdateControlFrameBlock* mutable_block() { |
| 722 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); | 788 return static_cast<SpdyWindowUpdateControlFrameBlock*>(frame_); |
| 723 } | 789 } |
| 724 | 790 |
| 725 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); | 791 DISALLOW_COPY_AND_ASSIGN(SpdyWindowUpdateControlFrame); |
| 726 }; | 792 }; |
| 727 | 793 |
| 728 } // namespace spdy | 794 } // namespace spdy |
| 729 | 795 |
| 730 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 796 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |