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

Side by Side Diff: net/quic/quic_connection.cc

Issue 968513002: Land Recent QUIC Changes until 2/21/2015. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed const from members of TransmissionInfo struct. Created 5 years, 9 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
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_stats.h » ('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/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <sys/types.h> 8 #include <sys/types.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 received_packet_manager_(&stats_), 236 received_packet_manager_(&stats_),
237 ack_queued_(false), 237 ack_queued_(false),
238 num_packets_received_since_last_ack_sent_(0), 238 num_packets_received_since_last_ack_sent_(0),
239 stop_waiting_count_(0), 239 stop_waiting_count_(0),
240 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), 240 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))),
241 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), 241 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))),
242 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), 242 send_alarm_(helper->CreateAlarm(new SendAlarm(this))),
243 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), 243 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))),
244 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), 244 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))),
245 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), 245 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))),
246 visitor_(nullptr),
247 debug_visitor_(nullptr),
246 packet_generator_(connection_id_, &framer_, random_generator_, this), 248 packet_generator_(connection_id_, &framer_, random_generator_, this),
247 fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))), 249 fec_alarm_(helper->CreateAlarm(new FecAlarm(&packet_generator_))),
248 idle_network_timeout_(QuicTime::Delta::Infinite()), 250 idle_network_timeout_(QuicTime::Delta::Infinite()),
249 overall_connection_timeout_(QuicTime::Delta::Infinite()), 251 overall_connection_timeout_(QuicTime::Delta::Infinite()),
250 time_of_last_received_packet_(clock_->ApproximateNow()), 252 time_of_last_received_packet_(clock_->ApproximateNow()),
251 time_of_last_sent_new_packet_(clock_->ApproximateNow()), 253 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
252 sequence_number_of_last_sent_packet_(0), 254 sequence_number_of_last_sent_packet_(0),
253 sent_packet_manager_( 255 sent_packet_manager_(
254 is_server, 256 is_server,
255 clock_, 257 clock_,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 last_window_update_frames_.empty() && 369 last_window_update_frames_.empty() &&
368 last_blocked_frames_.empty() && 370 last_blocked_frames_.empty() &&
369 last_ping_frames_.empty() && 371 last_ping_frames_.empty() &&
370 last_close_frames_.empty()); 372 last_close_frames_.empty());
371 last_packet_decrypted_ = false; 373 last_packet_decrypted_ = false;
372 last_packet_revived_ = false; 374 last_packet_revived_ = false;
373 } 375 }
374 376
375 void QuicConnection::OnPublicResetPacket( 377 void QuicConnection::OnPublicResetPacket(
376 const QuicPublicResetPacket& packet) { 378 const QuicPublicResetPacket& packet) {
377 if (debug_visitor_.get() != nullptr) { 379 if (debug_visitor_ != nullptr) {
378 debug_visitor_->OnPublicResetPacket(packet); 380 debug_visitor_->OnPublicResetPacket(packet);
379 } 381 }
380 CloseConnection(QUIC_PUBLIC_RESET, true); 382 CloseConnection(QUIC_PUBLIC_RESET, true);
381 383
382 DVLOG(1) << ENDPOINT << "Connection " << connection_id() 384 DVLOG(1) << ENDPOINT << "Connection " << connection_id()
383 << " closed via QUIC_PUBLIC_RESET from peer."; 385 << " closed via QUIC_PUBLIC_RESET from peer.";
384 } 386 }
385 387
386 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) { 388 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) {
387 DVLOG(1) << ENDPOINT << "Received packet with mismatched version " 389 DVLOG(1) << ENDPOINT << "Received packet with mismatched version "
388 << received_version; 390 << received_version;
389 // TODO(satyamshekhar): Implement no server state in this mode. 391 // TODO(satyamshekhar): Implement no server state in this mode.
390 if (!is_server_) { 392 if (!is_server_) {
391 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. " 393 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. "
392 << "Closing connection."; 394 << "Closing connection.";
393 CloseConnection(QUIC_INTERNAL_ERROR, false); 395 CloseConnection(QUIC_INTERNAL_ERROR, false);
394 return false; 396 return false;
395 } 397 }
396 DCHECK_NE(version(), received_version); 398 DCHECK_NE(version(), received_version);
397 399
398 if (debug_visitor_.get() != nullptr) { 400 if (debug_visitor_ != nullptr) {
399 debug_visitor_->OnProtocolVersionMismatch(received_version); 401 debug_visitor_->OnProtocolVersionMismatch(received_version);
400 } 402 }
401 403
402 switch (version_negotiation_state_) { 404 switch (version_negotiation_state_) {
403 case START_NEGOTIATION: 405 case START_NEGOTIATION:
404 if (!framer_.IsSupportedVersion(received_version)) { 406 if (!framer_.IsSupportedVersion(received_version)) {
405 SendVersionNegotiationPacket(); 407 SendVersionNegotiationPacket();
406 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; 408 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS;
407 return false; 409 return false;
408 } 410 }
(...skipping 10 matching lines...) Expand all
419 // Might be old packets that were sent by the client before the version 421 // Might be old packets that were sent by the client before the version
420 // was negotiated. Drop these. 422 // was negotiated. Drop these.
421 return false; 423 return false;
422 424
423 default: 425 default:
424 DCHECK(false); 426 DCHECK(false);
425 } 427 }
426 428
427 version_negotiation_state_ = NEGOTIATED_VERSION; 429 version_negotiation_state_ = NEGOTIATED_VERSION;
428 visitor_->OnSuccessfulVersionNegotiation(received_version); 430 visitor_->OnSuccessfulVersionNegotiation(received_version);
429 if (debug_visitor_.get() != nullptr) { 431 if (debug_visitor_ != nullptr) {
430 debug_visitor_->OnSuccessfulVersionNegotiation(received_version); 432 debug_visitor_->OnSuccessfulVersionNegotiation(received_version);
431 } 433 }
432 DVLOG(1) << ENDPOINT << "version negotiated " << received_version; 434 DVLOG(1) << ENDPOINT << "version negotiated " << received_version;
433 435
434 // Store the new version. 436 // Store the new version.
435 framer_.set_version(received_version); 437 framer_.set_version(received_version);
436 438
437 // TODO(satyamshekhar): Store the sequence number of this packet and close the 439 // TODO(satyamshekhar): Store the sequence number of this packet and close the
438 // connection if we ever received a packet with incorrect version and whose 440 // connection if we ever received a packet with incorrect version and whose
439 // sequence number is greater. 441 // sequence number is greater.
440 return true; 442 return true;
441 } 443 }
442 444
443 // Handles version negotiation for client connection. 445 // Handles version negotiation for client connection.
444 void QuicConnection::OnVersionNegotiationPacket( 446 void QuicConnection::OnVersionNegotiationPacket(
445 const QuicVersionNegotiationPacket& packet) { 447 const QuicVersionNegotiationPacket& packet) {
446 if (is_server_) { 448 if (is_server_) {
447 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket." 449 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket."
448 << " Closing connection."; 450 << " Closing connection.";
449 CloseConnection(QUIC_INTERNAL_ERROR, false); 451 CloseConnection(QUIC_INTERNAL_ERROR, false);
450 return; 452 return;
451 } 453 }
452 if (debug_visitor_.get() != nullptr) { 454 if (debug_visitor_ != nullptr) {
453 debug_visitor_->OnVersionNegotiationPacket(packet); 455 debug_visitor_->OnVersionNegotiationPacket(packet);
454 } 456 }
455 457
456 if (version_negotiation_state_ != START_NEGOTIATION) { 458 if (version_negotiation_state_ != START_NEGOTIATION) {
457 // Possibly a duplicate version negotiation packet. 459 // Possibly a duplicate version negotiation packet.
458 return; 460 return;
459 } 461 }
460 462
461 if (std::find(packet.versions.begin(), 463 if (std::find(packet.versions.begin(),
462 packet.versions.end(), version()) != 464 packet.versions.end(), version()) !=
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 last_packet_decrypted_ = true; 500 last_packet_decrypted_ = true;
499 // If this packet was foward-secure encrypted and the forward-secure encrypter 501 // If this packet was foward-secure encrypted and the forward-secure encrypter
500 // is not being used, start using it. 502 // is not being used, start using it.
501 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && 503 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
502 has_forward_secure_encrypter_ && level == ENCRYPTION_FORWARD_SECURE) { 504 has_forward_secure_encrypter_ && level == ENCRYPTION_FORWARD_SECURE) {
503 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 505 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
504 } 506 }
505 } 507 }
506 508
507 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { 509 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) {
508 if (debug_visitor_.get() != nullptr) { 510 if (debug_visitor_ != nullptr) {
509 debug_visitor_->OnPacketHeader(header); 511 debug_visitor_->OnPacketHeader(header);
510 } 512 }
511 513
512 if (!ProcessValidatedPacket()) { 514 if (!ProcessValidatedPacket()) {
513 return false; 515 return false;
514 } 516 }
515 517
516 // Will be decrement below if we fall through to return true; 518 // Will be decrement below if we fall through to return true;
517 ++stats_.packets_dropped; 519 ++stats_.packets_dropped;
518 520
519 if (header.public_header.connection_id != connection_id_) { 521 if (header.public_header.connection_id != connection_id_) {
520 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " 522 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: "
521 << header.public_header.connection_id << " instead of " 523 << header.public_header.connection_id << " instead of "
522 << connection_id_; 524 << connection_id_;
523 if (debug_visitor_.get() != nullptr) { 525 if (debug_visitor_ != nullptr) {
524 debug_visitor_->OnIncorrectConnectionId( 526 debug_visitor_->OnIncorrectConnectionId(
525 header.public_header.connection_id); 527 header.public_header.connection_id);
526 } 528 }
527 return false; 529 return false;
528 } 530 }
529 531
530 if (!Near(header.packet_sequence_number, 532 if (!Near(header.packet_sequence_number,
531 last_header_.packet_sequence_number)) { 533 last_header_.packet_sequence_number)) {
532 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number 534 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number
533 << " out of bounds. Discarding"; 535 << " out of bounds. Discarding";
534 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, 536 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER,
535 "Packet sequence number out of bounds"); 537 "Packet sequence number out of bounds");
536 return false; 538 return false;
537 } 539 }
538 540
539 // If this packet has already been seen, or that the sender 541 // If this packet has already been seen, or that the sender
540 // has told us will not be retransmitted, then stop processing the packet. 542 // has told us will not be retransmitted, then stop processing the packet.
541 if (!received_packet_manager_.IsAwaitingPacket( 543 if (!received_packet_manager_.IsAwaitingPacket(
542 header.packet_sequence_number)) { 544 header.packet_sequence_number)) {
543 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number 545 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number
544 << " no longer being waited for. Discarding."; 546 << " no longer being waited for. Discarding.";
545 if (debug_visitor_.get() != nullptr) { 547 if (debug_visitor_ != nullptr) {
546 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number); 548 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number);
547 } 549 }
548 return false; 550 return false;
549 } 551 }
550 552
551 if (version_negotiation_state_ != NEGOTIATED_VERSION) { 553 if (version_negotiation_state_ != NEGOTIATED_VERSION) {
552 if (is_server_) { 554 if (is_server_) {
553 if (!header.public_header.version_flag) { 555 if (!header.public_header.version_flag) {
554 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number 556 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number
555 << " without version flag before version negotiated."; 557 << " without version flag before version negotiated.";
556 // Packets should have the version flag till version negotiation is 558 // Packets should have the version flag till version negotiation is
557 // done. 559 // done.
558 CloseConnection(QUIC_INVALID_VERSION, false); 560 CloseConnection(QUIC_INVALID_VERSION, false);
559 return false; 561 return false;
560 } else { 562 } else {
561 DCHECK_EQ(1u, header.public_header.versions.size()); 563 DCHECK_EQ(1u, header.public_header.versions.size());
562 DCHECK_EQ(header.public_header.versions[0], version()); 564 DCHECK_EQ(header.public_header.versions[0], version());
563 version_negotiation_state_ = NEGOTIATED_VERSION; 565 version_negotiation_state_ = NEGOTIATED_VERSION;
564 visitor_->OnSuccessfulVersionNegotiation(version()); 566 visitor_->OnSuccessfulVersionNegotiation(version());
565 if (debug_visitor_.get() != nullptr) { 567 if (debug_visitor_ != nullptr) {
566 debug_visitor_->OnSuccessfulVersionNegotiation(version()); 568 debug_visitor_->OnSuccessfulVersionNegotiation(version());
567 } 569 }
568 } 570 }
569 } else { 571 } else {
570 DCHECK(!header.public_header.version_flag); 572 DCHECK(!header.public_header.version_flag);
571 // If the client gets a packet without the version flag from the server 573 // If the client gets a packet without the version flag from the server
572 // it should stop sending version since the version negotiation is done. 574 // it should stop sending version since the version negotiation is done.
573 packet_generator_.StopSendingVersion(); 575 packet_generator_.StopSendingVersion();
574 version_negotiation_state_ = NEGOTIATED_VERSION; 576 version_negotiation_state_ = NEGOTIATED_VERSION;
575 visitor_->OnSuccessfulVersionNegotiation(version()); 577 visitor_->OnSuccessfulVersionNegotiation(version());
576 if (debug_visitor_.get() != nullptr) { 578 if (debug_visitor_ != nullptr) {
577 debug_visitor_->OnSuccessfulVersionNegotiation(version()); 579 debug_visitor_->OnSuccessfulVersionNegotiation(version());
578 } 580 }
579 } 581 }
580 } 582 }
581 583
582 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_); 584 DCHECK_EQ(NEGOTIATED_VERSION, version_negotiation_state_);
583 585
584 --stats_.packets_dropped; 586 --stats_.packets_dropped;
585 DVLOG(1) << ENDPOINT << "Received packet header: " << header; 587 DVLOG(1) << ENDPOINT << "Received packet header: " << header;
586 last_header_ = header; 588 last_header_ = header;
587 DCHECK(connected_); 589 DCHECK(connected_);
588 return true; 590 return true;
589 } 591 }
590 592
591 void QuicConnection::OnFecProtectedPayload(StringPiece payload) { 593 void QuicConnection::OnFecProtectedPayload(StringPiece payload) {
592 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); 594 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group);
593 DCHECK_NE(0u, last_header_.fec_group); 595 DCHECK_NE(0u, last_header_.fec_group);
594 QuicFecGroup* group = GetFecGroup(); 596 QuicFecGroup* group = GetFecGroup();
595 if (group != nullptr) { 597 if (group != nullptr) {
596 group->Update(last_decrypted_packet_level_, last_header_, payload); 598 group->Update(last_decrypted_packet_level_, last_header_, payload);
597 } 599 }
598 } 600 }
599 601
600 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { 602 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) {
601 DCHECK(connected_); 603 DCHECK(connected_);
602 if (debug_visitor_.get() != nullptr) { 604 if (debug_visitor_ != nullptr) {
603 debug_visitor_->OnStreamFrame(frame); 605 debug_visitor_->OnStreamFrame(frame);
604 } 606 }
605 if (frame.stream_id != kCryptoStreamId && 607 if (frame.stream_id != kCryptoStreamId &&
606 last_decrypted_packet_level_ == ENCRYPTION_NONE) { 608 last_decrypted_packet_level_ == ENCRYPTION_NONE) {
607 DLOG(WARNING) << ENDPOINT 609 DLOG(WARNING) << ENDPOINT
608 << "Received an unencrypted data frame: closing connection"; 610 << "Received an unencrypted data frame: closing connection";
609 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA); 611 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA);
610 return false; 612 return false;
611 } 613 }
612 last_stream_frames_.push_back(frame); 614 last_stream_frames_.push_back(frame);
613 return true; 615 return true;
614 } 616 }
615 617
616 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { 618 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) {
617 DCHECK(connected_); 619 DCHECK(connected_);
618 if (debug_visitor_.get() != nullptr) { 620 if (debug_visitor_ != nullptr) {
619 debug_visitor_->OnAckFrame(incoming_ack); 621 debug_visitor_->OnAckFrame(incoming_ack);
620 } 622 }
621 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; 623 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack;
622 624
623 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) { 625 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) {
624 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; 626 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring";
625 return true; 627 return true;
626 } 628 }
627 629
628 if (!ValidateAckFrame(incoming_ack)) { 630 if (!ValidateAckFrame(incoming_ack)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 largest_seen_packet_with_stop_waiting_) { 668 largest_seen_packet_with_stop_waiting_) {
667 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; 669 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring";
668 return true; 670 return true;
669 } 671 }
670 672
671 if (!ValidateStopWaitingFrame(frame)) { 673 if (!ValidateStopWaitingFrame(frame)) {
672 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); 674 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA);
673 return false; 675 return false;
674 } 676 }
675 677
676 if (debug_visitor_.get() != nullptr) { 678 if (debug_visitor_ != nullptr) {
677 debug_visitor_->OnStopWaitingFrame(frame); 679 debug_visitor_->OnStopWaitingFrame(frame);
678 } 680 }
679 681
680 last_stop_waiting_frames_.push_back(frame); 682 last_stop_waiting_frames_.push_back(frame);
681 return connected_; 683 return connected_;
682 } 684 }
683 685
684 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { 686 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) {
685 DCHECK(connected_); 687 DCHECK(connected_);
686 if (debug_visitor_.get() != nullptr) { 688 if (debug_visitor_ != nullptr) {
687 debug_visitor_->OnPingFrame(frame); 689 debug_visitor_->OnPingFrame(frame);
688 } 690 }
689 last_ping_frames_.push_back(frame); 691 last_ping_frames_.push_back(frame);
690 return true; 692 return true;
691 } 693 }
692 694
693 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { 695 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) {
694 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { 696 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) {
695 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" 697 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:"
696 << incoming_ack.largest_observed << " vs " 698 << incoming_ack.largest_observed << " vs "
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 DCHECK_NE(0u, last_header_.fec_group); 777 DCHECK_NE(0u, last_header_.fec_group);
776 QuicFecGroup* group = GetFecGroup(); 778 QuicFecGroup* group = GetFecGroup();
777 if (group != nullptr) { 779 if (group != nullptr) {
778 group->UpdateFec(last_decrypted_packet_level_, 780 group->UpdateFec(last_decrypted_packet_level_,
779 last_header_.packet_sequence_number, fec); 781 last_header_.packet_sequence_number, fec);
780 } 782 }
781 } 783 }
782 784
783 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { 785 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) {
784 DCHECK(connected_); 786 DCHECK(connected_);
785 if (debug_visitor_.get() != nullptr) { 787 if (debug_visitor_ != nullptr) {
786 debug_visitor_->OnRstStreamFrame(frame); 788 debug_visitor_->OnRstStreamFrame(frame);
787 } 789 }
788 DVLOG(1) << ENDPOINT << "Stream reset with error " 790 DVLOG(1) << ENDPOINT << "Stream reset with error "
789 << QuicUtils::StreamErrorToString(frame.error_code); 791 << QuicUtils::StreamErrorToString(frame.error_code);
790 last_rst_frames_.push_back(frame); 792 last_rst_frames_.push_back(frame);
791 return connected_; 793 return connected_;
792 } 794 }
793 795
794 bool QuicConnection::OnConnectionCloseFrame( 796 bool QuicConnection::OnConnectionCloseFrame(
795 const QuicConnectionCloseFrame& frame) { 797 const QuicConnectionCloseFrame& frame) {
796 DCHECK(connected_); 798 DCHECK(connected_);
797 if (debug_visitor_.get() != nullptr) { 799 if (debug_visitor_ != nullptr) {
798 debug_visitor_->OnConnectionCloseFrame(frame); 800 debug_visitor_->OnConnectionCloseFrame(frame);
799 } 801 }
800 DVLOG(1) << ENDPOINT << "Connection " << connection_id() 802 DVLOG(1) << ENDPOINT << "Connection " << connection_id()
801 << " closed with error " 803 << " closed with error "
802 << QuicUtils::ErrorToString(frame.error_code) 804 << QuicUtils::ErrorToString(frame.error_code)
803 << " " << frame.error_details; 805 << " " << frame.error_details;
804 last_close_frames_.push_back(frame); 806 last_close_frames_.push_back(frame);
805 return connected_; 807 return connected_;
806 } 808 }
807 809
808 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { 810 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
809 DCHECK(connected_); 811 DCHECK(connected_);
810 if (debug_visitor_.get() != nullptr) { 812 if (debug_visitor_ != nullptr) {
811 debug_visitor_->OnGoAwayFrame(frame); 813 debug_visitor_->OnGoAwayFrame(frame);
812 } 814 }
813 DVLOG(1) << ENDPOINT << "Go away received with error " 815 DVLOG(1) << ENDPOINT << "Go away received with error "
814 << QuicUtils::ErrorToString(frame.error_code) 816 << QuicUtils::ErrorToString(frame.error_code)
815 << " and reason:" << frame.reason_phrase; 817 << " and reason:" << frame.reason_phrase;
816 last_goaway_frames_.push_back(frame); 818 last_goaway_frames_.push_back(frame);
817 return connected_; 819 return connected_;
818 } 820 }
819 821
820 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { 822 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) {
821 DCHECK(connected_); 823 DCHECK(connected_);
822 if (debug_visitor_.get() != nullptr) { 824 if (debug_visitor_ != nullptr) {
823 debug_visitor_->OnWindowUpdateFrame(frame); 825 debug_visitor_->OnWindowUpdateFrame(frame);
824 } 826 }
825 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " 827 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: "
826 << frame.stream_id << " with byte offset: " << frame.byte_offset; 828 << frame.stream_id << " with byte offset: " << frame.byte_offset;
827 last_window_update_frames_.push_back(frame); 829 last_window_update_frames_.push_back(frame);
828 return connected_; 830 return connected_;
829 } 831 }
830 832
831 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { 833 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) {
832 DCHECK(connected_); 834 DCHECK(connected_);
833 if (debug_visitor_.get() != nullptr) { 835 if (debug_visitor_ != nullptr) {
834 debug_visitor_->OnBlockedFrame(frame); 836 debug_visitor_->OnBlockedFrame(frame);
835 } 837 }
836 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " 838 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: "
837 << frame.stream_id; 839 << frame.stream_id;
838 last_blocked_frames_.push_back(frame); 840 last_blocked_frames_.push_back(frame);
839 return connected_; 841 return connected_;
840 } 842 }
841 843
842 void QuicConnection::OnPacketComplete() { 844 void QuicConnection::OnPacketComplete() {
843 // Don't do anything if this packet closed the connection. 845 // Don't do anything if this packet closed the connection.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 stats_.max_packet_size = packet_generator_.max_packet_length(); 1147 stats_.max_packet_size = packet_generator_.max_packet_length();
1146 return stats_; 1148 return stats_;
1147 } 1149 }
1148 1150
1149 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 1151 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
1150 const IPEndPoint& peer_address, 1152 const IPEndPoint& peer_address,
1151 const QuicEncryptedPacket& packet) { 1153 const QuicEncryptedPacket& packet) {
1152 if (!connected_) { 1154 if (!connected_) {
1153 return; 1155 return;
1154 } 1156 }
1155 if (debug_visitor_.get() != nullptr) { 1157 if (debug_visitor_ != nullptr) {
1156 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); 1158 debug_visitor_->OnPacketReceived(self_address, peer_address, packet);
1157 } 1159 }
1158 last_size_ = packet.length(); 1160 last_size_ = packet.length();
1159 1161
1160 CheckForAddressMigration(self_address, peer_address); 1162 CheckForAddressMigration(self_address, peer_address);
1161 1163
1162 stats_.bytes_received += packet.length(); 1164 stats_.bytes_received += packet.length();
1163 ++stats_.packets_received; 1165 ++stats_.packets_received;
1164 1166
1165 if (!framer_.ProcessPacket(packet)) { 1167 if (!framer_.ProcessPacket(packet)) {
1166 // If we are unable to decrypt this packet, it might be 1168 // If we are unable to decrypt this packet, it might be
1167 // because the CHLO or SHLO packet was lost. 1169 // because the CHLO or SHLO packet was lost.
1168 if (framer_.error() == QUIC_DECRYPTION_FAILURE) { 1170 if (framer_.error() == QUIC_DECRYPTION_FAILURE) {
1169 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && 1171 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
1170 undecryptable_packets_.size() < max_undecryptable_packets_) { 1172 undecryptable_packets_.size() < max_undecryptable_packets_) {
1171 QueueUndecryptablePacket(packet); 1173 QueueUndecryptablePacket(packet);
1172 } else if (debug_visitor_.get() != nullptr) { 1174 } else if (debug_visitor_ != nullptr) {
1173 debug_visitor_->OnUndecryptablePacket(); 1175 debug_visitor_->OnUndecryptablePacket();
1174 } 1176 }
1175 } 1177 }
1176 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " 1178 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: "
1177 << last_header_.packet_sequence_number; 1179 << last_header_.packet_sequence_number;
1178 return; 1180 return;
1179 } 1181 }
1180 1182
1181 ++stats_.packets_processed; 1183 ++stats_.packets_processed;
1182 MaybeProcessUndecryptablePackets(); 1184 MaybeProcessUndecryptablePackets();
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 << (packet->serialized_packet.is_fec_packet 1437 << (packet->serialized_packet.is_fec_packet
1436 ? "FEC " 1438 ? "FEC "
1437 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA 1439 : (IsRetransmittable(*packet) == HAS_RETRANSMITTABLE_DATA
1438 ? "data bearing " 1440 ? "data bearing "
1439 : " ack only ")) << ", encryption level: " 1441 : " ack only ")) << ", encryption level: "
1440 << QuicUtils::EncryptionLevelToString(packet->encryption_level) 1442 << QuicUtils::EncryptionLevelToString(packet->encryption_level)
1441 << ", encrypted length:" << encrypted->length(); 1443 << ", encrypted length:" << encrypted->length();
1442 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl 1444 DVLOG(2) << ENDPOINT << "packet(" << sequence_number << "): " << std::endl
1443 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece()); 1445 << QuicUtils::StringToHexASCIIDump(encrypted->AsStringPiece());
1444 1446
1445 QuicTime packet_send_time = QuicTime::Zero(); 1447 // Measure the RTT from before the write begins to avoid underestimating the
1446 if (FLAGS_quic_record_send_time_before_write) { 1448 // min_rtt_, especially in cases where the thread blocks or gets swapped out
1447 // Measure the RTT from before the write begins to avoid underestimating the 1449 // during the WritePacket below.
1448 // min_rtt_, especially in cases where the thread blocks or gets swapped out 1450 QuicTime packet_send_time = clock_->Now();
1449 // during the WritePacket below.
1450 packet_send_time = clock_->Now();
1451 }
1452 WriteResult result = writer_->WritePacket(encrypted->data(), 1451 WriteResult result = writer_->WritePacket(encrypted->data(),
1453 encrypted->length(), 1452 encrypted->length(),
1454 self_address().address(), 1453 self_address().address(),
1455 peer_address()); 1454 peer_address());
1456 if (result.error_code == ERR_IO_PENDING) { 1455 if (result.error_code == ERR_IO_PENDING) {
1457 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); 1456 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
1458 } 1457 }
1459 1458
1460 if (result.status == WRITE_STATUS_BLOCKED) { 1459 if (result.status == WRITE_STATUS_BLOCKED) {
1461 visitor_->OnWriteBlocked(); 1460 visitor_->OnWriteBlocked();
1462 // If the socket buffers the the data, then the packet should not 1461 // If the socket buffers the the data, then the packet should not
1463 // be queued and sent again, which would result in an unnecessary 1462 // be queued and sent again, which would result in an unnecessary
1464 // duplicate packet being sent. The helper must call OnCanWrite 1463 // duplicate packet being sent. The helper must call OnCanWrite
1465 // when the write completes, and OnWriteError if an error occurs. 1464 // when the write completes, and OnWriteError if an error occurs.
1466 if (!writer_->IsWriteBlockedDataBuffered()) { 1465 if (!writer_->IsWriteBlockedDataBuffered()) {
1467 return false; 1466 return false;
1468 } 1467 }
1469 } 1468 }
1470 if (!FLAGS_quic_record_send_time_before_write) { 1469 if (result.status != WRITE_STATUS_ERROR && debug_visitor_ != nullptr) {
1471 packet_send_time = clock_->Now();
1472 }
1473 if (!packet_send_time.IsInitialized()) {
1474 // TODO(jokulik): This is only needed because of the two code paths for
1475 // initializing packet_send_time. Once "quic_record_send_time_before_write"
1476 // is deprecated, this check can be removed.
1477 LOG(DFATAL) << "The packet send time should never be zero. "
1478 << "This is a programming bug, please report it.";
1479 }
1480 if (result.status != WRITE_STATUS_ERROR && debug_visitor_.get() != nullptr) {
1481 // Pass the write result to the visitor. 1470 // Pass the write result to the visitor.
1482 debug_visitor_->OnPacketSent(packet->serialized_packet, 1471 debug_visitor_->OnPacketSent(packet->serialized_packet,
1483 packet->original_sequence_number, 1472 packet->original_sequence_number,
1484 packet->encryption_level, 1473 packet->encryption_level,
1485 packet->transmission_type, 1474 packet->transmission_type,
1486 *encrypted, 1475 *encrypted,
1487 packet_send_time); 1476 packet_send_time);
1488 } 1477 }
1489 if (packet->transmission_type == NOT_RETRANSMISSION) { 1478 if (packet->transmission_type == NOT_RETRANSMISSION) {
1490 time_of_last_sent_new_packet_ = packet_send_time; 1479 time_of_last_sent_new_packet_ = packet_send_time;
1491 } 1480 }
1492 SetPingAlarm(); 1481 SetPingAlarm();
1493 MaybeSetFecAlarm(sequence_number); 1482 MaybeSetFecAlarm(sequence_number);
1494 DVLOG(1) << ENDPOINT << "time " 1483 DVLOG(1) << ENDPOINT << "time we began writing last sent packet: "
1495 << (FLAGS_quic_record_send_time_before_write ?
1496 "we began writing " : "we finished writing ")
1497 << "last sent packet: "
1498 << packet_send_time.ToDebuggingValue(); 1484 << packet_send_time.ToDebuggingValue();
1499 1485
1500 // TODO(ianswett): Change the sequence number length and other packet creator 1486 // TODO(ianswett): Change the sequence number length and other packet creator
1501 // options by a more explicit API than setting a struct value directly, 1487 // options by a more explicit API than setting a struct value directly,
1502 // perhaps via the NetworkChangeVisitor. 1488 // perhaps via the NetworkChangeVisitor.
1503 packet_generator_.UpdateSequenceNumberLength( 1489 packet_generator_.UpdateSequenceNumberLength(
1504 sent_packet_manager_.least_packet_awaited_by_peer(), 1490 sent_packet_manager_.least_packet_awaited_by_peer(),
1505 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length())); 1491 sent_packet_manager_.EstimateMaxPacketsInFlight(max_packet_length()));
1506 1492
1507 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent( 1493 bool reset_retransmission_alarm = sent_packet_manager_.OnPacketSent(
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; 1742 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!";
1757 ++stats_.packets_processed; 1743 ++stats_.packets_processed;
1758 delete packet; 1744 delete packet;
1759 undecryptable_packets_.pop_front(); 1745 undecryptable_packets_.pop_front();
1760 } 1746 }
1761 1747
1762 // Once forward secure encryption is in use, there will be no 1748 // Once forward secure encryption is in use, there will be no
1763 // new keys installed and hence any undecryptable packets will 1749 // new keys installed and hence any undecryptable packets will
1764 // never be able to be decrypted. 1750 // never be able to be decrypted.
1765 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { 1751 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) {
1766 if (debug_visitor_.get() != nullptr) { 1752 if (debug_visitor_ != nullptr) {
1767 // TODO(rtenneti): perhaps more efficient to pass the number of 1753 // TODO(rtenneti): perhaps more efficient to pass the number of
1768 // undecryptable packets as the argument to OnUndecryptablePacket so that 1754 // undecryptable packets as the argument to OnUndecryptablePacket so that
1769 // we just need to call OnUndecryptablePacket once? 1755 // we just need to call OnUndecryptablePacket once?
1770 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) { 1756 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) {
1771 debug_visitor_->OnUndecryptablePacket(); 1757 debug_visitor_->OnUndecryptablePacket();
1772 } 1758 }
1773 } 1759 }
1774 STLDeleteElements(&undecryptable_packets_); 1760 STLDeleteElements(&undecryptable_packets_);
1775 } 1761 }
1776 } 1762 }
(...skipping 15 matching lines...) Expand all
1792 last_header_.public_header.sequence_number_length; 1778 last_header_.public_header.sequence_number_length;
1793 revived_header.fec_flag = false; 1779 revived_header.fec_flag = false;
1794 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP; 1780 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP;
1795 revived_header.fec_group = 0; 1781 revived_header.fec_group = 0;
1796 group_map_.erase(last_header_.fec_group); 1782 group_map_.erase(last_header_.fec_group);
1797 last_decrypted_packet_level_ = group->effective_encryption_level(); 1783 last_decrypted_packet_level_ = group->effective_encryption_level();
1798 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS); 1784 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS);
1799 delete group; 1785 delete group;
1800 1786
1801 last_packet_revived_ = true; 1787 last_packet_revived_ = true;
1802 if (debug_visitor_.get() != nullptr) { 1788 if (debug_visitor_ != nullptr) {
1803 debug_visitor_->OnRevivedPacket(revived_header, 1789 debug_visitor_->OnRevivedPacket(revived_header,
1804 StringPiece(revived_payload, len)); 1790 StringPiece(revived_payload, len));
1805 } 1791 }
1806 1792
1807 ++stats_.packets_revived; 1793 ++stats_.packets_revived;
1808 framer_.ProcessRevivedPacket(&revived_header, 1794 framer_.ProcessRevivedPacket(&revived_header,
1809 StringPiece(revived_payload, len)); 1795 StringPiece(revived_payload, len));
1810 } 1796 }
1811 1797
1812 QuicFecGroup* QuicConnection::GetFecGroup() { 1798 QuicFecGroup* QuicConnection::GetFecGroup() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 packet_generator_.FlushAllQueuedFrames(); 1852 packet_generator_.FlushAllQueuedFrames();
1867 } 1853 }
1868 1854
1869 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) { 1855 void QuicConnection::CloseConnection(QuicErrorCode error, bool from_peer) {
1870 if (!connected_) { 1856 if (!connected_) {
1871 DLOG(DFATAL) << "Error: attempt to close an already closed connection" 1857 DLOG(DFATAL) << "Error: attempt to close an already closed connection"
1872 << base::debug::StackTrace().ToString(); 1858 << base::debug::StackTrace().ToString();
1873 return; 1859 return;
1874 } 1860 }
1875 connected_ = false; 1861 connected_ = false;
1876 if (debug_visitor_.get() != nullptr) { 1862 if (debug_visitor_ != nullptr) {
1877 debug_visitor_->OnConnectionClosed(error, from_peer); 1863 debug_visitor_->OnConnectionClosed(error, from_peer);
1878 } 1864 }
1879 visitor_->OnConnectionClosed(error, from_peer); 1865 visitor_->OnConnectionClosed(error, from_peer);
1880 // Cancel the alarms so they don't trigger any action now that the 1866 // Cancel the alarms so they don't trigger any action now that the
1881 // connection is closed. 1867 // connection is closed.
1882 ack_alarm_->Cancel(); 1868 ack_alarm_->Cancel();
1883 ping_alarm_->Cancel(); 1869 ping_alarm_->Cancel();
1884 fec_alarm_->Cancel(); 1870 fec_alarm_->Cancel();
1885 resume_writes_alarm_->Cancel(); 1871 resume_writes_alarm_->Cancel();
1886 retransmission_alarm_->Cancel(); 1872 retransmission_alarm_->Cancel();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 } 2082 }
2097 for (const QuicFrame& frame : retransmittable_frames->frames()) { 2083 for (const QuicFrame& frame : retransmittable_frames->frames()) {
2098 if (frame.type == CONNECTION_CLOSE_FRAME) { 2084 if (frame.type == CONNECTION_CLOSE_FRAME) {
2099 return true; 2085 return true;
2100 } 2086 }
2101 } 2087 }
2102 return false; 2088 return false;
2103 } 2089 }
2104 2090
2105 } // namespace net 2091 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.h ('k') | net/quic/quic_connection_stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698