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 #ifndef NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ | 5 #ifndef NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ |
6 #define NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ | 6 #define NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // d) already in the set of observed nonces | 109 // d) already in the set of observed nonces |
110 // and returns false if any of these are true. It is also free to return | 110 // and returns false if any of these are true. It is also free to return |
111 // false for other reasons as it's always safe to reject an nonce. | 111 // false for other reasons as it's always safe to reject an nonce. |
112 // | 112 // |
113 // nonces are: | 113 // nonces are: |
114 // 4 bytes of timestamp (UNIX epoch seconds) | 114 // 4 bytes of timestamp (UNIX epoch seconds) |
115 // 8 bytes of orbit value (a cluster id) | 115 // 8 bytes of orbit value (a cluster id) |
116 // 20 bytes of random data | 116 // 20 bytes of random data |
117 // | 117 // |
118 // Otherwise, it inserts |nonce| into the observed set and returns true. | 118 // Otherwise, it inserts |nonce| into the observed set and returns true. |
119 bool Insert(const uint8 nonce[32], const uint32 current_time); | 119 bool Insert(const uint8 nonce[32], uint32 current_time); |
120 | 120 |
121 // orbit returns a pointer to the 8-byte orbit value for this | 121 // orbit returns a pointer to the 8-byte orbit value for this |
122 // strike-register. | 122 // strike-register. |
123 const uint8* orbit() const; | 123 const uint8* orbit() const; |
124 | 124 |
125 // Time window for which the strike register has complete information. | 125 // Time window for which the strike register has complete information. |
126 uint32 EffectiveWindowSecs(const uint32 current_time_external) const; | 126 uint32 GetCurrentValidWindowSecs(uint32 current_time_external) const; |
127 | 127 |
128 // This is a debugging aid which checks the tree for sanity. | 128 // This is a debugging aid which checks the tree for sanity. |
129 void Validate(); | 129 void Validate(); |
130 | 130 |
131 private: | 131 private: |
132 class InternalNode; | 132 class InternalNode; |
133 | 133 |
134 // TimeFromBytes returns a big-endian uint32 from |d|. | 134 // TimeFromBytes returns a big-endian uint32 from |d|. |
135 static uint32 TimeFromBytes(const uint8 d[4]); | 135 static uint32 TimeFromBytes(const uint8 d[4]); |
136 | 136 |
| 137 // Range of internal times for which the strike register has |
| 138 // complete information. A nonce is within the valid range of the |
| 139 // strike register if: |
| 140 // valid_range.first <= nonce_time_internal <= valid_range.second |
| 141 std::pair<uint32, uint32> GetValidRange(uint32 current_time_internal) const; |
| 142 |
137 // ExternalTimeToInternal converts an external time value into an internal | 143 // ExternalTimeToInternal converts an external time value into an internal |
138 // time value using |internal_epoch_|. | 144 // time value using |internal_epoch_|. |
139 uint32 ExternalTimeToInternal(uint32 external_time) const; | 145 uint32 ExternalTimeToInternal(uint32 external_time) const; |
140 | 146 |
141 // BestMatch returns either kNil, or an external node index which could | 147 // BestMatch returns either kNil, or an external node index which could |
142 // possibly match |v|. | 148 // possibly match |v|. |
143 uint32 BestMatch(const uint8 v[24]) const; | 149 uint32 BestMatch(const uint8 v[24]) const; |
144 | 150 |
145 // external_node_next_ptr returns the 'next' pointer embedded in external | 151 // external_node_next_ptr returns the 'next' pointer embedded in external |
146 // node |i|. This is used to thread a free list through the external nodes. | 152 // node |i|. This is used to thread a free list through the external nodes. |
(...skipping 20 matching lines...) Expand all Loading... |
167 const std::set<uint32>& free_external_nodes, | 173 const std::set<uint32>& free_external_nodes, |
168 std::set<uint32>* used_internal_nodes, | 174 std::set<uint32>* used_internal_nodes, |
169 std::set<uint32>* used_external_nodes); | 175 std::set<uint32>* used_external_nodes); |
170 | 176 |
171 const uint32 max_entries_; | 177 const uint32 max_entries_; |
172 const uint32 window_secs_; | 178 const uint32 window_secs_; |
173 // internal_epoch_ contains the external time value of the start of internal | 179 // internal_epoch_ contains the external time value of the start of internal |
174 // time. | 180 // time. |
175 const uint32 internal_epoch_; | 181 const uint32 internal_epoch_; |
176 uint8 orbit_[8]; | 182 uint8 orbit_[8]; |
| 183 // The strike register will reject nonces with internal times < |horizon_| . |
177 uint32 horizon_; | 184 uint32 horizon_; |
178 | 185 |
179 uint32 internal_node_free_head_; | 186 uint32 internal_node_free_head_; |
180 uint32 external_node_free_head_; | 187 uint32 external_node_free_head_; |
181 uint32 internal_node_head_; | 188 uint32 internal_node_head_; |
182 // internal_nodes_ can't be a scoped_ptr because the type isn't defined in | 189 // internal_nodes_ can't be a scoped_ptr because the type isn't defined in |
183 // this header. | 190 // this header. |
184 InternalNode* internal_nodes_; | 191 InternalNode* internal_nodes_; |
185 scoped_ptr<uint8[]> external_nodes_; | 192 scoped_ptr<uint8[]> external_nodes_; |
186 | 193 |
187 DISALLOW_COPY_AND_ASSIGN(StrikeRegister); | 194 DISALLOW_COPY_AND_ASSIGN(StrikeRegister); |
188 }; | 195 }; |
189 | 196 |
190 } // namespace net | 197 } // namespace net |
191 | 198 |
192 #endif // NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ | 199 #endif // NET_QUIC_CRYPTO_STRIKE_REGISTER_H_ |
OLD | NEW |