• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "net/base/net_export.h"
9 #include "net/base/network_anonymization_key.h"
10 #include "net/base/network_isolation_key.h"
11 #include "net/base/privacy_mode.h"
12 #include "net/base/proxy_server.h"
13 #include "net/dns/public/secure_dns_policy.h"
14 #include "net/socket/socket_tag.h"
15 #include "third_party/abseil-cpp/absl/types/optional.h"
16 namespace net {
17 
18 // SpdySessionKey is used as unique index for SpdySessionPool.
19 class NET_EXPORT_PRIVATE SpdySessionKey {
20  public:
21   enum class IsProxySession {
22     kFalse,
23     // This means this is a ProxyServer::Direct() session for an HTTP2 proxy,
24     // with |host_port_pair| being the proxy host and port. This should not be
25     // confused with a tunnel over an HTTP2 proxy session, for which
26     // |proxy_server| will be information about the proxy being used, and
27     // |host_port_pair| will be information not about the proxy, but the host
28     // that we're proxying the connection to.
29     kTrue,
30   };
31 
32   SpdySessionKey();
33 
34   SpdySessionKey(const HostPortPair& host_port_pair,
35                  const ProxyServer& proxy_server,
36                  PrivacyMode privacy_mode,
37                  IsProxySession is_proxy_session,
38                  const SocketTag& socket_tag,
39                  const NetworkAnonymizationKey& network_anonymization_key,
40                  SecureDnsPolicy secure_dns_policy);
41 
42   SpdySessionKey(const SpdySessionKey& other);
43 
44   ~SpdySessionKey();
45 
46   // Comparator function so this can be placed in a std::map.
47   bool operator<(const SpdySessionKey& other) const;
48 
49   // Equality tests of contents.
50   bool operator==(const SpdySessionKey& other) const;
51   bool operator!=(const SpdySessionKey& other) const;
52 
53   // Struct returned by CompareForAliasing().
54   struct CompareForAliasingResult {
55     // True if the two SpdySessionKeys match, except possibly for their
56     // |host_port_pair| and |socket_tag|.
57     bool is_potentially_aliasable = false;
58     // True if the |socket_tag| fields match. If this is false, it's up to the
59     // caller to change the tag of the session (if possible) or to not alias the
60     // session, even if |is_potentially_aliasable| is true.
61     bool is_socket_tag_match = false;
62   };
63 
64   // Checks if requests using SpdySessionKey can potentially be used to service
65   // requests using another. The caller *MUST* also make sure that the session
66   // associated with one key has been verified for use with the other.
67   //
68   // Note that this method is symmetric, so it doesn't matter which key's method
69   // is called on the other.
70   CompareForAliasingResult CompareForAliasing(
71       const SpdySessionKey& other) const;
72 
host_port_proxy_pair()73   const HostPortProxyPair& host_port_proxy_pair() const {
74     return host_port_proxy_pair_;
75   }
76 
host_port_pair()77   const HostPortPair& host_port_pair() const {
78     return host_port_proxy_pair_.first;
79   }
80 
proxy_server()81   const ProxyServer& proxy_server() const {
82     return host_port_proxy_pair_.second;
83   }
84 
privacy_mode()85   PrivacyMode privacy_mode() const {
86     return privacy_mode_;
87   }
88 
is_proxy_session()89   IsProxySession is_proxy_session() const { return is_proxy_session_; }
90 
socket_tag()91   const SocketTag& socket_tag() const { return socket_tag_; }
92 
network_anonymization_key()93   const NetworkAnonymizationKey& network_anonymization_key() const {
94     return network_anonymization_key_;
95   }
96 
secure_dns_policy()97   SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
98 
99  private:
100   HostPortProxyPair host_port_proxy_pair_;
101   // If enabled, then session cannot be tracked by the server.
102   PrivacyMode privacy_mode_ = PRIVACY_MODE_DISABLED;
103   IsProxySession is_proxy_session_;
104   SocketTag socket_tag_;
105   // Used to separate requests made in different contexts. If network state
106   // partitioning is disabled this will be set to an empty key.
107   NetworkAnonymizationKey network_anonymization_key_;
108   SecureDnsPolicy secure_dns_policy_;
109 };
110 
111 }  // namespace net
112 
113 #endif  // NET_SPDY_SPDY_SESSION_KEY_H_
114