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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 WINDOW_UPDATE, | 284 WINDOW_UPDATE, |
285 CREDENTIAL, // No longer valid. Kept for identifiability/enum order. | 285 CREDENTIAL, // No longer valid. Kept for identifiability/enum order. |
286 BLOCKED, | 286 BLOCKED, |
287 PUSH_PROMISE, | 287 PUSH_PROMISE, |
288 CONTINUATION, | 288 CONTINUATION, |
289 LAST_CONTROL_TYPE = CONTINUATION | 289 LAST_CONTROL_TYPE = CONTINUATION |
290 }; | 290 }; |
291 | 291 |
292 // Flags on data packets. | 292 // Flags on data packets. |
293 enum SpdyDataFlags { | 293 enum SpdyDataFlags { |
294 DATA_FLAG_NONE = 0, | 294 DATA_FLAG_NONE = 0x00, |
295 DATA_FLAG_FIN = 1, | 295 DATA_FLAG_FIN = 0x01, |
| 296 DATA_FLAG_END_SEGMENT = 0x02, |
| 297 DATA_FLAG_PAD_LOW = 0x10, |
| 298 DATA_FLAG_PAD_HIGH = 0x20 |
296 }; | 299 }; |
297 | 300 |
298 // Flags on control packets | 301 // Flags on control packets |
299 enum SpdyControlFlags { | 302 enum SpdyControlFlags { |
300 CONTROL_FLAG_NONE = 0, | 303 CONTROL_FLAG_NONE = 0, |
301 CONTROL_FLAG_FIN = 1, | 304 CONTROL_FLAG_FIN = 1, |
302 CONTROL_FLAG_UNIDIRECTIONAL = 2 | 305 CONTROL_FLAG_UNIDIRECTIONAL = 2 |
303 }; | 306 }; |
304 | 307 |
305 enum SpdyPingFlags { | 308 enum SpdyPingFlags { |
(...skipping 20 matching lines...) Expand all Loading... |
326 | 329 |
327 // Flags for settings within a SETTINGS frame. | 330 // Flags for settings within a SETTINGS frame. |
328 enum SpdySettingsFlags { | 331 enum SpdySettingsFlags { |
329 SETTINGS_FLAG_NONE = 0x0, | 332 SETTINGS_FLAG_NONE = 0x0, |
330 SETTINGS_FLAG_PLEASE_PERSIST = 0x1, | 333 SETTINGS_FLAG_PLEASE_PERSIST = 0x1, |
331 SETTINGS_FLAG_PERSISTED = 0x2 | 334 SETTINGS_FLAG_PERSISTED = 0x2 |
332 }; | 335 }; |
333 | 336 |
334 // List of known settings. | 337 // List of known settings. |
335 enum SpdySettingsIds { | 338 enum SpdySettingsIds { |
336 SETTINGS_UPLOAD_BANDWIDTH = 0x1, | 339 SETTINGS_UPLOAD_BANDWIDTH, |
337 SETTINGS_DOWNLOAD_BANDWIDTH = 0x2, | 340 SETTINGS_DOWNLOAD_BANDWIDTH, |
338 // Network round trip time in milliseconds. | 341 // Network round trip time in milliseconds. |
339 SETTINGS_ROUND_TRIP_TIME = 0x3, | 342 SETTINGS_ROUND_TRIP_TIME, |
340 SETTINGS_MAX_CONCURRENT_STREAMS = 0x4, | 343 // The maximum number of simultaneous live streams in each direction. |
| 344 SETTINGS_MAX_CONCURRENT_STREAMS, |
341 // TCP congestion window in packets. | 345 // TCP congestion window in packets. |
342 SETTINGS_CURRENT_CWND = 0x5, | 346 SETTINGS_CURRENT_CWND, |
343 // Downstream byte retransmission rate in percentage. | 347 // Downstream byte retransmission rate in percentage. |
344 SETTINGS_DOWNLOAD_RETRANS_RATE = 0x6, | 348 SETTINGS_DOWNLOAD_RETRANS_RATE, |
345 // Initial window size in bytes | 349 // Initial window size in bytes |
346 SETTINGS_INITIAL_WINDOW_SIZE = 0x7 | 350 SETTINGS_INITIAL_WINDOW_SIZE, |
| 351 // HPACK header table maximum size. |
| 352 SETTINGS_HEADER_TABLE_SIZE, |
| 353 // Whether or not server push (PUSH_PROMISE) is enabled. |
| 354 SETTINGS_ENABLE_PUSH, |
347 }; | 355 }; |
348 | 356 |
349 // Status codes for RST_STREAM frames. | 357 // Status codes for RST_STREAM frames. |
350 enum SpdyRstStreamStatus { | 358 enum SpdyRstStreamStatus { |
351 RST_STREAM_INVALID = 0, | 359 RST_STREAM_INVALID = 0, |
352 RST_STREAM_PROTOCOL_ERROR = 1, | 360 RST_STREAM_PROTOCOL_ERROR = 1, |
353 RST_STREAM_INVALID_STREAM = 2, | 361 RST_STREAM_INVALID_STREAM = 2, |
354 RST_STREAM_REFUSED_STREAM = 3, | 362 RST_STREAM_REFUSED_STREAM = 3, |
355 RST_STREAM_UNSUPPORTED_VERSION = 4, | 363 RST_STREAM_UNSUPPORTED_VERSION = 4, |
356 RST_STREAM_CANCEL = 5, | 364 RST_STREAM_CANCEL = 5, |
(...skipping 17 matching lines...) Expand all Loading... |
374 | 382 |
375 // A SPDY priority is a number between 0 and 7 (inclusive). | 383 // A SPDY priority is a number between 0 and 7 (inclusive). |
376 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a | 384 // SPDY priority range is version-dependent. For SPDY 2 and below, priority is a |
377 // number between 0 and 3. | 385 // number between 0 and 3. |
378 typedef uint8 SpdyPriority; | 386 typedef uint8 SpdyPriority; |
379 | 387 |
380 typedef std::map<std::string, std::string> SpdyNameValueBlock; | 388 typedef std::map<std::string, std::string> SpdyNameValueBlock; |
381 | 389 |
382 typedef uint64 SpdyPingId; | 390 typedef uint64 SpdyPingId; |
383 | 391 |
| 392 // TODO(hkhalil): Add direct testing for this? It won't increase coverage any, |
| 393 // but is good to do anyway. |
| 394 class NET_EXPORT_PRIVATE SpdyConstants { |
| 395 public: |
| 396 // Returns true if a given on-the-wire enumeration of a frame type is valid |
| 397 // for a given protocol version, false otherwise. |
| 398 static bool IsValidFrameType(SpdyMajorVersion version, int frame_type_field); |
| 399 |
| 400 // Parses a frame type from an on-the-wire enumeration of a given protocol |
| 401 // version. |
| 402 // Behavior is undefined for invalid frame type fields; consumers should first |
| 403 // use IsValidFrameType() to verify validity of frame type fields. |
| 404 static SpdyFrameType ParseFrameType(SpdyMajorVersion version, |
| 405 int frame_type_field); |
| 406 |
| 407 // Serializes a given frame type to the on-the-wire enumeration value for the |
| 408 // given protocol version. |
| 409 // Returns -1 on failure (I.E. Invalid frame type for the given version). |
| 410 static int SerializeFrameType(SpdyMajorVersion version, |
| 411 SpdyFrameType frame_type); |
| 412 |
| 413 // Returns true if a given on-the-wire enumeration of a setting id is valid |
| 414 // for a given protocol version, false otherwise. |
| 415 static bool IsValidSettingId(SpdyMajorVersion version, int setting_id_field); |
| 416 |
| 417 // Parses a setting id from an on-the-wire enumeration of a given protocol |
| 418 // version. |
| 419 // Behavior is undefined for invalid setting id fields; consumers should first |
| 420 // use IsValidSettingId() to verify validity of setting id fields. |
| 421 static SpdySettingsIds ParseSettingId(SpdyMajorVersion version, |
| 422 int setting_id_field); |
| 423 |
| 424 // Serializes a given setting id to the on-the-wire enumeration value for the |
| 425 // given protocol version. |
| 426 // Returns -1 on failure (I.E. Invalid setting id for the given version). |
| 427 static int SerializeSettingId(SpdyMajorVersion version, SpdySettingsIds id); |
| 428 }; |
| 429 |
384 class SpdyFrame; | 430 class SpdyFrame; |
385 typedef SpdyFrame SpdySerializedFrame; | 431 typedef SpdyFrame SpdySerializedFrame; |
386 | 432 |
387 class SpdyFrameVisitor; | 433 class SpdyFrameVisitor; |
388 | 434 |
389 // Intermediate representation for SPDY frames. | 435 // Intermediate representation for SPDY frames. |
390 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is | 436 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is |
391 // gone. | 437 // gone. |
392 class NET_EXPORT_PRIVATE SpdyFrameIR { | 438 class NET_EXPORT_PRIVATE SpdyFrameIR { |
393 public: | 439 public: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 // Performs deep copy on data. | 522 // Performs deep copy on data. |
477 SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data); | 523 SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data); |
478 | 524 |
479 // Use in conjunction with SetDataShallow() for shallow-copy on data. | 525 // Use in conjunction with SetDataShallow() for shallow-copy on data. |
480 explicit SpdyDataIR(SpdyStreamId stream_id); | 526 explicit SpdyDataIR(SpdyStreamId stream_id); |
481 | 527 |
482 virtual ~SpdyDataIR(); | 528 virtual ~SpdyDataIR(); |
483 | 529 |
484 base::StringPiece data() const { return data_; } | 530 base::StringPiece data() const { return data_; } |
485 | 531 |
| 532 bool pad_low() const { return pad_low_; } |
| 533 |
| 534 bool pad_high() const { return pad_high_; } |
| 535 |
| 536 int padding_payload_len() const { return padding_payload_len_; } |
| 537 |
| 538 void set_padding_len(int padding_len) { |
| 539 // The padding_len should be in (0, 65535 + 2]. |
| 540 // Note that SpdyFramer::GetDataFrameMaximumPayload() enforces the overall |
| 541 // payload size later so we actually can't pad more than 16375 bytes. |
| 542 DCHECK_GT(padding_len, 0); |
| 543 DCHECK_LT(padding_len, 65537); |
| 544 |
| 545 if (padding_len <= 256) { |
| 546 pad_low_ = true; |
| 547 --padding_len; |
| 548 } else { |
| 549 pad_low_ = pad_high_ = true; |
| 550 padding_len -= 2; |
| 551 } |
| 552 padding_payload_len_ = padding_len; |
| 553 } |
| 554 |
486 // Deep-copy of data (keep private copy). | 555 // Deep-copy of data (keep private copy). |
487 void SetDataDeep(const base::StringPiece& data) { | 556 void SetDataDeep(const base::StringPiece& data) { |
488 data_store_.reset(new std::string(data.data(), data.length())); | 557 data_store_.reset(new std::string(data.data(), data.length())); |
489 data_ = *(data_store_.get()); | 558 data_ = *(data_store_.get()); |
490 } | 559 } |
491 | 560 |
492 // Shallow-copy of data (do not keep private copy). | 561 // Shallow-copy of data (do not keep private copy). |
493 void SetDataShallow(const base::StringPiece& data) { | 562 void SetDataShallow(const base::StringPiece& data) { |
494 data_store_.reset(); | 563 data_store_.reset(); |
495 data_ = data; | 564 data_ = data; |
496 } | 565 } |
497 | 566 |
498 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE; | 567 virtual void Visit(SpdyFrameVisitor* visitor) const OVERRIDE; |
499 | 568 |
500 private: | 569 private: |
501 // Used to store data that this SpdyDataIR should own. | 570 // Used to store data that this SpdyDataIR should own. |
502 scoped_ptr<std::string> data_store_; | 571 scoped_ptr<std::string> data_store_; |
503 base::StringPiece data_; | 572 base::StringPiece data_; |
504 | 573 |
| 574 bool pad_low_; |
| 575 bool pad_high_; |
| 576 // padding_payload_len_ = desired padding length - len(padding length field). |
| 577 int padding_payload_len_; |
| 578 |
505 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); | 579 DISALLOW_COPY_AND_ASSIGN(SpdyDataIR); |
506 }; | 580 }; |
507 | 581 |
508 class NET_EXPORT_PRIVATE SpdySynStreamIR | 582 class NET_EXPORT_PRIVATE SpdySynStreamIR |
509 : public SpdyFrameWithNameValueBlockIR { | 583 : public SpdyFrameWithNameValueBlockIR { |
510 public: | 584 public: |
511 explicit SpdySynStreamIR(SpdyStreamId stream_id) | 585 explicit SpdySynStreamIR(SpdyStreamId stream_id) |
512 : SpdyFrameWithNameValueBlockIR(stream_id), | 586 : SpdyFrameWithNameValueBlockIR(stream_id), |
513 associated_to_stream_id_(0), | 587 associated_to_stream_id_(0), |
514 priority_(0), | 588 priority_(0), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 SpdySettingsIR(); | 668 SpdySettingsIR(); |
595 | 669 |
596 virtual ~SpdySettingsIR(); | 670 virtual ~SpdySettingsIR(); |
597 | 671 |
598 // Overwrites as appropriate. | 672 // Overwrites as appropriate. |
599 const ValueMap& values() const { return values_; } | 673 const ValueMap& values() const { return values_; } |
600 void AddSetting(SpdySettingsIds id, | 674 void AddSetting(SpdySettingsIds id, |
601 bool persist_value, | 675 bool persist_value, |
602 bool persisted, | 676 bool persisted, |
603 int32 value) { | 677 int32 value) { |
604 // TODO(hkhalil): DCHECK_LE(SETTINGS_UPLOAD_BANDWIDTH, id); | |
605 // TODO(hkhalil): DCHECK_GE(SETTINGS_INITIAL_WINDOW_SIZE, id); | |
606 values_[id].persist_value = persist_value; | 678 values_[id].persist_value = persist_value; |
607 values_[id].persisted = persisted; | 679 values_[id].persisted = persisted; |
608 values_[id].value = value; | 680 values_[id].value = value; |
609 } | 681 } |
610 | 682 |
611 bool clear_settings() const { return clear_settings_; } | 683 bool clear_settings() const { return clear_settings_; } |
612 void set_clear_settings(bool clear_settings) { | 684 void set_clear_settings(bool clear_settings) { |
613 clear_settings_ = clear_settings; | 685 clear_settings_ = clear_settings; |
614 } | 686 } |
615 bool is_ack() const { return is_ack_; } | 687 bool is_ack() const { return is_ack_; } |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 SpdyFrameVisitor() {} | 911 SpdyFrameVisitor() {} |
840 virtual ~SpdyFrameVisitor() {} | 912 virtual ~SpdyFrameVisitor() {} |
841 | 913 |
842 private: | 914 private: |
843 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 915 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
844 }; | 916 }; |
845 | 917 |
846 } // namespace net | 918 } // namespace net |
847 | 919 |
848 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 920 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
OLD | NEW |