| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/local_strike_register_client.h" | 5 #include "net/quic/crypto/local_strike_register_client.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/crypto_protocol.h" | 7 #include "net/quic/crypto/crypto_protocol.h" |
| 8 | 8 |
| 9 using base::StringPiece; | 9 using base::StringPiece; |
| 10 using std::string; | 10 using std::string; |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 LocalStrikeRegisterClient::LocalStrikeRegisterClient( | 14 LocalStrikeRegisterClient::LocalStrikeRegisterClient( |
| 15 unsigned max_entries, | 15 unsigned max_entries, |
| 16 uint32 current_time_external, | 16 uint32_t current_time_external, |
| 17 uint32 window_secs, | 17 uint32_t window_secs, |
| 18 const uint8 orbit[8], | 18 const uint8_t orbit[8], |
| 19 StrikeRegister::StartupType startup) | 19 StrikeRegister::StartupType startup) |
| 20 : strike_register_(max_entries, | 20 : strike_register_(max_entries, |
| 21 current_time_external, | 21 current_time_external, |
| 22 window_secs, | 22 window_secs, |
| 23 orbit, | 23 orbit, |
| 24 startup) {} | 24 startup) {} |
| 25 | 25 |
| 26 bool LocalStrikeRegisterClient::IsKnownOrbit(StringPiece orbit) const { | 26 bool LocalStrikeRegisterClient::IsKnownOrbit(StringPiece orbit) const { |
| 27 base::AutoLock lock(m_); | 27 base::AutoLock lock(m_); |
| 28 if (orbit.length() != kOrbitSize) { | 28 if (orbit.length() != kOrbitSize) { |
| 29 return false; | 29 return false; |
| 30 } | 30 } |
| 31 return memcmp(orbit.data(), strike_register_.orbit(), kOrbitSize) == 0; | 31 return memcmp(orbit.data(), strike_register_.orbit(), kOrbitSize) == 0; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void LocalStrikeRegisterClient::VerifyNonceIsValidAndUnique( | 34 void LocalStrikeRegisterClient::VerifyNonceIsValidAndUnique( |
| 35 StringPiece nonce, | 35 StringPiece nonce, |
| 36 QuicWallTime now, | 36 QuicWallTime now, |
| 37 ResultCallback* cb) { | 37 ResultCallback* cb) { |
| 38 InsertStatus nonce_error; | 38 InsertStatus nonce_error; |
| 39 if (nonce.length() != kNonceSize) { | 39 if (nonce.length() != kNonceSize) { |
| 40 nonce_error = NONCE_INVALID_FAILURE; | 40 nonce_error = NONCE_INVALID_FAILURE; |
| 41 } else { | 41 } else { |
| 42 base::AutoLock lock(m_); | 42 base::AutoLock lock(m_); |
| 43 nonce_error = | 43 nonce_error = |
| 44 strike_register_.Insert(reinterpret_cast<const uint8*>(nonce.data()), | 44 strike_register_.Insert(reinterpret_cast<const uint8_t*>(nonce.data()), |
| 45 static_cast<uint32>(now.ToUNIXSeconds())); | 45 static_cast<uint32_t>(now.ToUNIXSeconds())); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // m_ must not be held when the ResultCallback runs. | 48 // m_ must not be held when the ResultCallback runs. |
| 49 cb->Run((nonce_error == NONCE_OK), nonce_error); | 49 cb->Run((nonce_error == NONCE_OK), nonce_error); |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace net | 52 } // namespace net |
| OLD | NEW |