| 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/test_tools/quic_crypto_server_config_peer.h" | 5 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 6 | 6 |
| 7 #include <cstdarg> | 7 #include <cstdarg> |
| 8 | 8 |
| 9 #include "net/quic/test_tools/mock_clock.h" | 9 #include "net/quic/test_tools/mock_clock.h" |
| 10 #include "net/quic/test_tools/mock_random.h" | 10 #include "net/quic/test_tools/mock_random.h" |
| 11 #include "net/quic/test_tools/quic_test_utils.h" | 11 #include "net/quic/test_tools/quic_test_utils.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 using std::string; | 14 using std::string; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 namespace test { | 17 namespace test { |
| 18 | 18 |
| 19 ProofSource* QuicCryptoServerConfigPeer::GetProofSource() { | 19 ProofSource* QuicCryptoServerConfigPeer::GetProofSource() { |
| 20 return server_config_->proof_source_.get(); | 20 return server_config_->proof_source_.get(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 scoped_refptr<QuicCryptoServerConfig::Config> | 23 scoped_refptr<QuicCryptoServerConfig::Config> |
| 24 QuicCryptoServerConfigPeer::GetPrimaryConfig() { | 24 QuicCryptoServerConfigPeer::GetPrimaryConfig() { |
| 25 base::AutoLock locked(server_config_->configs_lock_); | 25 QuicReaderMutexLock locked(&server_config_->configs_lock_); |
| 26 return scoped_refptr<QuicCryptoServerConfig::Config>( | 26 return scoped_refptr<QuicCryptoServerConfig::Config>( |
| 27 server_config_->primary_config_); | 27 server_config_->primary_config_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 scoped_refptr<QuicCryptoServerConfig::Config> | 30 scoped_refptr<QuicCryptoServerConfig::Config> |
| 31 QuicCryptoServerConfigPeer::GetConfig(string config_id) { | 31 QuicCryptoServerConfigPeer::GetConfig(string config_id) { |
| 32 base::AutoLock locked(server_config_->configs_lock_); | 32 QuicReaderMutexLock locked(&server_config_->configs_lock_); |
| 33 if (config_id == "<primary>") { | 33 if (config_id == "<primary>") { |
| 34 return scoped_refptr<QuicCryptoServerConfig::Config>( | 34 return scoped_refptr<QuicCryptoServerConfig::Config>( |
| 35 server_config_->primary_config_); | 35 server_config_->primary_config_); |
| 36 } else { | 36 } else { |
| 37 return server_config_->GetConfigWithScid(config_id); | 37 return server_config_->GetConfigWithScid(config_id); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 ProofSource* QuicCryptoServerConfigPeer::GetProofSource() const { | 41 ProofSource* QuicCryptoServerConfigPeer::GetProofSource() const { |
| 42 return server_config_->proof_source_.get(); | 42 return server_config_->proof_source_.get(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 // varargs will promote the value to an int so we have to read that from | 115 // varargs will promote the value to an int so we have to read that from |
| 116 // the stack and cast down. | 116 // the stack and cast down. |
| 117 const bool is_primary = static_cast<bool>(va_arg(ap, int)); | 117 const bool is_primary = static_cast<bool>(va_arg(ap, int)); |
| 118 expected.push_back(std::make_pair(server_config_id, is_primary)); | 118 expected.push_back(std::make_pair(server_config_id, is_primary)); |
| 119 } | 119 } |
| 120 | 120 |
| 121 va_end(ap); | 121 va_end(ap); |
| 122 | 122 |
| 123 base::AutoLock locked(server_config_->configs_lock_); | 123 QuicReaderMutexLock locked(&server_config_->configs_lock_); |
| 124 | 124 |
| 125 ASSERT_EQ(expected.size(), server_config_->configs_.size()) << ConfigsDebug(); | 125 ASSERT_EQ(expected.size(), server_config_->configs_.size()) << ConfigsDebug(); |
| 126 | 126 |
| 127 for (const std::pair<const ServerConfigID, | 127 for (const std::pair<const ServerConfigID, |
| 128 scoped_refptr<QuicCryptoServerConfig::Config>>& i : | 128 scoped_refptr<QuicCryptoServerConfig::Config>>& i : |
| 129 server_config_->configs_) { | 129 server_config_->configs_) { |
| 130 bool found = false; | 130 bool found = false; |
| 131 for (std::pair<ServerConfigID, bool>& j : expected) { | 131 for (std::pair<ServerConfigID, bool>& j : expected) { |
| 132 if (i.first == j.first && i.second->is_primary == j.second) { | 132 if (i.first == j.first && i.second->is_primary == j.second) { |
| 133 found = true; | 133 found = true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 159 s += " "; | 159 s += " "; |
| 160 } | 160 } |
| 161 s += config->id; | 161 s += config->id; |
| 162 s += "\n"; | 162 s += "\n"; |
| 163 } | 163 } |
| 164 | 164 |
| 165 return s; | 165 return s; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void QuicCryptoServerConfigPeer::SelectNewPrimaryConfig(int seconds) { | 168 void QuicCryptoServerConfigPeer::SelectNewPrimaryConfig(int seconds) { |
| 169 base::AutoLock locked(server_config_->configs_lock_); | 169 QuicWriterMutexLock locked(&server_config_->configs_lock_); |
| 170 server_config_->SelectNewPrimaryConfig( | 170 server_config_->SelectNewPrimaryConfig( |
| 171 QuicWallTime::FromUNIXSeconds(seconds)); | 171 QuicWallTime::FromUNIXSeconds(seconds)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 string QuicCryptoServerConfigPeer::CompressChain( | 174 string QuicCryptoServerConfigPeer::CompressChain( |
| 175 QuicCompressedCertsCache* compressed_certs_cache, | 175 QuicCompressedCertsCache* compressed_certs_cache, |
| 176 const scoped_refptr<ProofSource::Chain>& chain, | 176 const scoped_refptr<ProofSource::Chain>& chain, |
| 177 const string& client_common_set_hashes, | 177 const string& client_common_set_hashes, |
| 178 const string& client_cached_cert_hashes, | 178 const string& client_cached_cert_hashes, |
| 179 const CommonCertSets* common_sets) { | 179 const CommonCertSets* common_sets) { |
| 180 return QuicCryptoServerConfig::CompressChain( | 180 return QuicCryptoServerConfig::CompressChain( |
| 181 compressed_certs_cache, chain, client_common_set_hashes, | 181 compressed_certs_cache, chain, client_common_set_hashes, |
| 182 client_cached_cert_hashes, common_sets); | 182 client_cached_cert_hashes, common_sets); |
| 183 } | 183 } |
| 184 | 184 |
| 185 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() { | 185 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() { |
| 186 return server_config_->source_address_token_future_secs_; | 186 return server_config_->source_address_token_future_secs_; |
| 187 } | 187 } |
| 188 | 188 |
| 189 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() { | 189 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() { |
| 190 return server_config_->source_address_token_lifetime_secs_; | 190 return server_config_->source_address_token_lifetime_secs_; |
| 191 } | 191 } |
| 192 | 192 |
| 193 } // namespace test | 193 } // namespace test |
| 194 } // namespace net | 194 } // namespace net |
| OLD | NEW |