| 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 current_time_external, |
| 17 uint32 window_secs, | 17 uint32 window_secs, |
| 18 const uint8 orbit[8], | 18 const uint8 orbit[8], |
| 19 StrikeRegister::StartupType startup) | 19 StrikeRegister::StartupType startup) |
| 20 : strike_register_(max_entries, current_time_external, window_secs, | 20 : strike_register_(max_entries, current_time_external, window_secs, |
| 21 orbit, startup) { | 21 orbit, startup) { |
| 22 } | 22 } |
| 23 | 23 |
| 24 string LocalStrikeRegisterClient::orbit() { | 24 bool LocalStrikeRegisterClient::IsKnownOrbit(StringPiece orbit) const { |
| 25 base::AutoLock lock(m_); | 25 base::AutoLock lock(m_); |
| 26 return string(reinterpret_cast<const char*>(strike_register_.orbit()), | 26 if (orbit.length() != kOrbitSize) { |
| 27 kOrbitSize); | 27 return false; |
| 28 } |
| 29 return memcmp(orbit.data(), strike_register_.orbit(), kOrbitSize) == 0; |
| 28 } | 30 } |
| 29 | 31 |
| 30 void LocalStrikeRegisterClient::VerifyNonceIsValidAndUnique( | 32 void LocalStrikeRegisterClient::VerifyNonceIsValidAndUnique( |
| 31 StringPiece nonce, QuicWallTime now, ResultCallback* cb) { | 33 StringPiece nonce, QuicWallTime now, ResultCallback* cb) { |
| 32 bool nonce_is_valid_and_unique; | 34 bool nonce_is_valid_and_unique; |
| 33 if (nonce.length() != kNonceSize) { | 35 if (nonce.length() != kNonceSize) { |
| 34 nonce_is_valid_and_unique = false; | 36 nonce_is_valid_and_unique = false; |
| 35 } else { | 37 } else { |
| 36 base::AutoLock lock(m_); | 38 base::AutoLock lock(m_); |
| 37 nonce_is_valid_and_unique = strike_register_.Insert( | 39 nonce_is_valid_and_unique = strike_register_.Insert( |
| 38 reinterpret_cast<const uint8*>(nonce.data()), | 40 reinterpret_cast<const uint8*>(nonce.data()), |
| 39 static_cast<uint32>(now.ToUNIXSeconds())); | 41 static_cast<uint32>(now.ToUNIXSeconds())); |
| 40 } | 42 } |
| 41 | 43 |
| 42 // m_ must not be held when the ResultCallback runs. | 44 // m_ must not be held when the ResultCallback runs. |
| 43 cb->Run(nonce_is_valid_and_unique); | 45 cb->Run(nonce_is_valid_and_unique); |
| 44 } | 46 } |
| 45 | 47 |
| 46 } // namespace net | 48 } // namespace net |
| OLD | NEW |