Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: net/quic/crypto/strike_register_test.cc

Issue 1227353005: Cleanup changes: Rename QuicSession::MarkWriteBlocked to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/crypto/strike_register.cc ('k') | net/quic/quic_received_packet_manager_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/crypto/strike_register.h" 5 #include "net/quic/crypto/strike_register.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 // Check that the timestamp is in the current window. 227 // Check that the timestamp is in the current window.
228 if ((current_time > window_secs_ && 228 if ((current_time > window_secs_ &&
229 nonce_time < (current_time - window_secs_)) || 229 nonce_time < (current_time - window_secs_)) ||
230 nonce_time > (current_time + window_secs_)) { 230 nonce_time > (current_time + window_secs_)) {
231 return NONCE_INVALID_TIME_FAILURE; 231 return NONCE_INVALID_TIME_FAILURE;
232 } 232 }
233 233
234 pair<uint32, string> nonce = std::make_pair( 234 pair<uint32, string> nonce = std::make_pair(
235 nonce_time, string(reinterpret_cast<const char*>(nonce_bytes), 32)); 235 nonce_time, string(reinterpret_cast<const char*>(nonce_bytes), 32));
236 236
237 set<pair<uint32, string> >::const_iterator it = nonces_.find(nonce); 237 set<pair<uint32, string>>::const_iterator it = nonces_.find(nonce);
238 if (it != nonces_.end()) { 238 if (it != nonces_.end()) {
239 return NONCE_NOT_UNIQUE_FAILURE; 239 return NONCE_NOT_UNIQUE_FAILURE;
240 } 240 }
241 241
242 nonces_.insert(nonce); 242 nonces_.insert(nonce);
243 return NONCE_OK; 243 return NONCE_OK;
244 } 244 }
245 245
246 uint32 GetCurrentValidWindowSecs(const uint32 current_time_external) const { 246 uint32 GetCurrentValidWindowSecs(const uint32 current_time_external) const {
247 const uint32 current_time = ExternalTimeToInternal(current_time_external); 247 const uint32 current_time = ExternalTimeToInternal(current_time_external);
(...skipping 16 matching lines...) Expand all
264 static const uint32 kCreationTimeFromInternalEpoch = 63115200.0; 264 static const uint32 kCreationTimeFromInternalEpoch = 63115200.0;
265 uint32 internal_epoch = 0; 265 uint32 internal_epoch = 0;
266 if (creation_time_ > kCreationTimeFromInternalEpoch) { 266 if (creation_time_ > kCreationTimeFromInternalEpoch) {
267 internal_epoch = creation_time_ - kCreationTimeFromInternalEpoch; 267 internal_epoch = creation_time_ - kCreationTimeFromInternalEpoch;
268 } 268 }
269 269
270 return external_time - internal_epoch; 270 return external_time - internal_epoch;
271 } 271 }
272 272
273 void DropOldestEntry() { 273 void DropOldestEntry() {
274 set<pair<uint32, string> >::iterator oldest = nonces_.begin(); 274 set<pair<uint32, string>>::iterator oldest = nonces_.begin();
275 horizon_ = oldest->first + 1; 275 horizon_ = oldest->first + 1;
276 nonces_.erase(oldest); 276 nonces_.erase(oldest);
277 } 277 }
278 278
279 const unsigned max_entries_; 279 const unsigned max_entries_;
280 const unsigned window_secs_; 280 const unsigned window_secs_;
281 const uint32 creation_time_; 281 const uint32 creation_time_;
282 uint8 orbit_[8]; 282 uint8 orbit_[8];
283 uint32 horizon_; 283 uint32 horizon_;
284 284
285 set<pair<uint32, string> > nonces_; 285 set<pair<uint32, string>> nonces_;
286 }; 286 };
287 287
288 class StrikeRegisterStressTest : public ::testing::Test { 288 class StrikeRegisterStressTest : public ::testing::Test {
289 }; 289 };
290 290
291 TEST_F(StrikeRegisterStressTest, InOrderInsertion) { 291 TEST_F(StrikeRegisterStressTest, InOrderInsertion) {
292 // Fixed seed gives reproducibility for this test. 292 // Fixed seed gives reproducibility for this test.
293 srand(42); 293 srand(42);
294 294
295 unsigned max_entries = 64; 295 unsigned max_entries = 64;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 399 }
400 400
401 if (i != kMaxIterations) { 401 if (i != kMaxIterations) {
402 FAIL() << "Failed after " << i << " iterations"; 402 FAIL() << "Failed after " << i << " iterations";
403 } 403 }
404 } 404 }
405 405
406 } // namespace 406 } // namespace
407 407
408 } // namespace net 408 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/strike_register.cc ('k') | net/quic/quic_received_packet_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698