blob: e3ae6726e157ee476bf1c895327444bba676b4f4 [file] [log] [blame]
[email protected]662626642014-01-25 00:54:411// Copyright 2014 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
Ryan Hamiltona3ee93a72018-08-01 22:03:085#ifndef NET_QUIC_QUIC_SERVER_INFO_H_
6#define NET_QUIC_QUIC_SERVER_INFO_H_
[email protected]662626642014-01-25 00:54:417
xunjieli3a41b462017-01-24 14:41:398#include <memory>
[email protected]662626642014-01-25 00:54:419#include <string>
10#include <vector>
11
Avi Drissman13fc8932015-12-20 04:40:4612#include "base/macros.h"
[email protected]662626642014-01-25 00:54:4113#include "base/memory/weak_ptr.h"
14#include "base/time/time.h"
Victor Vasiliev6bb59d22019-03-08 21:34:5115#include "net/third_party/quiche/src/quic/core/quic_server_id.h"
16#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
[email protected]662626642014-01-25 00:54:4117
18namespace net {
19
[email protected]662626642014-01-25 00:54:4120// QuicServerInfo is an interface for fetching information about a QUIC server.
21// This information may be stored on disk so does not include keys or other
22// sensitive information. Primarily it's intended for caching the QUIC server's
23// crypto config.
rch175b1172016-12-09 04:28:3924class QUIC_EXPORT_PRIVATE QuicServerInfo {
[email protected]662626642014-01-25 00:54:4125 public:
rtennetic79d3f52016-08-10 18:34:5626 // Enum to track failure reasons to read/load/write of QuicServerInfo to
27 // and from disk cache.
28 enum FailureReason {
29 WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0,
30 GET_BACKEND_FAILURE = 1,
31 OPEN_FAILURE = 2,
32 CREATE_OR_OPEN_FAILURE = 3,
33 PARSE_NO_DATA_FAILURE = 4,
34 PARSE_FAILURE = 5,
35 READ_FAILURE = 6,
36 READY_TO_PERSIST_FAILURE = 7,
37 PERSIST_NO_BACKEND_FAILURE = 8,
38 WRITE_FAILURE = 9,
39 NO_FAILURE = 10,
40 PARSE_DATA_DECODE_FAILURE = 11,
41 NUM_OF_FAILURES = 12,
42 };
43
Ryan Hamilton8d9ee76e2018-05-29 23:52:5244 explicit QuicServerInfo(const quic::QuicServerId& server_id);
[email protected]662626642014-01-25 00:54:4145 virtual ~QuicServerInfo();
46
rch431dd4452017-04-19 15:22:3547 // Fetches the server config from the backing store, and returns true
48 // if the server config was found.
49 virtual bool Load() = 0;
[email protected]662626642014-01-25 00:54:4150
rch431dd4452017-04-19 15:22:3551 // Persist allows for the server information to be updated for future uses.
[email protected]662626642014-01-25 00:54:4152 virtual void Persist() = 0;
53
xunjieli48e4f102017-04-11 23:06:5354 // Returns the size of dynamically allocated memory in bytes.
55 virtual size_t EstimateMemoryUsage() const = 0;
56
[email protected]662626642014-01-25 00:54:4157 struct State {
58 State();
59 ~State();
60
61 void Clear();
62
David Benjamin0a0c9c0f2019-06-21 23:00:4663 // This class matches QuicCryptoClientConfig::CachedState.
[email protected]f9ca77a2014-02-20 18:02:3064 std::string server_config; // A serialized handshake message.
65 std::string source_address_token; // An opaque proof of IP ownership.
rtenneti61de3682016-03-24 00:50:0266 std::string cert_sct; // Signed timestamp of the leaf cert.
67 std::string chlo_hash; // Hash of the CHLO message.
[email protected]f9ca77a2014-02-20 18:02:3068 std::vector<std::string> certs; // A list of certificates in leaf-first
69 // order.
70 std::string server_config_sig; // A signature of |server_config_|.
[email protected]662626642014-01-25 00:54:4171
72 private:
73 DISALLOW_COPY_AND_ASSIGN(State);
74 };
75
76 // Once the data is ready, it can be read using the following members. These
77 // members can then be updated before calling |Persist|.
78 const State& state() const;
79 State* mutable_state();
80
81 protected:
[email protected]f9ca77a2014-02-20 18:02:3082 // Parse parses pickled data and fills out the public member fields of this
83 // object. It returns true iff the parse was successful. The public member
84 // fields will be set to something sane in any case.
[email protected]662626642014-01-25 00:54:4185 bool Parse(const std::string& data);
[email protected]db1505e2014-02-26 15:23:1786 std::string Serialize();
rtennetif5e45922015-10-09 05:23:1687
[email protected]662626642014-01-25 00:54:4188 State state_;
89
rtennetif5e45922015-10-09 05:23:1690 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for
91 // which we restore the crypto_config.
Ryan Hamilton8d9ee76e2018-05-29 23:52:5292 const quic::QuicServerId server_id_;
rtennetif5e45922015-10-09 05:23:1693
[email protected]662626642014-01-25 00:54:4194 private:
95 // ParseInner is a helper function for Parse.
96 bool ParseInner(const std::string& data);
97
[email protected]db1505e2014-02-26 15:23:1798 // SerializeInner is a helper function for Serialize.
99 std::string SerializeInner() const;
100
[email protected]b99c0fc2014-04-22 07:56:52101 DISALLOW_COPY_AND_ASSIGN(QuicServerInfo);
[email protected]662626642014-01-25 00:54:41102};
103
[email protected]662626642014-01-25 00:54:41104} // namespace net
105
Ryan Hamiltona3ee93a72018-08-01 22:03:08106#endif // NET_QUIC_QUIC_SERVER_INFO_H_