quic_session_key.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2018 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_QUIC_QUIC_SESSION_KEY_H_
  5. #define NET_QUIC_QUIC_SESSION_KEY_H_
  6. #include "net/base/host_port_pair.h"
  7. #include "net/base/network_isolation_key.h"
  8. #include "net/base/privacy_mode.h"
  9. #include "net/dns/public/secure_dns_policy.h"
  10. #include "net/socket/socket_tag.h"
  11. #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
  12. namespace net {
  13. // The key used to identify sessions. Includes the quic::QuicServerId and socket
  14. // tag.
  15. class NET_EXPORT_PRIVATE QuicSessionKey {
  16. public:
  17. QuicSessionKey();
  18. QuicSessionKey(const HostPortPair& host_port_pair,
  19. PrivacyMode privacy_mode,
  20. const SocketTag& socket_tag,
  21. const NetworkIsolationKey& network_isolation_key,
  22. SecureDnsPolicy secure_dns_policy,
  23. bool require_dns_https_alpn);
  24. QuicSessionKey(const std::string& host,
  25. uint16_t port,
  26. PrivacyMode privacy_mode,
  27. const SocketTag& socket_tag,
  28. const NetworkIsolationKey& network_isolation_key,
  29. SecureDnsPolicy secure_dns_policy,
  30. bool require_dns_https_alpn);
  31. QuicSessionKey(const quic::QuicServerId& server_id,
  32. const SocketTag& socket_tag,
  33. const NetworkIsolationKey& network_isolation_key,
  34. SecureDnsPolicy secure_dns_policy,
  35. bool require_dns_https_alpn);
  36. QuicSessionKey(const QuicSessionKey& other);
  37. ~QuicSessionKey() = default;
  38. // Needed to be an element of std::set.
  39. bool operator<(const QuicSessionKey& other) const;
  40. bool operator==(const QuicSessionKey& other) const;
  41. // Checks if requests using QuicSessionKey can potentially be used to service
  42. // requests using another. Returns true if all fields except QuicServerId's
  43. // host and port match. The caller *MUST* also make sure that the session
  44. // associated with one key has been verified for use with the host/port of the
  45. // other.
  46. //
  47. // Note that this method is symmetric, so it doesn't matter which key's method
  48. // is called on the other.
  49. bool CanUseForAliasing(const QuicSessionKey& other) const;
  50. const std::string& host() const { return server_id_.host(); }
  51. PrivacyMode privacy_mode() const {
  52. return server_id_.privacy_mode_enabled() ? PRIVACY_MODE_ENABLED
  53. : PRIVACY_MODE_DISABLED;
  54. }
  55. const quic::QuicServerId& server_id() const { return server_id_; }
  56. SocketTag socket_tag() const { return socket_tag_; }
  57. const NetworkIsolationKey& network_isolation_key() const {
  58. return network_isolation_key_;
  59. }
  60. SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
  61. bool require_dns_https_alpn() const { return require_dns_https_alpn_; }
  62. private:
  63. quic::QuicServerId server_id_;
  64. SocketTag socket_tag_;
  65. // Used to separate requests made in different contexts.
  66. NetworkIsolationKey network_isolation_key_;
  67. SecureDnsPolicy secure_dns_policy_;
  68. bool require_dns_https_alpn_ = false;
  69. };
  70. } // namespace net
  71. #endif // NET_QUIC_QUIC_SESSION_KEY_H_