| OLD | NEW |
| (Empty) |
| 1 // 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 | |
| 5 #ifndef NET_QUIC_CORE_CRYPTO_QUIC_SERVER_INFO_H_ | |
| 6 #define NET_QUIC_CORE_CRYPTO_QUIC_SERVER_INFO_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/time/time.h" | |
| 14 #include "net/base/completion_callback.h" | |
| 15 #include "net/quic/core/quic_server_id.h" | |
| 16 #include "net/quic/platform/api/quic_export.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 // 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. | |
| 24 class QUIC_EXPORT_PRIVATE QuicServerInfo { | |
| 25 public: | |
| 26 // Enum to track number of times data read/parse/write API calls of | |
| 27 // QuicServerInfo to and from disk cache is called. | |
| 28 enum QuicServerInfoAPICall { | |
| 29 QUIC_SERVER_INFO_START = 0, | |
| 30 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY = 1, | |
| 31 QUIC_SERVER_INFO_PARSE = 2, | |
| 32 QUIC_SERVER_INFO_WAIT_FOR_DATA_READY_CANCEL = 3, | |
| 33 QUIC_SERVER_INFO_READY_TO_PERSIST = 4, | |
| 34 QUIC_SERVER_INFO_PERSIST = 5, | |
| 35 QUIC_SERVER_INFO_EXTERNAL_CACHE_HIT = 6, | |
| 36 QUIC_SERVER_INFO_RESET_WAIT_FOR_DATA_READY = 7, | |
| 37 QUIC_SERVER_INFO_NUM_OF_API_CALLS = 8, | |
| 38 }; | |
| 39 | |
| 40 // Enum to track failure reasons to read/load/write of QuicServerInfo to | |
| 41 // and from disk cache. | |
| 42 enum FailureReason { | |
| 43 WAIT_FOR_DATA_READY_INVALID_ARGUMENT_FAILURE = 0, | |
| 44 GET_BACKEND_FAILURE = 1, | |
| 45 OPEN_FAILURE = 2, | |
| 46 CREATE_OR_OPEN_FAILURE = 3, | |
| 47 PARSE_NO_DATA_FAILURE = 4, | |
| 48 PARSE_FAILURE = 5, | |
| 49 READ_FAILURE = 6, | |
| 50 READY_TO_PERSIST_FAILURE = 7, | |
| 51 PERSIST_NO_BACKEND_FAILURE = 8, | |
| 52 WRITE_FAILURE = 9, | |
| 53 NO_FAILURE = 10, | |
| 54 PARSE_DATA_DECODE_FAILURE = 11, | |
| 55 NUM_OF_FAILURES = 12, | |
| 56 }; | |
| 57 | |
| 58 explicit QuicServerInfo(const QuicServerId& server_id); | |
| 59 virtual ~QuicServerInfo(); | |
| 60 | |
| 61 // Start will commence the lookup. This must be called before any other | |
| 62 // methods. By opportunistically calling this early, it may be possible to | |
| 63 // overlap this object's lookup and reduce latency. | |
| 64 virtual void Start() = 0; | |
| 65 | |
| 66 // WaitForDataReady returns OK if the fetch of the requested data has | |
| 67 // completed. Otherwise it returns ERR_IO_PENDING and will call |callback| on | |
| 68 // the current thread when ready. | |
| 69 // | |
| 70 // Only a single callback can be outstanding at a given time and, in the | |
| 71 // event that WaitForDataReady returns OK, it's the caller's responsibility | |
| 72 // to delete |callback|. | |
| 73 // | |
| 74 // |callback| may be NULL, in which case ERR_IO_PENDING may still be returned | |
| 75 // but, obviously, a callback will never be made. | |
| 76 virtual int WaitForDataReady(const CompletionCallback& callback) = 0; | |
| 77 | |
| 78 // Reset's WaitForDataReady callback. This method shouldn't have any side | |
| 79 // effects (could be called even if HttpCache doesn't exist). | |
| 80 virtual void ResetWaitForDataReadyCallback() = 0; | |
| 81 | |
| 82 // Cancel's WaitForDataReady callback. |callback| passed in WaitForDataReady | |
| 83 // will not be called. | |
| 84 virtual void CancelWaitForDataReadyCallback() = 0; | |
| 85 | |
| 86 // Returns true if data is loaded from disk cache and ready (WaitForDataReady | |
| 87 // doesn't have a pending callback). | |
| 88 virtual bool IsDataReady() = 0; | |
| 89 | |
| 90 // Returns true if the object is ready to persist data, in other words, if | |
| 91 // data is loaded from disk cache and ready and there are no pending writes. | |
| 92 virtual bool IsReadyToPersist() = 0; | |
| 93 | |
| 94 // Persist allows for the server information to be updated for future users. | |
| 95 // This is a fire and forget operation: the caller may drop its reference | |
| 96 // from this object and the store operation will still complete. This can | |
| 97 // only be called once WaitForDataReady has returned OK or called its | |
| 98 // callback. | |
| 99 virtual void Persist() = 0; | |
| 100 | |
| 101 // Called whenever an external cache reuses quic server config. | |
| 102 virtual void OnExternalCacheHit() = 0; | |
| 103 | |
| 104 struct State { | |
| 105 State(); | |
| 106 ~State(); | |
| 107 | |
| 108 void Clear(); | |
| 109 | |
| 110 // This class matches QuicClientCryptoConfig::CachedState. | |
| 111 std::string server_config; // A serialized handshake message. | |
| 112 std::string source_address_token; // An opaque proof of IP ownership. | |
| 113 std::string cert_sct; // Signed timestamp of the leaf cert. | |
| 114 std::string chlo_hash; // Hash of the CHLO message. | |
| 115 std::vector<std::string> certs; // A list of certificates in leaf-first | |
| 116 // order. | |
| 117 std::string server_config_sig; // A signature of |server_config_|. | |
| 118 | |
| 119 private: | |
| 120 DISALLOW_COPY_AND_ASSIGN(State); | |
| 121 }; | |
| 122 | |
| 123 // Once the data is ready, it can be read using the following members. These | |
| 124 // members can then be updated before calling |Persist|. | |
| 125 const State& state() const; | |
| 126 State* mutable_state(); | |
| 127 | |
| 128 base::TimeTicks wait_for_data_start_time() const { | |
| 129 return wait_for_data_start_time_; | |
| 130 } | |
| 131 | |
| 132 base::TimeTicks wait_for_data_end_time() const { | |
| 133 return wait_for_data_end_time_; | |
| 134 } | |
| 135 | |
| 136 protected: | |
| 137 // Parse parses pickled data and fills out the public member fields of this | |
| 138 // object. It returns true iff the parse was successful. The public member | |
| 139 // fields will be set to something sane in any case. | |
| 140 bool Parse(const std::string& data); | |
| 141 std::string Serialize(); | |
| 142 | |
| 143 State state_; | |
| 144 | |
| 145 // Time when WaitForDataReady was called and when it has finished. | |
| 146 base::TimeTicks wait_for_data_start_time_; | |
| 147 base::TimeTicks wait_for_data_end_time_; | |
| 148 | |
| 149 // This is the QUIC server (hostname, port, is_https, privacy_mode) tuple for | |
| 150 // which we restore the crypto_config. | |
| 151 const QuicServerId server_id_; | |
| 152 | |
| 153 private: | |
| 154 // ParseInner is a helper function for Parse. | |
| 155 bool ParseInner(const std::string& data); | |
| 156 | |
| 157 // SerializeInner is a helper function for Serialize. | |
| 158 std::string SerializeInner() const; | |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(QuicServerInfo); | |
| 161 }; | |
| 162 | |
| 163 class QUIC_EXPORT_PRIVATE QuicServerInfoFactory { | |
| 164 public: | |
| 165 QuicServerInfoFactory() {} | |
| 166 virtual ~QuicServerInfoFactory(); | |
| 167 | |
| 168 // GetForServer returns a fresh, allocated QuicServerInfo for the given | |
| 169 // |server_id| or NULL on failure. | |
| 170 virtual QuicServerInfo* GetForServer(const QuicServerId& server_id) = 0; | |
| 171 | |
| 172 private: | |
| 173 DISALLOW_COPY_AND_ASSIGN(QuicServerInfoFactory); | |
| 174 }; | |
| 175 | |
| 176 } // namespace net | |
| 177 | |
| 178 #endif // NET_QUIC_CORE_CRYPTO_QUIC_SERVER_INFO_H_ | |
| OLD | NEW |