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

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

Issue 2958133002: Change QuicStreamRequest::Request() to take a preferred QuicVersion so that (Closed)
Patch Set: Add QuicNetworkTransactionTest: select correct Quic Version Created 3 years, 5 months 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/chromium/quic_stream_factory.h" 5 #include "net/quic/chromium/quic_stream_factory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 base::WeakPtrFactory<CertVerifierJob> weak_factory_; 319 base::WeakPtrFactory<CertVerifierJob> weak_factory_;
320 320
321 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob); 321 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob);
322 }; 322 };
323 323
324 // Responsible for creating a new QUIC session to the specified server, and 324 // Responsible for creating a new QUIC session to the specified server, and
325 // for notifying any associated requests when complete. 325 // for notifying any associated requests when complete.
326 class QuicStreamFactory::Job { 326 class QuicStreamFactory::Job {
327 public: 327 public:
328 Job(QuicStreamFactory* factory, 328 Job(QuicStreamFactory* factory,
329 const QuicVersion& quic_version,
329 HostResolver* host_resolver, 330 HostResolver* host_resolver,
330 const QuicSessionKey& key, 331 const QuicSessionKey& key,
331 bool was_alternative_service_recently_broken, 332 bool was_alternative_service_recently_broken,
332 int cert_verify_flags, 333 int cert_verify_flags,
333 const NetLogWithSource& net_log); 334 const NetLogWithSource& net_log);
334 335
335 ~Job(); 336 ~Job();
336 337
337 int Run(const CompletionCallback& callback); 338 int Run(const CompletionCallback& callback);
338 339
(...skipping 20 matching lines...) Expand all
359 enum IoState { 360 enum IoState {
360 STATE_NONE, 361 STATE_NONE,
361 STATE_RESOLVE_HOST, 362 STATE_RESOLVE_HOST,
362 STATE_RESOLVE_HOST_COMPLETE, 363 STATE_RESOLVE_HOST_COMPLETE,
363 STATE_CONNECT, 364 STATE_CONNECT,
364 STATE_CONNECT_COMPLETE, 365 STATE_CONNECT_COMPLETE,
365 }; 366 };
366 IoState io_state_; 367 IoState io_state_;
367 368
368 QuicStreamFactory* factory_; 369 QuicStreamFactory* factory_;
370 QuicVersion quic_version_;
369 HostResolver* host_resolver_; 371 HostResolver* host_resolver_;
370 std::unique_ptr<HostResolver::Request> request_; 372 std::unique_ptr<HostResolver::Request> request_;
371 const QuicSessionKey key_; 373 const QuicSessionKey key_;
372 const int cert_verify_flags_; 374 const int cert_verify_flags_;
373 const bool was_alternative_service_recently_broken_; 375 const bool was_alternative_service_recently_broken_;
374 const NetLogWithSource net_log_; 376 const NetLogWithSource net_log_;
375 int num_sent_client_hellos_; 377 int num_sent_client_hellos_;
376 QuicChromiumClientSession* session_; 378 QuicChromiumClientSession* session_;
377 CompletionCallback callback_; 379 CompletionCallback callback_;
378 AddressList address_list_; 380 AddressList address_list_;
379 base::TimeTicks dns_resolution_start_time_; 381 base::TimeTicks dns_resolution_start_time_;
380 base::TimeTicks dns_resolution_end_time_; 382 base::TimeTicks dns_resolution_end_time_;
381 base::WeakPtrFactory<Job> weak_factory_; 383 base::WeakPtrFactory<Job> weak_factory_;
382 DISALLOW_COPY_AND_ASSIGN(Job); 384 DISALLOW_COPY_AND_ASSIGN(Job);
383 }; 385 };
384 386
385 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, 387 QuicStreamFactory::Job::Job(QuicStreamFactory* factory,
388 const QuicVersion& quic_version,
386 HostResolver* host_resolver, 389 HostResolver* host_resolver,
387 const QuicSessionKey& key, 390 const QuicSessionKey& key,
388 bool was_alternative_service_recently_broken, 391 bool was_alternative_service_recently_broken,
389 int cert_verify_flags, 392 int cert_verify_flags,
390 const NetLogWithSource& net_log) 393 const NetLogWithSource& net_log)
391 : io_state_(STATE_RESOLVE_HOST), 394 : io_state_(STATE_RESOLVE_HOST),
392 factory_(factory), 395 factory_(factory),
396 quic_version_(quic_version),
393 host_resolver_(host_resolver), 397 host_resolver_(host_resolver),
394 key_(key), 398 key_(key),
395 cert_verify_flags_(cert_verify_flags), 399 cert_verify_flags_(cert_verify_flags),
396 was_alternative_service_recently_broken_( 400 was_alternative_service_recently_broken_(
397 was_alternative_service_recently_broken), 401 was_alternative_service_recently_broken),
398 net_log_( 402 net_log_(
399 NetLogWithSource::Make(net_log.net_log(), 403 NetLogWithSource::Make(net_log.net_log(),
400 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), 404 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)),
401 num_sent_client_hellos_(0), 405 num_sent_client_hellos_(0),
402 session_(nullptr), 406 session_(nullptr),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 505
502 int QuicStreamFactory::Job::DoConnect() { 506 int QuicStreamFactory::Job::DoConnect() {
503 io_state_ = STATE_CONNECT_COMPLETE; 507 io_state_ = STATE_CONNECT_COMPLETE;
504 508
505 bool require_confirmation = factory_->require_confirmation() || 509 bool require_confirmation = factory_->require_confirmation() ||
506 was_alternative_service_recently_broken_; 510 was_alternative_service_recently_broken_;
507 net_log_.BeginEvent( 511 net_log_.BeginEvent(
508 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, 512 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT,
509 NetLog::BoolCallback("require_confirmation", require_confirmation)); 513 NetLog::BoolCallback("require_confirmation", require_confirmation));
510 514
511 int rv = 515 DCHECK_NE(quic_version_, QUIC_VERSION_UNSUPPORTED);
512 factory_->CreateSession(key_, cert_verify_flags_, require_confirmation, 516 int rv = factory_->CreateSession(
513 address_list_, dns_resolution_start_time_, 517 key_, quic_version_, cert_verify_flags_, require_confirmation,
514 dns_resolution_end_time_, net_log_, &session_); 518 address_list_, dns_resolution_start_time_, dns_resolution_end_time_,
519 net_log_, &session_);
515 if (rv != OK) { 520 if (rv != OK) {
516 DCHECK(rv != ERR_IO_PENDING); 521 DCHECK(rv != ERR_IO_PENDING);
517 DCHECK(!session_); 522 DCHECK(!session_);
518 return rv; 523 return rv;
519 } 524 }
520 525
521 if (!session_->connection()->connected()) 526 if (!session_->connection()->connected())
522 return ERR_CONNECTION_CLOSED; 527 return ERR_CONNECTION_CLOSED;
523 528
524 session_->StartReading(); 529 session_->StartReading();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 579
575 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory) 580 QuicStreamRequest::QuicStreamRequest(QuicStreamFactory* factory)
576 : factory_(factory) {} 581 : factory_(factory) {}
577 582
578 QuicStreamRequest::~QuicStreamRequest() { 583 QuicStreamRequest::~QuicStreamRequest() {
579 if (factory_ && !callback_.is_null()) 584 if (factory_ && !callback_.is_null())
580 factory_->CancelRequest(this); 585 factory_->CancelRequest(this);
581 } 586 }
582 587
583 int QuicStreamRequest::Request(const HostPortPair& destination, 588 int QuicStreamRequest::Request(const HostPortPair& destination,
589 const QuicVersionVector& advertised_versions,
584 PrivacyMode privacy_mode, 590 PrivacyMode privacy_mode,
585 int cert_verify_flags, 591 int cert_verify_flags,
586 const GURL& url, 592 const GURL& url,
587 QuicStringPiece method, 593 QuicStringPiece method,
588 const NetLogWithSource& net_log, 594 const NetLogWithSource& net_log,
589 const CompletionCallback& callback) { 595 const CompletionCallback& callback) {
590 DCHECK(callback_.is_null()); 596 DCHECK(callback_.is_null());
591 DCHECK(factory_); 597 DCHECK(factory_);
592 server_id_ = QuicServerId(HostPortPair::FromURL(url), privacy_mode); 598 server_id_ = QuicServerId(HostPortPair::FromURL(url), privacy_mode);
593 599
594 int rv = factory_->Create(server_id_, destination, cert_verify_flags, url, 600 int rv = factory_->Create(server_id_, destination, advertised_versions,
595 method, net_log, this); 601 cert_verify_flags, url, method, net_log, this);
596 if (rv == ERR_IO_PENDING) { 602 if (rv == ERR_IO_PENDING) {
597 net_log_ = net_log; 603 net_log_ = net_log;
598 callback_ = callback; 604 callback_ = callback;
599 } else { 605 } else {
600 factory_ = nullptr; 606 factory_ = nullptr;
601 } 607 }
602 if (rv == OK) 608 if (rv == OK)
603 DCHECK(session_); 609 DCHECK(session_);
604 return rv; 610 return rv;
605 } 611 }
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 session->CanPool(server_id.host(), server_id.privacy_mode())) { 848 session->CanPool(server_id.host(), server_id.privacy_mode())) {
843 return true; 849 return true;
844 } 850 }
845 } 851 }
846 852
847 return false; 853 return false;
848 } 854 }
849 855
850 int QuicStreamFactory::Create(const QuicServerId& server_id, 856 int QuicStreamFactory::Create(const QuicServerId& server_id,
851 const HostPortPair& destination, 857 const HostPortPair& destination,
858 const QuicVersionVector& advertised_versions,
852 int cert_verify_flags, 859 int cert_verify_flags,
853 const GURL& url, 860 const GURL& url,
854 QuicStringPiece method, 861 QuicStringPiece method,
855 const NetLogWithSource& net_log, 862 const NetLogWithSource& net_log,
856 QuicStreamRequest* request) { 863 QuicStreamRequest* request) {
857 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(), 864 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(),
858 base::Time::Now())) { 865 base::Time::Now())) {
859 while (!active_sessions_.empty()) { 866 while (!active_sessions_.empty()) {
860 QuicChromiumClientSession* session = active_sessions_.begin()->second; 867 QuicChromiumClientSession* session = active_sessions_.begin()->second;
861 OnSessionGoingAway(session); 868 OnSessionGoingAway(session);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 } 926 }
920 927
921 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ 928 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_
922 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. 929 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed.
923 if (!task_runner_) 930 if (!task_runner_)
924 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); 931 task_runner_ = base::ThreadTaskRunnerHandle::Get().get();
925 932
926 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); 933 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log));
927 934
928 QuicSessionKey key(destination, server_id); 935 QuicSessionKey key(destination, server_id);
936 QuicVersion quic_version = SelectQuicVersion(advertised_versions);
937 DCHECK_NE(quic_version, QUIC_VERSION_UNSUPPORTED);
929 std::unique_ptr<Job> job = base::MakeUnique<Job>( 938 std::unique_ptr<Job> job = base::MakeUnique<Job>(
930 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), 939 this, quic_version, host_resolver_, key, WasQuicRecentlyBroken(server_id),
931 cert_verify_flags, net_log); 940 cert_verify_flags, net_log);
932 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, 941 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete,
933 base::Unretained(this), job.get())); 942 base::Unretained(this), job.get()));
934 if (rv == ERR_IO_PENDING) { 943 if (rv == ERR_IO_PENDING) {
935 job_requests_map_[server_id].insert(request); 944 job_requests_map_[server_id].insert(request);
936 active_jobs_[server_id] = std::move(job); 945 active_jobs_[server_id] = std::move(job);
937 return rv; 946 return rv;
938 } 947 }
939 if (rv == OK) { 948 if (rv == OK) {
940 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() 949 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty()
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 IPAddress last_address; 1460 IPAddress last_address;
1452 if (http_server_properties_->GetSupportsQuic(&last_address) && 1461 if (http_server_properties_->GetSupportsQuic(&last_address) &&
1453 last_address == local_address_.address()) { 1462 last_address == local_address_.address()) {
1454 require_confirmation_ = false; 1463 require_confirmation_ = false;
1455 } 1464 }
1456 } 1465 }
1457 1466
1458 return OK; 1467 return OK;
1459 } 1468 }
1460 1469
1461 int QuicStreamFactory::CreateSession( 1470 int QuicStreamFactory::CreateSession(const QuicSessionKey& key,
1462 const QuicSessionKey& key, 1471 const QuicVersion& quic_version,
1463 int cert_verify_flags, 1472 int cert_verify_flags,
1464 bool require_confirmation, 1473 bool require_confirmation,
1465 const AddressList& address_list, 1474 const AddressList& address_list,
1466 base::TimeTicks dns_resolution_start_time, 1475 base::TimeTicks dns_resolution_start_time,
1467 base::TimeTicks dns_resolution_end_time, 1476 base::TimeTicks dns_resolution_end_time,
1468 const NetLogWithSource& net_log, 1477 const NetLogWithSource& net_log,
1469 QuicChromiumClientSession** session) { 1478 QuicChromiumClientSession** session) {
1470 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession"); 1479 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession");
1471 IPEndPoint addr = *address_list.begin(); 1480 IPEndPoint addr = *address_list.begin();
1472 const QuicServerId& server_id = key.server_id(); 1481 const QuicServerId& server_id = key.server_id();
1473 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND; 1482 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND;
1474 std::unique_ptr<DatagramClientSocket> socket( 1483 std::unique_ptr<DatagramClientSocket> socket(
1475 client_socket_factory_->CreateDatagramClientSocket( 1484 client_socket_factory_->CreateDatagramClientSocket(
1476 bind_type, RandIntCallback(), net_log.net_log(), net_log.source())); 1485 bind_type, RandIntCallback(), net_log.net_log(), net_log.source()));
1477 1486
1478 // Passing in kInvalidNetworkHandle binds socket to default network. 1487 // Passing in kInvalidNetworkHandle binds socket to default network.
1479 int rv = ConfigureSocket(socket.get(), addr, 1488 int rv = ConfigureSocket(socket.get(), addr,
(...skipping 15 matching lines...) Expand all
1495 if (store_server_configs_in_properties_) { 1504 if (store_server_configs_in_properties_) {
1496 server_info = base::MakeUnique<PropertiesBasedQuicServerInfo>( 1505 server_info = base::MakeUnique<PropertiesBasedQuicServerInfo>(
1497 server_id, http_server_properties_); 1506 server_id, http_server_properties_);
1498 } 1507 }
1499 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id); 1508 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id);
1500 1509
1501 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get()); 1510 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get());
1502 QuicConnection* connection = new QuicConnection( 1511 QuicConnection* connection = new QuicConnection(
1503 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)), 1512 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)),
1504 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */, 1513 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */,
1505 Perspective::IS_CLIENT, supported_versions_); 1514 Perspective::IS_CLIENT, {quic_version});
1506 connection->set_ping_timeout(ping_timeout_); 1515 connection->set_ping_timeout(ping_timeout_);
1507 connection->SetMaxPacketLength(max_packet_length_); 1516 connection->SetMaxPacketLength(max_packet_length_);
1508 1517
1509 QuicConfig config = config_; 1518 QuicConfig config = config_;
1510 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); 1519 config.set_max_undecryptable_packets(kMaxUndecryptablePackets);
1511 config.SetInitialSessionFlowControlWindowToSend( 1520 config.SetInitialSessionFlowControlWindowToSend(
1512 kQuicSessionMaxRecvWindowSize); 1521 kQuicSessionMaxRecvWindowSize);
1513 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize); 1522 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize);
1514 config.SetBytesForConnectionIdToSend(0); 1523 config.SetBytesForConnectionIdToSend(0);
1515 ConfigureInitialRttEstimate(server_id, &config); 1524 ConfigureInitialRttEstimate(server_id, &config);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1594
1586 if (type == NetworkChangeNotifier::CONNECTION_3G) { 1595 if (type == NetworkChangeNotifier::CONNECTION_3G) {
1587 SetInitialRttEstimate(base::TimeDelta::FromMilliseconds(400), 1596 SetInitialRttEstimate(base::TimeDelta::FromMilliseconds(400),
1588 INITIAL_RTT_CACHED, config); 1597 INITIAL_RTT_CACHED, config);
1589 return; 1598 return;
1590 } 1599 }
1591 1600
1592 SetInitialRttEstimate(base::TimeDelta(), INITIAL_RTT_DEFAULT, config); 1601 SetInitialRttEstimate(base::TimeDelta(), INITIAL_RTT_DEFAULT, config);
1593 } 1602 }
1594 1603
1604 QuicVersion QuicStreamFactory::SelectQuicVersion(
1605 const QuicVersionVector& advertised_versions) const {
1606 if (advertised_versions.empty())
1607 return supported_versions_[0];
1608
1609 for (const QuicVersion& supported : supported_versions_) {
1610 for (const QuicVersion& advertised : advertised_versions) {
1611 if (supported == advertised)
1612 return supported;
1613 }
1614 }
1615 return supported_versions_[0];
Bence 2017/06/28 19:08:58 Optional: add DCHECK(!supported_versions_.empty())
Zhongyi Shi 2017/07/05 23:08:59 Acknowledged.
1616 }
1617
1595 const base::TimeDelta* QuicStreamFactory::GetServerNetworkStatsSmoothedRtt( 1618 const base::TimeDelta* QuicStreamFactory::GetServerNetworkStatsSmoothedRtt(
1596 const QuicServerId& server_id) const { 1619 const QuicServerId& server_id) const {
1597 url::SchemeHostPort server("https", server_id.host_port_pair().host(), 1620 url::SchemeHostPort server("https", server_id.host_port_pair().host(),
1598 server_id.host_port_pair().port()); 1621 server_id.host_port_pair().port());
1599 const ServerNetworkStats* stats = 1622 const ServerNetworkStats* stats =
1600 http_server_properties_->GetServerNetworkStats(server); 1623 http_server_properties_->GetServerNetworkStats(server);
1601 if (stats == nullptr) 1624 if (stats == nullptr)
1602 return nullptr; 1625 return nullptr;
1603 return &(stats->srtt); 1626 return &(stats->srtt);
1604 } 1627 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 // Since the session was active, there's no longer an 1736 // Since the session was active, there's no longer an
1714 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP 1737 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP
1715 // job also fails. So to avoid not using QUIC when we otherwise could, we mark 1738 // job also fails. So to avoid not using QUIC when we otherwise could, we mark
1716 // it as recently broken, which means that 0-RTT will be disabled but we'll 1739 // it as recently broken, which means that 0-RTT will be disabled but we'll
1717 // still race. 1740 // still race.
1718 http_server_properties_->MarkAlternativeServiceRecentlyBroken( 1741 http_server_properties_->MarkAlternativeServiceRecentlyBroken(
1719 alternative_service); 1742 alternative_service);
1720 } 1743 }
1721 1744
1722 } // namespace net 1745 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698