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( |
| 1966 const DiversificationNonce& nonce) { |
1996 DCHECK_EQ(Perspective::IS_SERVER, perspective_); | 1967 DCHECK_EQ(Perspective::IS_SERVER, perspective_); |
1997 packet_generator_.SetDiversificationNonce(nonce); | 1968 packet_generator_.SetDiversificationNonce(nonce); |
1998 } | 1969 } |
1999 | 1970 |
2000 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { | 1971 void QuicConnection::SetDefaultEncryptionLevel(EncryptionLevel level) { |
2001 encryption_level_ = level; | 1972 encryption_level_ = level; |
2002 packet_generator_.set_encryption_level(level); | 1973 packet_generator_.set_encryption_level(level); |
2003 } | 1974 } |
2004 | 1975 |
2005 void QuicConnection::SetDecrypter(EncryptionLevel level, | 1976 void QuicConnection::SetDecrypter(EncryptionLevel level, |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 // There are two important approaches to remedy this situation: | 2343 // There are two important approaches to remedy this situation: |
2373 // (1) Instantiate ScopedPacketBundler before performing multiple subsequent | 2344 // (1) Instantiate ScopedPacketBundler before performing multiple subsequent |
2374 // writes, thus deferring this check until all writes are done. | 2345 // writes, thus deferring this check until all writes are done. |
2375 // (2) Write data in chunks sufficiently large so that they cause the | 2346 // (2) Write data in chunks sufficiently large so that they cause the |
2376 // connection to be limited by the congestion control. Typically, this | 2347 // connection to be limited by the congestion control. Typically, this |
2377 // would mean writing chunks larger than the product of the current | 2348 // would mean writing chunks larger than the product of the current |
2378 // pacing rate and the pacer granularity. So, for instance, if the | 2349 // pacing rate and the pacer granularity. So, for instance, if the |
2379 // pacing rate of the connection is 1 Gbps, and the pacer granularity is | 2350 // pacing rate of the connection is 1 Gbps, and the pacer granularity is |
2380 // 1 ms, the caller should send at least 125k bytes in order to not | 2351 // 1 ms, the caller should send at least 125k bytes in order to not |
2381 // be marked as application-limited. | 2352 // be marked as application-limited. |
2382 if (FLAGS_quic_enable_app_limited_check) { | 2353 connection_->CheckIfApplicationLimited(); |
2383 connection_->CheckIfApplicationLimited(); | |
2384 } | |
2385 } | 2354 } |
2386 DCHECK_EQ(already_in_batch_mode_, | 2355 DCHECK_EQ(already_in_batch_mode_, |
2387 connection_->packet_generator_.InBatchMode()); | 2356 connection_->packet_generator_.InBatchMode()); |
2388 } | 2357 } |
2389 | 2358 |
2390 QuicConnection::ScopedRetransmissionScheduler::ScopedRetransmissionScheduler( | 2359 QuicConnection::ScopedRetransmissionScheduler::ScopedRetransmissionScheduler( |
2391 QuicConnection* connection) | 2360 QuicConnection* connection) |
2392 : connection_(connection), | 2361 : connection_(connection), |
2393 already_delayed_(connection_->delay_setting_retransmission_alarm_) { | 2362 already_delayed_(connection_->delay_setting_retransmission_alarm_) { |
2394 connection_->delay_setting_retransmission_alarm_ = true; | 2363 connection_->delay_setting_retransmission_alarm_ = true; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 | 2553 |
2585 void QuicConnection::CheckIfApplicationLimited() { | 2554 void QuicConnection::CheckIfApplicationLimited() { |
2586 if (queued_packets_.empty() && | 2555 if (queued_packets_.empty() && |
2587 !sent_packet_manager_->HasPendingRetransmissions() && | 2556 !sent_packet_manager_->HasPendingRetransmissions() && |
2588 !visitor_->WillingAndAbleToWrite()) { | 2557 !visitor_->WillingAndAbleToWrite()) { |
2589 sent_packet_manager_->OnApplicationLimited(); | 2558 sent_packet_manager_->OnApplicationLimited(); |
2590 } | 2559 } |
2591 } | 2560 } |
2592 | 2561 |
2593 } // namespace net | 2562 } // namespace net |
OLD | NEW |