| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/core/crypto/quic_compressed_certs_cache.h" | 5 #include "net/quic/core/crypto/quic_compressed_certs_cache.h" |
| 6 | 6 |
| 7 using std::string; | 7 using std::string; |
| 8 | 8 |
| 9 namespace net { | 9 namespace net { |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 const string* QuicCompressedCertsCache::GetCompressedCert( | 70 const string* QuicCompressedCertsCache::GetCompressedCert( |
| 71 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, | 71 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
| 72 const string& client_common_set_hashes, | 72 const string& client_common_set_hashes, |
| 73 const string& client_cached_cert_hashes) { | 73 const string& client_cached_cert_hashes) { |
| 74 UncompressedCerts uncompressed_certs(chain, &client_common_set_hashes, | 74 UncompressedCerts uncompressed_certs(chain, &client_common_set_hashes, |
| 75 &client_cached_cert_hashes); | 75 &client_cached_cert_hashes); |
| 76 | 76 |
| 77 uint64_t key = ComputeUncompressedCertsHash(uncompressed_certs); | 77 uint64_t key = ComputeUncompressedCertsHash(uncompressed_certs); |
| 78 | 78 |
| 79 auto cached_it = certs_cache_.Get(key); | 79 CachedCerts* cached_value = certs_cache_.Lookup(key); |
| 80 | 80 if (cached_value != nullptr && |
| 81 if (cached_it != certs_cache_.end()) { | 81 cached_value->MatchesUncompressedCerts(uncompressed_certs)) { |
| 82 const CachedCerts& cached_value = cached_it->second; | 82 return cached_value->compressed_cert(); |
| 83 if (cached_value.MatchesUncompressedCerts(uncompressed_certs)) { | |
| 84 return cached_value.compressed_cert(); | |
| 85 } | |
| 86 } | 83 } |
| 87 return nullptr; | 84 return nullptr; |
| 88 } | 85 } |
| 89 | 86 |
| 90 void QuicCompressedCertsCache::Insert( | 87 void QuicCompressedCertsCache::Insert( |
| 91 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, | 88 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
| 92 const string& client_common_set_hashes, | 89 const string& client_common_set_hashes, |
| 93 const string& client_cached_cert_hashes, | 90 const string& client_cached_cert_hashes, |
| 94 const string& compressed_cert) { | 91 const string& compressed_cert) { |
| 95 UncompressedCerts uncompressed_certs(chain, &client_common_set_hashes, | 92 UncompressedCerts uncompressed_certs(chain, &client_common_set_hashes, |
| 96 &client_cached_cert_hashes); | 93 &client_cached_cert_hashes); |
| 97 | 94 |
| 98 uint64_t key = ComputeUncompressedCertsHash(uncompressed_certs); | 95 uint64_t key = ComputeUncompressedCertsHash(uncompressed_certs); |
| 99 | 96 |
| 100 // Insert one unit to the cache. | 97 // Insert one unit to the cache. |
| 101 certs_cache_.Put(key, CachedCerts(uncompressed_certs, compressed_cert)); | 98 std::unique_ptr<CachedCerts> cached_certs( |
| 99 new CachedCerts(uncompressed_certs, compressed_cert)); |
| 100 certs_cache_.Insert(key, std::move(cached_certs)); |
| 102 } | 101 } |
| 103 | 102 |
| 104 size_t QuicCompressedCertsCache::MaxSize() { | 103 size_t QuicCompressedCertsCache::MaxSize() { |
| 105 return certs_cache_.max_size(); | 104 return certs_cache_.MaxSize(); |
| 106 } | 105 } |
| 107 | 106 |
| 108 size_t QuicCompressedCertsCache::Size() { | 107 size_t QuicCompressedCertsCache::Size() { |
| 109 return certs_cache_.size(); | 108 return certs_cache_.Size(); |
| 110 } | 109 } |
| 111 | 110 |
| 112 uint64_t QuicCompressedCertsCache::ComputeUncompressedCertsHash( | 111 uint64_t QuicCompressedCertsCache::ComputeUncompressedCertsHash( |
| 113 const UncompressedCerts& uncompressed_certs) { | 112 const UncompressedCerts& uncompressed_certs) { |
| 114 uint64_t hash = | 113 uint64_t hash = |
| 115 std::hash<string>()(*uncompressed_certs.client_common_set_hashes); | 114 std::hash<string>()(*uncompressed_certs.client_common_set_hashes); |
| 116 uint64_t h = | 115 uint64_t h = |
| 117 std::hash<string>()(*uncompressed_certs.client_cached_cert_hashes); | 116 std::hash<string>()(*uncompressed_certs.client_cached_cert_hashes); |
| 118 hash_combine(&hash, h); | 117 hash_combine(&hash, h); |
| 119 | 118 |
| 120 hash_combine(&hash, | 119 hash_combine(&hash, |
| 121 reinterpret_cast<uint64_t>(uncompressed_certs.chain.get())); | 120 reinterpret_cast<uint64_t>(uncompressed_certs.chain.get())); |
| 122 return hash; | 121 return hash; |
| 123 } | 122 } |
| 124 | 123 |
| 125 } // namespace net | 124 } // namespace net |
| OLD | NEW |