private TimeSpan DefaultTimeout { get; } = new TimeSpan(0, 0, 0, 0, 500); // FUTURE use configuration value public LoginAttemptController( LoginAttemptClient loginAttemptClient, UserAccountClient userAccountClient, MemoryUsageLimiter memoryUsageLimiter, BlockingAlgorithmOptions blockingOptions, IStableStore stableStore) { _options = blockingOptions;//optionsAccessor.Options; _stableStore = stableStore; _passwordPopularityTracker = new PasswordPopularityTracker("FIXME-uniquekeyfromconfig" //FIXME -- use configuration to get options here"FIXME-uniquekeyfromconfig", thresholdRequiredToTrackPreciseOccurrences: 10); ); _loginAttemptCache = new FixedSizeLruCache<string, LoginAttempt>(80000); // FIXME -- use configuration file for size _loginAttemptsInProgress = new Dictionary<string, Task<LoginAttempt>>(); _ipHistoryCache = new SelfLoadingCache<IPAddress, IpHistory>( (id, cancellationToken) => { return Task.Run(() => new IpHistory(id), cancellationToken); // FUTURE -- option to load from stable store }); _loginAttemptClient = loginAttemptClient; _loginAttemptClient.SetLocalLoginAttemptController(this); SetUserAccountClient(userAccountClient); memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage; }
public DistributedBinomialLadderFilterClient(int numberOfShards, int defaultHeightOfLadder, IDistributedResponsibilitySet <RemoteHost> shardToHostMapping, string configurationKey, TimeSpan?mininmumCacheFreshnessRequired = null) { NumberOfShards = numberOfShards; MaxLadderHeight = defaultHeightOfLadder; MinimumCacheFreshnessRequired = mininmumCacheFreshnessRequired ?? new TimeSpan(0, 0, 1); CacheOfElementsAtTopOfLadder = new FixedSizeLruCache <string, DateTime>(2 * NumberOfShards); ShardHashFunction = new UniversalHashFunction(configurationKey); ShardToHostMapping = shardToHostMapping; }
/// <summary> /// Create a client for a distributed binomial ladder filter /// </summary> /// <param name="numberOfShards">The number of shards that the bit array of the binomial ladder filter will be divided into. /// The greater the number of shards, the more evently it can be distributed. However, the number of shards should still /// be a few orders of magnitude smaller than the ladder height.</param> /// <param name="defaultHeightOfLadder">The default ladder height for elements on the ladder.</param> /// <param name="shardToHostMapping">An object that maps each shard number to the host responsible for that shard.</param> /// <param name="configurationKey">A key used to protect the hashing from algorithmic complexity attacks. /// This key should not be unique to the application using the filter and should not be known to any untrusted /// systems that might control which elements get sent to the filter. If an attacker could submit elements to the filter /// and knew this key, the attacker could arrange for all elements to go to the same shard and in so doing overload that shard.</param> /// <param name="mininmumCacheFreshnessRequired">The maximum time that an element should be kept in the cache of elements at the top of their ladder. /// In other words, how long to bound the possible time that an element may still appear to be at the top of its ladder in the cache /// when it is no longer at the top of the ladder based on the filter array. Defaults to one minute.</param> public DistributedBinomialLadderFilterClient(int numberOfShards, int defaultHeightOfLadder, IDistributedResponsibilitySet<RemoteHost> shardToHostMapping, string configurationKey, TimeSpan? mininmumCacheFreshnessRequired = null) { NumberOfShards = numberOfShards; MaxLadderHeight = defaultHeightOfLadder; MinimumCacheFreshnessRequired = mininmumCacheFreshnessRequired ?? new TimeSpan(0,0,1); CacheOfElementsAtTopOfLadder = new FixedSizeLruCache<string, DateTime>(2*NumberOfShards); ShardHashFunction = new UniversalHashFunction(configurationKey); ShardToHostMapping = shardToHostMapping; }