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 QuicReferenceCountedPointer<QuicCryptoServerConfig::Config> |
24 QuicCryptoServerConfigPeer::GetPrimaryConfig() { | 24 QuicCryptoServerConfigPeer::GetPrimaryConfig() { |
25 QuicReaderMutexLock locked(&server_config_->configs_lock_); | 25 QuicReaderMutexLock locked(&server_config_->configs_lock_); |
26 return scoped_refptr<QuicCryptoServerConfig::Config>( | 26 return QuicReferenceCountedPointer<QuicCryptoServerConfig::Config>( |
27 server_config_->primary_config_); | 27 server_config_->primary_config_); |
28 } | 28 } |
29 | 29 |
30 scoped_refptr<QuicCryptoServerConfig::Config> | 30 QuicReferenceCountedPointer<QuicCryptoServerConfig::Config> |
31 QuicCryptoServerConfigPeer::GetConfig(string config_id) { | 31 QuicCryptoServerConfigPeer::GetConfig(string config_id) { |
32 QuicReaderMutexLock 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 QuicReferenceCountedPointer<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(); |
43 } | 43 } |
44 | 44 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 QuicReaderMutexLock 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< |
128 scoped_refptr<QuicCryptoServerConfig::Config>>& i : | 128 const ServerConfigID, |
| 129 QuicReferenceCountedPointer<QuicCryptoServerConfig::Config>>& i : |
129 server_config_->configs_) { | 130 server_config_->configs_) { |
130 bool found = false; | 131 bool found = false; |
131 for (std::pair<ServerConfigID, bool>& j : expected) { | 132 for (std::pair<ServerConfigID, bool>& j : expected) { |
132 if (i.first == j.first && i.second->is_primary == j.second) { | 133 if (i.first == j.first && i.second->is_primary == j.second) { |
133 found = true; | 134 found = true; |
134 j.first.clear(); | 135 j.first.clear(); |
135 break; | 136 break; |
136 } | 137 } |
137 } | 138 } |
138 | 139 |
139 ASSERT_TRUE(found) << "Failed to find match for " << i.first | 140 ASSERT_TRUE(found) << "Failed to find match for " << i.first |
140 << " in configs:\n" | 141 << " in configs:\n" |
141 << ConfigsDebug(); | 142 << ConfigsDebug(); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 // ConfigsDebug returns a string that contains debugging information about | 146 // ConfigsDebug returns a string that contains debugging information about |
146 // the set of Configs loaded in |server_config_| and their status. | 147 // the set of Configs loaded in |server_config_| and their status. |
147 string QuicCryptoServerConfigPeer::ConfigsDebug() { | 148 string QuicCryptoServerConfigPeer::ConfigsDebug() { |
148 if (server_config_->configs_.empty()) { | 149 if (server_config_->configs_.empty()) { |
149 return "No Configs in QuicCryptoServerConfig"; | 150 return "No Configs in QuicCryptoServerConfig"; |
150 } | 151 } |
151 | 152 |
152 string s; | 153 string s; |
153 | 154 |
154 for (const auto& i : server_config_->configs_) { | 155 for (const auto& i : server_config_->configs_) { |
155 const scoped_refptr<QuicCryptoServerConfig::Config> config = i.second; | 156 const QuicReferenceCountedPointer<QuicCryptoServerConfig::Config> config = |
| 157 i.second; |
156 if (config->is_primary) { | 158 if (config->is_primary) { |
157 s += "(primary) "; | 159 s += "(primary) "; |
158 } else { | 160 } else { |
159 s += " "; | 161 s += " "; |
160 } | 162 } |
161 s += config->id; | 163 s += config->id; |
162 s += "\n"; | 164 s += "\n"; |
163 } | 165 } |
164 | 166 |
165 return s; | 167 return s; |
166 } | 168 } |
167 | 169 |
168 void QuicCryptoServerConfigPeer::SelectNewPrimaryConfig(int seconds) { | 170 void QuicCryptoServerConfigPeer::SelectNewPrimaryConfig(int seconds) { |
169 QuicWriterMutexLock locked(&server_config_->configs_lock_); | 171 QuicWriterMutexLock locked(&server_config_->configs_lock_); |
170 server_config_->SelectNewPrimaryConfig( | 172 server_config_->SelectNewPrimaryConfig( |
171 QuicWallTime::FromUNIXSeconds(seconds)); | 173 QuicWallTime::FromUNIXSeconds(seconds)); |
172 } | 174 } |
173 | 175 |
174 string QuicCryptoServerConfigPeer::CompressChain( | 176 string QuicCryptoServerConfigPeer::CompressChain( |
175 QuicCompressedCertsCache* compressed_certs_cache, | 177 QuicCompressedCertsCache* compressed_certs_cache, |
176 const scoped_refptr<ProofSource::Chain>& chain, | 178 const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
177 const string& client_common_set_hashes, | 179 const string& client_common_set_hashes, |
178 const string& client_cached_cert_hashes, | 180 const string& client_cached_cert_hashes, |
179 const CommonCertSets* common_sets) { | 181 const CommonCertSets* common_sets) { |
180 return QuicCryptoServerConfig::CompressChain( | 182 return QuicCryptoServerConfig::CompressChain( |
181 compressed_certs_cache, chain, client_common_set_hashes, | 183 compressed_certs_cache, chain, client_common_set_hashes, |
182 client_cached_cert_hashes, common_sets); | 184 client_cached_cert_hashes, common_sets); |
183 } | 185 } |
184 | 186 |
185 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() { | 187 uint32_t QuicCryptoServerConfigPeer::source_address_token_future_secs() { |
186 return server_config_->source_address_token_future_secs_; | 188 return server_config_->source_address_token_future_secs_; |
187 } | 189 } |
188 | 190 |
189 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() { | 191 uint32_t QuicCryptoServerConfigPeer::source_address_token_lifetime_secs() { |
190 return server_config_->source_address_token_lifetime_secs_; | 192 return server_config_->source_address_token_lifetime_secs_; |
191 } | 193 } |
192 | 194 |
193 } // namespace test | 195 } // namespace test |
194 } // namespace net | 196 } // namespace net |
OLD | NEW |