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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "net/quic/crypto/channel_id_chromium.h" | 31 #include "net/quic/crypto/channel_id_chromium.h" |
32 #include "net/quic/crypto/proof_verifier_chromium.h" | 32 #include "net/quic/crypto/proof_verifier_chromium.h" |
33 #include "net/quic/crypto/properties_based_quic_server_info.h" | 33 #include "net/quic/crypto/properties_based_quic_server_info.h" |
34 #include "net/quic/crypto/quic_random.h" | 34 #include "net/quic/crypto/quic_random.h" |
35 #include "net/quic/crypto/quic_server_info.h" | 35 #include "net/quic/crypto/quic_server_info.h" |
36 #include "net/quic/port_suggester.h" | 36 #include "net/quic/port_suggester.h" |
37 #include "net/quic/quic_chromium_client_session.h" | 37 #include "net/quic/quic_chromium_client_session.h" |
38 #include "net/quic/quic_chromium_connection_helper.h" | 38 #include "net/quic/quic_chromium_connection_helper.h" |
39 #include "net/quic/quic_chromium_packet_reader.h" | 39 #include "net/quic/quic_chromium_packet_reader.h" |
40 #include "net/quic/quic_chromium_packet_writer.h" | 40 #include "net/quic/quic_chromium_packet_writer.h" |
| 41 #include "net/quic/quic_client_promised_info.h" |
41 #include "net/quic/quic_clock.h" | 42 #include "net/quic/quic_clock.h" |
42 #include "net/quic/quic_connection.h" | 43 #include "net/quic/quic_connection.h" |
43 #include "net/quic/quic_crypto_client_stream_factory.h" | 44 #include "net/quic/quic_crypto_client_stream_factory.h" |
44 #include "net/quic/quic_flags.h" | 45 #include "net/quic/quic_flags.h" |
45 #include "net/quic/quic_http_stream.h" | 46 #include "net/quic/quic_http_stream.h" |
46 #include "net/quic/quic_protocol.h" | 47 #include "net/quic/quic_protocol.h" |
47 #include "net/quic/quic_server_id.h" | 48 #include "net/quic/quic_server_id.h" |
48 #include "net/socket/client_socket_factory.h" | 49 #include "net/socket/client_socket_factory.h" |
49 #include "net/ssl/token_binding.h" | 50 #include "net/ssl/token_binding.h" |
50 #include "net/udp/udp_client_socket.h" | 51 #include "net/udp/udp_client_socket.h" |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 : factory_(factory) {} | 501 : factory_(factory) {} |
501 | 502 |
502 QuicStreamRequest::~QuicStreamRequest() { | 503 QuicStreamRequest::~QuicStreamRequest() { |
503 if (factory_ && !callback_.is_null()) | 504 if (factory_ && !callback_.is_null()) |
504 factory_->CancelRequest(this); | 505 factory_->CancelRequest(this); |
505 } | 506 } |
506 | 507 |
507 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, | 508 int QuicStreamRequest::Request(const HostPortPair& host_port_pair, |
508 PrivacyMode privacy_mode, | 509 PrivacyMode privacy_mode, |
509 int cert_verify_flags, | 510 int cert_verify_flags, |
510 base::StringPiece origin_host, | 511 const GURL& url, |
511 base::StringPiece method, | 512 base::StringPiece method, |
512 const BoundNetLog& net_log, | 513 const BoundNetLog& net_log, |
513 const CompletionCallback& callback) { | 514 const CompletionCallback& callback) { |
514 DCHECK(!stream_); | 515 DCHECK(!stream_); |
515 DCHECK(callback_.is_null()); | 516 DCHECK(callback_.is_null()); |
516 DCHECK(factory_); | 517 DCHECK(factory_); |
517 origin_host_ = origin_host.as_string(); | 518 origin_host_ = url.host(); |
518 privacy_mode_ = privacy_mode; | 519 privacy_mode_ = privacy_mode; |
519 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, | 520 int rv = factory_->Create(host_port_pair, privacy_mode, cert_verify_flags, |
520 origin_host, method, net_log, this); | 521 url, method, net_log, this); |
521 if (rv == ERR_IO_PENDING) { | 522 if (rv == ERR_IO_PENDING) { |
522 host_port_pair_ = host_port_pair; | 523 host_port_pair_ = host_port_pair; |
523 net_log_ = net_log; | 524 net_log_ = net_log; |
524 callback_ = callback; | 525 callback_ = callback; |
525 } else { | 526 } else { |
526 factory_ = nullptr; | 527 factory_ = nullptr; |
527 } | 528 } |
528 if (rv == OK) | 529 if (rv == OK) |
529 DCHECK(stream_); | 530 DCHECK(stream_); |
530 return rv; | 531 return rv; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 kQuicYieldAfterDurationMilliseconds)), | 638 kQuicYieldAfterDurationMilliseconds)), |
638 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 639 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
639 migrate_sessions_on_network_change_( | 640 migrate_sessions_on_network_change_( |
640 migrate_sessions_on_network_change && | 641 migrate_sessions_on_network_change && |
641 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 642 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
642 migrate_sessions_early_(migrate_sessions_early && | 643 migrate_sessions_early_(migrate_sessions_early && |
643 migrate_sessions_on_network_change_), | 644 migrate_sessions_on_network_change_), |
644 port_seed_(random_generator_->RandUint64()), | 645 port_seed_(random_generator_->RandUint64()), |
645 check_persisted_supports_quic_(true), | 646 check_persisted_supports_quic_(true), |
646 has_initialized_data_(false), | 647 has_initialized_data_(false), |
| 648 num_push_streams_created_(0), |
647 task_runner_(nullptr), | 649 task_runner_(nullptr), |
648 weak_factory_(this) { | 650 weak_factory_(this) { |
649 if (disable_quic_on_timeout_with_open_streams) | 651 if (disable_quic_on_timeout_with_open_streams) |
650 threshold_timeouts_with_open_streams_ = 1; | 652 threshold_timeouts_with_open_streams_ = 1; |
651 DCHECK(transport_security_state_); | 653 DCHECK(transport_security_state_); |
652 DCHECK(http_server_properties_); | 654 DCHECK(http_server_properties_); |
653 crypto_config_.set_user_agent_id(user_agent_id); | 655 crypto_config_.set_user_agent_id(user_agent_id); |
654 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 656 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
655 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 657 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
656 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); | 658 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 SessionMap::iterator it = active_sessions_.find(server_id); | 759 SessionMap::iterator it = active_sessions_.find(server_id); |
758 if (it == active_sessions_.end()) | 760 if (it == active_sessions_.end()) |
759 return false; | 761 return false; |
760 QuicChromiumClientSession* session = it->second; | 762 QuicChromiumClientSession* session = it->second; |
761 return session->CanPool(origin_host.as_string(), privacy_mode); | 763 return session->CanPool(origin_host.as_string(), privacy_mode); |
762 } | 764 } |
763 | 765 |
764 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, | 766 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, |
765 PrivacyMode privacy_mode, | 767 PrivacyMode privacy_mode, |
766 int cert_verify_flags, | 768 int cert_verify_flags, |
767 base::StringPiece origin_host, | 769 const GURL& url, |
768 base::StringPiece method, | 770 base::StringPiece method, |
769 const BoundNetLog& net_log, | 771 const BoundNetLog& net_log, |
770 QuicStreamRequest* request) { | 772 QuicStreamRequest* request) { |
| 773 // Enforce session affinity for promised streams. |
| 774 QuicClientPromisedInfo* promised = |
| 775 push_promise_index_.GetPromised(url.spec()); |
| 776 if (promised) { |
| 777 QuicChromiumClientSession* session = |
| 778 static_cast<QuicChromiumClientSession*>(promised->session()); |
| 779 DCHECK(session); |
| 780 if (session->server_id().privacy_mode() == privacy_mode) { |
| 781 request->set_stream(CreateFromSession(session)); |
| 782 ++num_push_streams_created_; |
| 783 return OK; |
| 784 } |
| 785 // This should happen extremely rarely (if ever), but if somehow a |
| 786 // request comes in with a mismatched privacy mode, consider the |
| 787 // promise borked. |
| 788 promised->Cancel(); |
| 789 } |
| 790 |
771 QuicServerId server_id(host_port_pair, privacy_mode); | 791 QuicServerId server_id(host_port_pair, privacy_mode); |
772 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. | 792 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. |
773 if (!active_sessions_.empty()) { | 793 if (!active_sessions_.empty()) { |
774 SessionMap::iterator it = active_sessions_.find(server_id); | 794 SessionMap::iterator it = active_sessions_.find(server_id); |
775 if (it != active_sessions_.end()) { | 795 if (it != active_sessions_.end()) { |
776 QuicChromiumClientSession* session = it->second; | 796 QuicChromiumClientSession* session = it->second; |
777 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 797 if (!session->CanPool(url.host(), privacy_mode)) |
778 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 798 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
779 request->set_stream(CreateFromSession(session)); | 799 request->set_stream(CreateFromSession(session)); |
780 return OK; | 800 return OK; |
781 } | 801 } |
782 } | 802 } |
783 | 803 |
784 if (HasActiveJob(server_id)) { | 804 if (HasActiveJob(server_id)) { |
785 active_requests_[request] = server_id; | 805 active_requests_[request] = server_id; |
786 job_requests_map_[server_id].insert(request); | 806 job_requests_map_[server_id].insert(request); |
787 return ERR_IO_PENDING; | 807 return ERR_IO_PENDING; |
(...skipping 12 matching lines...) Expand all Loading... |
800 server_id.host_port_pair())) { | 820 server_id.host_port_pair())) { |
801 // If there is no entry for QUIC, consider that as a new server and | 821 // If there is no entry for QUIC, consider that as a new server and |
802 // don't wait for Cache thread to load the data for that server. | 822 // don't wait for Cache thread to load the data for that server. |
803 load_from_disk_cache = false; | 823 load_from_disk_cache = false; |
804 } | 824 } |
805 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { | 825 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { |
806 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 826 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
807 } | 827 } |
808 } | 828 } |
809 | 829 |
810 bool server_and_origin_have_same_host = host_port_pair.host() == origin_host; | 830 bool server_and_origin_have_same_host = host_port_pair.host() == url.host(); |
811 scoped_ptr<Job> job(new Job( | 831 scoped_ptr<Job> job(new Job( |
812 this, host_resolver_, host_port_pair, server_and_origin_have_same_host, | 832 this, host_resolver_, host_port_pair, server_and_origin_have_same_host, |
813 WasQuicRecentlyBroken(server_id), privacy_mode, cert_verify_flags, | 833 WasQuicRecentlyBroken(server_id), privacy_mode, cert_verify_flags, |
814 method == "POST" /* is_post */, quic_server_info, net_log)); | 834 method == "POST" /* is_post */, quic_server_info, net_log)); |
815 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 835 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
816 base::Unretained(this), job.get())); | 836 base::Unretained(this), job.get())); |
817 if (rv == ERR_IO_PENDING) { | 837 if (rv == ERR_IO_PENDING) { |
818 active_requests_[request] = server_id; | 838 active_requests_[request] = server_id; |
819 job_requests_map_[server_id].insert(request); | 839 job_requests_map_[server_id].insert(request); |
820 active_jobs_[server_id].insert(job.release()); | 840 active_jobs_[server_id].insert(job.release()); |
821 return rv; | 841 return rv; |
822 } | 842 } |
823 if (rv == OK) { | 843 if (rv == OK) { |
824 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() | 844 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() |
825 // related changes. | 845 // related changes. |
826 if (active_sessions_.empty()) | 846 if (active_sessions_.empty()) |
827 return ERR_QUIC_PROTOCOL_ERROR; | 847 return ERR_QUIC_PROTOCOL_ERROR; |
828 SessionMap::iterator it = active_sessions_.find(server_id); | 848 SessionMap::iterator it = active_sessions_.find(server_id); |
829 DCHECK(it != active_sessions_.end()); | 849 DCHECK(it != active_sessions_.end()); |
830 if (it == active_sessions_.end()) | 850 if (it == active_sessions_.end()) |
831 return ERR_QUIC_PROTOCOL_ERROR; | 851 return ERR_QUIC_PROTOCOL_ERROR; |
832 QuicChromiumClientSession* session = it->second; | 852 QuicChromiumClientSession* session = it->second; |
833 if (!session->CanPool(origin_host.as_string(), privacy_mode)) | 853 if (!session->CanPool(url.host(), privacy_mode)) |
834 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; | 854 return ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN; |
835 request->set_stream(CreateFromSession(session)); | 855 request->set_stream(CreateFromSession(session)); |
836 } | 856 } |
837 return rv; | 857 return rv; |
838 } | 858 } |
839 | 859 |
840 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, | 860 void QuicStreamFactory::CreateAuxilaryJob(const QuicServerId server_id, |
841 int cert_verify_flags, | 861 int cert_verify_flags, |
842 bool server_and_origin_have_same_host, | 862 bool server_and_origin_have_same_host, |
843 bool is_post, | 863 bool is_post, |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 // Since the session was active, there's no longer an | 1669 // Since the session was active, there's no longer an |
1650 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1670 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1651 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1671 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1652 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1672 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1653 // still race. | 1673 // still race. |
1654 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1674 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1655 alternative_service); | 1675 alternative_service); |
1656 } | 1676 } |
1657 | 1677 |
1658 } // namespace net | 1678 } // namespace net |
OLD | NEW |