Chromium Code Reviews| 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" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/metrics/histogram.h" | |
| 12 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 #include "net/cert/cert_verifier.h" | 18 #include "net/cert/cert_verifier.h" |
| 18 #include "net/dns/host_resolver.h" | 19 #include "net/dns/host_resolver.h" |
| 19 #include "net/dns/single_request_host_resolver.h" | 20 #include "net/dns/single_request_host_resolver.h" |
| 20 #include "net/http/http_server_properties.h" | 21 #include "net/http/http_server_properties.h" |
| 21 #include "net/quic/congestion_control/tcp_receiver.h" | 22 #include "net/quic/congestion_control/tcp_receiver.h" |
| 22 #include "net/quic/crypto/proof_verifier_chromium.h" | 23 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 23 #include "net/quic/crypto/quic_random.h" | 24 #include "net/quic/crypto/quic_random.h" |
| 25 #include "net/quic/port_suggester.h" | |
| 24 #include "net/quic/quic_client_session.h" | 26 #include "net/quic/quic_client_session.h" |
| 25 #include "net/quic/quic_clock.h" | 27 #include "net/quic/quic_clock.h" |
| 26 #include "net/quic/quic_connection.h" | 28 #include "net/quic/quic_connection.h" |
| 27 #include "net/quic/quic_connection_helper.h" | 29 #include "net/quic/quic_connection_helper.h" |
| 28 #include "net/quic/quic_crypto_client_stream_factory.h" | 30 #include "net/quic/quic_crypto_client_stream_factory.h" |
| 29 #include "net/quic/quic_default_packet_writer.h" | 31 #include "net/quic/quic_default_packet_writer.h" |
| 30 #include "net/quic/quic_http_stream.h" | 32 #include "net/quic/quic_http_stream.h" |
| 31 #include "net/quic/quic_protocol.h" | 33 #include "net/quic/quic_protocol.h" |
| 32 #include "net/socket/client_socket_factory.h" | 34 #include "net/socket/client_socket_factory.h" |
| 33 | 35 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 QuicClock* clock, | 251 QuicClock* clock, |
| 250 size_t max_packet_length) | 252 size_t max_packet_length) |
| 251 : require_confirmation_(true), | 253 : require_confirmation_(true), |
| 252 host_resolver_(host_resolver), | 254 host_resolver_(host_resolver), |
| 253 client_socket_factory_(client_socket_factory), | 255 client_socket_factory_(client_socket_factory), |
| 254 http_server_properties_(http_server_properties), | 256 http_server_properties_(http_server_properties), |
| 255 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 257 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
| 256 random_generator_(random_generator), | 258 random_generator_(random_generator), |
| 257 clock_(clock), | 259 clock_(clock), |
| 258 max_packet_length_(max_packet_length), | 260 max_packet_length_(max_packet_length), |
| 259 weak_factory_(this) { | 261 weak_factory_(this), |
| 262 port_entropy_(random_generator_->RandUint64()) { | |
| 260 config_.SetDefaults(); | 263 config_.SetDefaults(); |
| 261 config_.set_idle_connection_state_lifetime( | 264 config_.set_idle_connection_state_lifetime( |
| 262 QuicTime::Delta::FromSeconds(30), | 265 QuicTime::Delta::FromSeconds(30), |
| 263 QuicTime::Delta::FromSeconds(30)); | 266 QuicTime::Delta::FromSeconds(30)); |
| 264 cannoncial_suffixes_.push_back(string(".c.youtube.com")); | 267 cannoncial_suffixes_.push_back(string(".c.youtube.com")); |
| 265 cannoncial_suffixes_.push_back(string(".googlevideo.com")); | 268 cannoncial_suffixes_.push_back(string(".googlevideo.com")); |
| 266 } | 269 } |
| 267 | 270 |
| 268 QuicStreamFactory::~QuicStreamFactory() { | 271 QuicStreamFactory::~QuicStreamFactory() { |
| 269 CloseAllSessions(ERR_ABORTED); | 272 CloseAllSessions(ERR_ABORTED); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 443 } |
| 441 | 444 |
| 442 QuicClientSession* QuicStreamFactory::CreateSession( | 445 QuicClientSession* QuicStreamFactory::CreateSession( |
| 443 const HostPortProxyPair& host_port_proxy_pair, | 446 const HostPortProxyPair& host_port_proxy_pair, |
| 444 bool is_https, | 447 bool is_https, |
| 445 CertVerifier* cert_verifier, | 448 CertVerifier* cert_verifier, |
| 446 const AddressList& address_list, | 449 const AddressList& address_list, |
| 447 const BoundNetLog& net_log) { | 450 const BoundNetLog& net_log) { |
| 448 QuicGuid guid = random_generator_->RandUint64(); | 451 QuicGuid guid = random_generator_->RandUint64(); |
| 449 IPEndPoint addr = *address_list.begin(); | 452 IPEndPoint addr = *address_list.begin(); |
| 453 scoped_refptr<PortSuggester> port_suggester = | |
| 454 new PortSuggester(host_port_proxy_pair.first, port_entropy_); | |
| 450 scoped_ptr<DatagramClientSocket> socket( | 455 scoped_ptr<DatagramClientSocket> socket( |
| 451 client_socket_factory_->CreateDatagramClientSocket( | 456 client_socket_factory_->CreateDatagramClientSocket( |
| 452 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), | 457 DatagramSocket::RANDOM_BIND, |
| 458 base::Bind(&PortSuggester::SuggestPort, port_suggester), | |
| 453 net_log.net_log(), net_log.source())); | 459 net_log.net_log(), net_log.source())); |
| 454 socket->Connect(addr); | 460 socket->Connect(addr); |
| 455 | 461 |
| 462 DCHECK(port_suggester->call_count() >= 1); | |
| 463 IPEndPoint address; // For debugging only. | |
| 464 // This DCHECK will try to validate that our port_suggester was used, and not | |
| 465 // just consulted. Non-Mock Chromium tries using the port_suggester up to 10 | |
| 466 // times before giving up, and accepting an OS selected port, in which case we | |
| 467 // *can't* validate the source port. | |
| 468 // Since the Mock tests don't really use the suggestions, we'll allow Mocks to | |
| 469 // signal this non-use by requesting 3 or more suggestions, and then we won't | |
| 470 // validate the source port. | |
| 471 // Bottom line: More than 2 suggestions, and we won't validate the port. | |
| 472 // Common use cases result in only one suggestion being requested, and it is | |
| 473 // immediately used as the source port, so this DCHECK is very meaningful. | |
| 474 DCHECK(ERR_SOCKET_NOT_CONNECTED == socket->GetLocalAddress(&address) || | |
| 475 port_suggester->call_count() > 2 || | |
|
jar (doing other things)
2013/12/08 21:12:58
The polarity of the first clause (line 474) was wr
Ryan Hamilton
2013/12/08 22:54:15
Yay for tests :>
| |
| 476 address.port() == port_suggester->previous_suggestion()); | |
| 477 UMA_HISTOGRAM_COUNTS("Net.QuicEphemeralPortsSuggested", | |
| 478 port_suggester->call_count()); | |
| 479 | |
| 456 // We should adaptively set this buffer size, but for now, we'll use a size | 480 // We should adaptively set this buffer size, but for now, we'll use a size |
| 457 // that is more than large enough for a full receive window, and yet | 481 // that is more than large enough for a full receive window, and yet |
| 458 // does not consume "too much" memory. If we see bursty packet loss, we may | 482 // does not consume "too much" memory. If we see bursty packet loss, we may |
| 459 // revisit this setting and test for its impact. | 483 // revisit this setting and test for its impact. |
| 460 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP); | 484 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP); |
| 461 socket->SetReceiveBufferSize(kSocketBufferSize); | 485 socket->SetReceiveBufferSize(kSocketBufferSize); |
| 462 // Set a buffer large enough to contain the initial CWND's worth of packet | 486 // Set a buffer large enough to contain the initial CWND's worth of packet |
| 463 // to work around the problem with CHLO packets being sent out with the | 487 // to work around the problem with CHLO packets being sent out with the |
| 464 // wrong encryption level, when the send buffer is full. | 488 // wrong encryption level, when the send buffer is full. |
| 465 socket->SetSendBufferSize(kMaxPacketSize * 20); // Support 20 packets. | 489 socket->SetSendBufferSize(kMaxPacketSize * 20); // Support 20 packets. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 // Copy the CachedState for the canonical server from canonical_crypto_config | 584 // Copy the CachedState for the canonical server from canonical_crypto_config |
| 561 // as the initial CachedState for the server_hostname in crypto_config. | 585 // as the initial CachedState for the server_hostname in crypto_config. |
| 562 crypto_config->InitializeFrom(server_hostname, | 586 crypto_config->InitializeFrom(server_hostname, |
| 563 canonical_host_port_proxy_pair.first.host(), | 587 canonical_host_port_proxy_pair.first.host(), |
| 564 canonical_crypto_config); | 588 canonical_crypto_config); |
| 565 // Update canonical version to point at the "most recent" crypto_config. | 589 // Update canonical version to point at the "most recent" crypto_config. |
| 566 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair; | 590 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair; |
| 567 } | 591 } |
| 568 | 592 |
| 569 } // namespace net | 593 } // namespace net |
| OLD | NEW |