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 "base/feature_list.h"
8 #include "net/base/features.h"
9 #include "net/dns/public/secure_dns_policy.h"
10
11 namespace net {
12
13 QuicSessionKey::QuicSessionKey() = default;
14
QuicSessionKey(const HostPortPair & host_port_pair,PrivacyMode privacy_mode,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool require_dns_https_alpn)15 QuicSessionKey::QuicSessionKey(
16 const HostPortPair& host_port_pair,
17 PrivacyMode privacy_mode,
18 const SocketTag& socket_tag,
19 const NetworkAnonymizationKey& network_anonymization_key,
20 SecureDnsPolicy secure_dns_policy,
21 bool require_dns_https_alpn)
22 : QuicSessionKey(host_port_pair.host(),
23 host_port_pair.port(),
24 privacy_mode,
25 socket_tag,
26 network_anonymization_key,
27 secure_dns_policy,
28 require_dns_https_alpn) {}
29
QuicSessionKey(const std::string & host,uint16_t port,PrivacyMode privacy_mode,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool require_dns_https_alpn)30 QuicSessionKey::QuicSessionKey(
31 const std::string& host,
32 uint16_t port,
33 PrivacyMode privacy_mode,
34 const SocketTag& socket_tag,
35 const NetworkAnonymizationKey& network_anonymization_key,
36 SecureDnsPolicy secure_dns_policy,
37 bool require_dns_https_alpn)
38 : QuicSessionKey(
39 // TODO(crbug.com/1103350): Handle non-boolean privacy modes.
40 quic::QuicServerId(host, port, privacy_mode != PRIVACY_MODE_DISABLED),
41 socket_tag,
42 network_anonymization_key,
43 secure_dns_policy,
44 require_dns_https_alpn) {}
45
QuicSessionKey(const quic::QuicServerId & server_id,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy,bool require_dns_https_alpn)46 QuicSessionKey::QuicSessionKey(
47 const quic::QuicServerId& server_id,
48 const SocketTag& socket_tag,
49 const NetworkAnonymizationKey& network_anonymization_key,
50 SecureDnsPolicy secure_dns_policy,
51 bool require_dns_https_alpn)
52 : server_id_(server_id),
53 socket_tag_(socket_tag),
54 network_anonymization_key_(
55 NetworkAnonymizationKey::IsPartitioningEnabled()
56 ? network_anonymization_key
57 : NetworkAnonymizationKey()),
58 secure_dns_policy_(secure_dns_policy),
59 require_dns_https_alpn_(require_dns_https_alpn) {}
60
61 QuicSessionKey::QuicSessionKey(const QuicSessionKey& other) = default;
62
operator <(const QuicSessionKey & other) const63 bool QuicSessionKey::operator<(const QuicSessionKey& other) const {
64 return std::tie(server_id_, socket_tag_, network_anonymization_key_,
65 secure_dns_policy_, require_dns_https_alpn_) <
66 std::tie(other.server_id_, other.socket_tag_,
67 other.network_anonymization_key_, other.secure_dns_policy_,
68 other.require_dns_https_alpn_);
69 }
operator ==(const QuicSessionKey & other) const70 bool QuicSessionKey::operator==(const QuicSessionKey& other) const {
71 return server_id_ == other.server_id_ && socket_tag_ == other.socket_tag_ &&
72 network_anonymization_key_ == other.network_anonymization_key_ &&
73 secure_dns_policy_ == other.secure_dns_policy_ &&
74 require_dns_https_alpn_ == other.require_dns_https_alpn_;
75 }
76
CanUseForAliasing(const QuicSessionKey & other) const77 bool QuicSessionKey::CanUseForAliasing(const QuicSessionKey& other) const {
78 return server_id_.privacy_mode_enabled() ==
79 other.server_id_.privacy_mode_enabled() &&
80 socket_tag_ == other.socket_tag_ &&
81 network_anonymization_key_ == other.network_anonymization_key_ &&
82 secure_dns_policy_ == other.secure_dns_policy_ &&
83 require_dns_https_alpn_ == other.require_dns_https_alpn_;
84 }
85
86 } // namespace net
87