• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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_QUIC_QUIC_SESSION_KEY_H_
6 #define NET_QUIC_QUIC_SESSION_KEY_H_
7 
8 #include "net/base/host_port_pair.h"
9 #include "net/base/network_anonymization_key.h"
10 #include "net/base/privacy_mode.h"
11 #include "net/base/proxy_chain.h"
12 #include "net/base/session_usage.h"
13 #include "net/dns/public/secure_dns_policy.h"
14 #include "net/socket/socket_tag.h"
15 #include "net/third_party/quiche/src/quiche/quic/core/quic_server_id.h"
16 
17 namespace net {
18 
19 // The key used to identify sessions. Includes the quic::QuicServerId and socket
20 // tag.
21 class NET_EXPORT_PRIVATE QuicSessionKey {
22  public:
23   QuicSessionKey();
24   QuicSessionKey(const HostPortPair& host_port_pair,
25                  PrivacyMode privacy_mode,
26                  const ProxyChain& proxy_chain,
27                  SessionUsage session_usage,
28                  const SocketTag& socket_tag,
29                  const NetworkAnonymizationKey& network_anonymization_key,
30                  SecureDnsPolicy secure_dns_policy,
31                  bool require_dns_https_alpn);
32   QuicSessionKey(std::string host,
33                  uint16_t port,
34                  PrivacyMode privacy_mode,
35                  const ProxyChain& proxy_chain,
36                  SessionUsage session_usage,
37                  const SocketTag& socket_tag,
38                  const NetworkAnonymizationKey& network_anonymization_key,
39                  SecureDnsPolicy secure_dns_policy,
40                  bool require_dns_https_alpn);
41   QuicSessionKey(const quic::QuicServerId& server_id,
42                  PrivacyMode privacy_mode,
43                  const ProxyChain& proxy_chain,
44                  SessionUsage session_usage,
45                  const SocketTag& socket_tag,
46                  const NetworkAnonymizationKey& network_anonymization_key,
47                  SecureDnsPolicy secure_dns_policy,
48                  bool require_dns_https_alpn);
49   QuicSessionKey(const QuicSessionKey& other);
50   QuicSessionKey(QuicSessionKey&& other);
51   QuicSessionKey& operator=(const QuicSessionKey& other);
52   QuicSessionKey& operator=(QuicSessionKey&& other);
53   ~QuicSessionKey() = default;
54 
55   // Needed to be an element of std::set.
56   bool operator<(const QuicSessionKey& other) const;
57   bool operator==(const QuicSessionKey& other) const;
58 
59   // Checks if requests using QuicSessionKey can potentially be used to service
60   // requests using another.  Returns true if all fields except QuicServerId's
61   // host and port match. The caller *MUST* also make sure that the session
62   // associated with one key has been verified for use with the host/port of the
63   // 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   bool CanUseForAliasing(const QuicSessionKey& other) const;
68 
host()69   const std::string& host() const { return server_id_.host(); }
70 
privacy_mode()71   PrivacyMode privacy_mode() const { return privacy_mode_; }
72 
server_id()73   const quic::QuicServerId& server_id() const { return server_id_; }
74 
proxy_chain()75   const ProxyChain& proxy_chain() const { return proxy_chain_; }
76 
session_usage()77   SessionUsage session_usage() const { return session_usage_; }
78 
socket_tag()79   SocketTag socket_tag() const { return socket_tag_; }
80 
network_anonymization_key()81   const NetworkAnonymizationKey& network_anonymization_key() const {
82     return network_anonymization_key_;
83   }
84 
secure_dns_policy()85   SecureDnsPolicy secure_dns_policy() const { return secure_dns_policy_; }
86 
require_dns_https_alpn()87   bool require_dns_https_alpn() const { return require_dns_https_alpn_; }
88 
89  private:
90   quic::QuicServerId server_id_;
91   PrivacyMode privacy_mode_ = PRIVACY_MODE_DISABLED;
92   ProxyChain proxy_chain_;
93   SessionUsage session_usage_ = SessionUsage::kDestination;
94   SocketTag socket_tag_;
95   // Used to separate requests made in different contexts.
96   NetworkAnonymizationKey network_anonymization_key_;
97   SecureDnsPolicy secure_dns_policy_ = SecureDnsPolicy::kAllow;
98   bool require_dns_https_alpn_ = false;
99 };
100 
101 }  // namespace net
102 
103 #endif  // NET_QUIC_QUIC_SESSION_KEY_H_
104