public void Remove(T node) { _lock.EnterWriteLock(); try { byte[] key = _keyProvider(node); int offset = key.Length; Array.Resize(ref key, offset + 1); for (byte i = 0; i < _replicate; i++) { key[offset] = i; var hash = (int)_hashGenerator.Hash(key); if (!_circle.Remove(hash)) throw new Exception("can not remove a node that not added"); } _keyCache = RebuildKeyCache(); } finally { _lock.ExitWriteLock(); } }
public T this[string key] { get { var hash = (int)_hashGenerator.Hash(key); return(GetNode(hash)); } }
public void Hash_AreNotEqual_ReturnsTrue() { // Arrange const string plainText = "test"; var salt = _hashGenerator.Salt(); // Act var result = _hashGenerator.Hash(plainText, salt); // Assert Assert.AreNotEqual(plainText, result); }
public async Task Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { var key = _keyProvider(context); if (key == null) { throw new InvalidOperationException("The key cannot be null"); } var hash = _hashGenerator.Hash(key); var partitionId = hash % _partitionCount; try { Interlocked.Increment(ref _attemptCount[partitionId]); await _partitions[partitionId].Send(context, next); Interlocked.Increment(ref _successCount[partitionId]); } catch { Interlocked.Increment(ref _failureCount[partitionId]); throw; } }
public async Task <User> RegisterPasswordAsync(string username, string email, string password) { if (!_regexValidator.IsValidEmail(email)) { throw new InvalidEmailException(); } if (!_regexValidator.IsValidPassword(password)) { throw new InvalidPasswordException(); } if (await _repository.ReadByUsernameAsync(username) != null) { throw new UsernameAlreadyExistsException(); } if (await _repository.ReadByEmailAsync(email) != null) { throw new EmailAlreadyExistsException(); } var salt = _hashGenerator.Salt(); var hashedPassword = _hashGenerator.Hash(password, salt); var user = await _repository.CreateAsync( new User { Username = username, Email = email, Password = hashedPassword, Salt = salt } ); await _messageQueuePublisher.PublishMessageAsync( "Dwetter", "EmailMicroservice", "RegisterUser", JsonConvert.SerializeObject(new { email = user.Email, username = user.Username } )); await _messageQueuePublisher.PublishMessageAsync( "Dwetter", "ProfileMicroservice", "RegisterUser", new { userId = user.Id, username = user.Username } ); return(user.WithoutSensitiveData()); }
public void Remove(T node) { _lock.EnterWriteLock(); try { for (int i = 0; i < _replicate; i++) { var hash = (int)_hashGenerator.Hash(_keyProvider(node) + i); if (!_circle.Remove(hash)) { throw new Exception("can not remove a node that not added"); } } _keyCache = RebuildKeyCache(); } finally { _lock.ExitWriteLock(); } }
private static Guid ToGuid(byte[] data, IHashGenerator hashGenerator) { #if DEBUG if (data.IsEmpty()) { throw new ArgumentNullException("data"); } #endif if (data.IsEmpty()) { return(Guid.Empty); } byte[] value = hashGenerator.Hash(data); var destination = new byte[16]; Array.Copy(value, destination, destination.Length); return(new Guid(destination)); }
internal byte[] HashSHA1FromASCIIToBytes(string plain) { return(_hashSHA1Generator.Hash(Encoding.ASCII.GetBytes(plain))); }
private static string HashUsingUTF16(string bytes, IHashGenerator hashGenerator) { return(EncodeBase64(hashGenerator.Hash(EncodeUTF16(bytes)))); }
private static string HashUsingDefaultEncoding(string plain, IHashGenerator hashGenerator) { return(EncodeBase64(hashGenerator.Hash(EncodeDefault(plain)))); }
private string Hash(string plain, IHashGenerator hashGenerator) { return(EncodeBase64(hashGenerator.Hash(Encode(plain)))); }
private static string Hash(byte[] bytes, IHashGenerator hashGenerator) { return(EncodeBase64(hashGenerator.Hash(bytes))); }
private static byte[] HashToBytes(byte[] bytes, IHashGenerator hashGenerator) { return(hashGenerator.Hash(bytes)); }
private static string HexDeriveUsingUTF16(string plainText, string salt, IHashGenerator hashGenerator) { return((BitConverter.ToString(hashGenerator.Hash(EncodeUTF16(plainText + salt)))).Replace("-", "")); }