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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 270 } |
271 | 271 |
272 QuicStreamFactory::QuicStreamFactory( | 272 QuicStreamFactory::QuicStreamFactory( |
273 HostResolver* host_resolver, | 273 HostResolver* host_resolver, |
274 ClientSocketFactory* client_socket_factory, | 274 ClientSocketFactory* client_socket_factory, |
275 base::WeakPtr<HttpServerProperties> http_server_properties, | 275 base::WeakPtr<HttpServerProperties> http_server_properties, |
276 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, | 276 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
277 QuicRandom* random_generator, | 277 QuicRandom* random_generator, |
278 QuicClock* clock, | 278 QuicClock* clock, |
279 size_t max_packet_length, | 279 size_t max_packet_length, |
280 const QuicVersionVector& supported_versions) | 280 const QuicVersionVector& supported_versions, |
| 281 bool enable_port_selection) |
281 : require_confirmation_(true), | 282 : require_confirmation_(true), |
282 host_resolver_(host_resolver), | 283 host_resolver_(host_resolver), |
283 client_socket_factory_(client_socket_factory), | 284 client_socket_factory_(client_socket_factory), |
284 http_server_properties_(http_server_properties), | 285 http_server_properties_(http_server_properties), |
285 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 286 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
286 random_generator_(random_generator), | 287 random_generator_(random_generator), |
287 clock_(clock), | 288 clock_(clock), |
288 max_packet_length_(max_packet_length), | 289 max_packet_length_(max_packet_length), |
289 supported_versions_(supported_versions), | 290 supported_versions_(supported_versions), |
| 291 enable_port_selection_(enable_port_selection), |
290 port_seed_(random_generator_->RandUint64()), | 292 port_seed_(random_generator_->RandUint64()), |
291 weak_factory_(this) { | 293 weak_factory_(this) { |
292 config_.SetDefaults(); | 294 config_.SetDefaults(); |
293 config_.set_idle_connection_state_lifetime( | 295 config_.set_idle_connection_state_lifetime( |
294 QuicTime::Delta::FromSeconds(30), | 296 QuicTime::Delta::FromSeconds(30), |
295 QuicTime::Delta::FromSeconds(30)); | 297 QuicTime::Delta::FromSeconds(30)); |
296 | 298 |
297 cannoncial_suffixes_.push_back(string(".c.youtube.com")); | 299 cannoncial_suffixes_.push_back(string(".c.youtube.com")); |
298 cannoncial_suffixes_.push_back(string(".googlevideo.com")); | 300 cannoncial_suffixes_.push_back(string(".googlevideo.com")); |
299 } | 301 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 const HostPortProxyPair& host_port_proxy_pair, | 509 const HostPortProxyPair& host_port_proxy_pair, |
508 bool is_https, | 510 bool is_https, |
509 CertVerifier* cert_verifier, | 511 CertVerifier* cert_verifier, |
510 const AddressList& address_list, | 512 const AddressList& address_list, |
511 const BoundNetLog& net_log, | 513 const BoundNetLog& net_log, |
512 QuicClientSession** session) { | 514 QuicClientSession** session) { |
513 QuicGuid guid = random_generator_->RandUint64(); | 515 QuicGuid guid = random_generator_->RandUint64(); |
514 IPEndPoint addr = *address_list.begin(); | 516 IPEndPoint addr = *address_list.begin(); |
515 scoped_refptr<PortSuggester> port_suggester = | 517 scoped_refptr<PortSuggester> port_suggester = |
516 new PortSuggester(host_port_proxy_pair.first, port_seed_); | 518 new PortSuggester(host_port_proxy_pair.first, port_seed_); |
| 519 DatagramSocket::BindType bind_type = enable_port_selection_ ? |
| 520 DatagramSocket::RANDOM_BIND : // Use our callback. |
| 521 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. |
517 scoped_ptr<DatagramClientSocket> socket( | 522 scoped_ptr<DatagramClientSocket> socket( |
518 client_socket_factory_->CreateDatagramClientSocket( | 523 client_socket_factory_->CreateDatagramClientSocket( |
519 DatagramSocket::RANDOM_BIND, | 524 bind_type, |
520 base::Bind(&PortSuggester::SuggestPort, port_suggester), | 525 base::Bind(&PortSuggester::SuggestPort, port_suggester), |
521 net_log.net_log(), net_log.source())); | 526 net_log.net_log(), net_log.source())); |
522 int rv = socket->Connect(addr); | 527 int rv = socket->Connect(addr); |
523 if (rv != OK) | 528 if (rv != OK) |
524 return rv; | 529 return rv; |
525 UMA_HISTOGRAM_COUNTS("Net.QuicEphemeralPortsSuggested", | 530 UMA_HISTOGRAM_COUNTS("Net.QuicEphemeralPortsSuggested", |
526 port_suggester->call_count()); | 531 port_suggester->call_count()); |
527 DCHECK_LE(1u, port_suggester->call_count()); | 532 if (enable_port_selection_) { |
| 533 DCHECK_LE(1u, port_suggester->call_count()); |
| 534 } else { |
| 535 DCHECK_EQ(0u, port_suggester->call_count()); |
| 536 } |
528 | 537 |
529 // We should adaptively set this buffer size, but for now, we'll use a size | 538 // We should adaptively set this buffer size, but for now, we'll use a size |
530 // that is more than large enough for a full receive window, and yet | 539 // that is more than large enough for a full receive window, and yet |
531 // does not consume "too much" memory. If we see bursty packet loss, we may | 540 // does not consume "too much" memory. If we see bursty packet loss, we may |
532 // revisit this setting and test for its impact. | 541 // revisit this setting and test for its impact. |
533 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP); | 542 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP); |
534 socket->SetReceiveBufferSize(kSocketBufferSize); | 543 socket->SetReceiveBufferSize(kSocketBufferSize); |
535 // Set a buffer large enough to contain the initial CWND's worth of packet | 544 // Set a buffer large enough to contain the initial CWND's worth of packet |
536 // to work around the problem with CHLO packets being sent out with the | 545 // to work around the problem with CHLO packets being sent out with the |
537 // wrong encryption level, when the send buffer is full. | 546 // wrong encryption level, when the send buffer is full. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 // Copy the CachedState for the canonical server from canonical_crypto_config | 644 // Copy the CachedState for the canonical server from canonical_crypto_config |
636 // as the initial CachedState for the server_hostname in crypto_config. | 645 // as the initial CachedState for the server_hostname in crypto_config. |
637 crypto_config->InitializeFrom(server_hostname, | 646 crypto_config->InitializeFrom(server_hostname, |
638 canonical_host_port_proxy_pair.first.host(), | 647 canonical_host_port_proxy_pair.first.host(), |
639 canonical_crypto_config); | 648 canonical_crypto_config); |
640 // Update canonical version to point at the "most recent" crypto_config. | 649 // Update canonical version to point at the "most recent" crypto_config. |
641 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair; | 650 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair; |
642 } | 651 } |
643 | 652 |
644 } // namespace net | 653 } // namespace net |
OLD | NEW |