xref: /aosp_15_r20/external/cronet/net/quic/quic_session_key.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 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/quic/quic_session_key.h"
6 
7 #include <tuple>
8 
9 #include "net/base/host_port_pair.h"
10 #include "net/base/network_anonymization_key.h"
11 #include "net/base/privacy_mode.h"
12 #include "net/base/proxy_chain.h"
13 #include "net/base/session_usage.h"
14 #include "net/dns/public/secure_dns_policy.h"
15 #include "net/socket/socket_tag.h"
16 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
17 
18 namespace net {
19 
20 QuicSessionKey::QuicSessionKey() = default;
21 
QuicSessionKey(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 require_dns_https_alpn)22 QuicSessionKey::QuicSessionKey(
23     const HostPortPair& host_port_pair,
24     PrivacyMode privacy_mode,
25     const ProxyChain& proxy_chain,
26     SessionUsage session_usage,
27     const SocketTag& socket_tag,
28     const NetworkAnonymizationKey& network_anonymization_key,
29     SecureDnsPolicy secure_dns_policy,
30     bool require_dns_https_alpn)
31     : QuicSessionKey(host_port_pair.host(),
32                      host_port_pair.port(),
33                      privacy_mode,
34                      proxy_chain,
35                      session_usage,
36                      socket_tag,
37                      network_anonymization_key,
38                      secure_dns_policy,
39                      require_dns_https_alpn) {}
40 
QuicSessionKey(const std::string & host,uint16_t port,PrivacyMode privacy_mode,const ProxyChain & proxy_chain,SessionUsage session_usage,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool require_dns_https_alpn)41 QuicSessionKey::QuicSessionKey(
42     const std::string& host,
43     uint16_t port,
44     PrivacyMode privacy_mode,
45     const ProxyChain& proxy_chain,
46     SessionUsage session_usage,
47     const SocketTag& socket_tag,
48     const NetworkAnonymizationKey& network_anonymization_key,
49     SecureDnsPolicy secure_dns_policy,
50     bool require_dns_https_alpn)
51     : QuicSessionKey(
52           // TODO(crbug.com/1103350): Handle non-boolean privacy modes.
53           quic::QuicServerId(host, port, privacy_mode != PRIVACY_MODE_DISABLED),
54           proxy_chain,
55           session_usage,
56           socket_tag,
57           network_anonymization_key,
58           secure_dns_policy,
59           require_dns_https_alpn) {}
60 
QuicSessionKey(const quic::QuicServerId & server_id,const ProxyChain & proxy_chain,SessionUsage session_usage,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool require_dns_https_alpn)61 QuicSessionKey::QuicSessionKey(
62     const quic::QuicServerId& server_id,
63     const ProxyChain& proxy_chain,
64     SessionUsage session_usage,
65     const SocketTag& socket_tag,
66     const NetworkAnonymizationKey& network_anonymization_key,
67     SecureDnsPolicy secure_dns_policy,
68     bool require_dns_https_alpn)
69     : server_id_(server_id),
70       proxy_chain_(proxy_chain),
71       session_usage_(session_usage),
72       socket_tag_(socket_tag),
73       network_anonymization_key_(
74           NetworkAnonymizationKey::IsPartitioningEnabled()
75               ? network_anonymization_key
76               : NetworkAnonymizationKey()),
77       secure_dns_policy_(secure_dns_policy),
78       require_dns_https_alpn_(require_dns_https_alpn) {}
79 
80 QuicSessionKey::QuicSessionKey(const QuicSessionKey& other) = default;
81 
operator <(const QuicSessionKey & other) const82 bool QuicSessionKey::operator<(const QuicSessionKey& other) const {
83   return std::tie(server_id_, proxy_chain_, session_usage_, socket_tag_,
84                   network_anonymization_key_, secure_dns_policy_,
85                   require_dns_https_alpn_) <
86          std::tie(other.server_id_, other.proxy_chain_, other.session_usage_,
87                   other.socket_tag_, other.network_anonymization_key_,
88                   other.secure_dns_policy_, other.require_dns_https_alpn_);
89 }
operator ==(const QuicSessionKey & other) const90 bool QuicSessionKey::operator==(const QuicSessionKey& other) const {
91   return server_id_ == other.server_id_ && proxy_chain_ == other.proxy_chain_ &&
92          session_usage_ == other.session_usage_ &&
93          socket_tag_ == other.socket_tag_ &&
94          network_anonymization_key_ == other.network_anonymization_key_ &&
95          secure_dns_policy_ == other.secure_dns_policy_ &&
96          require_dns_https_alpn_ == other.require_dns_https_alpn_;
97 }
98 
CanUseForAliasing(const QuicSessionKey & other) const99 bool QuicSessionKey::CanUseForAliasing(const QuicSessionKey& other) const {
100   return server_id_.privacy_mode_enabled() ==
101              other.server_id_.privacy_mode_enabled() &&
102          socket_tag_ == other.socket_tag_ &&
103          proxy_chain_ == other.proxy_chain_ &&
104          session_usage_ == other.session_usage_ &&
105          network_anonymization_key_ == other.network_anonymization_key_ &&
106          secure_dns_policy_ == other.secure_dns_policy_ &&
107          require_dns_https_alpn_ == other.require_dns_https_alpn_;
108 }
109 
110 }  // namespace net
111