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 <tuple>
8
9 #include "base/feature_list.h"
10 #include "base/logging.h"
11 #include "base/trace_event/memory_usage_estimator.h"
12 #include "net/base/features.h"
13 #include "net/base/host_port_pair.h"
14 #include "net/base/proxy_server.h"
15 #include "net/base/proxy_string_util.h"
16 #include "net/dns/public/secure_dns_policy.h"
17 #include "third_party/abseil-cpp/absl/types/optional.h"
18
19 namespace net {
20
21 SpdySessionKey::SpdySessionKey() = default;
22
SpdySessionKey(const HostPortPair & host_port_pair,const ProxyServer & proxy_server,PrivacyMode privacy_mode,IsProxySession is_proxy_session,const SocketTag & socket_tag,const NetworkAnonymizationKey & network_anonymization_key,SecureDnsPolicy secure_dns_policy)23 SpdySessionKey::SpdySessionKey(
24 const HostPortPair& host_port_pair,
25 const ProxyServer& proxy_server,
26 PrivacyMode privacy_mode,
27 IsProxySession is_proxy_session,
28 const SocketTag& socket_tag,
29 const NetworkAnonymizationKey& network_anonymization_key,
30 SecureDnsPolicy secure_dns_policy)
31 : host_port_proxy_pair_(host_port_pair, proxy_server),
32 privacy_mode_(privacy_mode),
33 is_proxy_session_(is_proxy_session),
34 socket_tag_(socket_tag),
35 network_anonymization_key_(
36 NetworkAnonymizationKey::IsPartitioningEnabled()
37 ? network_anonymization_key
38 : NetworkAnonymizationKey()),
39 secure_dns_policy_(secure_dns_policy) {
40 // IsProxySession::kTrue should only be used with direct connections, since
41 // using multiple layers of proxies on top of each other isn't supported.
42 DCHECK(is_proxy_session != IsProxySession::kTrue || proxy_server.is_direct());
43 DVLOG(1) << "SpdySessionKey(host=" << host_port_pair.ToString()
44 << ", proxy=" << ProxyServerToProxyUri(proxy_server)
45 << ", privacy=" << privacy_mode;
46 }
47
48 SpdySessionKey::SpdySessionKey(const SpdySessionKey& other) = default;
49
50 SpdySessionKey::~SpdySessionKey() = default;
51
operator <(const SpdySessionKey & other) const52 bool SpdySessionKey::operator<(const SpdySessionKey& other) const {
53 return std::tie(privacy_mode_, host_port_proxy_pair_.first,
54 host_port_proxy_pair_.second, is_proxy_session_,
55 network_anonymization_key_, secure_dns_policy_, socket_tag_) <
56 std::tie(other.privacy_mode_, other.host_port_proxy_pair_.first,
57 other.host_port_proxy_pair_.second, other.is_proxy_session_,
58 other.network_anonymization_key_, other.secure_dns_policy_,
59 other.socket_tag_);
60 }
61
operator ==(const SpdySessionKey & other) const62 bool SpdySessionKey::operator==(const SpdySessionKey& other) const {
63 return privacy_mode_ == other.privacy_mode_ &&
64 host_port_proxy_pair_.first.Equals(
65 other.host_port_proxy_pair_.first) &&
66 host_port_proxy_pair_.second == other.host_port_proxy_pair_.second &&
67 is_proxy_session_ == other.is_proxy_session_ &&
68 network_anonymization_key_ == other.network_anonymization_key_ &&
69 secure_dns_policy_ == other.secure_dns_policy_ &&
70 socket_tag_ == other.socket_tag_;
71 }
72
operator !=(const SpdySessionKey & other) const73 bool SpdySessionKey::operator!=(const SpdySessionKey& other) const {
74 return !(*this == other);
75 }
76
CompareForAliasing(const SpdySessionKey & other) const77 SpdySessionKey::CompareForAliasingResult SpdySessionKey::CompareForAliasing(
78 const SpdySessionKey& other) const {
79 CompareForAliasingResult result;
80 result.is_potentially_aliasable =
81 (privacy_mode_ == other.privacy_mode_ &&
82 host_port_proxy_pair_.second == other.host_port_proxy_pair_.second &&
83 is_proxy_session_ == other.is_proxy_session_ &&
84 network_anonymization_key_ == other.network_anonymization_key_ &&
85 secure_dns_policy_ == other.secure_dns_policy_);
86 result.is_socket_tag_match = (socket_tag_ == other.socket_tag_);
87 return result;
88 }
89
90 } // namespace net
91