OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 SendConnectionClose(QUIC_INVALID_ACK_DATA); | 551 SendConnectionClose(QUIC_INVALID_ACK_DATA); |
552 return false; | 552 return false; |
553 } | 553 } |
554 | 554 |
555 last_ack_frames_.push_back(incoming_ack); | 555 last_ack_frames_.push_back(incoming_ack); |
556 return connected_; | 556 return connected_; |
557 } | 557 } |
558 | 558 |
559 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { | 559 void QuicConnection::ProcessAckFrame(const QuicAckFrame& incoming_ack) { |
560 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; | 560 largest_seen_packet_with_ack_ = last_header_.packet_sequence_number; |
561 received_packet_manager_.UpdatePacketInformationReceivedByPeer(incoming_ack); | |
562 | |
563 sent_entropy_manager_.ClearEntropyBefore( | |
564 received_packet_manager_.least_packet_awaited_by_peer() - 1); | |
565 | |
566 sent_packet_manager_.OnIncomingAck(incoming_ack, | 561 sent_packet_manager_.OnIncomingAck(incoming_ack, |
567 time_of_last_received_packet_); | 562 time_of_last_received_packet_); |
| 563 sent_entropy_manager_.ClearEntropyBefore( |
| 564 sent_packet_manager_.least_packet_awaited_by_peer() - 1); |
568 if (sent_packet_manager_.HasPendingRetransmissions()) { | 565 if (sent_packet_manager_.HasPendingRetransmissions()) { |
569 WriteIfNotBlocked(); | 566 WriteIfNotBlocked(); |
570 } | 567 } |
571 | 568 |
572 // Always reset the retransmission alarm when an ack comes in, since we now | 569 // Always reset the retransmission alarm when an ack comes in, since we now |
573 // have a better estimate of the current rtt than when it was set. | 570 // have a better estimate of the current rtt than when it was set. |
574 QuicTime retransmission_time = | 571 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); |
575 sent_packet_manager_.GetRetransmissionTime(); | |
576 retransmission_alarm_->Update(retransmission_time, | 572 retransmission_alarm_->Update(retransmission_time, |
577 QuicTime::Delta::FromMilliseconds(1)); | 573 QuicTime::Delta::FromMilliseconds(1)); |
578 } | 574 } |
579 | 575 |
580 void QuicConnection::ProcessStopWaitingFrame( | 576 void QuicConnection::ProcessStopWaitingFrame( |
581 const QuicStopWaitingFrame& stop_waiting) { | 577 const QuicStopWaitingFrame& stop_waiting) { |
582 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; | 578 largest_seen_packet_with_stop_waiting_ = last_header_.packet_sequence_number; |
583 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); | 579 received_packet_manager_.UpdatePacketInformationSentByPeer(stop_waiting); |
584 // Possibly close any FecGroups which are now irrelevant. | 580 // Possibly close any FecGroups which are now irrelevant. |
585 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); | 581 CloseFecGroupsBefore(stop_waiting.least_unacked + 1); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 623 |
628 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { | 624 bool QuicConnection::ValidateAckFrame(const QuicAckFrame& incoming_ack) { |
629 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { | 625 if (incoming_ack.largest_observed > packet_generator_.sequence_number()) { |
630 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" | 626 DLOG(ERROR) << ENDPOINT << "Peer's observed unsent packet:" |
631 << incoming_ack.largest_observed << " vs " | 627 << incoming_ack.largest_observed << " vs " |
632 << packet_generator_.sequence_number(); | 628 << packet_generator_.sequence_number(); |
633 // We got an error for data we have not sent. Error out. | 629 // We got an error for data we have not sent. Error out. |
634 return false; | 630 return false; |
635 } | 631 } |
636 | 632 |
637 if (incoming_ack.largest_observed < | 633 if (incoming_ack.largest_observed < sent_packet_manager_.largest_observed()) { |
638 received_packet_manager_.peer_largest_observed_packet()) { | |
639 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" | 634 DLOG(ERROR) << ENDPOINT << "Peer's largest_observed packet decreased:" |
640 << incoming_ack.largest_observed << " vs " | 635 << incoming_ack.largest_observed << " vs " |
641 << received_packet_manager_.peer_largest_observed_packet(); | 636 << sent_packet_manager_.largest_observed(); |
642 // A new ack has a diminished largest_observed value. Error out. | 637 // A new ack has a diminished largest_observed value. Error out. |
643 // If this was an old packet, we wouldn't even have checked. | 638 // If this was an old packet, we wouldn't even have checked. |
644 return false; | 639 return false; |
645 } | 640 } |
646 | 641 |
647 if (!incoming_ack.missing_packets.empty() && | 642 if (!incoming_ack.missing_packets.empty() && |
648 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { | 643 *incoming_ack.missing_packets.rbegin() > incoming_ack.largest_observed) { |
649 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 644 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
650 << *incoming_ack.missing_packets.rbegin() | 645 << *incoming_ack.missing_packets.rbegin() |
651 << " which is greater than largest observed: " | 646 << " which is greater than largest observed: " |
652 << incoming_ack.largest_observed; | 647 << incoming_ack.largest_observed; |
653 return false; | 648 return false; |
654 } | 649 } |
655 | 650 |
656 if (!incoming_ack.missing_packets.empty() && | 651 if (!incoming_ack.missing_packets.empty() && |
657 *incoming_ack.missing_packets.begin() < | 652 *incoming_ack.missing_packets.begin() < |
658 received_packet_manager_.least_packet_awaited_by_peer()) { | 653 sent_packet_manager_.least_packet_awaited_by_peer()) { |
659 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " | 654 DLOG(ERROR) << ENDPOINT << "Peer sent missing packet: " |
660 << *incoming_ack.missing_packets.begin() | 655 << *incoming_ack.missing_packets.begin() |
661 << " which is smaller than least_packet_awaited_by_peer_: " | 656 << " which is smaller than least_packet_awaited_by_peer_: " |
662 << received_packet_manager_.least_packet_awaited_by_peer(); | 657 << sent_packet_manager_.least_packet_awaited_by_peer(); |
663 return false; | 658 return false; |
664 } | 659 } |
665 | 660 |
666 if (!sent_entropy_manager_.IsValidEntropy( | 661 if (!sent_entropy_manager_.IsValidEntropy( |
667 incoming_ack.largest_observed, | 662 incoming_ack.largest_observed, |
668 incoming_ack.missing_packets, | 663 incoming_ack.missing_packets, |
669 incoming_ack.entropy_hash)) { | 664 incoming_ack.entropy_hash)) { |
670 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; | 665 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; |
671 return false; | 666 return false; |
672 } | 667 } |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 if (transmission_type == NOT_RETRANSMISSION) { | 1492 if (transmission_type == NOT_RETRANSMISSION) { |
1498 time_of_last_sent_new_packet_ = now; | 1493 time_of_last_sent_new_packet_ = now; |
1499 } | 1494 } |
1500 SetPingAlarm(); | 1495 SetPingAlarm(); |
1501 DVLOG(1) << ENDPOINT << "time of last sent packet: " | 1496 DVLOG(1) << ENDPOINT << "time of last sent packet: " |
1502 << now.ToDebuggingValue(); | 1497 << now.ToDebuggingValue(); |
1503 | 1498 |
1504 // TODO(ianswett): Change the sequence number length and other packet creator | 1499 // TODO(ianswett): Change the sequence number length and other packet creator |
1505 // options by a more explicit API than setting a struct value directly. | 1500 // options by a more explicit API than setting a struct value directly. |
1506 packet_generator_.UpdateSequenceNumberLength( | 1501 packet_generator_.UpdateSequenceNumberLength( |
1507 received_packet_manager_.least_packet_awaited_by_peer(), | 1502 sent_packet_manager_.least_packet_awaited_by_peer(), |
1508 sent_packet_manager_.GetCongestionWindow()); | 1503 sent_packet_manager_.GetCongestionWindow()); |
1509 | 1504 |
1510 bool reset_retransmission_alarm = | 1505 bool reset_retransmission_alarm = |
1511 sent_packet_manager_.OnPacketSent(sequence_number, now, length, | 1506 sent_packet_manager_.OnPacketSent(sequence_number, now, length, |
1512 transmission_type, retransmittable); | 1507 transmission_type, retransmittable); |
1513 | 1508 |
1514 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { | 1509 if (reset_retransmission_alarm || !retransmission_alarm_->IsSet()) { |
1515 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); | 1510 QuicTime retransmission_time = sent_packet_manager_.GetRetransmissionTime(); |
1516 retransmission_alarm_->Update(retransmission_time, | 1511 retransmission_alarm_->Update(retransmission_time, |
1517 QuicTime::Delta::FromMilliseconds(1)); | 1512 QuicTime::Delta::FromMilliseconds(1)); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2014 // If we changed the generator's batch state, restore original batch state. | 2009 // If we changed the generator's batch state, restore original batch state. |
2015 if (!already_in_batch_mode_) { | 2010 if (!already_in_batch_mode_) { |
2016 DVLOG(1) << "Leaving Batch Mode."; | 2011 DVLOG(1) << "Leaving Batch Mode."; |
2017 connection_->packet_generator_.FinishBatchOperations(); | 2012 connection_->packet_generator_.FinishBatchOperations(); |
2018 } | 2013 } |
2019 DCHECK_EQ(already_in_batch_mode_, | 2014 DCHECK_EQ(already_in_batch_mode_, |
2020 connection_->packet_generator_.InBatchMode()); | 2015 connection_->packet_generator_.InBatchMode()); |
2021 } | 2016 } |
2022 | 2017 |
2023 } // namespace net | 2018 } // namespace net |
OLD | NEW |