Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: net/spdy/spdy_protocol.cc

Issue 247243003: SPDY: Use SpdyMajorVersion rather than ints for SPDY version number. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Also include cr/64899106 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | net/spdy/spdy_protocol_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) : SpdyFrameWithFinIR(stream_id) {}
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return false; 42 return false;
43 } 43 }
44 44
45 // The valid range is non-contiguous. 45 // The valid range is non-contiguous.
46 if (frame_type_field == NOOP) { 46 if (frame_type_field == NOOP) {
47 return false; 47 return false;
48 } 48 }
49 49
50 return true; 50 return true;
51 case SPDY4: 51 case SPDY4:
52 case SPDY5:
52 // DATA is the first valid frame. 53 // DATA is the first valid frame.
53 if (frame_type_field < SerializeFrameType(version, DATA)) { 54 if (frame_type_field < SerializeFrameType(version, DATA)) {
54 return false; 55 return false;
55 } 56 }
56 57
57 // BLOCKED is the last valid frame. 58 // BLOCKED is the last valid frame.
58 if (frame_type_field > SerializeFrameType(version, BLOCKED)) { 59 if (frame_type_field > SerializeFrameType(version, BLOCKED)) {
59 return false; 60 return false;
60 } 61 }
61 62
(...skipping 22 matching lines...) Expand all
84 return PING; 85 return PING;
85 case 7: 86 case 7:
86 return GOAWAY; 87 return GOAWAY;
87 case 8: 88 case 8:
88 return HEADERS; 89 return HEADERS;
89 case 9: 90 case 9:
90 return WINDOW_UPDATE; 91 return WINDOW_UPDATE;
91 } 92 }
92 break; 93 break;
93 case SPDY4: 94 case SPDY4:
95 case SPDY5:
94 switch (frame_type_field) { 96 switch (frame_type_field) {
95 case 0: 97 case 0:
96 return DATA; 98 return DATA;
97 case 1: 99 case 1:
98 return HEADERS; 100 return HEADERS;
99 // TODO(hkhalil): Add PRIORITY. 101 // TODO(hkhalil): Add PRIORITY.
100 case 3: 102 case 3:
101 return RST_STREAM; 103 return RST_STREAM;
102 case 4: 104 case 4:
103 return SETTINGS; 105 return SETTINGS;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return 7; 143 return 7;
142 case HEADERS: 144 case HEADERS:
143 return 8; 145 return 8;
144 case WINDOW_UPDATE: 146 case WINDOW_UPDATE:
145 return 9; 147 return 9;
146 default: 148 default:
147 LOG(DFATAL) << "Serializing unhandled frame type " << frame_type; 149 LOG(DFATAL) << "Serializing unhandled frame type " << frame_type;
148 return -1; 150 return -1;
149 } 151 }
150 case SPDY4: 152 case SPDY4:
153 case SPDY5:
151 switch (frame_type) { 154 switch (frame_type) {
152 case DATA: 155 case DATA:
153 return 0; 156 return 0;
154 case HEADERS: 157 case HEADERS:
155 return 1; 158 return 1;
156 // TODO(hkhalil): Add PRIORITY. 159 // TODO(hkhalil): Add PRIORITY.
157 case RST_STREAM: 160 case RST_STREAM:
158 return 3; 161 return 3;
159 case SETTINGS: 162 case SETTINGS:
160 return 4; 163 return 4;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 195 }
193 196
194 // INITIAL_WINDOW_SIZE is the last valid setting id. 197 // INITIAL_WINDOW_SIZE is the last valid setting id.
195 if (setting_id_field > 198 if (setting_id_field >
196 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) { 199 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) {
197 return false; 200 return false;
198 } 201 }
199 202
200 return true; 203 return true;
201 case SPDY4: 204 case SPDY4:
205 case SPDY5:
202 // HEADER_TABLE_SIZE is the first valid setting id. 206 // HEADER_TABLE_SIZE is the first valid setting id.
203 if (setting_id_field < 207 if (setting_id_field <
204 SerializeSettingId(version, SETTINGS_HEADER_TABLE_SIZE)) { 208 SerializeSettingId(version, SETTINGS_HEADER_TABLE_SIZE)) {
205 return false; 209 return false;
206 } 210 }
207 211
208 // INITIAL_WINDOW_SIZE is the last valid setting id. 212 // INITIAL_WINDOW_SIZE is the last valid setting id.
209 if (setting_id_field > 213 if (setting_id_field >
210 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) { 214 SerializeSettingId(version, SETTINGS_INITIAL_WINDOW_SIZE)) {
211 return false; 215 return false;
(...skipping 22 matching lines...) Expand all
234 return SETTINGS_MAX_CONCURRENT_STREAMS; 238 return SETTINGS_MAX_CONCURRENT_STREAMS;
235 case 5: 239 case 5:
236 return SETTINGS_CURRENT_CWND; 240 return SETTINGS_CURRENT_CWND;
237 case 6: 241 case 6:
238 return SETTINGS_DOWNLOAD_RETRANS_RATE; 242 return SETTINGS_DOWNLOAD_RETRANS_RATE;
239 case 7: 243 case 7:
240 return SETTINGS_INITIAL_WINDOW_SIZE; 244 return SETTINGS_INITIAL_WINDOW_SIZE;
241 } 245 }
242 break; 246 break;
243 case SPDY4: 247 case SPDY4:
248 case SPDY5:
244 switch (setting_id_field) { 249 switch (setting_id_field) {
245 case 1: 250 case 1:
246 return SETTINGS_HEADER_TABLE_SIZE; 251 return SETTINGS_HEADER_TABLE_SIZE;
247 case 2: 252 case 2:
248 return SETTINGS_ENABLE_PUSH; 253 return SETTINGS_ENABLE_PUSH;
249 case 3: 254 case 3:
250 return SETTINGS_MAX_CONCURRENT_STREAMS; 255 return SETTINGS_MAX_CONCURRENT_STREAMS;
251 case 4: 256 case 4:
252 return SETTINGS_INITIAL_WINDOW_SIZE; 257 return SETTINGS_INITIAL_WINDOW_SIZE;
253 } 258 }
(...skipping 22 matching lines...) Expand all
276 return 5; 281 return 5;
277 case SETTINGS_DOWNLOAD_RETRANS_RATE: 282 case SETTINGS_DOWNLOAD_RETRANS_RATE:
278 return 6; 283 return 6;
279 case SETTINGS_INITIAL_WINDOW_SIZE: 284 case SETTINGS_INITIAL_WINDOW_SIZE:
280 return 7; 285 return 7;
281 default: 286 default:
282 LOG(DFATAL) << "Serializing unhandled setting id " << id; 287 LOG(DFATAL) << "Serializing unhandled setting id " << id;
283 return -1; 288 return -1;
284 } 289 }
285 case SPDY4: 290 case SPDY4:
291 case SPDY5:
286 switch (id) { 292 switch (id) {
287 case SETTINGS_HEADER_TABLE_SIZE: 293 case SETTINGS_HEADER_TABLE_SIZE:
288 return 1; 294 return 1;
289 case SETTINGS_ENABLE_PUSH: 295 case SETTINGS_ENABLE_PUSH:
290 return 2; 296 return 2;
291 case SETTINGS_MAX_CONCURRENT_STREAMS: 297 case SETTINGS_MAX_CONCURRENT_STREAMS:
292 return 3; 298 return 3;
293 case SETTINGS_INITIAL_WINDOW_SIZE: 299 case SETTINGS_INITIAL_WINDOW_SIZE:
294 return 4; 300 return 4;
295 default: 301 default:
(...skipping 17 matching lines...) Expand all
313 } 319 }
314 320
315 // FRAME_TOO_LARGE is the valid last status code. 321 // FRAME_TOO_LARGE is the valid last status code.
316 if (rst_stream_status_field > 322 if (rst_stream_status_field >
317 SerializeRstStreamStatus(version, RST_STREAM_FRAME_TOO_LARGE)) { 323 SerializeRstStreamStatus(version, RST_STREAM_FRAME_TOO_LARGE)) {
318 return false; 324 return false;
319 } 325 }
320 326
321 return true; 327 return true;
322 case SPDY4: 328 case SPDY4:
329 case SPDY5:
323 // NO_ERROR is the first valid status code. 330 // NO_ERROR is the first valid status code.
324 if (rst_stream_status_field < 331 if (rst_stream_status_field <
325 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) { 332 SerializeRstStreamStatus(version, RST_STREAM_PROTOCOL_ERROR)) {
326 return false; 333 return false;
327 } 334 }
328 335
329 // TODO(hkhalil): Omit COMPRESSION_ERROR and SETTINGS_TIMEOUT 336 // TODO(hkhalil): Omit COMPRESSION_ERROR and SETTINGS_TIMEOUT
330 /* 337 /*
331 // This works because GOAWAY and RST_STREAM share a namespace. 338 // This works because GOAWAY and RST_STREAM share a namespace.
332 if (rst_stream_status_field == 339 if (rst_stream_status_field ==
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 return RST_STREAM_STREAM_IN_USE; 379 return RST_STREAM_STREAM_IN_USE;
373 case 9: 380 case 9:
374 return RST_STREAM_STREAM_ALREADY_CLOSED; 381 return RST_STREAM_STREAM_ALREADY_CLOSED;
375 case 10: 382 case 10:
376 return RST_STREAM_INVALID_CREDENTIALS; 383 return RST_STREAM_INVALID_CREDENTIALS;
377 case 11: 384 case 11:
378 return RST_STREAM_FRAME_TOO_LARGE; 385 return RST_STREAM_FRAME_TOO_LARGE;
379 } 386 }
380 break; 387 break;
381 case SPDY4: 388 case SPDY4:
389 case SPDY5:
382 switch (rst_stream_status_field) { 390 switch (rst_stream_status_field) {
383 case 1: 391 case 1:
384 return RST_STREAM_PROTOCOL_ERROR; 392 return RST_STREAM_PROTOCOL_ERROR;
385 case 2: 393 case 2:
386 return RST_STREAM_INTERNAL_ERROR; 394 return RST_STREAM_INTERNAL_ERROR;
387 case 3: 395 case 3:
388 return RST_STREAM_FLOW_CONTROL_ERROR; 396 return RST_STREAM_FLOW_CONTROL_ERROR;
389 case 5: 397 case 5:
390 return RST_STREAM_STREAM_CLOSED; 398 return RST_STREAM_STREAM_CLOSED;
391 case 6: 399 case 6:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 case RST_STREAM_INVALID_CREDENTIALS: 442 case RST_STREAM_INVALID_CREDENTIALS:
435 return 10; 443 return 10;
436 case RST_STREAM_FRAME_TOO_LARGE: 444 case RST_STREAM_FRAME_TOO_LARGE:
437 return 11; 445 return 11;
438 default: 446 default:
439 LOG(DFATAL) << "Unhandled RST_STREAM status " 447 LOG(DFATAL) << "Unhandled RST_STREAM status "
440 << rst_stream_status; 448 << rst_stream_status;
441 return -1; 449 return -1;
442 } 450 }
443 case SPDY4: 451 case SPDY4:
452 case SPDY5:
444 switch (rst_stream_status) { 453 switch (rst_stream_status) {
445 case RST_STREAM_PROTOCOL_ERROR: 454 case RST_STREAM_PROTOCOL_ERROR:
446 return 1; 455 return 1;
447 case RST_STREAM_INTERNAL_ERROR: 456 case RST_STREAM_INTERNAL_ERROR:
448 return 2; 457 return 2;
449 case RST_STREAM_FLOW_CONTROL_ERROR: 458 case RST_STREAM_FLOW_CONTROL_ERROR:
450 return 3; 459 return 3;
451 case RST_STREAM_STREAM_CLOSED: 460 case RST_STREAM_STREAM_CLOSED:
452 return 5; 461 return 5;
453 case RST_STREAM_FRAME_SIZE_ERROR: 462 case RST_STREAM_FRAME_SIZE_ERROR:
(...skipping 25 matching lines...) Expand all
479 } 488 }
480 489
481 // GOAWAY_INTERNAL_ERROR is the last valid status. 490 // GOAWAY_INTERNAL_ERROR is the last valid status.
482 if (goaway_status_field > SerializeGoAwayStatus(version, 491 if (goaway_status_field > SerializeGoAwayStatus(version,
483 GOAWAY_INTERNAL_ERROR)) { 492 GOAWAY_INTERNAL_ERROR)) {
484 return false; 493 return false;
485 } 494 }
486 495
487 return true; 496 return true;
488 case SPDY4: 497 case SPDY4:
498 case SPDY5:
489 // GOAWAY_NO_ERROR is the first valid status. 499 // GOAWAY_NO_ERROR is the first valid status.
490 if (goaway_status_field < SerializeGoAwayStatus(version, 500 if (goaway_status_field < SerializeGoAwayStatus(version,
491 GOAWAY_NO_ERROR)) { 501 GOAWAY_NO_ERROR)) {
492 return false; 502 return false;
493 } 503 }
494 504
495 // GOAWAY_INADEQUATE_SECURITY is the last valid status. 505 // GOAWAY_INADEQUATE_SECURITY is the last valid status.
496 if (goaway_status_field > 506 if (goaway_status_field >
497 SerializeGoAwayStatus(version, GOAWAY_INADEQUATE_SECURITY)) { 507 SerializeGoAwayStatus(version, GOAWAY_INADEQUATE_SECURITY)) {
498 return false; 508 return false;
(...skipping 11 matching lines...) Expand all
510 switch (goaway_status_field) { 520 switch (goaway_status_field) {
511 case 0: 521 case 0:
512 return GOAWAY_OK; 522 return GOAWAY_OK;
513 case 1: 523 case 1:
514 return GOAWAY_PROTOCOL_ERROR; 524 return GOAWAY_PROTOCOL_ERROR;
515 case 2: 525 case 2:
516 return GOAWAY_INTERNAL_ERROR; 526 return GOAWAY_INTERNAL_ERROR;
517 } 527 }
518 break; 528 break;
519 case SPDY4: 529 case SPDY4:
530 case SPDY5:
520 switch (goaway_status_field) { 531 switch (goaway_status_field) {
521 case 0: 532 case 0:
522 return GOAWAY_NO_ERROR; 533 return GOAWAY_NO_ERROR;
523 case 1: 534 case 1:
524 return GOAWAY_PROTOCOL_ERROR; 535 return GOAWAY_PROTOCOL_ERROR;
525 case 2: 536 case 2:
526 return GOAWAY_INTERNAL_ERROR; 537 return GOAWAY_INTERNAL_ERROR;
527 case 3: 538 case 3:
528 return GOAWAY_FLOW_CONTROL_ERROR; 539 return GOAWAY_FLOW_CONTROL_ERROR;
529 case 4: 540 case 4:
(...skipping 15 matching lines...) Expand all
545 case 12: 556 case 12:
546 return GOAWAY_INADEQUATE_SECURITY; 557 return GOAWAY_INADEQUATE_SECURITY;
547 } 558 }
548 break; 559 break;
549 } 560 }
550 561
551 LOG(DFATAL) << "Unhandled GOAWAY status " << goaway_status_field; 562 LOG(DFATAL) << "Unhandled GOAWAY status " << goaway_status_field;
552 return GOAWAY_PROTOCOL_ERROR; 563 return GOAWAY_PROTOCOL_ERROR;
553 } 564 }
554 565
566 SpdyMajorVersion SpdyConstants::ParseMajorVersion(int version_number) {
567 switch (version_number) {
568 case 2:
569 return SPDY2;
570 case 3:
571 return SPDY3;
572 case 4:
573 return SPDY4;
574 case 5:
575 return SPDY5;
576 default:
577 LOG(DFATAL) << "Unsupported SPDY version number: " << version_number;
578 return SPDY3;
579 }
580 }
581
582 int SpdyConstants::SerializeMajorVersion(SpdyMajorVersion version) {
583 switch (version) {
584 case SPDY2:
585 return 2;
586 case SPDY3:
587 return 3;
588 case SPDY4:
589 return 4;
590 case SPDY5:
591 return 5;
592 default:
593 LOG(DFATAL) << "Unsupported SPDY major version: " << version;
594 return -1;
595 }
596 }
597
598 std::string SpdyConstants::GetVersionString(SpdyMajorVersion version) {
599 switch (version) {
600 case SPDY2:
601 return "spdy/2";
602 case SPDY3:
603 return "spdy/3";
604 case SPDY4:
605 return "spdy/4";
606 case SPDY5:
607 return "spdy/5";
608 default:
609 LOG(DFATAL) << "Unsupported SPDY major version: " << version;
610 return "spdy/3";
611 }
612 }
613
555 int SpdyConstants::SerializeGoAwayStatus(SpdyMajorVersion version, 614 int SpdyConstants::SerializeGoAwayStatus(SpdyMajorVersion version,
556 SpdyGoAwayStatus status) { 615 SpdyGoAwayStatus status) {
557 switch (version) { 616 switch (version) {
558 case SPDY2: 617 case SPDY2:
559 case SPDY3: 618 case SPDY3:
560 switch (status) { 619 switch (status) {
561 case GOAWAY_OK: 620 case GOAWAY_OK:
562 return 0; 621 return 0;
563 case GOAWAY_PROTOCOL_ERROR: 622 case GOAWAY_PROTOCOL_ERROR:
564 return 1; 623 return 1;
565 case GOAWAY_INTERNAL_ERROR: 624 case GOAWAY_INTERNAL_ERROR:
566 return 2; 625 return 2;
567 default: 626 default:
568 LOG(DFATAL) << "Serializing unhandled GOAWAY status " << status; 627 LOG(DFATAL) << "Serializing unhandled GOAWAY status " << status;
569 return -1; 628 return -1;
570 } 629 }
571 case SPDY4: 630 case SPDY4:
631 case SPDY5:
572 switch (status) { 632 switch (status) {
573 case GOAWAY_NO_ERROR: 633 case GOAWAY_NO_ERROR:
574 return 0; 634 return 0;
575 case GOAWAY_PROTOCOL_ERROR: 635 case GOAWAY_PROTOCOL_ERROR:
576 return 1; 636 return 1;
577 case GOAWAY_INTERNAL_ERROR: 637 case GOAWAY_INTERNAL_ERROR:
578 return 2; 638 return 2;
579 case GOAWAY_FLOW_CONTROL_ERROR: 639 case GOAWAY_FLOW_CONTROL_ERROR:
580 return 3; 640 return 3;
581 case GOAWAY_SETTINGS_TIMEOUT: 641 case GOAWAY_SETTINGS_TIMEOUT:
(...skipping 23 matching lines...) Expand all
605 665
606 size_t SpdyConstants::GetDataFrameMinimumSize() { 666 size_t SpdyConstants::GetDataFrameMinimumSize() {
607 return 8; 667 return 8;
608 } 668 }
609 669
610 size_t SpdyConstants::GetControlFrameHeaderSize(SpdyMajorVersion version) { 670 size_t SpdyConstants::GetControlFrameHeaderSize(SpdyMajorVersion version) {
611 switch (version) { 671 switch (version) {
612 case SPDY2: 672 case SPDY2:
613 case SPDY3: 673 case SPDY3:
614 case SPDY4: 674 case SPDY4:
675 case SPDY5:
615 return 8; 676 return 8;
616 } 677 }
617 LOG(DFATAL) << "Unhandled SPDY version."; 678 LOG(DFATAL) << "Unhandled SPDY version.";
618 return 0; 679 return 0;
619 } 680 }
620 681
621 size_t SpdyConstants::GetPrefixLength(SpdyFrameType type, 682 size_t SpdyConstants::GetPrefixLength(SpdyFrameType type,
622 SpdyMajorVersion version) { 683 SpdyMajorVersion version) {
623 if (type != DATA) { 684 if (type != DATA) {
624 return GetControlFrameHeaderSize(version); 685 return GetControlFrameHeaderSize(version);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 770
710 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { 771 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const {
711 return visitor->VisitPushPromise(*this); 772 return visitor->VisitPushPromise(*this);
712 } 773 }
713 774
714 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { 775 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const {
715 return visitor->VisitContinuation(*this); 776 return visitor->VisitContinuation(*this);
716 } 777 }
717 778
718 } // namespace net 779 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | net/spdy/spdy_protocol_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698