OLD | NEW |
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 "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 using std::pair; | 9 using std::pair; |
10 using std::set; | 10 using std::set; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // <24 bits> right child | 53 // <24 bits> right child |
54 // <8 bits> other-bits | 54 // <8 bits> other-bits |
55 uint32 data_[2]; | 55 uint32 data_[2]; |
56 }; | 56 }; |
57 | 57 |
58 // kCreationTimeFromInternalEpoch contains the number of seconds between the | 58 // kCreationTimeFromInternalEpoch contains the number of seconds between the |
59 // start of the internal epoch and the creation time. This allows us | 59 // start of the internal epoch and the creation time. This allows us |
60 // to consider times that are before the creation time. | 60 // to consider times that are before the creation time. |
61 static const uint32 kCreationTimeFromInternalEpoch = 63115200.0; // 2 years. | 61 static const uint32 kCreationTimeFromInternalEpoch = 63115200.0; // 2 years. |
62 | 62 |
| 63 void StrikeRegister::ValidateStrikeRegisterConfig(unsigned max_entries) { |
| 64 // We only have 23 bits of index available. |
| 65 CHECK_LT(max_entries, 1u << 23); |
| 66 CHECK_GT(max_entries, 1u); // There must be at least two entries. |
| 67 CHECK_EQ(sizeof(InternalNode), 8u); // in case of compiler changes. |
| 68 } |
| 69 |
63 StrikeRegister::StrikeRegister(unsigned max_entries, | 70 StrikeRegister::StrikeRegister(unsigned max_entries, |
64 uint32 current_time, | 71 uint32 current_time, |
65 uint32 window_secs, | 72 uint32 window_secs, |
66 const uint8 orbit[8], | 73 const uint8 orbit[8], |
67 StartupType startup) | 74 StartupType startup) |
68 : max_entries_(max_entries), | 75 : max_entries_(max_entries), |
69 window_secs_(window_secs), | 76 window_secs_(window_secs), |
70 internal_epoch_(current_time > kCreationTimeFromInternalEpoch | 77 internal_epoch_(current_time > kCreationTimeFromInternalEpoch |
71 ? current_time - kCreationTimeFromInternalEpoch | 78 ? current_time - kCreationTimeFromInternalEpoch |
72 : 0), | 79 : 0), |
73 // The horizon is initially set |window_secs| into the future because, if | 80 // The horizon is initially set |window_secs| into the future because, if |
74 // we just crashed, then we may have accepted nonces in the span | 81 // we just crashed, then we may have accepted nonces in the span |
75 // [current_time...current_time+window_secs) and so we conservatively | 82 // [current_time...current_time+window_secs) and so we conservatively |
76 // reject the whole timespan unless |startup| tells us otherwise. | 83 // reject the whole timespan unless |startup| tells us otherwise. |
77 horizon_(ExternalTimeToInternal(current_time) + window_secs), | 84 horizon_(ExternalTimeToInternal(current_time) + window_secs), |
78 horizon_valid_(startup == DENY_REQUESTS_AT_STARTUP) { | 85 horizon_valid_(startup == DENY_REQUESTS_AT_STARTUP) { |
79 memcpy(orbit_, orbit, sizeof(orbit_)); | 86 memcpy(orbit_, orbit, sizeof(orbit_)); |
80 | 87 |
81 // We only have 23 bits of index available. | 88 ValidateStrikeRegisterConfig(max_entries); |
82 CHECK_LT(max_entries, 1u << 23); | |
83 CHECK_GT(max_entries, 1u); // There must be at least two entries. | |
84 CHECK_EQ(sizeof(InternalNode), 8u); // in case of compiler changes. | |
85 internal_nodes_ = new InternalNode[max_entries]; | 89 internal_nodes_ = new InternalNode[max_entries]; |
86 external_nodes_.reset(new uint8[kExternalNodeSize * max_entries]); | 90 external_nodes_.reset(new uint8[kExternalNodeSize * max_entries]); |
87 | 91 |
88 Reset(); | 92 Reset(); |
89 } | 93 } |
90 | 94 |
91 StrikeRegister::~StrikeRegister() { delete[] internal_nodes_; } | 95 StrikeRegister::~StrikeRegister() { delete[] internal_nodes_; } |
92 | 96 |
93 void StrikeRegister::Reset() { | 97 void StrikeRegister::Reset() { |
94 // Thread a free list through all of the internal nodes. | 98 // Thread a free list through all of the internal nodes. |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 CHECK_EQ(free_internal_nodes.count(inter), 0u); | 455 CHECK_EQ(free_internal_nodes.count(inter), 0u); |
452 CHECK_EQ(used_internal_nodes->count(inter), 0u); | 456 CHECK_EQ(used_internal_nodes->count(inter), 0u); |
453 used_internal_nodes->insert(inter); | 457 used_internal_nodes->insert(inter); |
454 ValidateTree(inter, bit, bits, free_internal_nodes, free_external_nodes, | 458 ValidateTree(inter, bit, bits, free_internal_nodes, free_external_nodes, |
455 used_internal_nodes, used_external_nodes); | 459 used_internal_nodes, used_external_nodes); |
456 } | 460 } |
457 } | 461 } |
458 } | 462 } |
459 | 463 |
460 } // namespace net | 464 } // namespace net |
OLD | NEW |