Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Side by Side Diff: net/quic/quic_stream_factory.cc

Issue 107803002: Consistently suggest ephemeral port for QUIC client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disable new assertions in quic_factory_stream.cc Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 // TODO(jar): Get NetworkStatsTests working with these assertion.
463 #if 0
464 DCHECK(port_suggester->call_count() >= 1);
465 IPEndPoint address; // For debugging only.
466 // This DCHECK will try to validate that our port_suggester was used, and not
467 // just consulted. Non-Mock Chromium tries using the port_suggester up to 10
468 // times before giving up, and accepting an OS selected port, in which case we
469 // *can't* validate the source port.
470 // Since the Mock tests don't really use the suggestions, we'll allow Mocks to
471 // signal this non-use by requesting 3 or more suggestions, and then we won't
472 // validate the source port.
473 // Bottom line: More than 2 suggestions, and we won't validate the port.
474 // Common use cases result in only one suggestion being requested, and it is
475 // immediately used as the source port, so this DCHECK is very meaningful.
476 DCHECK(ERR_SOCKET_NOT_CONNECTED == socket->GetLocalAddress(&address) ||
477 port_suggester->call_count() > 2 ||
478 address.port() == port_suggester->previous_suggestion());
479 #endif // 0
Ryan Hamilton 2013/12/08 23:22:21 Please go ahead and remove this code for now. You
jar (doing other things) 2013/12/08 23:30:46 Done.
480
481 UMA_HISTOGRAM_COUNTS("Net.QuicEphemeralPortsSuggested",
482 port_suggester->call_count());
483
456 // We should adaptively set this buffer size, but for now, we'll use a size 484 // 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 485 // 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 486 // does not consume "too much" memory. If we see bursty packet loss, we may
459 // revisit this setting and test for its impact. 487 // revisit this setting and test for its impact.
460 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP); 488 const int32 kSocketBufferSize(TcpReceiver::kReceiveWindowTCP);
461 socket->SetReceiveBufferSize(kSocketBufferSize); 489 socket->SetReceiveBufferSize(kSocketBufferSize);
462 // Set a buffer large enough to contain the initial CWND's worth of packet 490 // 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 491 // to work around the problem with CHLO packets being sent out with the
464 // wrong encryption level, when the send buffer is full. 492 // wrong encryption level, when the send buffer is full.
465 socket->SetSendBufferSize(kMaxPacketSize * 20); // Support 20 packets. 493 socket->SetSendBufferSize(kMaxPacketSize * 20); // Support 20 packets.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // Copy the CachedState for the canonical server from canonical_crypto_config 588 // Copy the CachedState for the canonical server from canonical_crypto_config
561 // as the initial CachedState for the server_hostname in crypto_config. 589 // as the initial CachedState for the server_hostname in crypto_config.
562 crypto_config->InitializeFrom(server_hostname, 590 crypto_config->InitializeFrom(server_hostname,
563 canonical_host_port_proxy_pair.first.host(), 591 canonical_host_port_proxy_pair.first.host(),
564 canonical_crypto_config); 592 canonical_crypto_config);
565 // Update canonical version to point at the "most recent" crypto_config. 593 // Update canonical version to point at the "most recent" crypto_config.
566 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair; 594 canonical_hostname_to_origin_map_[canonical_host_port] = host_port_proxy_pair;
567 } 595 }
568 596
569 } // namespace net 597 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698