| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_CRYPTO_QUIC_COMPRESSED_CERTS_CACHE_H_ | |
| 6 #define NET_QUIC_CRYPTO_QUIC_COMPRESSED_CERTS_CACHE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/containers/mru_cache.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "net/quic/crypto/proof_source.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 // QuicCompressedCertsCache is a cache to track most recently compressed certs. | |
| 18 class NET_EXPORT_PRIVATE QuicCompressedCertsCache { | |
| 19 public: | |
| 20 explicit QuicCompressedCertsCache(int64_t max_num_certs); | |
| 21 ~QuicCompressedCertsCache(); | |
| 22 | |
| 23 // Returns the pointer to the cached compressed cert if | |
| 24 // |chain, client_common_set_hashes, client_cached_cert_hashes| hits cache. | |
| 25 // Otherwise, return nullptr. | |
| 26 // Returned pointer might become invalid on the next call to Insert(). | |
| 27 const std::string* GetCompressedCert( | |
| 28 const scoped_refptr<ProofSource::Chain>& chain, | |
| 29 const std::string& client_common_set_hashes, | |
| 30 const std::string& client_cached_cert_hashes); | |
| 31 | |
| 32 // Inserts the specified | |
| 33 // |chain, client_common_set_hashes, | |
| 34 // client_cached_cert_hashes, compressed_cert| tuple to the cache. | |
| 35 // If the insertion causes the cache to become overfull, entries will | |
| 36 // be deleted in an LRU order to make room. | |
| 37 void Insert(const scoped_refptr<ProofSource::Chain>& chain, | |
| 38 const std::string& client_common_set_hashes, | |
| 39 const std::string& client_cached_cert_hashes, | |
| 40 const std::string& compressed_cert); | |
| 41 | |
| 42 // Returns max number of cache entries the cache can carry. | |
| 43 size_t MaxSize(); | |
| 44 | |
| 45 // Returns current number of cache entries in the cache. | |
| 46 size_t Size(); | |
| 47 | |
| 48 // Default size of the QuicCompressedCertsCache per server side investigation. | |
| 49 static const size_t kQuicCompressedCertsCacheSize = 225; | |
| 50 | |
| 51 private: | |
| 52 // A wrapper of the tuple: | |
| 53 // |chain, client_common_set_hashes, client_cached_cert_hashes| | |
| 54 // to identify uncompressed representation of certs. | |
| 55 struct UncompressedCerts { | |
| 56 UncompressedCerts(); | |
| 57 UncompressedCerts(const scoped_refptr<ProofSource::Chain>& chain, | |
| 58 const std::string* client_common_set_hashes, | |
| 59 const std::string* client_cached_cert_hashes); | |
| 60 ~UncompressedCerts(); | |
| 61 | |
| 62 const scoped_refptr<ProofSource::Chain> chain; | |
| 63 const std::string* client_common_set_hashes; | |
| 64 const std::string* client_cached_cert_hashes; | |
| 65 }; | |
| 66 | |
| 67 // Certs stored by QuicCompressedCertsCache where uncompressed certs data is | |
| 68 // used to identify the uncompressed representation of certs and | |
| 69 // |compressed_cert| is the cached compressed representation. | |
| 70 class CachedCerts { | |
| 71 public: | |
| 72 CachedCerts(); | |
| 73 CachedCerts(const UncompressedCerts& uncompressed_certs, | |
| 74 const std::string& compressed_cert); | |
| 75 CachedCerts(const CachedCerts& other); | |
| 76 | |
| 77 ~CachedCerts(); | |
| 78 | |
| 79 // Returns true if the |uncompressed_certs| matches uncompressed | |
| 80 // representation of this cert. | |
| 81 bool MatchesUncompressedCerts( | |
| 82 const UncompressedCerts& uncompressed_certs) const; | |
| 83 | |
| 84 const std::string* compressed_cert() const; | |
| 85 | |
| 86 private: | |
| 87 // Uncompressed certs data. | |
| 88 scoped_refptr<ProofSource::Chain> chain_; | |
| 89 const std::string client_common_set_hashes_; | |
| 90 const std::string client_cached_cert_hashes_; | |
| 91 | |
| 92 // Cached compressed representation derived from uncompressed certs. | |
| 93 const std::string compressed_cert_; | |
| 94 }; | |
| 95 | |
| 96 // Computes a uint64_t hash for |uncompressed_certs|. | |
| 97 uint64_t ComputeUncompressedCertsHash( | |
| 98 const UncompressedCerts& uncompressed_certs); | |
| 99 | |
| 100 // Key is a unit64_t hash for UncompressedCerts. Stored associated value is | |
| 101 // CachedCerts which has both original uncompressed certs data and the | |
| 102 // compressed representation of the certs. | |
| 103 base::MRUCache<uint64_t, CachedCerts> certs_cache_; | |
| 104 }; | |
| 105 | |
| 106 } // namespace net | |
| 107 | |
| 108 #endif // NET_QUIC_CRYPTO_QUIC_COMPRESSED_CERTS_CACHE_H_ | |
| OLD | NEW |