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

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

Issue 420313005: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0723
Patch Set: change QUIC packet size to 1350 Created 6 years, 4 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
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 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 pending_version_negotiation_packet_(false), 213 pending_version_negotiation_packet_(false),
214 received_packet_manager_(kTCP, &stats_), 214 received_packet_manager_(kTCP, &stats_),
215 ack_queued_(false), 215 ack_queued_(false),
216 stop_waiting_count_(0), 216 stop_waiting_count_(0),
217 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))), 217 ack_alarm_(helper->CreateAlarm(new AckAlarm(this))),
218 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))), 218 retransmission_alarm_(helper->CreateAlarm(new RetransmissionAlarm(this))),
219 send_alarm_(helper->CreateAlarm(new SendAlarm(this))), 219 send_alarm_(helper->CreateAlarm(new SendAlarm(this))),
220 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))), 220 resume_writes_alarm_(helper->CreateAlarm(new SendAlarm(this))),
221 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))), 221 timeout_alarm_(helper->CreateAlarm(new TimeoutAlarm(this))),
222 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))), 222 ping_alarm_(helper->CreateAlarm(new PingAlarm(this))),
223 debug_visitor_(NULL),
224 packet_generator_(connection_id_, &framer_, random_generator_, this), 223 packet_generator_(connection_id_, &framer_, random_generator_, this),
225 idle_network_timeout_( 224 idle_network_timeout_(
226 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)), 225 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)),
227 overall_connection_timeout_(QuicTime::Delta::Infinite()), 226 overall_connection_timeout_(QuicTime::Delta::Infinite()),
228 time_of_last_received_packet_(clock_->ApproximateNow()), 227 time_of_last_received_packet_(clock_->ApproximateNow()),
229 time_of_last_sent_new_packet_(clock_->ApproximateNow()), 228 time_of_last_sent_new_packet_(clock_->ApproximateNow()),
230 sequence_number_of_last_sent_packet_(0), 229 sequence_number_of_last_sent_packet_(0),
231 sent_packet_manager_( 230 sent_packet_manager_(
232 is_server, clock_, &stats_, kCubic, 231 is_server, clock_, &stats_, kCubic,
233 FLAGS_quic_use_time_loss_detection ? kTime : kNack), 232 FLAGS_quic_use_time_loss_detection ? kTime : kNack),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 last_window_update_frames_.empty() && 301 last_window_update_frames_.empty() &&
303 last_blocked_frames_.empty() && 302 last_blocked_frames_.empty() &&
304 last_rst_frames_.empty() && 303 last_rst_frames_.empty() &&
305 last_ack_frames_.empty() && 304 last_ack_frames_.empty() &&
306 last_congestion_frames_.empty() && 305 last_congestion_frames_.empty() &&
307 last_stop_waiting_frames_.empty()); 306 last_stop_waiting_frames_.empty());
308 } 307 }
309 308
310 void QuicConnection::OnPublicResetPacket( 309 void QuicConnection::OnPublicResetPacket(
311 const QuicPublicResetPacket& packet) { 310 const QuicPublicResetPacket& packet) {
312 if (debug_visitor_) { 311 if (debug_visitor_.get() != NULL) {
313 debug_visitor_->OnPublicResetPacket(packet); 312 debug_visitor_->OnPublicResetPacket(packet);
314 } 313 }
315 CloseConnection(QUIC_PUBLIC_RESET, true); 314 CloseConnection(QUIC_PUBLIC_RESET, true);
316 315
317 DVLOG(1) << ENDPOINT << "Connection " << connection_id() 316 DVLOG(1) << ENDPOINT << "Connection " << connection_id()
318 << " closed via QUIC_PUBLIC_RESET from peer."; 317 << " closed via QUIC_PUBLIC_RESET from peer.";
319 } 318 }
320 319
321 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) { 320 bool QuicConnection::OnProtocolVersionMismatch(QuicVersion received_version) {
322 DVLOG(1) << ENDPOINT << "Received packet with mismatched version " 321 DVLOG(1) << ENDPOINT << "Received packet with mismatched version "
323 << received_version; 322 << received_version;
324 // TODO(satyamshekhar): Implement no server state in this mode. 323 // TODO(satyamshekhar): Implement no server state in this mode.
325 if (!is_server_) { 324 if (!is_server_) {
326 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. " 325 LOG(DFATAL) << ENDPOINT << "Framer called OnProtocolVersionMismatch. "
327 << "Closing connection."; 326 << "Closing connection.";
328 CloseConnection(QUIC_INTERNAL_ERROR, false); 327 CloseConnection(QUIC_INTERNAL_ERROR, false);
329 return false; 328 return false;
330 } 329 }
331 DCHECK_NE(version(), received_version); 330 DCHECK_NE(version(), received_version);
332 331
333 if (debug_visitor_) { 332 if (debug_visitor_.get() != NULL) {
334 debug_visitor_->OnProtocolVersionMismatch(received_version); 333 debug_visitor_->OnProtocolVersionMismatch(received_version);
335 } 334 }
336 335
337 switch (version_negotiation_state_) { 336 switch (version_negotiation_state_) {
338 case START_NEGOTIATION: 337 case START_NEGOTIATION:
339 if (!framer_.IsSupportedVersion(received_version)) { 338 if (!framer_.IsSupportedVersion(received_version)) {
340 SendVersionNegotiationPacket(); 339 SendVersionNegotiationPacket();
341 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS; 340 version_negotiation_state_ = NEGOTIATION_IN_PROGRESS;
342 return false; 341 return false;
343 } 342 }
(...skipping 30 matching lines...) Expand all
374 373
375 // Handles version negotiation for client connection. 374 // Handles version negotiation for client connection.
376 void QuicConnection::OnVersionNegotiationPacket( 375 void QuicConnection::OnVersionNegotiationPacket(
377 const QuicVersionNegotiationPacket& packet) { 376 const QuicVersionNegotiationPacket& packet) {
378 if (is_server_) { 377 if (is_server_) {
379 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket." 378 LOG(DFATAL) << ENDPOINT << "Framer parsed VersionNegotiationPacket."
380 << " Closing connection."; 379 << " Closing connection.";
381 CloseConnection(QUIC_INTERNAL_ERROR, false); 380 CloseConnection(QUIC_INTERNAL_ERROR, false);
382 return; 381 return;
383 } 382 }
384 if (debug_visitor_) { 383 if (debug_visitor_.get() != NULL) {
385 debug_visitor_->OnVersionNegotiationPacket(packet); 384 debug_visitor_->OnVersionNegotiationPacket(packet);
386 } 385 }
387 386
388 if (version_negotiation_state_ != START_NEGOTIATION) { 387 if (version_negotiation_state_ != START_NEGOTIATION) {
389 // Possibly a duplicate version negotiation packet. 388 // Possibly a duplicate version negotiation packet.
390 return; 389 return;
391 } 390 }
392 391
393 if (std::find(packet.versions.begin(), 392 if (std::find(packet.versions.begin(),
394 packet.versions.end(), version()) != 393 packet.versions.end(), version()) !=
(...skipping 27 matching lines...) Expand all
422 421
423 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) { 422 bool QuicConnection::OnUnauthenticatedHeader(const QuicPacketHeader& header) {
424 return true; 423 return true;
425 } 424 }
426 425
427 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { 426 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) {
428 last_decrypted_packet_level_ = level; 427 last_decrypted_packet_level_ = level;
429 } 428 }
430 429
431 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { 430 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) {
432 if (debug_visitor_) { 431 if (debug_visitor_.get() != NULL) {
433 debug_visitor_->OnPacketHeader(header); 432 debug_visitor_->OnPacketHeader(header);
434 } 433 }
435 434
436 if (!ProcessValidatedPacket()) { 435 if (!ProcessValidatedPacket()) {
437 return false; 436 return false;
438 } 437 }
439 438
440 // Will be decrement below if we fall through to return true; 439 // Will be decrement below if we fall through to return true;
441 ++stats_.packets_dropped; 440 ++stats_.packets_dropped;
442 441
443 if (header.public_header.connection_id != connection_id_) { 442 if (header.public_header.connection_id != connection_id_) {
444 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: " 443 DVLOG(1) << ENDPOINT << "Ignoring packet from unexpected ConnectionId: "
445 << header.public_header.connection_id << " instead of " 444 << header.public_header.connection_id << " instead of "
446 << connection_id_; 445 << connection_id_;
446 if (debug_visitor_.get() != NULL) {
447 debug_visitor_->OnIncorrectConnectionId(
448 header.public_header.connection_id);
449 }
447 return false; 450 return false;
448 } 451 }
449 452
450 if (!Near(header.packet_sequence_number, 453 if (!Near(header.packet_sequence_number,
451 last_header_.packet_sequence_number)) { 454 last_header_.packet_sequence_number)) {
452 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number 455 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number
453 << " out of bounds. Discarding"; 456 << " out of bounds. Discarding";
454 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER, 457 SendConnectionCloseWithDetails(QUIC_INVALID_PACKET_HEADER,
455 "Packet sequence number out of bounds"); 458 "Packet sequence number out of bounds");
456 return false; 459 return false;
457 } 460 }
458 461
459 // If this packet has already been seen, or that the sender 462 // If this packet has already been seen, or that the sender
460 // has told us will not be retransmitted, then stop processing the packet. 463 // has told us will not be retransmitted, then stop processing the packet.
461 if (!received_packet_manager_.IsAwaitingPacket( 464 if (!received_packet_manager_.IsAwaitingPacket(
462 header.packet_sequence_number)) { 465 header.packet_sequence_number)) {
463 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number 466 DVLOG(1) << ENDPOINT << "Packet " << header.packet_sequence_number
464 << " no longer being waited for. Discarding."; 467 << " no longer being waited for. Discarding.";
465 // TODO(jri): Log reception of duplicate packets or packets the peer has 468 if (debug_visitor_.get() != NULL) {
466 // told us to stop waiting for. 469 debug_visitor_->OnDuplicatePacket(header.packet_sequence_number);
470 }
467 return false; 471 return false;
468 } 472 }
469 473
470 if (version_negotiation_state_ != NEGOTIATED_VERSION) { 474 if (version_negotiation_state_ != NEGOTIATED_VERSION) {
471 if (is_server_) { 475 if (is_server_) {
472 if (!header.public_header.version_flag) { 476 if (!header.public_header.version_flag) {
473 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number 477 DLOG(WARNING) << ENDPOINT << "Packet " << header.packet_sequence_number
474 << " without version flag before version negotiated."; 478 << " without version flag before version negotiated.";
475 // Packets should have the version flag till version negotiation is 479 // Packets should have the version flag till version negotiation is
476 // done. 480 // done.
(...skipping 28 matching lines...) Expand all
505 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group); 509 DCHECK_EQ(IN_FEC_GROUP, last_header_.is_in_fec_group);
506 DCHECK_NE(0u, last_header_.fec_group); 510 DCHECK_NE(0u, last_header_.fec_group);
507 QuicFecGroup* group = GetFecGroup(); 511 QuicFecGroup* group = GetFecGroup();
508 if (group != NULL) { 512 if (group != NULL) {
509 group->Update(last_decrypted_packet_level_, last_header_, payload); 513 group->Update(last_decrypted_packet_level_, last_header_, payload);
510 } 514 }
511 } 515 }
512 516
513 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) { 517 bool QuicConnection::OnStreamFrame(const QuicStreamFrame& frame) {
514 DCHECK(connected_); 518 DCHECK(connected_);
515 if (debug_visitor_) { 519 if (debug_visitor_.get() != NULL) {
516 debug_visitor_->OnStreamFrame(frame); 520 debug_visitor_->OnStreamFrame(frame);
517 } 521 }
518 if (frame.stream_id != kCryptoStreamId && 522 if (frame.stream_id != kCryptoStreamId &&
519 last_decrypted_packet_level_ == ENCRYPTION_NONE) { 523 last_decrypted_packet_level_ == ENCRYPTION_NONE) {
520 DLOG(WARNING) << ENDPOINT 524 DLOG(WARNING) << ENDPOINT
521 << "Received an unencrypted data frame: closing connection"; 525 << "Received an unencrypted data frame: closing connection";
522 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA); 526 SendConnectionClose(QUIC_UNENCRYPTED_STREAM_DATA);
523 return false; 527 return false;
524 } 528 }
525 last_stream_frames_.push_back(frame); 529 last_stream_frames_.push_back(frame);
526 return true; 530 return true;
527 } 531 }
528 532
529 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) { 533 bool QuicConnection::OnAckFrame(const QuicAckFrame& incoming_ack) {
530 DCHECK(connected_); 534 DCHECK(connected_);
531 if (debug_visitor_) { 535 if (debug_visitor_.get() != NULL) {
532 debug_visitor_->OnAckFrame(incoming_ack); 536 debug_visitor_->OnAckFrame(incoming_ack);
533 } 537 }
534 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack; 538 DVLOG(1) << ENDPOINT << "OnAckFrame: " << incoming_ack;
535 539
536 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) { 540 if (last_header_.packet_sequence_number <= largest_seen_packet_with_ack_) {
537 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring"; 541 DVLOG(1) << ENDPOINT << "Received an old ack frame: ignoring";
538 return true; 542 return true;
539 } 543 }
540 544
541 if (!ValidateAckFrame(incoming_ack)) { 545 if (!ValidateAckFrame(incoming_ack)) {
542 SendConnectionClose(QUIC_INVALID_ACK_DATA); 546 SendConnectionClose(QUIC_INVALID_ACK_DATA);
543 return false; 547 return false;
544 } 548 }
545 549
546 last_ack_frames_.push_back(incoming_ack); 550 last_ack_frames_.push_back(incoming_ack);
547 return connected_; 551 return connected_;
548 } 552 }
549 553
550 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { 554 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) {
551 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; 555 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number;
552 received_packet_manager_.UpdatePacketInformationReceivedByPeer( 556 received_packet_manager_.UpdatePacketInformationReceivedByPeer(incoming_ack);
553 incoming_ack.received_info);
554 if (version() <= QUIC_VERSION_15) {
555 ProcessStopWaitingFrame(incoming_ack.sent_info);
556 }
557 557
558 sent_entropy_manager_.ClearEntropyBefore( 558 sent_entropy_manager_.ClearEntropyBefore(
559 received_packet_manager_.least_packet_awaited_by_peer() - 1); 559 received_packet_manager_.least_packet_awaited_by_peer() - 1);
560 560
561 sent_packet_manager_.OnIncomingAck(incoming_ack.received_info, 561 sent_packet_manager_.OnIncomingAck(incoming_ack,
562 time_of_last_received_packet_); 562 time_of_last_received_packet_);
563 if (sent_packet_manager_.HasPendingRetransmissions()) { 563 if (sent_packet_manager_.HasPendingRetransmissions()) {
564 WriteIfNotBlocked(); 564 WriteIfNotBlocked();
565 } 565 }
566 566
567 // Always reset the retransmission alarm when an ack comes in, since we now 567 // Always reset the retransmission alarm when an ack comes in, since we now
568 // have a better estimate of the current rtt than when it was set. 568 // have a better estimate of the current rtt than when it was set.
569 retransmission_alarm_->Cancel(); 569 retransmission_alarm_->Cancel();
570 QuicTime retransmission_time = 570 QuicTime retransmission_time =
571 sent_packet_manager_.GetRetransmissionTime(); 571 sent_packet_manager_.GetRetransmissionTime();
572 if (retransmission_time != QuicTime::Zero()) { 572 if (retransmission_time != QuicTime::Zero()) {
573 retransmission_alarm_->Set(retransmission_time); 573 retransmission_alarm_->Set(retransmission_time);
574 } 574 }
575 } 575 }
576 576
577 void QuicConnection::ProcessStopWaitingFrame( 577 void QuicConnection::ProcessStopWaitingFrame(
578 const QuicStopWaitingFrame& stop_waiting) { 578 const QuicStopWaitingFrame& stop_waiting) {
579 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; 579 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number;
580 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); 580 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting);
581 // Possibly close any FecGroups which are now irrelevant. 581 // Possibly close any FecGroups which are now irrelevant.
582 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); 582 CloseFecGroupsBefore(stop_waiting.least_unacked + 1);
583 } 583 }
584 584
585 bool QuicConnection::OnCongestionFeedbackFrame( 585 bool QuicConnection::OnCongestionFeedbackFrame(
586 const QuicCongestionFeedbackFrame& feedback) { 586 const QuicCongestionFeedbackFrame& feedback) {
587 DCHECK(connected_); 587 DCHECK(connected_);
588 if (debug_visitor_) { 588 if (debug_visitor_.get() != NULL) {
589 debug_visitor_->OnCongestionFeedbackFrame(feedback); 589 debug_visitor_->OnCongestionFeedbackFrame(feedback);
590 } 590 }
591 last_congestion_frames_.push_back(feedback); 591 last_congestion_frames_.push_back(feedback);
592 return connected_; 592 return connected_;
593 } 593 }
594 594
595 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) { 595 bool QuicConnection::OnStopWaitingFrame(const QuicStopWaitingFrame& frame) {
596 DCHECK(connected_); 596 DCHECK(connected_);
597 597
598 if (last_header_.packet_sequence_number <= 598 if (last_header_.packet_sequence_number <=
599 largest_seen_packet_with_stop_waiting_) { 599 largest_seen_packet_with_stop_waiting_) {
600 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring"; 600 DVLOG(1) << ENDPOINT << "Received an old stop waiting frame: ignoring";
601 return true; 601 return true;
602 } 602 }
603 603
604 if (!ValidateStopWaitingFrame(frame)) { 604 if (!ValidateStopWaitingFrame(frame)) {
605 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA); 605 SendConnectionClose(QUIC_INVALID_STOP_WAITING_DATA);
606 return false; 606 return false;
607 } 607 }
608 608
609 if (debug_visitor_) { 609 if (debug_visitor_.get() != NULL) {
610 debug_visitor_->OnStopWaitingFrame(frame); 610 debug_visitor_->OnStopWaitingFrame(frame);
611 } 611 }
612 612
613 last_stop_waiting_frames_.push_back(frame); 613 last_stop_waiting_frames_.push_back(frame);
614 return connected_; 614 return connected_;
615 } 615 }
616 616
617 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) { 617 bool QuicConnection::OnPingFrame(const QuicPingFrame& frame) {
618 DCHECK(connected_); 618 DCHECK(connected_);
619 if (debug_visitor_) { 619 if (debug_visitor_.get() != NULL) {
620 debug_visitor_->OnPingFrame(frame); 620 debug_visitor_->OnPingFrame(frame);
621 } 621 }
622 return true; 622 return true;
623 } 623 }
624 624
625 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { 625 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) {
626 if (incoming_ack.received_info.largest_observed > 626 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) {
627 packet_generator_.sequence_number()) {
628 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" 627 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:"
629 << incoming_ack.received_info.largest_observed << " vs " 628 << incoming_ack.largest_observed << " vs "
630 << packet_generator_.sequence_number(); 629 << packet_generator_.sequence_number();
631 // We got an error for data we have not sent. Error out. 630 // We got an error for data we have not sent. Error out.
632 return false; 631 return false;
633 } 632 }
634 633
635 if (incoming_ack.received_info.largest_observed < 634 if (incoming_ack.largest_observed <
636 received_packet_manager_.peer_largest_observed_packet()) { 635 received_packet_manager_.peer_largest_observed_packet()) {
637 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" 636 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:"
638 << incoming_ack.received_info.largest_observed << " vs " 637 << incoming_ack.largest_observed << " vs "
639 << received_packet_manager_.peer_largest_observed_packet(); 638 << received_packet_manager_.peer_largest_observed_packet();
640 // A new ack has a diminished largest_observed value. Error out. 639 // A new ack has a diminished largest_observed value. Error out.
641 // If this was an old packet, we wouldn't even have checked. 640 // If this was an old packet, we wouldn't even have checked.
642 return false; 641 return false;
643 } 642 }
644 643
645 if (version() <= QUIC_VERSION_15) { 644 if (!incoming_ack.missing_packets.empty() &&
646 if (!ValidateStopWaitingFrame(incoming_ack.sent_info)) { 645 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) {
647 return false;
648 }
649 }
650
651 if (!incoming_ack.received_info.missing_packets.empty() &&
652 *incoming_ack.received_info.missing_packets.rbegin() >
653 incoming_ack.received_info.largest_observed) {
654 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " 646 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: "
655 << *incoming_ack.received_info.missing_packets.rbegin() 647 << *incoming_ack.missing_packets.rbegin()
656 << " which is greater than largest observed: " 648 << " which is greater than largest observed: "
657 << incoming_ack.received_info.largest_observed; 649 << incoming_ack.largest_observed;
658 return false; 650 return false;
659 } 651 }
660 652
661 if (!incoming_ack.received_info.missing_packets.empty() && 653 if (!incoming_ack.missing_packets.empty() &&
662 *incoming_ack.received_info.missing_packets.begin() < 654 *incoming_ack.missing_packets.begin() <
663 received_packet_manager_.least_packet_awaited_by_peer()) { 655 received_packet_manager_.least_packet_awaited_by_peer()) {
664 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " 656 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: "
665 << *incoming_ack.received_info.missing_packets.begin() 657 << *incoming_ack.missing_packets.begin()
666 << " which is smaller than least_packet_awaited_by_peer_: " 658 << " which is smaller than least_packet_awaited_by_peer_: "
667 << received_packet_manager_.least_packet_awaited_by_peer(); 659 << received_packet_manager_.least_packet_awaited_by_peer();
668 return false; 660 return false;
669 } 661 }
670 662
671 if (!sent_entropy_manager_.IsValidEntropy( 663 if (!sent_entropy_manager_.IsValidEntropy(
672 incoming_ack.received_info.largest_observed, 664 incoming_ack.largest_observed,
673 incoming_ack.received_info.missing_packets, 665 incoming_ack.missing_packets,
674 incoming_ack.received_info.entropy_hash)) { 666 incoming_ack.entropy_hash)) {
675 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; 667 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy.";
676 return false; 668 return false;
677 } 669 }
678 670
679 for (SequenceNumberSet::const_iterator iter = 671 for (SequenceNumberSet::const_iterator iter =
680 incoming_ack.received_info.revived_packets.begin(); 672 incoming_ack.revived_packets.begin();
681 iter != incoming_ack.received_info.revived_packets.end(); ++iter) { 673 iter != incoming_ack.revived_packets.end(); ++iter) {
682 if (!ContainsKey(incoming_ack.received_info.missing_packets, *iter)) { 674 if (!ContainsKey(incoming_ack.missing_packets, *iter)) {
683 DLOG(ERROR) << ENDPOINT 675 DLOG(ERROR) << ENDPOINT
684 << "Peer specified revived packet which was not missing."; 676 << "Peer specified revived packet which was not missing.";
685 return false; 677 return false;
686 } 678 }
687 } 679 }
688 return true; 680 return true;
689 } 681 }
690 682
691 bool QuicConnection::ValidateStopWaitingFrame( 683 bool QuicConnection::ValidateStopWaitingFrame(
692 const QuicStopWaitingFrame& stop_waiting) { 684 const QuicStopWaitingFrame& stop_waiting) {
(...skipping 23 matching lines...) Expand all
716 DCHECK_NE(0u, last_header_.fec_group); 708 DCHECK_NE(0u, last_header_.fec_group);
717 QuicFecGroup* group = GetFecGroup(); 709 QuicFecGroup* group = GetFecGroup();
718 if (group != NULL) { 710 if (group != NULL) {
719 group->UpdateFec(last_decrypted_packet_level_, 711 group->UpdateFec(last_decrypted_packet_level_,
720 last_header_.packet_sequence_number, fec); 712 last_header_.packet_sequence_number, fec);
721 } 713 }
722 } 714 }
723 715
724 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) { 716 bool QuicConnection::OnRstStreamFrame(const QuicRstStreamFrame& frame) {
725 DCHECK(connected_); 717 DCHECK(connected_);
726 if (debug_visitor_) { 718 if (debug_visitor_.get() != NULL) {
727 debug_visitor_->OnRstStreamFrame(frame); 719 debug_visitor_->OnRstStreamFrame(frame);
728 } 720 }
729 DVLOG(1) << ENDPOINT << "Stream reset with error " 721 DVLOG(1) << ENDPOINT << "Stream reset with error "
730 << QuicUtils::StreamErrorToString(frame.error_code); 722 << QuicUtils::StreamErrorToString(frame.error_code);
731 last_rst_frames_.push_back(frame); 723 last_rst_frames_.push_back(frame);
732 return connected_; 724 return connected_;
733 } 725 }
734 726
735 bool QuicConnection::OnConnectionCloseFrame( 727 bool QuicConnection::OnConnectionCloseFrame(
736 const QuicConnectionCloseFrame& frame) { 728 const QuicConnectionCloseFrame& frame) {
737 DCHECK(connected_); 729 DCHECK(connected_);
738 if (debug_visitor_) { 730 if (debug_visitor_.get() != NULL) {
739 debug_visitor_->OnConnectionCloseFrame(frame); 731 debug_visitor_->OnConnectionCloseFrame(frame);
740 } 732 }
741 DVLOG(1) << ENDPOINT << "Connection " << connection_id() 733 DVLOG(1) << ENDPOINT << "Connection " << connection_id()
742 << " closed with error " 734 << " closed with error "
743 << QuicUtils::ErrorToString(frame.error_code) 735 << QuicUtils::ErrorToString(frame.error_code)
744 << " " << frame.error_details; 736 << " " << frame.error_details;
745 last_close_frames_.push_back(frame); 737 last_close_frames_.push_back(frame);
746 return connected_; 738 return connected_;
747 } 739 }
748 740
749 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) { 741 bool QuicConnection::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
750 DCHECK(connected_); 742 DCHECK(connected_);
751 if (debug_visitor_) { 743 if (debug_visitor_.get() != NULL) {
752 debug_visitor_->OnGoAwayFrame(frame); 744 debug_visitor_->OnGoAwayFrame(frame);
753 } 745 }
754 DVLOG(1) << ENDPOINT << "Go away received with error " 746 DVLOG(1) << ENDPOINT << "Go away received with error "
755 << QuicUtils::ErrorToString(frame.error_code) 747 << QuicUtils::ErrorToString(frame.error_code)
756 << " and reason:" << frame.reason_phrase; 748 << " and reason:" << frame.reason_phrase;
757 last_goaway_frames_.push_back(frame); 749 last_goaway_frames_.push_back(frame);
758 return connected_; 750 return connected_;
759 } 751 }
760 752
761 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) { 753 bool QuicConnection::OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) {
762 DCHECK(connected_); 754 DCHECK(connected_);
763 if (debug_visitor_) { 755 if (debug_visitor_.get() != NULL) {
764 debug_visitor_->OnWindowUpdateFrame(frame); 756 debug_visitor_->OnWindowUpdateFrame(frame);
765 } 757 }
766 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: " 758 DVLOG(1) << ENDPOINT << "WindowUpdate received for stream: "
767 << frame.stream_id << " with byte offset: " << frame.byte_offset; 759 << frame.stream_id << " with byte offset: " << frame.byte_offset;
768 last_window_update_frames_.push_back(frame); 760 last_window_update_frames_.push_back(frame);
769 return connected_; 761 return connected_;
770 } 762 }
771 763
772 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) { 764 bool QuicConnection::OnBlockedFrame(const QuicBlockedFrame& frame) {
773 DCHECK(connected_); 765 DCHECK(connected_);
774 if (debug_visitor_) { 766 if (debug_visitor_.get() != NULL) {
775 debug_visitor_->OnBlockedFrame(frame); 767 debug_visitor_->OnBlockedFrame(frame);
776 } 768 }
777 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: " 769 DVLOG(1) << ENDPOINT << "Blocked frame received for stream: "
778 << frame.stream_id; 770 << frame.stream_id;
779 last_blocked_frames_.push_back(frame); 771 last_blocked_frames_.push_back(frame);
780 return connected_; 772 return connected_;
781 } 773 }
782 774
783 void QuicConnection::OnPacketComplete() { 775 void QuicConnection::OnPacketComplete() {
784 // Don't do anything if this packet closed the connection. 776 // Don't do anything if this packet closed the connection.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 last_blocked_frames_.clear(); 889 last_blocked_frames_.clear();
898 last_rst_frames_.clear(); 890 last_rst_frames_.clear();
899 last_ack_frames_.clear(); 891 last_ack_frames_.clear();
900 last_stop_waiting_frames_.clear(); 892 last_stop_waiting_frames_.clear();
901 last_congestion_frames_.clear(); 893 last_congestion_frames_.clear();
902 } 894 }
903 895
904 QuicAckFrame* QuicConnection::CreateAckFrame() { 896 QuicAckFrame* QuicConnection::CreateAckFrame() {
905 QuicAckFrame* outgoing_ack = new QuicAckFrame(); 897 QuicAckFrame* outgoing_ack = new QuicAckFrame();
906 received_packet_manager_.UpdateReceivedPacketInfo( 898 received_packet_manager_.UpdateReceivedPacketInfo(
907 &(outgoing_ack->received_info), clock_->ApproximateNow()); 899 outgoing_ack, clock_->ApproximateNow());
908 UpdateStopWaiting(&(outgoing_ack->sent_info));
909 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack; 900 DVLOG(1) << ENDPOINT << "Creating ack frame: " << *outgoing_ack;
910 return outgoing_ack; 901 return outgoing_ack;
911 } 902 }
912 903
913 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() { 904 QuicCongestionFeedbackFrame* QuicConnection::CreateFeedbackFrame() {
914 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_); 905 return new QuicCongestionFeedbackFrame(outgoing_congestion_feedback_);
915 } 906 }
916 907
917 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() { 908 QuicStopWaitingFrame* QuicConnection::CreateStopWaitingFrame() {
918 QuicStopWaitingFrame stop_waiting; 909 QuicStopWaitingFrame stop_waiting;
919 UpdateStopWaiting(&stop_waiting); 910 UpdateStopWaiting(&stop_waiting);
920 return new QuicStopWaitingFrame(stop_waiting); 911 return new QuicStopWaitingFrame(stop_waiting);
921 } 912 }
922 913
923 bool QuicConnection::ShouldLastPacketInstigateAck() const { 914 bool QuicConnection::ShouldLastPacketInstigateAck() const {
924 if (!last_stream_frames_.empty() || 915 if (!last_stream_frames_.empty() ||
925 !last_goaway_frames_.empty() || 916 !last_goaway_frames_.empty() ||
926 !last_rst_frames_.empty() || 917 !last_rst_frames_.empty() ||
927 !last_window_update_frames_.empty() || 918 !last_window_update_frames_.empty() ||
928 !last_blocked_frames_.empty()) { 919 !last_blocked_frames_.empty()) {
929 return true; 920 return true;
930 } 921 }
931 922
932 if (!last_ack_frames_.empty() && 923 if (!last_ack_frames_.empty() && last_ack_frames_.back().is_truncated) {
933 last_ack_frames_.back().received_info.is_truncated) {
934 return true; 924 return true;
935 } 925 }
936 return false; 926 return false;
937 } 927 }
938 928
939 void QuicConnection::UpdateStopWaitingCount() { 929 void QuicConnection::UpdateStopWaitingCount() {
940 if (last_ack_frames_.empty()) { 930 if (last_ack_frames_.empty()) {
941 return; 931 return;
942 } 932 }
943 933
944 // If the peer is still waiting for a packet that we are no longer planning to 934 // If the peer is still waiting for a packet that we are no longer planning to
945 // send, send an ack to raise the high water mark. 935 // send, send an ack to raise the high water mark.
946 if (!last_ack_frames_.back().received_info.missing_packets.empty() && 936 if (!last_ack_frames_.back().missing_packets.empty() &&
947 GetLeastUnacked() > 937 GetLeastUnacked() > *last_ack_frames_.back().missing_packets.begin()) {
948 *last_ack_frames_.back().received_info.missing_packets.begin()) {
949 ++stop_waiting_count_; 938 ++stop_waiting_count_;
950 } else { 939 } else {
951 stop_waiting_count_ = 0; 940 stop_waiting_count_ = 0;
952 } 941 }
953 } 942 }
954 943
955 QuicPacketSequenceNumber QuicConnection::GetLeastUnacked() const { 944 QuicPacketSequenceNumber QuicConnection::GetLeastUnacked() const {
956 return sent_packet_manager_.HasUnackedPackets() ? 945 return sent_packet_manager_.HasUnackedPackets() ?
957 sent_packet_manager_.GetLeastUnackedSentPacket() : 946 sent_packet_manager_.GetLeastUnackedSentPacket() :
958 packet_generator_.sequence_number() + 1; 947 packet_generator_.sequence_number() + 1;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 stats_.max_packet_size = packet_generator_.max_packet_length(); 1071 stats_.max_packet_size = packet_generator_.max_packet_length();
1083 return stats_; 1072 return stats_;
1084 } 1073 }
1085 1074
1086 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address, 1075 void QuicConnection::ProcessUdpPacket(const IPEndPoint& self_address,
1087 const IPEndPoint& peer_address, 1076 const IPEndPoint& peer_address,
1088 const QuicEncryptedPacket& packet) { 1077 const QuicEncryptedPacket& packet) {
1089 if (!connected_) { 1078 if (!connected_) {
1090 return; 1079 return;
1091 } 1080 }
1092 if (debug_visitor_) { 1081 if (debug_visitor_.get() != NULL) {
1093 debug_visitor_->OnPacketReceived(self_address, peer_address, packet); 1082 debug_visitor_->OnPacketReceived(self_address, peer_address, packet);
1094 } 1083 }
1095 last_packet_revived_ = false; 1084 last_packet_revived_ = false;
1096 last_size_ = packet.length(); 1085 last_size_ = packet.length();
1097 1086
1098 CheckForAddressMigration(self_address, peer_address); 1087 CheckForAddressMigration(self_address, peer_address);
1099 1088
1100 stats_.bytes_received += packet.length(); 1089 stats_.bytes_received += packet.length();
1101 ++stats_.packets_received; 1090 ++stats_.packets_received;
1102 1091
1103 if (!framer_.ProcessPacket(packet)) { 1092 if (!framer_.ProcessPacket(packet)) {
1104 // If we are unable to decrypt this packet, it might be 1093 // If we are unable to decrypt this packet, it might be
1105 // because the CHLO or SHLO packet was lost. 1094 // because the CHLO or SHLO packet was lost.
1106 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && 1095 if (framer_.error() == QUIC_DECRYPTION_FAILURE) {
1107 framer_.error() == QUIC_DECRYPTION_FAILURE && 1096 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE &&
1108 undecryptable_packets_.size() < kMaxUndecryptablePackets) { 1097 undecryptable_packets_.size() < kMaxUndecryptablePackets) {
1109 QueueUndecryptablePacket(packet); 1098 QueueUndecryptablePacket(packet);
1099 } else if (debug_visitor_.get() != NULL) {
1100 debug_visitor_->OnUndecryptablePacket();
1101 }
1110 } 1102 }
1111 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " 1103 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: "
1112 << last_header_.packet_sequence_number; 1104 << last_header_.packet_sequence_number;
1113 return; 1105 return;
1114 } 1106 }
1115 1107
1116 ++stats_.packets_processed; 1108 ++stats_.packets_processed;
1117 MaybeProcessUndecryptablePackets(); 1109 MaybeProcessUndecryptablePackets();
1118 MaybeProcessRevivedPacket(); 1110 MaybeProcessRevivedPacket();
1119 MaybeSendInResponseToPacket(); 1111 MaybeSendInResponseToPacket();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 // Flush the packet generator before making a new packet. 1246 // Flush the packet generator before making a new packet.
1255 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that 1247 // TODO(ianswett): Implement ReserializeAllFrames as a separate path that
1256 // does not require the creator to be flushed. 1248 // does not require the creator to be flushed.
1257 packet_generator_.FlushAllQueuedFrames(); 1249 packet_generator_.FlushAllQueuedFrames();
1258 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames( 1250 SerializedPacket serialized_packet = packet_generator_.ReserializeAllFrames(
1259 pending.retransmittable_frames.frames(), 1251 pending.retransmittable_frames.frames(),
1260 pending.sequence_number_length); 1252 pending.sequence_number_length);
1261 1253
1262 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number 1254 DVLOG(1) << ENDPOINT << "Retransmitting " << pending.sequence_number
1263 << " as " << serialized_packet.sequence_number; 1255 << " as " << serialized_packet.sequence_number;
1264 if (debug_visitor_) { 1256 if (debug_visitor_.get() != NULL) {
1265 debug_visitor_->OnPacketRetransmitted( 1257 debug_visitor_->OnPacketRetransmitted(
1266 pending.sequence_number, serialized_packet.sequence_number); 1258 pending.sequence_number, serialized_packet.sequence_number);
1267 } 1259 }
1268 sent_packet_manager_.OnRetransmittedPacket( 1260 sent_packet_manager_.OnRetransmittedPacket(
1269 pending.sequence_number, 1261 pending.sequence_number,
1270 serialized_packet.sequence_number); 1262 serialized_packet.sequence_number);
1271 1263
1272 SendOrQueuePacket(pending.retransmittable_frames.encryption_level(), 1264 SendOrQueuePacket(pending.retransmittable_frames.encryption_level(),
1273 serialized_packet, 1265 serialized_packet,
1274 pending.transmission_type); 1266 pending.transmission_type);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 DCHECK(pending_write_.get() == NULL); 1395 DCHECK(pending_write_.get() == NULL);
1404 pending_write_.reset(new QueuedPacket(packet)); 1396 pending_write_.reset(new QueuedPacket(packet));
1405 1397
1406 WriteResult result = writer_->WritePacket(encrypted->data(), 1398 WriteResult result = writer_->WritePacket(encrypted->data(),
1407 encrypted->length(), 1399 encrypted->length(),
1408 self_address().address(), 1400 self_address().address(),
1409 peer_address()); 1401 peer_address());
1410 if (result.error_code == ERR_IO_PENDING) { 1402 if (result.error_code == ERR_IO_PENDING) {
1411 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status); 1403 DCHECK_EQ(WRITE_STATUS_BLOCKED, result.status);
1412 } 1404 }
1413 if (debug_visitor_) { 1405 if (debug_visitor_.get() != NULL) {
1414 // Pass the write result to the visitor. 1406 // Pass the write result to the visitor.
1415 debug_visitor_->OnPacketSent(sequence_number, 1407 debug_visitor_->OnPacketSent(sequence_number,
1416 packet.encryption_level, 1408 packet.encryption_level,
1417 packet.transmission_type, 1409 packet.transmission_type,
1418 *encrypted, 1410 *encrypted,
1419 result); 1411 result);
1420 } 1412 }
1421 if (result.status == WRITE_STATUS_BLOCKED) { 1413 if (result.status == WRITE_STATUS_BLOCKED) {
1422 visitor_->OnWriteBlocked(); 1414 visitor_->OnWriteBlocked();
1423 // If the socket buffers the the data, then the packet should not 1415 // If the socket buffers the the data, then the packet should not
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) { 1568 void QuicConnection::UpdateStopWaiting(QuicStopWaitingFrame* stop_waiting) {
1577 stop_waiting->least_unacked = GetLeastUnacked(); 1569 stop_waiting->least_unacked = GetLeastUnacked();
1578 stop_waiting->entropy_hash = sent_entropy_manager_.EntropyHash( 1570 stop_waiting->entropy_hash = sent_entropy_manager_.EntropyHash(
1579 stop_waiting->least_unacked - 1); 1571 stop_waiting->least_unacked - 1);
1580 } 1572 }
1581 1573
1582 void QuicConnection::SendPing() { 1574 void QuicConnection::SendPing() {
1583 if (retransmission_alarm_->IsSet()) { 1575 if (retransmission_alarm_->IsSet()) {
1584 return; 1576 return;
1585 } 1577 }
1586 if (version() <= QUIC_VERSION_16) { 1578 if (version() == QUIC_VERSION_16) {
1587 // TODO(rch): remove this when we remove version 15 and 16. 1579 // TODO(rch): remove this when we remove version 15 and 16.
1588 // This is a horrible hideous hack which we should not support. 1580 // This is a horrible hideous hack which we should not support.
1589 IOVector data; 1581 IOVector data;
1590 char c_data[] = "C"; 1582 char c_data[] = "C";
1591 data.Append(c_data, 1); 1583 data.Append(c_data, 1);
1592 QuicConsumedData consumed_data = 1584 QuicConsumedData consumed_data =
1593 packet_generator_.ConsumeData(kCryptoStreamId, data, 0, false, 1585 packet_generator_.ConsumeData(kCryptoStreamId, data, 0, false,
1594 MAY_FEC_PROTECT, NULL); 1586 MAY_FEC_PROTECT, NULL);
1595 if (consumed_data.bytes_consumed == 0) { 1587 if (consumed_data.bytes_consumed == 0) {
1596 DLOG(ERROR) << "Unable to send ping!?"; 1588 DLOG(ERROR) << "Unable to send ping!?";
(...skipping 10 matching lines...) Expand all
1607 // method is invoked. This requires changes SetShouldSendAck 1599 // method is invoked. This requires changes SetShouldSendAck
1608 // to be a no-arg method, and re-jiggering its implementation. 1600 // to be a no-arg method, and re-jiggering its implementation.
1609 bool send_feedback = false; 1601 bool send_feedback = false;
1610 if (received_packet_manager_.GenerateCongestionFeedback( 1602 if (received_packet_manager_.GenerateCongestionFeedback(
1611 &outgoing_congestion_feedback_)) { 1603 &outgoing_congestion_feedback_)) {
1612 DVLOG(1) << ENDPOINT << "Sending feedback: " 1604 DVLOG(1) << ENDPOINT << "Sending feedback: "
1613 << outgoing_congestion_feedback_; 1605 << outgoing_congestion_feedback_;
1614 send_feedback = true; 1606 send_feedback = true;
1615 } 1607 }
1616 1608
1617 packet_generator_.SetShouldSendAck(send_feedback, 1609 packet_generator_.SetShouldSendAck(send_feedback, true);
1618 version() > QUIC_VERSION_15);
1619 } 1610 }
1620 1611
1621 void QuicConnection::OnRetransmissionTimeout() { 1612 void QuicConnection::OnRetransmissionTimeout() {
1622 if (!sent_packet_manager_.HasUnackedPackets()) { 1613 if (!sent_packet_manager_.HasUnackedPackets()) {
1623 return; 1614 return;
1624 } 1615 }
1625 1616
1626 sent_packet_manager_.OnRetransmissionTimeout(); 1617 sent_packet_manager_.OnRetransmissionTimeout();
1627 WriteIfNotBlocked(); 1618 WriteIfNotBlocked();
1628 // In the TLP case, the SentPacketManager gives the connection the opportunity 1619 // In the TLP case, the SentPacketManager gives the connection the opportunity
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!"; 1688 DVLOG(1) << ENDPOINT << "Processed undecryptable packet!";
1698 ++stats_.packets_processed; 1689 ++stats_.packets_processed;
1699 delete packet; 1690 delete packet;
1700 undecryptable_packets_.pop_front(); 1691 undecryptable_packets_.pop_front();
1701 } 1692 }
1702 1693
1703 // Once forward secure encryption is in use, there will be no 1694 // Once forward secure encryption is in use, there will be no
1704 // new keys installed and hence any undecryptable packets will 1695 // new keys installed and hence any undecryptable packets will
1705 // never be able to be decrypted. 1696 // never be able to be decrypted.
1706 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) { 1697 if (encryption_level_ == ENCRYPTION_FORWARD_SECURE) {
1698 if (debug_visitor_ != NULL) {
wtc 2014/08/04 23:28:12 debug_visitor_ => debug_visitor_.get()
ramant (doing other things) 2014/08/09 02:53:19 Done.
1699 for (size_t i = 0; i < undecryptable_packets_.size(); ++i) {
1700 debug_visitor_->OnUndecryptablePacket();
wtc 2014/08/04 23:28:12 Nit: perhaps more efficient to pass the number of
ramant (doing other things) 2014/08/09 02:53:19 Good point. We are not using this method yet. Adde
1701 }
1702 }
1707 STLDeleteElements(&undecryptable_packets_); 1703 STLDeleteElements(&undecryptable_packets_);
1708 } 1704 }
1709 } 1705 }
1710 1706
1711 void QuicConnection::MaybeProcessRevivedPacket() { 1707 void QuicConnection::MaybeProcessRevivedPacket() {
1712 QuicFecGroup* group = GetFecGroup(); 1708 QuicFecGroup* group = GetFecGroup();
1713 if (!connected_ || group == NULL || !group->CanRevive()) { 1709 if (!connected_ || group == NULL || !group->CanRevive()) {
1714 return; 1710 return;
1715 } 1711 }
1716 QuicPacketHeader revived_header; 1712 QuicPacketHeader revived_header;
1717 char revived_payload[kMaxPacketSize]; 1713 char revived_payload[kMaxPacketSize];
1718 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize); 1714 size_t len = group->Revive(&revived_header, revived_payload, kMaxPacketSize);
1719 revived_header.public_header.connection_id = connection_id_; 1715 revived_header.public_header.connection_id = connection_id_;
1720 revived_header.public_header.connection_id_length = 1716 revived_header.public_header.connection_id_length =
1721 last_header_.public_header.connection_id_length; 1717 last_header_.public_header.connection_id_length;
1722 revived_header.public_header.version_flag = false; 1718 revived_header.public_header.version_flag = false;
1723 revived_header.public_header.reset_flag = false; 1719 revived_header.public_header.reset_flag = false;
1724 revived_header.public_header.sequence_number_length = 1720 revived_header.public_header.sequence_number_length =
1725 last_header_.public_header.sequence_number_length; 1721 last_header_.public_header.sequence_number_length;
1726 revived_header.fec_flag = false; 1722 revived_header.fec_flag = false;
1727 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP; 1723 revived_header.is_in_fec_group = NOT_IN_FEC_GROUP;
1728 revived_header.fec_group = 0; 1724 revived_header.fec_group = 0;
1729 group_map_.erase(last_header_.fec_group); 1725 group_map_.erase(last_header_.fec_group);
1730 last_decrypted_packet_level_ = group->effective_encryption_level(); 1726 last_decrypted_packet_level_ = group->effective_encryption_level();
1731 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS); 1727 DCHECK_LT(last_decrypted_packet_level_, NUM_ENCRYPTION_LEVELS);
1732 delete group; 1728 delete group;
1733 1729
1734 last_packet_revived_ = true; 1730 last_packet_revived_ = true;
1735 if (debug_visitor_) { 1731 if (debug_visitor_.get() != NULL) {
1736 debug_visitor_->OnRevivedPacket(revived_header, 1732 debug_visitor_->OnRevivedPacket(revived_header,
1737 StringPiece(revived_payload, len)); 1733 StringPiece(revived_payload, len));
1738 } 1734 }
1739 1735
1740 ++stats_.packets_revived; 1736 ++stats_.packets_revived;
1741 framer_.ProcessRevivedPacket(&revived_header, 1737 framer_.ProcessRevivedPacket(&revived_header,
1742 StringPiece(revived_payload, len)); 1738 StringPiece(revived_payload, len));
1743 } 1739 }
1744 1740
1745 QuicFecGroup* QuicConnection::GetFecGroup() { 1741 QuicFecGroup* QuicConnection::GetFecGroup() {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 // If we changed the generator's batch state, restore original batch state. 1983 // If we changed the generator's batch state, restore original batch state.
1988 if (!already_in_batch_mode_) { 1984 if (!already_in_batch_mode_) {
1989 DVLOG(1) << "Leaving Batch Mode."; 1985 DVLOG(1) << "Leaving Batch Mode.";
1990 connection_->packet_generator_.FinishBatchOperations(); 1986 connection_->packet_generator_.FinishBatchOperations();
1991 } 1987 }
1992 DCHECK_EQ(already_in_batch_mode_, 1988 DCHECK_EQ(already_in_batch_mode_,
1993 connection_->packet_generator_.InBatchMode()); 1989 connection_->packet_generator_.InBatchMode());
1994 } 1990 }
1995 1991
1996 } // namespace net 1992 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698