xref: /aosp_15_r20/external/cronet/net/spdy/spdy_session_key.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/spdy/spdy_session_key.h"
6 
7 #include <optional>
8 #include <tuple>
9 
10 #include "base/feature_list.h"
11 #include "base/logging.h"
12 #include "base/trace_event/memory_usage_estimator.h"
13 #include "net/base/features.h"
14 #include "net/base/host_port_pair.h"
15 #include "net/base/proxy_chain.h"
16 #include "net/base/proxy_string_util.h"
17 #include "net/base/session_usage.h"
18 #include "net/dns/public/secure_dns_policy.h"
19 
20 namespace net {
21 
22 SpdySessionKey::SpdySessionKey() = default;
23 
SpdySessionKey(const HostPortPair & host_port_pair,PrivacyMode privacy_mode,const ProxyChain & proxy_chain,SessionUsage session_usage,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool disable_cert_verification_network_fetches)24 SpdySessionKey::SpdySessionKey(
25     const HostPortPair& host_port_pair,
26     PrivacyMode privacy_mode,
27     const ProxyChain& proxy_chain,
28     SessionUsage session_usage,
29     const SocketTag& socket_tag,
30     const NetworkAnonymizationKey& network_anonymization_key,
31     SecureDnsPolicy secure_dns_policy,
32     bool disable_cert_verification_network_fetches)
33     : host_port_proxy_pair_(host_port_pair, proxy_chain),
34       privacy_mode_(privacy_mode),
35       session_usage_(session_usage),
36       socket_tag_(socket_tag),
37       network_anonymization_key_(
38           NetworkAnonymizationKey::IsPartitioningEnabled()
39               ? network_anonymization_key
40               : NetworkAnonymizationKey()),
41       secure_dns_policy_(secure_dns_policy),
42       disable_cert_verification_network_fetches_(
43           disable_cert_verification_network_fetches) {
44   DVLOG(1) << "SpdySessionKey(host=" << host_port_pair.ToString()
45            << ", proxy_chain=" << proxy_chain << ", privacy=" << privacy_mode;
46   DCHECK(disable_cert_verification_network_fetches_ ||
47          session_usage_ != SessionUsage::kProxy);
48   DCHECK(privacy_mode_ == PRIVACY_MODE_DISABLED ||
49          session_usage_ != SessionUsage::kProxy);
50 }
51 
52 SpdySessionKey::SpdySessionKey(const SpdySessionKey& other) = default;
53 
54 SpdySessionKey::~SpdySessionKey() = default;
55 
operator <(const SpdySessionKey & other) const56 bool SpdySessionKey::operator<(const SpdySessionKey& other) const {
57   return std::tie(privacy_mode_, host_port_proxy_pair_.first,
58                   host_port_proxy_pair_.second, session_usage_,
59                   network_anonymization_key_, secure_dns_policy_,
60                   disable_cert_verification_network_fetches_, socket_tag_) <
61          std::tie(other.privacy_mode_, other.host_port_proxy_pair_.first,
62                   other.host_port_proxy_pair_.second, other.session_usage_,
63                   other.network_anonymization_key_, other.secure_dns_policy_,
64                   other.disable_cert_verification_network_fetches_,
65                   other.socket_tag_);
66 }
67 
operator ==(const SpdySessionKey & other) const68 bool SpdySessionKey::operator==(const SpdySessionKey& other) const {
69   return privacy_mode_ == other.privacy_mode_ &&
70          host_port_proxy_pair_.first.Equals(
71              other.host_port_proxy_pair_.first) &&
72          host_port_proxy_pair_.second == other.host_port_proxy_pair_.second &&
73          session_usage_ == other.session_usage_ &&
74          network_anonymization_key_ == other.network_anonymization_key_ &&
75          secure_dns_policy_ == other.secure_dns_policy_ &&
76          disable_cert_verification_network_fetches_ ==
77              other.disable_cert_verification_network_fetches_ &&
78          socket_tag_ == other.socket_tag_;
79 }
80 
operator !=(const SpdySessionKey & other) const81 bool SpdySessionKey::operator!=(const SpdySessionKey& other) const {
82   return !(*this == other);
83 }
84 
CompareForAliasing(const SpdySessionKey & other) const85 SpdySessionKey::CompareForAliasingResult SpdySessionKey::CompareForAliasing(
86     const SpdySessionKey& other) const {
87   CompareForAliasingResult result;
88   result.is_potentially_aliasable =
89       (privacy_mode_ == other.privacy_mode_ &&
90        host_port_proxy_pair_.second == other.host_port_proxy_pair_.second &&
91        session_usage_ == other.session_usage_ &&
92        network_anonymization_key_ == other.network_anonymization_key_ &&
93        secure_dns_policy_ == other.secure_dns_policy_ &&
94        disable_cert_verification_network_fetches_ ==
95            other.disable_cert_verification_network_fetches_);
96   result.is_socket_tag_match = (socket_tag_ == other.socket_tag_);
97   return result;
98 }
99 
100 }  // namespace net
101