Ejemplo n.º 1
0
        // This method gets called by a runtime.
        // Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add Application Insights data collection services to the services container.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddMvc();
            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            var hosts = new MaxWeightHashing<RemoteHost>("FIXME-uniquekeyfromconfig");
            RemoteHost localHost = new RemoteHost {Uri = new Uri("http://localhost:35358")};

            services.AddSingleton<RemoteHost>(x => localHost);
            hosts.Add("localhost", localHost);

            // Use memory only stable store if none other is available.  FUTURE -- use azure SQL or tables
            services.AddSingleton<IStableStore, MemoryOnlyStableStore>();

            var options = new BlockingAlgorithmOptions();


            services.AddSingleton<BlockingAlgorithmOptions>(x => options);
            services.AddSingleton<BlockingAlgorithmOptions>(x => options);

            services.AddSingleton<MemoryUsageLimiter, MemoryUsageLimiter>();

            services.AddSingleton<IDistributedResponsibilitySet<RemoteHost>>(x => hosts);
            services.AddSingleton<UserAccountClient>();
            services.AddSingleton<LoginAttemptClient>();
            services.AddSingleton<UserAccountController>();
            services.AddSingleton<LoginAttemptController>();
        }
                "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };//,
   //             "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"};

    private MaxWeightHashing<string> CreateMaxWeightHasher()
        {
            MaxWeightHashing<string> hasher = new MaxWeightHashing<string>(
                // For testing purposes only, the private key we will use to initialize
                // the universal hash function for the hash ring will be the key master from Ghostbusters
                "Louis Tully as played by Rick Moranis",
                // The ring will contain the words one to ten, capitalized.
                _nodeNames.Select(word => new KeyValuePair<string, string>(word, word)));
            return hasher;
        }
Ejemplo n.º 3
0
        };                                                                                      //,
        //             "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"};

        private MaxWeightHashing <string> CreateMaxWeightHasher()
        {
            MaxWeightHashing <string> hasher = new MaxWeightHashing <string>(
                // For testing purposes only, the private key we will use to initialize
                // the universal hash function for the hash ring will be the key master from Ghostbusters
                "Louis Tully as played by Rick Moranis",
                // The ring will contain the words one to ten, capitalized.
                _nodeNames.Select(word => new KeyValuePair <string, string>(word, word)));

            return(hasher);
        }
Ejemplo n.º 4
0
        public void Init()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath("")
                          .AddJsonFile("appsettings.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            sqlConnectionString = Configuration["Data:ConnectionString"];
            string cloudStorageConnectionString = Configuration["Data:StorageConnectionString"];

            _options = new BlockingAlgorithmOptions();

            DbContextOptionsBuilder <DbUserAccountContext> dbOptionsBuilder = new DbContextOptionsBuilder <DbUserAccountContext>();

            dbOptionsBuilder.UseSqlServer(sqlConnectionString);
            dbOptions = dbOptionsBuilder.Options;

            _CloudStorageAccount         = CloudStorageAccount.Parse(cloudStorageConnectionString);
            userAccountControllerFactory = new DbUserAccountControllerFactory(_CloudStorageAccount, dbOptions);
            userAccountController        = userAccountControllerFactory.CreateDbUserAccountController();

            RemoteHost localHost = new RemoteHost {
                Uri = new Uri("http://localhost:35358")
            };
            MaxWeightHashing <RemoteHost> hosts = new MaxWeightHashing <RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]);

            LoginAttemptClient <DbUserAccount> loginAttemptClient = new LoginAttemptClient <DbUserAccount>(hosts, localHost);

            _UserAccountRepositoryFactory = new DbUserAccountRepositoryFactory(dbOptions);

            BinomialLadderFilter localPasswordBinomialLadderFilter = new BinomialLadderFilter(
                _options.NumberOfBitsInBinomialLadderFilter_N, _options.HeightOfBinomialLadder_H);

            _loginAttemptController = new LoginAttemptController <DbUserAccount>(
                userAccountControllerFactory, _UserAccountRepositoryFactory,
                localPasswordBinomialLadderFilter,
                new MemoryUsageLimiter(), _options);

            //services.AddEntityFramework()
            //    .AddSqlServer()
            //    .AddDbContext<DbUserAccountContext>(opt => opt.UseSqlServer(sqlConnectionString));
            //DbUserAccountContext context = new DbUserAccountContext();

            //var db = new DbContextOptionsBuilder();
            //db.UseInMemoryDatabase();
            //_context = new MyContext(db.Options);
        }
Ejemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            BlockingAlgorithmOptions options = new BlockingAlgorithmOptions();

            services.AddSingleton <BlockingAlgorithmOptions>(x => options);

            RemoteHost localHost = new RemoteHost {
                Uri = new Uri("http://localhost:35358")
            };

            services.AddSingleton <RemoteHost>(x => localHost);

            MaxWeightHashing <RemoteHost> hosts = new MaxWeightHashing <RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]);

            hosts.Add("localhost", localHost);
            services.AddSingleton <IDistributedResponsibilitySet <RemoteHost> >(x => hosts);

            string cloudStorageConnectionString     = Configuration["Data:StorageConnectionString"];
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString);

            services.AddSingleton <CloudStorageAccount>(a => cloudStorageAccount);

            services.AddSingleton <MemoryUsageLimiter, MemoryUsageLimiter>();

            if (hosts.Count > 0)
            {
                DistributedBinomialLadderFilterClient dblfClient = new DistributedBinomialLadderFilterClient(
                    options.NumberOfVirtualNodesForDistributedBinomialLadder,
                    options.HeightOfBinomialLadder_H,
                    hosts,
                    options.PrivateConfigurationKey,
                    options.MinimumBinomialLadderFilterCacheFreshness);
                services.AddSingleton <IBinomialLadderFilter, DistributedBinomialLadderFilterClient>(x => dblfClient);
            }
            else
            {
                BinomialLadderFilter localPasswordBinomialLadderFilter =
                    new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);
                services.AddSingleton <IBinomialLadderFilter>(x => localPasswordBinomialLadderFilter);
            }

            LoginAttemptClient <MemoryUserAccount> loginAttemptClient = new LoginAttemptClient <MemoryUserAccount>(hosts, localHost);

            services.AddSingleton <ILoginAttemptClient, LoginAttemptClient <MemoryUserAccount> >(i => loginAttemptClient);
            services.AddSingleton <ILoginAttemptController, LoginAttemptController <MemoryUserAccount> >();
        }
Ejemplo n.º 6
0
        public void Init()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath("")
                .AddJsonFile("appsettings.json");

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();

            sqlConnectionString = Configuration["Data:ConnectionString"];
            string cloudStorageConnectionString = Configuration["Data:StorageConnectionString"];

            _options = new BlockingAlgorithmOptions();

            DbContextOptionsBuilder<DbUserAccountContext> dbOptionsBuilder = new DbContextOptionsBuilder<DbUserAccountContext>();
            dbOptionsBuilder.UseSqlServer(sqlConnectionString);
            dbOptions = dbOptionsBuilder.Options;

            _CloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString);
            userAccountControllerFactory = new DbUserAccountControllerFactory(_CloudStorageAccount, dbOptions);
            userAccountController = userAccountControllerFactory.CreateDbUserAccountController();

            RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:35358") };
            MaxWeightHashing<RemoteHost> hosts = new MaxWeightHashing<RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]);

            LoginAttemptClient<DbUserAccount> loginAttemptClient = new LoginAttemptClient<DbUserAccount>(hosts, localHost);

            _UserAccountRepositoryFactory = new DbUserAccountRepositoryFactory(dbOptions);

            BinomialLadderFilter localPasswordBinomialLadderFilter = new BinomialLadderFilter(
                _options.NumberOfBitsInBinomialLadderFilter_N, _options.HeightOfBinomialLadder_H);

            _loginAttemptController = new LoginAttemptController<DbUserAccount>(
                userAccountControllerFactory, _UserAccountRepositoryFactory,
                localPasswordBinomialLadderFilter,
                new MemoryUsageLimiter(), _options);

            //services.AddEntityFramework()
            //    .AddSqlServer()
            //    .AddDbContext<DbUserAccountContext>(opt => opt.UseSqlServer(sqlConnectionString));
            //DbUserAccountContext context = new DbUserAccountContext();

            //var db = new DbContextOptionsBuilder();
            //db.UseInMemoryDatabase();
            //_context = new MyContext(db.Options);

        }
Ejemplo n.º 7
0
        public void MaxWeightHasherEvenDistributionTest()
        {
            Pseudorandom pseudo = new Pseudorandom();
            int          trials = 10000000;
            MaxWeightHashing <string> hasher = CreateMaxWeightHasher();

            double expectedFraction = 1d / ((double)_nodeNames.Length);


            Dictionary <string, Int64> counts = new Dictionary <string, Int64>();

            foreach (string number in _nodeNames)
            {
                counts[number] = 0;
            }

            for (int i = 0; i < trials; i++)
            {
                string rand = pseudo.GetString(13);
                string word = hasher.FindMemberResponsible(rand);
                counts[word]++;
            }

            double greatestAdjustedError = 0;

            foreach (string word in _nodeNames)
            {
                double freq          = ((double)counts[word]) / (double)trials;
                double error         = freq - expectedFraction;
                double adjustedError = error / expectedFraction;
                if (adjustedError > greatestAdjustedError)
                {
                    greatestAdjustedError = adjustedError;
                }
                Assert.True(Math.Abs(adjustedError) < 0.005);
            }

            Console.Out.WriteLine("Highest adjusted error: {0}", greatestAdjustedError);
        }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            string sqlConnectionString = Configuration["Data:ConnectionString"];
            services.AddDbContext<DbUserAccountContext>(
                opt => opt.UseSqlServer(sqlConnectionString));

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            BlockingAlgorithmOptions options = new BlockingAlgorithmOptions();

            services.AddSingleton<BlockingAlgorithmOptions>(x => options);

            RemoteHost localHost = new RemoteHost { Uri = new Uri("http://localhost:35358") };
            services.AddSingleton<RemoteHost>(x => localHost);

            MaxWeightHashing<RemoteHost> hosts = new MaxWeightHashing<RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]);
            hosts.Add("localhost", localHost);
            services.AddSingleton<IDistributedResponsibilitySet<RemoteHost>>(x => hosts);

            string cloudStorageConnectionString = Configuration["Data:StorageConnectionString"];
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString);
            services.AddSingleton<CloudStorageAccount>(a => cloudStorageAccount);

            services.AddSingleton<MemoryUsageLimiter, MemoryUsageLimiter>();

            if (hosts.Count > 0)
            {
                DistributedBinomialLadderFilterClient dblfClient = new DistributedBinomialLadderFilterClient(
                    options.NumberOfVirtualNodesForDistributedBinomialLadder,
                    options.HeightOfBinomialLadder_H,
                    hosts,
                    options.PrivateConfigurationKey,
                    options.MinimumBinomialLadderFilterCacheFreshness);
                // If running as a distributed system
                services.AddSingleton<IBinomialLadderFilter, DistributedBinomialLadderFilterClient>(x => dblfClient);

                DistributedBinomialLadderFilterController filterController =
                    new DistributedBinomialLadderFilterController(dblfClient, options.NumberOfBitsPerShardInBinomialLadderFilter, options.PrivateConfigurationKey);
                services.AddSingleton<DistributedBinomialLadderFilterController>(x => filterController);

                //services.AddSingleton<IFrequenciesProvider<string>>(x =>
                //    new IncorrectPasswordFrequencyClient(hosts, options.NumberOfRedundantHostsToCachePasswordPopularity));
            }
            else
            {
                BinomialLadderFilter localPasswordBinomialLadderFilter =
                    new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);
                services.AddSingleton<IBinomialLadderFilter>(x => localPasswordBinomialLadderFilter);
            }

            LoginAttemptClient<DbUserAccount> loginAttemptClient = new LoginAttemptClient<DbUserAccount>(hosts, localHost);
            services.AddSingleton<IUserAccountRepositoryFactory<DbUserAccount>, DbUserAccountRepositoryFactory>();
            services.AddSingleton<IUserAccountControllerFactory<DbUserAccount>, DbUserAccountControllerFactory>();
            //LoginAttemptController<DbUserAccount> loginAttemptController = new LoginAttemptController<DbUserAccount>( 
            //     new DbUserAccountControllerFactory(cloudStorageAccount), new DbUserAccountRepositoryFactory());
            services.AddSingleton<ILoginAttemptClient, LoginAttemptClient<DbUserAccount>>(i => loginAttemptClient);
            services.AddSingleton<ILoginAttemptController, LoginAttemptController<DbUserAccount>>();
        }
Ejemplo n.º 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddMvc();

            string sqlConnectionString = Configuration["Data:ConnectionString"];

            services.AddDbContext <DbUserAccountContext>(
                opt => opt.UseSqlServer(sqlConnectionString));

            // Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
            // You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
            // services.AddWebApiConventions();

            BlockingAlgorithmOptions options = new BlockingAlgorithmOptions();

            services.AddSingleton <BlockingAlgorithmOptions>(x => options);

            RemoteHost localHost = new RemoteHost {
                Uri = new Uri("http://localhost:35358")
            };

            services.AddSingleton <RemoteHost>(x => localHost);

            MaxWeightHashing <RemoteHost> hosts = new MaxWeightHashing <RemoteHost>(Configuration["Data:UniqueConfigurationSecretPhrase"]);

            hosts.Add("localhost", localHost);
            services.AddSingleton <IDistributedResponsibilitySet <RemoteHost> >(x => hosts);

            string cloudStorageConnectionString     = Configuration["Data:StorageConnectionString"];
            CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(cloudStorageConnectionString);

            services.AddSingleton <CloudStorageAccount>(a => cloudStorageAccount);

            services.AddSingleton <MemoryUsageLimiter, MemoryUsageLimiter>();

            if (hosts.Count > 0)
            {
                DistributedBinomialLadderFilterClient dblfClient = new DistributedBinomialLadderFilterClient(
                    options.NumberOfVirtualNodesForDistributedBinomialLadder,
                    options.HeightOfBinomialLadder_H,
                    hosts,
                    options.PrivateConfigurationKey,
                    options.MinimumBinomialLadderFilterCacheFreshness);
                // If running as a distributed system
                services.AddSingleton <IBinomialLadderFilter, DistributedBinomialLadderFilterClient>(x => dblfClient);

                DistributedBinomialLadderFilterController filterController =
                    new DistributedBinomialLadderFilterController(dblfClient, options.NumberOfBitsPerShardInBinomialLadderFilter, options.PrivateConfigurationKey);
                services.AddSingleton <DistributedBinomialLadderFilterController>(x => filterController);

                //services.AddSingleton<IFrequenciesProvider<string>>(x =>
                //    new IncorrectPasswordFrequencyClient(hosts, options.NumberOfRedundantHostsToCachePasswordPopularity));
            }
            else
            {
                BinomialLadderFilter localPasswordBinomialLadderFilter =
                    new BinomialLadderFilter(options.NumberOfBitsInBinomialLadderFilter_N, options.HeightOfBinomialLadder_H);
                services.AddSingleton <IBinomialLadderFilter>(x => localPasswordBinomialLadderFilter);
            }

            LoginAttemptClient <DbUserAccount> loginAttemptClient = new LoginAttemptClient <DbUserAccount>(hosts, localHost);

            services.AddSingleton <IUserAccountRepositoryFactory <DbUserAccount>, DbUserAccountRepositoryFactory>();
            services.AddSingleton <IUserAccountControllerFactory <DbUserAccount>, DbUserAccountControllerFactory>();
            //LoginAttemptController<DbUserAccount> loginAttemptController = new LoginAttemptController<DbUserAccount>(
            //     new DbUserAccountControllerFactory(cloudStorageAccount), new DbUserAccountRepositoryFactory());
            services.AddSingleton <ILoginAttemptClient, LoginAttemptClient <DbUserAccount> >(i => loginAttemptClient);
            services.AddSingleton <ILoginAttemptController, LoginAttemptController <DbUserAccount> >();
        }