spdy_session_key.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_SPDY_SPDY_SESSION_KEY_H_
  5. #define NET_SPDY_SPDY_SESSION_KEY_H_
  6. #include "net/base/net_export.h"
  7. #include "net/base/network_isolation_key.h"
  8. #include "net/base/privacy_mode.h"
  9. #include "net/base/proxy_server.h"
  10. #include "net/dns/public/secure_dns_policy.h"
  11. #include "net/socket/socket_tag.h"
  12. namespace net {
  13. // SpdySessionKey is used as unique index for SpdySessionPool.
  14. class NET_EXPORT_PRIVATE SpdySessionKey {
  15. public:
  16. enum class IsProxySession {
  17. kFalse,
  18. // This means this is a ProxyServer::Direct() session for an HTTP2 proxy,
  19. // with |host_port_pair| being the proxy host and port. This should not be
  20. // confused with a tunnel over an HTTP2 proxy session, for which
  21. // |proxy_server| will be information about the proxy being used, and
  22. // |host_port_pair| will be information not about the proxy, but the host
  23. // that we're proxying the connection to.
  24. kTrue,
  25. };
  26. SpdySessionKey();
  27. SpdySessionKey(const HostPortPair& host_port_pair,
  28. const ProxyServer& proxy_server,
  29. PrivacyMode privacy_mode,
  30. IsProxySession is_proxy_session,
  31. const SocketTag& socket_tag,
  32. const NetworkIsolationKey& network_isolation_key,
  33. SecureDnsPolicy secure_dns_policy);
  34. SpdySessionKey(const SpdySessionKey& other);
  35. ~SpdySessionKey();
  36. // Comparator function so this can be placed in a std::map.
  37. bool operator<(const SpdySessionKey& other) const;
  38. // Equality tests of contents.
  39. bool operator==(const SpdySessionKey& other) const;
  40. bool operator!=(const SpdySessionKey& other) const;
  41. // Struct returned by CompareForAliasing().
  42. struct CompareForAliasingResult {
  43. // True if the two SpdySessionKeys match, except possibly for their
  44. // |host_port_pair| and |socket_tag|.
  45. bool is_potentially_aliasable = false;
  46. // True if the |socket_tag| fields match. If this is false, it's up to the
  47. // caller to change the tag of the session (if possible) or to not alias the
  48. // session, even if |is_potentially_aliasable| is true.
  49. bool is_socket_tag_match = false;
  50. };
  51. // Checks if requests using SpdySessionKey can potentially be used to service
  52. // requests using another. The caller *MUST* also make sure that the session
  53. // associated with one key has been verified for use with the other.
  54. //
  55. // Note that this method is symmetric, so it doesn't matter which key's method
  56. // is called on the other.
  57. CompareForAliasingResult CompareForAliasing(
  58. const SpdySessionKey& other) const;
  59. const HostPortProxyPair& host_port_proxy_pair() const {
  60. return host_port_proxy_pair_;
  61. }
  62. const HostPortPair& host_port_pair() const {
  63. return host_port_proxy_pair_.first;
  64. }
  65. const ProxyServer& proxy_server() const {
  66. return host_port_proxy_pair_.second;
  67. }
  68. PrivacyMode privacy_mode() const {
  69. return privacy_mode_;
  70. }
  71. IsProxySession is_proxy_session() const { return is_proxy_session_; }
  72. const SocketTag& socket_tag() const { return socket_tag_; }
  73. const NetworkIsolationKey& network_isolation_key() const {
  74. return network_isolation_key_;
  75. }
  76. SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
  77. private:
  78. HostPortProxyPair host_port_proxy_pair_;
  79. // If enabled, then session cannot be tracked by the server.
  80. PrivacyMode privacy_mode_ = PRIVACY_MODE_DISABLED;
  81. IsProxySession is_proxy_session_;
  82. SocketTag socket_tag_;
  83. // Used to separate requests made in different contexts.
  84. NetworkIsolationKey network_isolation_key_;
  85. SecureDnsPolicy secure_dns_policy_;
  86. };
  87. } // namespace net
  88. #endif // NET_SPDY_SPDY_SESSION_KEY_H_