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/core/quic_connection.h" | 5 #include "net/quic/core/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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const QuicVersionVector& supported_versions) | 192 const QuicVersionVector& supported_versions) |
193 : framer_(supported_versions, | 193 : framer_(supported_versions, |
194 helper->GetClock()->ApproximateNow(), | 194 helper->GetClock()->ApproximateNow(), |
195 perspective), | 195 perspective), |
196 helper_(helper), | 196 helper_(helper), |
197 alarm_factory_(alarm_factory), | 197 alarm_factory_(alarm_factory), |
198 per_packet_options_(nullptr), | 198 per_packet_options_(nullptr), |
199 writer_(writer), | 199 writer_(writer), |
200 owns_writer_(owns_writer), | 200 owns_writer_(owns_writer), |
201 encryption_level_(ENCRYPTION_NONE), | 201 encryption_level_(ENCRYPTION_NONE), |
202 has_forward_secure_encrypter_(false), | |
203 first_required_forward_secure_packet_(0), | |
204 clock_(helper->GetClock()), | 202 clock_(helper->GetClock()), |
205 random_generator_(helper->GetRandomGenerator()), | 203 random_generator_(helper->GetRandomGenerator()), |
206 connection_id_(connection_id), | 204 connection_id_(connection_id), |
207 peer_address_(address), | 205 peer_address_(address), |
208 active_peer_migration_type_(NO_CHANGE), | 206 active_peer_migration_type_(NO_CHANGE), |
209 highest_packet_sent_before_peer_migration_(0), | 207 highest_packet_sent_before_peer_migration_(0), |
210 last_packet_decrypted_(false), | 208 last_packet_decrypted_(false), |
211 last_size_(0), | 209 last_size_(0), |
212 current_packet_data_(nullptr), | 210 current_packet_data_(nullptr), |
213 last_decrypted_packet_level_(ENCRYPTION_NONE), | 211 last_decrypted_packet_level_(ENCRYPTION_NONE), |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 return false; | 628 return false; |
631 } | 629 } |
632 | 630 |
633 return true; | 631 return true; |
634 } | 632 } |
635 | 633 |
636 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { | 634 void QuicConnection::OnDecryptedPacket(EncryptionLevel level) { |
637 last_decrypted_packet_level_ = level; | 635 last_decrypted_packet_level_ = level; |
638 last_packet_decrypted_ = true; | 636 last_packet_decrypted_ = true; |
639 | 637 |
640 // If this packet was foward-secure encrypted and the forward-secure encrypter | |
641 // is not being used, start using it. | |
642 if (encryption_level_ != ENCRYPTION_FORWARD_SECURE && | |
643 has_forward_secure_encrypter_ && level == ENCRYPTION_FORWARD_SECURE) { | |
644 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | |
645 } | |
646 | |
647 // Once the server receives a forward secure packet, the handshake is | 638 // Once the server receives a forward secure packet, the handshake is |
648 // confirmed. | 639 // confirmed. |
649 if (level == ENCRYPTION_FORWARD_SECURE && | 640 if (level == ENCRYPTION_FORWARD_SECURE && |
650 perspective_ == Perspective::IS_SERVER) { | 641 perspective_ == Perspective::IS_SERVER) { |
651 sent_packet_manager_->SetHandshakeConfirmed(); | 642 sent_packet_manager_->SetHandshakeConfirmed(); |
652 } | 643 } |
653 } | 644 } |
654 | 645 |
655 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { | 646 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { |
656 if (debug_visitor_ != nullptr) { | 647 if (debug_visitor_ != nullptr) { |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 // If there are already queued packets, queue this one immediately to ensure | 1885 // If there are already queued packets, queue this one immediately to ensure |
1895 // it's written in sequence number order. | 1886 // it's written in sequence number order. |
1896 if (!queued_packets_.empty() || !WritePacket(packet)) { | 1887 if (!queued_packets_.empty() || !WritePacket(packet)) { |
1897 // Take ownership of the underlying encrypted packet. | 1888 // Take ownership of the underlying encrypted packet. |
1898 packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet); | 1889 packet->encrypted_buffer = QuicUtils::CopyBuffer(*packet); |
1899 queued_packets_.push_back(*packet); | 1890 queued_packets_.push_back(*packet); |
1900 packet->retransmittable_frames.clear(); | 1891 packet->retransmittable_frames.clear(); |
1901 } | 1892 } |
1902 | 1893 |
1903 QuicUtils::ClearSerializedPacket(packet); | 1894 QuicUtils::ClearSerializedPacket(packet); |
1904 // If a forward-secure encrypter is available but is not being used and the | |
1905 // next packet number is the first packet which requires | |
1906 // forward security, start using the forward-secure encrypter. | |
1907 if (!FLAGS_quic_remove_obsolete_forward_secure && | |
1908 encryption_level_ != ENCRYPTION_FORWARD_SECURE && | |
1909 has_forward_secure_encrypter_ && | |
1910 packet->packet_number >= first_required_forward_secure_packet_ - 1) { | |
1911 SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); | |
1912 } | |
1913 } | 1895 } |
1914 | 1896 |
1915 void QuicConnection::OnPingTimeout() { | 1897 void QuicConnection::OnPingTimeout() { |
1916 if (!retransmission_alarm_->IsSet()) { | 1898 if (!retransmission_alarm_->IsSet()) { |
1917 SendPing(); | 1899 SendPing(); |
1918 } | 1900 } |
1919 } | 1901 } |
1920 | 1902 |
1921 void QuicConnection::SendPing() { | 1903 void QuicConnection::SendPing() { |
1922 ScopedPacketBundler bundler(this, SEND_ACK_IF_QUEUED); | 1904 ScopedPacketBundler bundler(this, SEND_ACK_IF_QUEUED); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1971 // This happens if the loss algorithm invokes a timer based loss, but the | 1953 // This happens if the loss algorithm invokes a timer based loss, but the |
1972 // packet doesn't need to be retransmitted. | 1954 // packet doesn't need to be retransmitted. |
1973 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) { | 1955 if (!HasQueuedData() && !retransmission_alarm_->IsSet()) { |
1974 SetRetransmissionAlarm(); | 1956 SetRetransmissionAlarm(); |
1975 } | 1957 } |
1976 } | 1958 } |
1977 | 1959 |
1978 void QuicConnection::SetEncrypter(EncryptionLevel level, | 1960 void QuicConnection::SetEncrypter(EncryptionLevel level, |
1979 QuicEncrypter* encrypter) { | 1961 QuicEncrypter* encrypter) { |
1980 packet_generator_.SetEncrypter(level, encrypter); | 1962 packet_generator_.SetEncrypter(level, encrypter); |
1981 if (!FLAGS_quic_remove_obsolete_forward_secure && | |
1982 level == ENCRYPTION_FORWARD_SECURE) { | |
1983 has_forward_secure_encrypter_ = true; | |
1984 first_required_forward_secure_packet_ = | |
1985 packet_number_of_last_sent_packet_ + | |
1986 // 3 times the current congestion window (in slow start) should cover | |
1987 // about two full round trips worth of packets, which should be | |
1988 // sufficient. | |
1989 3 * | |
1990 sent_packet_manager_->EstimateMaxPacketsInFlight( | |
1991 max_packet_length()); | |
1992 } | |
1993 } | 1963 } |
1994 | 1964 |
1995 void QuicConnection::SetDiversificationNonce(const DiversificationNonce nonce) { | 1965 void QuicConnection::SetDiversificationNonce(const DiversificationNonce nonce) { |
1996 DCHECK_EQ(Perspective::IS_SERVER, perspective_); | 1966 DCHECK_EQ(Perspective::IS_SERVER, perspective_); |
1997 packet_generator_.SetDiversificationNonce(nonce); | 1967 packet_generator_.SetDiversificationNonce(nonce); |
1998 } | 1968 } |
1999 | 1969 |
2000 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { | 1970 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { |
2001 encryption_level_ = level; | 1971 encryption_level_ = level; |
2002 packet_generator_.set_encryption_level(level); | 1972 packet_generator_.set_encryption_level(level); |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 | 2552 |
2583 void QuicConnection::CheckIfApplicationLimited() { | 2553 void QuicConnection::CheckIfApplicationLimited() { |
2584 if (queued_packets_.empty() && | 2554 if (queued_packets_.empty() && |
2585 !sent_packet_manager_->HasPendingRetransmissions() && | 2555 !sent_packet_manager_->HasPendingRetransmissions() && |
2586 !visitor_->WillingAndAbleToWrite()) { | 2556 !visitor_->WillingAndAbleToWrite()) { |
2587 sent_packet_manager_->OnApplicationLimited(); | 2557 sent_packet_manager_->OnApplicationLimited(); |
2588 } | 2558 } |
2589 } | 2559 } |
2590 | 2560 |
2591 } // namespace net | 2561 } // namespace net |
OLD | NEW |