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 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 TransmissionType transmission_type, | 237 TransmissionType transmission_type, |
238 QuicPacketNumber original_packet_number) | 238 QuicPacketNumber original_packet_number) |
239 : serialized_packet(packet), | 239 : serialized_packet(packet), |
240 encryption_level(level), | 240 encryption_level(level), |
241 transmission_type(transmission_type), | 241 transmission_type(transmission_type), |
242 original_packet_number(original_packet_number) {} | 242 original_packet_number(original_packet_number) {} |
243 | 243 |
244 #define ENDPOINT \ | 244 #define ENDPOINT \ |
245 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") | 245 (perspective_ == Perspective::IS_SERVER ? "Server: " : "Client: ") |
246 | 246 |
247 QuicConnection::QuicConnection(QuicConnectionId connection_id, | 247 QuicConnection::QuicConnection( |
248 IPEndPoint address, | 248 QuicConnectionId connection_id, |
249 QuicConnectionHelperInterface* helper, | 249 IPEndPoint address, |
250 const PacketWriterFactory& writer_factory, | 250 QuicConnectionHelperInterface* helper, |
251 bool owns_writer, | 251 const PacketWriterFactory& writer_factory, |
252 Perspective perspective, | 252 bool owns_writer, |
253 bool is_secure, | 253 Perspective perspective, |
254 const QuicVersionVector& supported_versions) | 254 bool is_secure, |
| 255 const QuicVersionVector& supported_versions, |
| 256 scoped_ptr<SocketPerformanceWatcher> socket_performance_watcher) |
255 : framer_(supported_versions, | 257 : framer_(supported_versions, |
256 helper->GetClock()->ApproximateNow(), | 258 helper->GetClock()->ApproximateNow(), |
257 perspective), | 259 perspective), |
258 helper_(helper), | 260 helper_(helper), |
259 writer_(writer_factory.Create(this)), | 261 writer_(writer_factory.Create(this)), |
260 owns_writer_(owns_writer), | 262 owns_writer_(owns_writer), |
261 encryption_level_(ENCRYPTION_NONE), | 263 encryption_level_(ENCRYPTION_NONE), |
262 has_forward_secure_encrypter_(false), | 264 has_forward_secure_encrypter_(false), |
263 first_required_forward_secure_packet_(0), | 265 first_required_forward_secure_packet_(0), |
264 clock_(helper->GetClock()), | 266 clock_(helper->GetClock()), |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 self_ip_changed_(false), | 315 self_ip_changed_(false), |
314 self_port_changed_(false), | 316 self_port_changed_(false), |
315 can_truncate_connection_ids_(true), | 317 can_truncate_connection_ids_(true), |
316 is_secure_(is_secure), | 318 is_secure_(is_secure), |
317 mtu_discovery_target_(0), | 319 mtu_discovery_target_(0), |
318 mtu_probe_count_(0), | 320 mtu_probe_count_(0), |
319 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), | 321 packets_between_mtu_probes_(kPacketsBetweenMtuProbesBase), |
320 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), | 322 next_mtu_probe_at_(kPacketsBetweenMtuProbesBase), |
321 largest_received_packet_size_(0), | 323 largest_received_packet_size_(0), |
322 goaway_sent_(false), | 324 goaway_sent_(false), |
323 goaway_received_(false) { | 325 goaway_received_(false), |
| 326 socket_performance_watcher_(socket_performance_watcher.Pass()) { |
324 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " | 327 DVLOG(1) << ENDPOINT << "Created connection with connection_id: " |
325 << connection_id; | 328 << connection_id; |
326 framer_.set_visitor(this); | 329 framer_.set_visitor(this); |
327 framer_.set_received_entropy_calculator(&received_packet_manager_); | 330 framer_.set_received_entropy_calculator(&received_packet_manager_); |
328 stats_.connection_creation_time = clock_->ApproximateNow(); | 331 stats_.connection_creation_time = clock_->ApproximateNow(); |
329 sent_packet_manager_.set_network_change_visitor(this); | 332 sent_packet_manager_.set_network_change_visitor(this); |
330 if (perspective_ == Perspective::IS_SERVER) { | 333 if (perspective_ == Perspective::IS_SERVER) { |
331 set_max_packet_length(kDefaultServerMaxPacketSize); | 334 set_max_packet_length(kDefaultServerMaxPacketSize); |
332 } | 335 } |
333 } | 336 } |
(...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " | 1384 DVLOG(1) << ENDPOINT << "Unable to process packet. Last packet processed: " |
1382 << last_header_.packet_packet_number; | 1385 << last_header_.packet_packet_number; |
1383 return; | 1386 return; |
1384 } | 1387 } |
1385 | 1388 |
1386 ++stats_.packets_processed; | 1389 ++stats_.packets_processed; |
1387 MaybeProcessUndecryptablePackets(); | 1390 MaybeProcessUndecryptablePackets(); |
1388 MaybeProcessRevivedPacket(); | 1391 MaybeProcessRevivedPacket(); |
1389 MaybeSendInResponseToPacket(); | 1392 MaybeSendInResponseToPacket(); |
1390 SetPingAlarm(); | 1393 SetPingAlarm(); |
| 1394 |
| 1395 // Notify socket performance watcher of the updated RTT value. |
| 1396 if (socket_performance_watcher_) { |
| 1397 socket_performance_watcher_->OnUpdatedRTTAvailable( |
| 1398 base::TimeDelta::FromMicroseconds(sent_packet_manager_.GetRttStats() |
| 1399 ->smoothed_rtt() |
| 1400 .ToMicroseconds())); |
| 1401 } |
1391 } | 1402 } |
1392 | 1403 |
1393 void QuicConnection::CheckForAddressMigration( | 1404 void QuicConnection::CheckForAddressMigration( |
1394 const IPEndPoint& self_address, const IPEndPoint& peer_address) { | 1405 const IPEndPoint& self_address, const IPEndPoint& peer_address) { |
1395 peer_ip_changed_ = false; | 1406 peer_ip_changed_ = false; |
1396 peer_port_changed_ = false; | 1407 peer_port_changed_ = false; |
1397 self_ip_changed_ = false; | 1408 self_ip_changed_ = false; |
1398 self_port_changed_ = false; | 1409 self_port_changed_ = false; |
1399 | 1410 |
1400 if (peer_address_.address().empty()) { | 1411 if (peer_address_.address().empty()) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1723 | 1734 |
1724 if (result.status == WRITE_STATUS_ERROR) { | 1735 if (result.status == WRITE_STATUS_ERROR) { |
1725 OnWriteError(result.error_code); | 1736 OnWriteError(result.error_code); |
1726 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() | 1737 DLOG(ERROR) << ENDPOINT << "failed writing " << encrypted->length() |
1727 << " bytes " | 1738 << " bytes " |
1728 << " from host " << self_address().ToStringWithoutPort() | 1739 << " from host " << self_address().ToStringWithoutPort() |
1729 << " to address " << peer_address().ToString(); | 1740 << " to address " << peer_address().ToString(); |
1730 return false; | 1741 return false; |
1731 } | 1742 } |
1732 | 1743 |
| 1744 // Notify socket performance watcher of the updated RTT value. |
| 1745 if (socket_performance_watcher_) { |
| 1746 socket_performance_watcher_->OnUpdatedRTTAvailable( |
| 1747 base::TimeDelta::FromMicroseconds(sent_packet_manager_.GetRttStats() |
| 1748 ->smoothed_rtt() |
| 1749 .ToMicroseconds())); |
| 1750 } |
1733 return true; | 1751 return true; |
1734 } | 1752 } |
1735 | 1753 |
1736 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { | 1754 bool QuicConnection::ShouldDiscardPacket(const QueuedPacket& packet) { |
1737 if (!connected_) { | 1755 if (!connected_) { |
1738 DVLOG(1) << ENDPOINT | 1756 DVLOG(1) << ENDPOINT |
1739 << "Not sending packet as connection is disconnected."; | 1757 << "Not sending packet as connection is disconnected."; |
1740 return true; | 1758 return true; |
1741 } | 1759 } |
1742 | 1760 |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2396 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; | 2414 packet_number_of_last_sent_packet_ + packets_between_mtu_probes_ + 1; |
2397 ++mtu_probe_count_; | 2415 ++mtu_probe_count_; |
2398 | 2416 |
2399 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; | 2417 DVLOG(2) << "Sending a path MTU discovery packet #" << mtu_probe_count_; |
2400 SendMtuDiscoveryPacket(mtu_discovery_target_); | 2418 SendMtuDiscoveryPacket(mtu_discovery_target_); |
2401 | 2419 |
2402 DCHECK(!mtu_discovery_alarm_->IsSet()); | 2420 DCHECK(!mtu_discovery_alarm_->IsSet()); |
2403 } | 2421 } |
2404 | 2422 |
2405 } // namespace net | 2423 } // namespace net |
OLD | NEW |