xref: /aosp_15_r20/external/cronet/net/spdy/spdy_session_key.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 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 #ifndef NET_SPDY_SPDY_SESSION_KEY_H_
6 #define NET_SPDY_SPDY_SESSION_KEY_H_
7 
8 #include <optional>
9 
10 #include "net/base/net_export.h"
11 #include "net/base/network_anonymization_key.h"
12 #include "net/base/network_isolation_key.h"
13 #include "net/base/privacy_mode.h"
14 #include "net/base/proxy_chain.h"
15 #include "net/base/session_usage.h"
16 #include "net/dns/public/secure_dns_policy.h"
17 #include "net/socket/socket_tag.h"
18 namespace net {
19 
20 // SpdySessionKey is used as unique index for SpdySessionPool.
21 class NET_EXPORT_PRIVATE SpdySessionKey {
22  public:
23   SpdySessionKey();
24 
25   // Note that if `session_usage` is kProxy, then:
26   // * `privacy_mode` must be PRIVACY_MODE_DISABLED to pool credentialed and
27   //     uncredetialed requests onto the same proxy connections.
28   // * `disable_cert_verification_network_fetches` must be true, to avoid
29   //     depending on cert fetches, which would be made through the proxy.
30   SpdySessionKey(const HostPortPair& host_port_pair,
31                  PrivacyMode privacy_mode,
32                  const ProxyChain& proxy_chain,
33                  SessionUsage session_usage,
34                  const SocketTag& socket_tag,
35                  const NetworkAnonymizationKey& network_anonymization_key,
36                  SecureDnsPolicy secure_dns_policy,
37                  bool disable_cert_verification_network_fetches);
38 
39   SpdySessionKey(const SpdySessionKey& other);
40 
41   ~SpdySessionKey();
42 
43   // Comparator function so this can be placed in a std::map.
44   bool operator<(const SpdySessionKey& other) const;
45 
46   // Equality tests of contents.
47   bool operator==(const SpdySessionKey& other) const;
48   bool operator!=(const SpdySessionKey& other) const;
49 
50   // Struct returned by CompareForAliasing().
51   struct CompareForAliasingResult {
52     // True if the two SpdySessionKeys match, except possibly for their
53     // |host_port_pair| and |socket_tag|.
54     bool is_potentially_aliasable = false;
55     // True if the |socket_tag| fields match. If this is false, it's up to the
56     // caller to change the tag of the session (if possible) or to not alias the
57     // session, even if |is_potentially_aliasable| is true.
58     bool is_socket_tag_match = false;
59   };
60 
61   // Checks if requests using SpdySessionKey can potentially be used to service
62   // requests using another. The caller *MUST* also make sure that the session
63   // associated with one key has been verified for use with the other.
64   //
65   // Note that this method is symmetric, so it doesn't matter which key's method
66   // is called on the other.
67   CompareForAliasingResult CompareForAliasing(
68       const SpdySessionKey& other) const;
69 
host_port_proxy_pair()70   const HostPortProxyPair& host_port_proxy_pair() const {
71     return host_port_proxy_pair_;
72   }
73 
host_port_pair()74   const HostPortPair& host_port_pair() const {
75     return host_port_proxy_pair_.first;
76   }
77 
proxy_chain()78   const ProxyChain& proxy_chain() const { return host_port_proxy_pair_.second; }
79 
privacy_mode()80   PrivacyMode privacy_mode() const {
81     return privacy_mode_;
82   }
83 
session_usage()84   SessionUsage session_usage() const { return session_usage_; }
85 
socket_tag()86   const SocketTag& socket_tag() const { return socket_tag_; }
87 
network_anonymization_key()88   const NetworkAnonymizationKey& network_anonymization_key() const {
89     return network_anonymization_key_;
90   }
91 
secure_dns_policy()92   SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
93 
disable_cert_verification_network_fetches()94   bool disable_cert_verification_network_fetches() const {
95     return disable_cert_verification_network_fetches_;
96   }
97 
98  private:
99   HostPortProxyPair host_port_proxy_pair_;
100   // If enabled, then session cannot be tracked by the server.
101   PrivacyMode privacy_mode_ = PRIVACY_MODE_DISABLED;
102   SessionUsage session_usage_;
103   SocketTag socket_tag_;
104   // Used to separate requests made in different contexts. If network state
105   // partitioning is disabled this will be set to an empty key.
106   NetworkAnonymizationKey network_anonymization_key_;
107   SecureDnsPolicy secure_dns_policy_;
108   bool disable_cert_verification_network_fetches_;
109 };
110 
111 }  // namespace net
112 
113 #endif  // NET_SPDY_SPDY_SESSION_KEY_H_
114