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 #include "net/spdy/spdy_protocol.h" | 5 #include "net/spdy/spdy_protocol.h" |
6 | 6 |
7 namespace net { | 7 namespace net { |
8 | 8 |
9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( | 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( |
10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} | 10 SpdyStreamId stream_id) |
| 11 : SpdyFrameWithFinIR(stream_id) { |
| 12 } |
11 | 13 |
12 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() {} | 14 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() { |
| 15 } |
13 | 16 |
14 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data) | 17 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data) |
15 : SpdyFrameWithFinIR(stream_id), | 18 : SpdyFrameWithFinIR(stream_id), |
16 pad_low_(false), | 19 pad_low_(false), |
17 pad_high_(false), | 20 pad_high_(false), |
18 padding_payload_len_(0) { | 21 padding_payload_len_(0) { |
19 SetDataDeep(data); | 22 SetDataDeep(data); |
20 } | 23 } |
21 | 24 |
22 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id) | 25 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id) |
23 : SpdyFrameWithFinIR(stream_id), | 26 : SpdyFrameWithFinIR(stream_id), |
24 pad_low_(false), | 27 pad_low_(false), |
25 pad_high_(false), | 28 pad_high_(false), |
26 padding_payload_len_(0) {} | 29 padding_payload_len_(0) { |
| 30 } |
27 | 31 |
28 SpdyDataIR::~SpdyDataIR() {} | 32 SpdyDataIR::~SpdyDataIR() { |
| 33 } |
29 | 34 |
30 bool SpdyConstants::IsValidFrameType(SpdyMajorVersion version, | 35 bool SpdyConstants::IsValidFrameType(SpdyMajorVersion version, |
31 int frame_type_field) { | 36 int frame_type_field) { |
32 switch (version) { | 37 switch (version) { |
33 case SPDY2: | 38 case SPDY2: |
34 case SPDY3: | 39 case SPDY3: |
35 // SYN_STREAM is the first valid frame. | 40 // SYN_STREAM is the first valid frame. |
36 if (frame_type_field < SerializeFrameType(version, SYN_STREAM)) { | 41 if (frame_type_field < SerializeFrameType(version, SYN_STREAM)) { |
37 return false; | 42 return false; |
38 } | 43 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 return SETTINGS_INITIAL_WINDOW_SIZE; | 262 return SETTINGS_INITIAL_WINDOW_SIZE; |
258 } | 263 } |
259 break; | 264 break; |
260 } | 265 } |
261 | 266 |
262 LOG(DFATAL) << "Unhandled setting ID " << setting_id_field; | 267 LOG(DFATAL) << "Unhandled setting ID " << setting_id_field; |
263 return SETTINGS_UPLOAD_BANDWIDTH; | 268 return SETTINGS_UPLOAD_BANDWIDTH; |
264 } | 269 } |
265 | 270 |
266 int SpdyConstants::SerializeSettingId(SpdyMajorVersion version, | 271 int SpdyConstants::SerializeSettingId(SpdyMajorVersion version, |
267 SpdySettingsIds id) { | 272 SpdySettingsIds id) { |
268 switch (version) { | 273 switch (version) { |
269 case SPDY2: | 274 case SPDY2: |
270 case SPDY3: | 275 case SPDY3: |
271 switch (id) { | 276 switch (id) { |
272 case SETTINGS_UPLOAD_BANDWIDTH: | 277 case SETTINGS_UPLOAD_BANDWIDTH: |
273 return 1; | 278 return 1; |
274 case SETTINGS_DOWNLOAD_BANDWIDTH: | 279 case SETTINGS_DOWNLOAD_BANDWIDTH: |
275 return 2; | 280 return 2; |
276 case SETTINGS_ROUND_TRIP_TIME: | 281 case SETTINGS_ROUND_TRIP_TIME: |
277 return 3; | 282 return 3; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 return 7; | 444 return 7; |
440 case RST_STREAM_STREAM_IN_USE: | 445 case RST_STREAM_STREAM_IN_USE: |
441 return 8; | 446 return 8; |
442 case RST_STREAM_STREAM_ALREADY_CLOSED: | 447 case RST_STREAM_STREAM_ALREADY_CLOSED: |
443 return 9; | 448 return 9; |
444 case RST_STREAM_INVALID_CREDENTIALS: | 449 case RST_STREAM_INVALID_CREDENTIALS: |
445 return 10; | 450 return 10; |
446 case RST_STREAM_FRAME_TOO_LARGE: | 451 case RST_STREAM_FRAME_TOO_LARGE: |
447 return 11; | 452 return 11; |
448 default: | 453 default: |
449 LOG(DFATAL) << "Unhandled RST_STREAM status " | 454 LOG(DFATAL) << "Unhandled RST_STREAM status " << rst_stream_status; |
450 << rst_stream_status; | |
451 return -1; | 455 return -1; |
452 } | 456 } |
453 case SPDY4: | 457 case SPDY4: |
454 case SPDY5: | 458 case SPDY5: |
455 switch (rst_stream_status) { | 459 switch (rst_stream_status) { |
456 case RST_STREAM_PROTOCOL_ERROR: | 460 case RST_STREAM_PROTOCOL_ERROR: |
457 return 1; | 461 return 1; |
458 case RST_STREAM_INTERNAL_ERROR: | 462 case RST_STREAM_INTERNAL_ERROR: |
459 return 2; | 463 return 2; |
460 case RST_STREAM_FLOW_CONTROL_ERROR: | 464 case RST_STREAM_FLOW_CONTROL_ERROR: |
461 return 3; | 465 return 3; |
462 case RST_STREAM_STREAM_CLOSED: | 466 case RST_STREAM_STREAM_CLOSED: |
463 return 5; | 467 return 5; |
464 case RST_STREAM_FRAME_SIZE_ERROR: | 468 case RST_STREAM_FRAME_SIZE_ERROR: |
465 return 6; | 469 return 6; |
466 case RST_STREAM_REFUSED_STREAM: | 470 case RST_STREAM_REFUSED_STREAM: |
467 return 7; | 471 return 7; |
468 case RST_STREAM_CANCEL: | 472 case RST_STREAM_CANCEL: |
469 return 8; | 473 return 8; |
470 case RST_STREAM_CONNECT_ERROR: | 474 case RST_STREAM_CONNECT_ERROR: |
471 return 10; | 475 return 10; |
472 case RST_STREAM_ENHANCE_YOUR_CALM: | 476 case RST_STREAM_ENHANCE_YOUR_CALM: |
473 return 11; | 477 return 11; |
474 default: | 478 default: |
475 LOG(DFATAL) << "Unhandled RST_STREAM status " | 479 LOG(DFATAL) << "Unhandled RST_STREAM status " << rst_stream_status; |
476 << rst_stream_status; | |
477 return -1; | 480 return -1; |
478 } | 481 } |
479 } | 482 } |
480 LOG(DFATAL) << "Unhandled SPDY version " << version; | 483 LOG(DFATAL) << "Unhandled SPDY version " << version; |
481 return -1; | 484 return -1; |
482 } | 485 } |
483 | 486 |
484 bool SpdyConstants::IsValidGoAwayStatus(SpdyMajorVersion version, | 487 bool SpdyConstants::IsValidGoAwayStatus(SpdyMajorVersion version, |
485 int goaway_status_field) { | 488 int goaway_status_field) { |
486 switch (version) { | 489 switch (version) { |
487 case SPDY2: | 490 case SPDY2: |
488 case SPDY3: | 491 case SPDY3: |
489 // GOAWAY_OK is the first valid status. | 492 // GOAWAY_OK is the first valid status. |
490 if (goaway_status_field < SerializeGoAwayStatus(version, GOAWAY_OK)) { | 493 if (goaway_status_field < SerializeGoAwayStatus(version, GOAWAY_OK)) { |
491 return false; | 494 return false; |
492 } | 495 } |
493 | 496 |
494 // GOAWAY_INTERNAL_ERROR is the last valid status. | 497 // GOAWAY_INTERNAL_ERROR is the last valid status. |
495 if (goaway_status_field > SerializeGoAwayStatus(version, | 498 if (goaway_status_field > |
496 GOAWAY_INTERNAL_ERROR)) { | 499 SerializeGoAwayStatus(version, GOAWAY_INTERNAL_ERROR)) { |
497 return false; | 500 return false; |
498 } | 501 } |
499 | 502 |
500 return true; | 503 return true; |
501 case SPDY4: | 504 case SPDY4: |
502 case SPDY5: | 505 case SPDY5: |
503 // GOAWAY_NO_ERROR is the first valid status. | 506 // GOAWAY_NO_ERROR is the first valid status. |
504 if (goaway_status_field < SerializeGoAwayStatus(version, | 507 if (goaway_status_field < |
505 GOAWAY_NO_ERROR)) { | 508 SerializeGoAwayStatus(version, GOAWAY_NO_ERROR)) { |
506 return false; | 509 return false; |
507 } | 510 } |
508 | 511 |
509 // GOAWAY_INADEQUATE_SECURITY is the last valid status. | 512 // GOAWAY_INADEQUATE_SECURITY is the last valid status. |
510 if (goaway_status_field > | 513 if (goaway_status_field > |
511 SerializeGoAwayStatus(version, GOAWAY_INADEQUATE_SECURITY)) { | 514 SerializeGoAwayStatus(version, GOAWAY_INADEQUATE_SECURITY)) { |
512 return false; | 515 return false; |
513 } | 516 } |
514 | 517 |
515 return true; | 518 return true; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 case SPDY5: | 686 case SPDY5: |
684 return 8; | 687 return 8; |
685 } | 688 } |
686 LOG(DFATAL) << "Unhandled SPDY version."; | 689 LOG(DFATAL) << "Unhandled SPDY version."; |
687 return 0; | 690 return 0; |
688 } | 691 } |
689 | 692 |
690 size_t SpdyConstants::GetPrefixLength(SpdyFrameType type, | 693 size_t SpdyConstants::GetPrefixLength(SpdyFrameType type, |
691 SpdyMajorVersion version) { | 694 SpdyMajorVersion version) { |
692 if (type != DATA) { | 695 if (type != DATA) { |
693 return GetControlFrameHeaderSize(version); | 696 return GetControlFrameHeaderSize(version); |
694 } else { | 697 } else { |
695 return GetDataFrameMinimumSize(); | 698 return GetDataFrameMinimumSize(); |
696 } | 699 } |
697 } | 700 } |
698 | 701 |
699 size_t SpdyConstants::GetFrameMaximumSize(SpdyMajorVersion version) { | 702 size_t SpdyConstants::GetFrameMaximumSize(SpdyMajorVersion version) { |
700 if (version < SPDY4) { | 703 if (version < SPDY4) { |
701 // 24-bit length field plus eight-byte frame header. | 704 // 24-bit length field plus eight-byte frame header. |
702 return ((1<<24) - 1) + 8; | 705 return ((1 << 24) - 1) + 8; |
703 } else { | 706 } else { |
704 // 14-bit length field. | 707 // 14-bit length field. |
705 return (1<<14) - 1; | 708 return (1 << 14) - 1; |
706 } | 709 } |
707 } | 710 } |
708 | 711 |
709 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { | 712 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { |
710 return visitor->VisitData(*this); | 713 return visitor->VisitData(*this); |
711 } | 714 } |
712 | 715 |
713 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { | 716 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { |
714 return visitor->VisitSynStream(*this); | 717 return visitor->VisitSynStream(*this); |
715 } | 718 } |
716 | 719 |
717 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { | 720 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { |
718 return visitor->VisitSynReply(*this); | 721 return visitor->VisitSynReply(*this); |
719 } | 722 } |
720 | 723 |
721 SpdyRstStreamIR::SpdyRstStreamIR(SpdyStreamId stream_id, | 724 SpdyRstStreamIR::SpdyRstStreamIR(SpdyStreamId stream_id, |
722 SpdyRstStreamStatus status, | 725 SpdyRstStreamStatus status, |
723 base::StringPiece description) | 726 base::StringPiece description) |
724 : SpdyFrameWithStreamIdIR(stream_id), | 727 : SpdyFrameWithStreamIdIR(stream_id), description_(description) { |
725 description_(description) { | |
726 set_status(status); | 728 set_status(status); |
727 } | 729 } |
728 | 730 |
729 SpdyRstStreamIR::~SpdyRstStreamIR() {} | 731 SpdyRstStreamIR::~SpdyRstStreamIR() { |
| 732 } |
730 | 733 |
731 void SpdyRstStreamIR::Visit(SpdyFrameVisitor* visitor) const { | 734 void SpdyRstStreamIR::Visit(SpdyFrameVisitor* visitor) const { |
732 return visitor->VisitRstStream(*this); | 735 return visitor->VisitRstStream(*this); |
733 } | 736 } |
734 | 737 |
735 SpdySettingsIR::SpdySettingsIR() | 738 SpdySettingsIR::SpdySettingsIR() : clear_settings_(false), is_ack_(false) { |
736 : clear_settings_(false), | 739 } |
737 is_ack_(false) {} | |
738 | 740 |
739 SpdySettingsIR::~SpdySettingsIR() {} | 741 SpdySettingsIR::~SpdySettingsIR() { |
| 742 } |
740 | 743 |
741 void SpdySettingsIR::Visit(SpdyFrameVisitor* visitor) const { | 744 void SpdySettingsIR::Visit(SpdyFrameVisitor* visitor) const { |
742 return visitor->VisitSettings(*this); | 745 return visitor->VisitSettings(*this); |
743 } | 746 } |
744 | 747 |
745 void SpdyPingIR::Visit(SpdyFrameVisitor* visitor) const { | 748 void SpdyPingIR::Visit(SpdyFrameVisitor* visitor) const { |
746 return visitor->VisitPing(*this); | 749 return visitor->VisitPing(*this); |
747 } | 750 } |
748 | 751 |
749 SpdyGoAwayIR::SpdyGoAwayIR(SpdyStreamId last_good_stream_id, | 752 SpdyGoAwayIR::SpdyGoAwayIR(SpdyStreamId last_good_stream_id, |
750 SpdyGoAwayStatus status, | 753 SpdyGoAwayStatus status, |
751 const base::StringPiece& description) | 754 const base::StringPiece& description) |
752 : description_(description) { | 755 : description_(description) { |
753 set_last_good_stream_id(last_good_stream_id); | 756 set_last_good_stream_id(last_good_stream_id); |
754 set_status(status); | 757 set_status(status); |
755 } | 758 } |
756 | 759 |
757 SpdyGoAwayIR::~SpdyGoAwayIR() {} | 760 SpdyGoAwayIR::~SpdyGoAwayIR() { |
| 761 } |
758 | 762 |
759 const base::StringPiece& SpdyGoAwayIR::description() const { | 763 const base::StringPiece& SpdyGoAwayIR::description() const { |
760 return description_; | 764 return description_; |
761 } | 765 } |
762 | 766 |
763 void SpdyGoAwayIR::Visit(SpdyFrameVisitor* visitor) const { | 767 void SpdyGoAwayIR::Visit(SpdyFrameVisitor* visitor) const { |
764 return visitor->VisitGoAway(*this); | 768 return visitor->VisitGoAway(*this); |
765 } | 769 } |
766 | 770 |
767 void SpdyHeadersIR::Visit(SpdyFrameVisitor* visitor) const { | 771 void SpdyHeadersIR::Visit(SpdyFrameVisitor* visitor) const { |
(...skipping 10 matching lines...) Expand all Loading... |
778 | 782 |
779 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { | 783 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { |
780 return visitor->VisitPushPromise(*this); | 784 return visitor->VisitPushPromise(*this); |
781 } | 785 } |
782 | 786 |
783 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { | 787 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { |
784 return visitor->VisitContinuation(*this); | 788 return visitor->VisitContinuation(*this); |
785 } | 789 } |
786 | 790 |
787 } // namespace net | 791 } // namespace net |
OLD | NEW |