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 UserAccountController( UserAccountClient userAccountClient, LoginAttemptClient loginAttemptClient, MemoryUsageLimiter memoryUsageLimiter, BlockingAlgorithmOptions options, IStableStore stableStore, LimitPerTimePeriod[] creditLimits) { // _options = optionsAccessor.Options; _options = options; _stableStore = stableStore; _userAccountClient = userAccountClient; CreditLimits = creditLimits; _userAccountCache = new SelfLoadingCache<string, UserAccount>(_stableStore.ReadAccountAsync); SetLoginAttemptClient(loginAttemptClient); userAccountClient.SetLocalUserAccountController(this); memoryUsageLimiter.OnReduceMemoryUsageEventHandler += ReduceMemoryUsage; }
public static TestConfiguration InitTest(BlockingAlgorithmOptions options = default(BlockingAlgorithmOptions)) { if (options == null) options = new BlockingAlgorithmOptions(); TestConfiguration configuration = new TestConfiguration(); configuration.MyBlockingAlgorithmOptions = options ?? new BlockingAlgorithmOptions(); //configuration.MyResponsibleHosts = new MaxWeightHashing<RemoteHost>("FIXME-uniquekeyfromconfig"); //RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:80") }; //configuration.MyResponsibleHosts.Add("localhost", localHost); //IStableStore stableStore = configuration.StableStore = new MemoryOnlyStableStore(); //configuration.MyLoginAttemptClient = new LoginAttemptClient(configuration.MyResponsibleHosts, localHost); MemoryUsageLimiter memoryUsageLimiter = new MemoryUsageLimiter(); BinomialLadderFilter localPasswordBinomialLadderFilter = new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H); //MultiperiodFrequencyTracker<string> localPasswordFrequencyTracker = // new MultiperiodFrequencyTracker<string>( // options.NumberOfPopularityMeasurementPeriods, // options.LengthOfShortestPopularityMeasurementPeriod, // options.FactorOfGrowthBetweenPopularityMeasurementPeriods); configuration.MyAccountFactory = new MemoryOnlyUserAccountFactory(); configuration.MemUserAccountController = new MemoryUserAccountController(); LoginAttemptController<MemoryUserAccount> myLoginAttemptController = new LoginAttemptController<MemoryUserAccount>( new MemoryUserAccountControllerFactory(), configuration.MyAccountFactory, localPasswordBinomialLadderFilter, memoryUsageLimiter, configuration.MyBlockingAlgorithmOptions); configuration.MyLoginAttemptClient = myLoginAttemptController; //configuration.MyLoginAttemptClient.SetLocalLoginAttemptController(myLoginAttemptController); return configuration; }
public Simulator(ExperimentalConfiguration myExperimentalConfiguration, BlockingAlgorithmOptions options = default(BlockingAlgorithmOptions)) { MyExperimentalConfiguration = myExperimentalConfiguration; if (options == null) options = new BlockingAlgorithmOptions(); CreditLimits = new[] { // 3 per hour new LimitPerTimePeriod(new TimeSpan(1, 0, 0), 3f), // 6 per day (24 hours, not calendar day) new LimitPerTimePeriod(new TimeSpan(1, 0, 0, 0), 6f), // 10 per week new LimitPerTimePeriod(new TimeSpan(6, 0, 0, 0), 10f), // 15 per month new LimitPerTimePeriod(new TimeSpan(30, 0, 0, 0), 15f) }; //We are testing with local server now MyResponsibleHosts = new MaxWeightHashing<RemoteHost>("FIXME-uniquekeyfromconfig"); //configuration.MyResponsibleHosts.Add("localhost", new RemoteHost { Uri = new Uri("http://localhost:80"), IsLocalHost = true }); RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:80") }; MyResponsibleHosts.Add("localhost", localHost); MyUserAccountClient = new UserAccountClient(MyResponsibleHosts, localHost); MyLoginAttemptClient = new LoginAttemptClient(MyResponsibleHosts, localHost); MemoryUsageLimiter memoryUsageLimiter = new MemoryUsageLimiter(); MyUserAccountController = new UserAccountController(MyUserAccountClient, MyLoginAttemptClient, memoryUsageLimiter, options, StableStore, CreditLimits); MyLoginAttemptController = new LoginAttemptController(MyLoginAttemptClient, MyUserAccountClient, memoryUsageLimiter, options, StableStore); MyUserAccountController.SetLoginAttemptClient(MyLoginAttemptClient); MyUserAccountClient.SetLocalUserAccountController(MyUserAccountController); MyLoginAttemptController.SetUserAccountClient(MyUserAccountClient); MyLoginAttemptClient.SetLocalLoginAttemptController(MyLoginAttemptController); //fix outofmemory bug by setting the loginattempt field to null StableStore.LoginAttempts = null; }
public static TestConfiguration InitTest(BlockingAlgorithmOptions options = default(BlockingAlgorithmOptions)) { TestConfiguration configuration = new TestConfiguration(); if (options == null) options = new BlockingAlgorithmOptions(); configuration.CreditLimits = new[] { // 3 per hour new LimitPerTimePeriod(new TimeSpan(1, 0, 0), 3f), // 6 per day (24 hours, not calendar day) new LimitPerTimePeriod(new TimeSpan(1, 0, 0, 0), 6f), // 10 per week new LimitPerTimePeriod(new TimeSpan(6, 0, 0, 0), 10f), // 15 per month new LimitPerTimePeriod(new TimeSpan(30, 0, 0, 0), 15f) }; configuration.MyResponsibleHosts = new MaxWeightHashing<RemoteHost>("FIXME-uniquekeyfromconfig"); RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:80") }; configuration.MyResponsibleHosts.Add("localhost", localHost); IStableStore stableStore = configuration.StableStore = new MemoryOnlyStableStore(); configuration.MyUserAccountClient = new UserAccountClient(configuration.MyResponsibleHosts, localHost); configuration.MyLoginAttemptClient = new LoginAttemptClient(configuration.MyResponsibleHosts, localHost); MemoryUsageLimiter memoryUsageLimiter = new MemoryUsageLimiter(); configuration.MyUserAccountController = new UserAccountController(configuration.MyUserAccountClient, configuration.MyLoginAttemptClient, memoryUsageLimiter, options, stableStore, configuration.CreditLimits); LoginAttemptController myLoginAttemptController = new LoginAttemptController(configuration.MyLoginAttemptClient, configuration.MyUserAccountClient, memoryUsageLimiter, options, stableStore); configuration.MyUserAccountController.SetLoginAttemptClient(configuration.MyLoginAttemptClient); configuration.MyUserAccountClient.SetLocalUserAccountController(configuration.MyUserAccountController); myLoginAttemptController.SetUserAccountClient(configuration.MyUserAccountClient); configuration.MyLoginAttemptClient.SetLocalLoginAttemptController(myLoginAttemptController); return configuration; }
/// <summary> /// When memory runs low, call this function to remove a fraction of the space used by non-fixed-size data structures /// (In this case, it is the history of information about IP addresses) /// </summary> public void ReduceMemoryUsage(object sender, MemoryUsageLimiter.ReduceMemoryUsageEventParameters parameters) { _ipHistoryCache.RecoverSpace(parameters.FractionOfMemoryToTryToRemove); }