• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(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     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(quic::QuicServerId(std::move(host), port),
52                      privacy_mode,
53                      proxy_chain,
54                      session_usage,
55                      socket_tag,
56                      network_anonymization_key,
57                      secure_dns_policy,
58                      require_dns_https_alpn) {}
59 
QuicSessionKey(const quic::QuicServerId & server_id,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)60 QuicSessionKey::QuicSessionKey(
61     const quic::QuicServerId& server_id,
62     PrivacyMode privacy_mode,
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       privacy_mode_(privacy_mode),
71       proxy_chain_(proxy_chain),
72       session_usage_(session_usage),
73       socket_tag_(socket_tag),
74       network_anonymization_key_(
75           NetworkAnonymizationKey::IsPartitioningEnabled()
76               ? network_anonymization_key
77               : NetworkAnonymizationKey()),
78       secure_dns_policy_(secure_dns_policy),
79       require_dns_https_alpn_(require_dns_https_alpn) {}
80 
81 QuicSessionKey::QuicSessionKey(const QuicSessionKey& other) = default;
82 QuicSessionKey::QuicSessionKey(QuicSessionKey&& other) = default;
83 QuicSessionKey& QuicSessionKey::operator=(const QuicSessionKey& other) =
84     default;
85 QuicSessionKey& QuicSessionKey::operator=(QuicSessionKey&& other) = default;
86 
operator <(const QuicSessionKey & other) const87 bool QuicSessionKey::operator<(const QuicSessionKey& other) const {
88   const uint16_t port = server_id_.port();
89   const uint16_t other_port = other.server_id_.port();
90   return std::tie(port, server_id_.host(), privacy_mode_, proxy_chain_,
91                   session_usage_, socket_tag_, network_anonymization_key_,
92                   secure_dns_policy_, require_dns_https_alpn_) <
93          std::tie(other_port, other.server_id_.host(), other.privacy_mode_,
94                   other.proxy_chain_, other.session_usage_, other.socket_tag_,
95                   other.network_anonymization_key_, other.secure_dns_policy_,
96                   other.require_dns_https_alpn_);
97 }
operator ==(const QuicSessionKey & other) const98 bool QuicSessionKey::operator==(const QuicSessionKey& other) const {
99   return server_id_.port() == other.server_id_.port() &&
100          server_id_.host() == other.server_id_.host() &&
101          privacy_mode_ == other.privacy_mode_ &&
102          proxy_chain_ == other.proxy_chain_ &&
103          session_usage_ == other.session_usage_ &&
104          socket_tag_ == other.socket_tag_ &&
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 
CanUseForAliasing(const QuicSessionKey & other) const110 bool QuicSessionKey::CanUseForAliasing(const QuicSessionKey& other) const {
111   return privacy_mode_ == other.privacy_mode() &&
112          socket_tag_ == other.socket_tag_ &&
113          proxy_chain_ == other.proxy_chain_ &&
114          session_usage_ == other.session_usage_ &&
115          network_anonymization_key_ == other.network_anonymization_key_ &&
116          secure_dns_policy_ == other.secure_dns_policy_ &&
117          require_dns_https_alpn_ == other.require_dns_https_alpn_;
118 }
119 
120 }  // namespace net
121