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_chain.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_chain| 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 ProxyChain& proxy_chain, 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_chain()81 const ProxyChain& proxy_chain() const { return host_port_proxy_pair_.second; } 82 privacy_mode()83 PrivacyMode privacy_mode() const { 84 return privacy_mode_; 85 } 86 is_proxy_session()87 IsProxySession is_proxy_session() const { return is_proxy_session_; } 88 socket_tag()89 const SocketTag& socket_tag() const { return socket_tag_; } 90 network_anonymization_key()91 const NetworkAnonymizationKey& network_anonymization_key() const { 92 return network_anonymization_key_; 93 } 94 secure_dns_policy()95 SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; } 96 97 private: 98 HostPortProxyPair host_port_proxy_pair_; 99 // If enabled, then session cannot be tracked by the server. 100 PrivacyMode privacy_mode_ = PRIVACY_MODE_DISABLED; 101 IsProxySession is_proxy_session_; 102 SocketTag socket_tag_; 103 // Used to separate requests made in different contexts. If network state 104 // partitioning is disabled this will be set to an empty key. 105 NetworkAnonymizationKey network_anonymization_key_; 106 SecureDnsPolicy secure_dns_policy_; 107 }; 108 109 } // namespace net 110 111 #endif // NET_SPDY_SPDY_SESSION_KEY_H_ 112