summaryrefslogtreecommitdiff
path: root/chromium/net/quic/quic_session_key.h
blob: c91ebd54c5aa43126d676d2ead518486f60f1b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_QUIC_QUIC_SESSION_KEY_H_
#define NET_QUIC_QUIC_SESSION_KEY_H_

#include "net/base/host_port_pair.h"
#include "net/base/network_isolation_key.h"
#include "net/base/privacy_mode.h"
#include "net/socket/socket_tag.h"
#include "net/third_party/quiche/src/quic/core/quic_server_id.h"

namespace net {

// The key used to identify sessions. Includes the quic::QuicServerId and socket
// tag.
class QUIC_EXPORT_PRIVATE QuicSessionKey {
 public:
  QuicSessionKey();
  QuicSessionKey(const HostPortPair& host_port_pair,
                 PrivacyMode privacy_mode,
                 const SocketTag& socket_tag,
                 const NetworkIsolationKey& network_isolation_key,
                 bool disable_secure_dns);
  QuicSessionKey(const std::string& host,
                 uint16_t port,
                 PrivacyMode privacy_mode,
                 const SocketTag& socket_tag,
                 const NetworkIsolationKey& network_isolation_key,
                 bool disable_secure_dns);
  QuicSessionKey(const quic::QuicServerId& server_id,
                 const SocketTag& socket_tag,
                 const NetworkIsolationKey& network_isolation_key,
                 bool disable_secure_dns);
  QuicSessionKey(const QuicSessionKey& other);
  ~QuicSessionKey() = default;

  // Needed to be an element of std::set.
  bool operator<(const QuicSessionKey& other) const;
  bool operator==(const QuicSessionKey& other) const;

  // Checks if requests using QuicSessionKey can potentially be used to service
  // requests using another.  Returns true if all fields except QuicServerId's
  // host and port match. The caller *MUST* also make sure that the session
  // associated with one key has been verified for use with the host/port of the
  // other.
  //
  // Note that this method is symmetric, so it doesn't matter which key's method
  // is called on the other.
  bool CanUseForAliasing(const QuicSessionKey& other) const;

  const std::string& host() const { return server_id_.host(); }

  PrivacyMode privacy_mode() const {
    return server_id_.privacy_mode_enabled() ? PRIVACY_MODE_ENABLED
                                             : PRIVACY_MODE_DISABLED;
  }

  const quic::QuicServerId& server_id() const { return server_id_; }

  SocketTag socket_tag() const { return socket_tag_; }

  const NetworkIsolationKey& network_isolation_key() const {
    return network_isolation_key_;
  }

  bool disable_secure_dns() const { return disable_secure_dns_; }

  size_t EstimateMemoryUsage() const;

 private:
  quic::QuicServerId server_id_;
  SocketTag socket_tag_;
  // Used to separate requests made in different contexts.
  NetworkIsolationKey network_isolation_key_;
  bool disable_secure_dns_;
};

}  // namespace net

#endif  // NET_QUIC_QUIC_SERVER_ID_H_