Beispiel #1
0
 public void Correctly_creates_topics_filter(IEnumerable <object> topics)
 {
     FilterBlock from   = new FilterBlock(100);
     FilterBlock to     = new FilterBlock(FilterBlockType.Latest);
     FilterStore store  = new FilterStore();
     LogFilter   filter = store.CreateLogFilter(from, to, null, topics);
 }
Beispiel #2
0
        public void TestFilterStore()
        {
            var start = new DateTime(1970, 1, 1, 0, 0, 0);
            var sb    = new StringBuilder();
            var env   = new Environment(start)
            {
                Logger = new StringWriter(sb)
            };
            var sto = new FilterStore(env, capacity: 1);

            env.Process(FilterStoreProducer(env, sto));
            env.Process(FilterStoreConsumerA(env, sto));
            env.Process(FilterStoreConsumerB(env, sto));
            env.Run(TimeSpan.FromSeconds(20));
            Assert.AreEqual(sb.ToString(),
                            @"4: Produce A
4: Consume A
6: Produce B
6: Consume B
10: Produce A
14: Consume A
14: Produce B
14: Consume B
18: Produce A
");
        }
 public void Correctly_creates_topics_filter(IEnumerable <object> topics)
 {
     BlockParameter from   = new BlockParameter(100);
     BlockParameter to     = new BlockParameter(BlockParameterType.Latest);
     FilterStore    store  = new FilterStore();
     LogFilter      filter = store.CreateLogFilter(from, to, null, topics);
 }
Beispiel #4
0
        private IEnumerable <Event> TestFilterCallsWorseCaseGetProcess(FilterStore store, Func <object, bool> filterLogger, List <string> log)
        {
            var req = store.Get(filterLogger);

            yield return(req);

            log.Add(string.Format("get {0}", req.Value));
        }
Beispiel #5
0
 private IEnumerable <Event> TestFilterCallsWorstCasePutProcess(FilterStore store, List <string> log)
 {
     for (var i = 0; i < 4; i++)
     {
         log.Add(string.Format("put {0}", i));
         yield return(store.Put(i));
     }
 }
Beispiel #6
0
        public void Can_save_and_load_log_filter()
        {
            FilterStore store  = new FilterStore();
            LogFilter   filter = store.CreateLogFilter(new FilterBlock(1), new FilterBlock(2));

            store.SaveFilter(filter);
            Assert.True(store.FilterExists(0), "exists");
            Assert.AreEqual(FilterType.LogFilter, store.GetFilterType(filter.Id), "type");
        }
Beispiel #7
0
        public void Cannot_overwrite_filters()
        {
            FilterStore store = new FilterStore();

            BlockFilter externalFilter = new BlockFilter(100, 1);

            store.SaveFilter(externalFilter);
            Assert.Throws <InvalidOperationException>(() => store.SaveFilter(externalFilter));
        }
Beispiel #8
0
        public void Can_save_and_load_block_filter()
        {
            FilterStore store  = new FilterStore();
            BlockFilter filter = store.CreateBlockFilter(1);

            store.SaveFilter(filter);
            Assert.True(store.FilterExists(0), "exists");
            Assert.AreEqual(FilterType.BlockFilter, store.GetFilterType(filter.Id), "type");
        }
Beispiel #9
0
        public void Correctly_creates_address_filter(object address, AddressFilter expected)
        {
            FilterBlock from   = new FilterBlock(100);
            FilterBlock to     = new FilterBlock(FilterBlockType.Latest);
            FilterStore store  = new FilterStore();
            LogFilter   filter = store.CreateLogFilter(from, to, address);

            filter.AddressFilter.Should().BeEquivalentTo(expected);
        }
Beispiel #10
0
        private IEnumerable <Event> FilterStoreConsumerB(Environment env, FilterStore sto)
        {
            while (true)
            {
                yield return(sto.Get(x => x == FilterStoreObjB));

                env.Log("{0}: Consume B", env.Now.Second);
                yield return(env.Timeout(TimeSpan.FromSeconds(3)));
            }
        }
 public void TestFilterCallsBestCase()
 {
     var env = new Environment();
       var store = new FilterStore(env, new object[] { 1, 2, 3 }, 3);
       var log = new List<string>();
       Func<object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return true; };
       env.Process(TestFilterCallsBestCaseProcess(store, filterLogger, log));
       env.Run();
       Assert.IsTrue(log.SequenceEqual(new[] { "check 1", "get 1", "check 2", "get 2", "check 3", "get 3" }));
 }
Beispiel #12
0
        SimEvents StorePutter_SameEvent(FilterStore <int> store)
        {
            var putEv = store.Put(0);

            while (true)
            {
                yield return(putEv);

                yield return(Env.Timeout(1));
            }
        }
        protected override async Task <TestBlockchain> Build(ISpecProvider specProvider = null)
        {
            await base.Build();

            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, BlockProcessor, TxPool, LimboLogs.Instance);

            Bridge ??= new BlockchainBridge(StateReader, State, Storage, BlockTree, TxPool, ReceiptStorage, filterStore, filterManager, NullWallet.Instance, TxProcessor, EthereumEcdsa, NullBloomStorage.Instance, LimboLogs.Instance, false);
            EthModule = new EthModule(new JsonRpcConfig(), Bridge, LimboLogs.Instance);
            return(this);
        }
Beispiel #14
0
    protected void FilterStore_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        if (gridPanel == null)
        {
            gridPanel = GridController.GetInstance().GetGridPanel(GridPanelName);
        }
        List <GridFilterPermissionInfo> rsList = gridPanel.GetAllFilter(-1);

        FilterStore.DataSource = rsList;
        FilterStore.DataBind();
    }
Beispiel #15
0
        public void TestFilterCallsBestCase()
        {
            var env   = new Environment();
            var store = new FilterStore(env, new object[] { 1, 2, 3 }, 3);
            var log   = new List <string>();
            Func <object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return(true); };

            env.Process(TestFilterCallsBestCaseProcess(store, filterLogger, log));
            env.Run();
            Assert.IsTrue(log.SequenceEqual(new[] { "check 1", "get 1", "check 2", "get 2", "check 3", "get 3" }));
        }
Beispiel #16
0
        public void TestFilterStoreGetAfterMismatch()
        {
            var env   = new Environment(new DateTime(2014, 1, 1));
            var store = new FilterStore(env, capacity: 2);
            var proc1 = env.Process(TestFilterStoreGetAfterMismatch_Getter(env, store, 1));
            var proc2 = env.Process(TestFilterStoreGetAfterMismatch_Getter(env, store, 2));

            env.Process(TestFilterStoreGetAfterMismatch_Putter(env, store));
            env.Run();
            Assert.AreEqual(proc1.Value, 1);
            Assert.AreEqual(proc2.Value, 0);
        }
Beispiel #17
0
        SimEvents StoreGetter_SameEvent(FilterStore <int> store)
        {
            var getEv = store.Get();

            while (true)
            {
                yield return(store.Put(5));

                yield return(getEv);

                yield return(Env.Timeout(1));
            }
        }
Beispiel #18
0
        public void Remove_filter_removes_and_notifies()
        {
            FilterStore store  = new FilterStore();
            BlockFilter filter = store.CreateBlockFilter(1);

            store.SaveFilter(filter);
            bool hasNotified = false;

            store.FilterRemoved += (s, e) => hasNotified = true;
            store.RemoveFilter(0);

            Assert.True(hasNotified, "notied");
            Assert.False(store.FilterExists(0), "exists");
        }
Beispiel #19
0
        public void Ids_are_incremented_when_storing_externally_created_filter()
        {
            FilterStore store = new FilterStore();

            BlockFilter externalFilter = new BlockFilter(100, 1);

            store.SaveFilter(externalFilter);
            LogFilter filter = store.CreateLogFilter(new FilterBlock(1), new FilterBlock(2));

            store.SaveFilter(filter);

            Assert.True(store.FilterExists(100), "exists 100");
            Assert.True(store.FilterExists(101), "exists 101");
            Assert.AreEqual(FilterType.LogFilter, store.GetFilterType(filter.Id), "type");
        }
Beispiel #20
0
        SimEvents StorePutter(FilterStore <int> store, int putCount, int timeout)
        {
            Debug.Assert(putCount >= 0);
            Debug.Assert(timeout >= 0);
            for (var i = 0; i < putCount; ++i)
            {
                Integers.Add(i);
                yield return(store.Put(i));

                if (timeout > 0)
                {
                    yield return(Env.Timeout(timeout));
                }
            }
        }
Beispiel #21
0
        SimEvents StoreGetter(FilterStore <int> store, int getCount, int timeout)
        {
            Debug.Assert(getCount >= 0);
            Debug.Assert(timeout >= 0);
            for (var i = 0; i < getCount; ++i)
            {
                var getEv = store.Get();
                yield return(getEv);

                Assert.AreEqual(Integers[GetIdx++], getEv.Value);
                if (timeout > 0)
                {
                    yield return(Env.Timeout(timeout));
                }
            }
        }
 public void TestFilterCallsWorstCase()
 {
     var env = new Environment();
       var store = new FilterStore(env, 4);
       var log = new List<string>();
       Func<object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return (int)o >= 3; };
       env.Process(TestFilterCallsWorseCaseGetProcess(store, filterLogger, log));
       env.Process(TestFilterCallsWorstCasePutProcess(store, log));
       env.Run();
       Assert.IsTrue(log.SequenceEqual(new[] {
     "put 0", "check 0",
     "put 1", "check 0", "check 1",
     "put 2", "check 0", "check 1", "check 2",
     "put 3", "check 0", "check 1", "check 2", "check 3", "get 3"
       }));
 }
Beispiel #23
0
        private IEnumerable <Event> FilterStoreProducer(Environment env, FilterStore sto)
        {
            while (true)
            {
                yield return(env.Timeout(TimeSpan.FromSeconds(4)));

                yield return(sto.Put(FilterStoreObjA));

                env.Log("{0}: Produce A", env.Now.Second);
                yield return(env.Timeout(TimeSpan.FromSeconds(2)));

                yield return(sto.Put(FilterStoreObjB));

                env.Log("{0}: Produce B", env.Now.Second);
            }
        }
Beispiel #24
0
        private IEnumerable <Event> TestFilterCallsBestCaseProcess(FilterStore store, Func <object, bool> filter, List <string> log)
        {
            var get = store.Get(filter);

            yield return(get);

            log.Add(string.Format("get {0}", get.Value));
            get = store.Get(filter);
            yield return(get);

            log.Add(string.Format("get {0}", get.Value));
            get = store.Get(filter);
            yield return(get);

            log.Add(string.Format("get {0}", get.Value));
        }
Beispiel #25
0
        protected override async Task <TestBlockchain> Build(ISpecProvider specProvider = null)
        {
            BloomStorage bloomStorage = new BloomStorage(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());

            specProvider ??= MainnetSpecProvider.Instance;
            await base.Build(specProvider);

            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, BlockProcessor, TxPool, LimboLogs.Instance);

            LogFinder = new LogFinder(BlockTree, ReceiptStorage, bloomStorage, LimboLogs.Instance, new ReceiptsRecovery());
            Bridge ??= new BlockchainBridge(StateReader, State, Storage, BlockTree, TxPool, ReceiptStorage, filterStore, filterManager, TestWallet, TxProcessor, EthereumEcdsa, NullBloomStorage.Instance, Timestamper, LimboLogs.Instance, false);
            TxPoolBridge ??= new TxPoolBridge(TxPool, TestWallet, Timestamper, specProvider?.ChainId ?? 0);

            EthModule = new EthModule(new JsonRpcConfig(), Bridge, TxPoolBridge, LimboLogs.Instance);
            return(this);
        }
Beispiel #26
0
        public void TestFilterCallsWorstCase()
        {
            var env   = new Environment();
            var store = new FilterStore(env, 4);
            var log   = new List <string>();
            Func <object, bool> filterLogger = o => { log.Add(string.Format("check {0}", o)); return((int)o >= 3); };

            env.Process(TestFilterCallsWorseCaseGetProcess(store, filterLogger, log));
            env.Process(TestFilterCallsWorstCasePutProcess(store, log));
            env.Run();
            Assert.IsTrue(log.SequenceEqual(new[] {
                "put 0", "check 0",
                "put 1", "check 0", "check 1",
                "put 2", "check 0", "check 1", "check 2",
                "put 3", "check 0", "check 1", "check 2", "check 3", "get 3"
            }));
        }
Beispiel #27
0
        public static IServices Init(RequiredServices services)
        {
            AddDecoders();
            var config          = services.NdmConfig;
            var providerAddress = string.IsNullOrWhiteSpace(config.ProviderAddress)
                ? Address.Zero
                : new Address(config.ProviderAddress);
            var consumerAddress = string.IsNullOrWhiteSpace(config.ConsumerAddress)
                ? Address.Zero
                : new Address(config.ConsumerAddress);

            UnlockHardcodedAccounts(providerAddress, consumerAddress, services.Wallet);
            var readOnlyDbProvider = new ReadOnlyDbProvider(services.RocksProvider, false);
            var filterStore        = new FilterStore();
            var filterManager      = new FilterManager(filterStore, services.BlockProcessor, services.TransactionPool,
                                                       services.LogManager);
            var state = new RpcState(services.BlockTree, services.SpecProvider, readOnlyDbProvider,
                                     services.LogManager);
            var blockchainBridge = new BlockchainBridge(
                state.StateReader,
                state.StateProvider,
                state.StorageProvider,
                state.BlockTree,
                services.TransactionPool,
                services.TransactionPoolInfoProvider,
                services.ReceiptStorage,
                filterStore,
                filterManager,
                services.Wallet,
                state.TransactionProcessor,
                services.Ecdsa);
            var dataHeaderRlpDecoder = new DataHeaderDecoder();
            var encoder        = new AbiEncoder();
            var depositService = new DepositService(blockchainBridge, encoder, services.Wallet, config,
                                                    LimboLogs.Instance);
            var ndmConsumerChannelManager = services.NdmConsumerChannelManager;
            var ndmDataPublisher          = services.NdmDataPublisher;
            var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel();

//            ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel);

            return(new Services(services, new CreatedServices(consumerAddress, encoder, dataHeaderRlpDecoder,
                                                              depositService, ndmDataPublisher, jsonRpcNdmConsumerChannel, ndmConsumerChannelManager,
                                                              blockchainBridge)));
        }
Beispiel #28
0
        public void Can_get_filters_by_type()
        {
            FilterStore store   = new FilterStore();
            BlockFilter filter1 = store.CreateBlockFilter(1);

            store.SaveFilter(filter1);
            LogFilter filter2 = store.CreateLogFilter(new FilterBlock(1), new FilterBlock(2));

            store.SaveFilter(filter2);

            LogFilter[]   logFilters   = store.GetFilters <LogFilter>();
            BlockFilter[] blockFilters = store.GetFilters <BlockFilter>();

            Assert.AreEqual(1, logFilters.Length, "log filters length");
            Assert.AreEqual(1, logFilters[0].Id, "log filters ids");
            Assert.AreEqual(1, blockFilters.Length, "block Filters length");
            Assert.AreEqual(0, blockFilters[0].Id, "block filters ids");
        }
Beispiel #29
0
        protected override async Task <TestBlockchain> Build(ISpecProvider specProvider = null, UInt256?initialValues = null)
        {
            BloomStorage bloomStorage = new BloomStorage(new BloomConfig(), new MemDb(), new InMemoryDictionaryFileStoreFactory());

            specProvider ??= MainnetSpecProvider.Instance;
            await base.Build(specProvider, initialValues);

            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, BlockProcessor, TxPool, LimboLogs.Instance);

            ReceiptsRecovery receiptsRecovery = new ReceiptsRecovery(new EthereumEcdsa(specProvider.ChainId, LimboLogs.Instance), specProvider);

            LogFinder = new LogFinder(BlockTree, ReceiptStorage, bloomStorage, LimboLogs.Instance, receiptsRecovery);

            ReadOnlyTxProcessingEnv processingEnv = new ReadOnlyTxProcessingEnv(
                new ReadOnlyDbProvider(DbProvider, false),
                new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly(),
                new ReadOnlyBlockTree(BlockTree),
                SpecProvider,
                LimboLogs.Instance);

            Bridge ??= new BlockchainBridge(processingEnv, TxPool, ReceiptStorage, filterStore, filterManager, EthereumEcdsa, Timestamper, LogFinder, SpecProvider, false, false);
            BlockFinder ??= BlockTree;

            ITxSigner txSigner  = new WalletTxSigner(TestWallet, specProvider?.ChainId ?? 0);
            ITxSealer txSealer0 = new TxSealer(txSigner, Timestamper);
            ITxSealer txSealer1 = new NonceReservingTxSealer(txSigner, Timestamper, TxPool);

            TxSender ??= new TxPoolSender(TxPool, txSealer0, txSealer1);

            EthRpcModule = new EthRpcModule(
                new JsonRpcConfig(),
                Bridge,
                BlockFinder,
                StateReader,
                TxPool,
                TxSender,
                TestWallet,
                LimboLogs.Instance,
                SpecProvider);

            return(this);
        }
 public void TestFilterStore()
 {
     var start = new DateTime(1970, 1, 1, 0, 0, 0);
       var sb = new StringBuilder();
       var env = new Environment(start) {
     Logger = new StringWriter(sb)
       };
       var sto = new FilterStore(env, capacity: 1);
       env.Process(FilterStoreProducer(env, sto));
       env.Process(FilterStoreConsumerA(env, sto));
       env.Process(FilterStoreConsumerB(env, sto));
       env.Run(TimeSpan.FromSeconds(20));
       Assert.AreEqual(sb.ToString(),
     @"4: Produce A
     4: Consume A
     6: Produce B
     6: Consume B
     10: Produce A
     14: Consume A
     14: Produce B
     14: Consume B
     18: Produce A
     ");
 }
Beispiel #31
0
        private List <Namespace> Filter(IEnumerable <Namespace> namespaces, FilterStore filterStore, FrameworkIndex frameworks)
        {
            var filteredNS = namespaces.ToList();

            foreach (var ns in filteredNS)
            {
                if (ns.Types?.Count > 0)
                {
                    ns.Types = ns.Types.Where(t =>
                    {
                        bool expose = true;
                        if (filterStore?.TypeFilters?.Count > 0)
                        {
                            var applicableFilters = filterStore.TypeFilters.Where(tf => tf.Filter(t).HasValue).ToList();
                            if (applicableFilters.Count == 1)
                            {
                                expose = applicableFilters.First().Filter(t).Value;
                            }
                            else if (applicableFilters.Count > 1)
                            {
                                var filtersPerNS = applicableFilters.GroupBy(tf => tf.Namespace).Select(tfg => tfg.FirstOrDefault(tf => tf.Name != "*") ?? tfg.First()).ToList();
                                foreach (var filter in filtersPerNS)
                                {
                                    expose = expose && filter.Filter(t).Value;
                                }
                            }
                        }

                        return(expose && frameworks.DocIdToFrameworkDict.ContainsKey(t.DocId));
                    }).ToList();
                }
            }
            filteredNS = filteredNS.Where(ns => ns.Types?.Count > 0 && frameworks.DocIdToFrameworkDict.ContainsKey(ns.CommentId)).ToList();
            foreach (var ns in filteredNS)
            {
                foreach (var t in ns.Types)
                {
                    if (t.Members?.Count > 0)
                    {
                        t.Members = t.Members.Where(m =>
                        {
                            bool expose = true;
                            if (filterStore?.MemberFilters?.Count > 0)
                            {
                                foreach (var filter in filterStore.MemberFilters.Where(mf => mf.Filter(m).HasValue))
                                {
                                    expose = expose && filter.Filter(m).Value;
                                }
                            }
                            return(expose && frameworks.DocIdToFrameworkDict.ContainsKey(m.DocId));;
                        }).ToList();
                    }
                }
            }
            //workaournd for https://github.com/mono/api-doc-tools/issues/89, bug #1022788
            foreach (var ns in filteredNS)
            {
                foreach (var t in ns.Types)
                {
                    if (t.Signatures.IsPublishSealedClass)
                    {
                        t.Members = t.Members.Where(m => !m.Signatures.IsProtected).ToList();
                    }
                }
            }
            return(filteredNS);
        }
Beispiel #32
0
        private void RegisterJsonRpcModules()
        {
            if (!_initConfig.JsonRpcEnabled)
            {
                return;
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Resolving CLI ({nameof(Cli.CliModuleLoader)})");
            }

            IReadOnlyDbProvider rpcDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            AlternativeChain    rpcChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, _transactionPool, _receiptStorage);

            ITracer        tracer        = new Tracer(rpcChain.Processor, _receiptStorage, _blockTree, _dbProvider.TraceDb);
            IFilterStore   filterStore   = new FilterStore();
            IFilterManager filterManager = new FilterManager(filterStore, _blockProcessor, _transactionPool, _logManager);

            RpcState rpcState = new RpcState(_blockTree, _specProvider, rpcDbProvider, _logManager);

            //creating blockchain bridge
            var blockchainBridge = new BlockchainBridge(
                rpcState.StateReader,
                rpcState.StateProvider,
                rpcState.StorageProvider,
                rpcState.BlockTree,
                _transactionPool,
                _transactionPoolInfoProvider,
                _receiptStorage,
                filterStore,
                filterManager,
                _wallet,
                rpcState.TransactionProcessor);

            TransactionPool debugTransactionPool = new TransactionPool(new PersistentTransactionStorage(_dbProvider.PendingTxsDb, _specProvider),
                                                                       new PendingTransactionThresholdValidator(_initConfig.ObsoletePendingTransactionInterval, _initConfig.RemovePendingTransactionInterval),
                                                                       _timestamp,
                                                                       _ethereumEcdsa,
                                                                       _specProvider,
                                                                       _logManager,
                                                                       _initConfig.RemovePendingTransactionInterval,
                                                                       _initConfig.PeerNotificationThreshold);

            var debugReceiptStorage             = new PersistentReceiptStorage(_dbProvider.ReceiptsDb, _specProvider);
            AlternativeChain    debugChain      = new AlternativeChain(_blockTree, _blockValidator, _rewardCalculator, _specProvider, rpcDbProvider, _recoveryStep, _logManager, debugTransactionPool, debugReceiptStorage);
            IReadOnlyDbProvider debugDbProvider = new ReadOnlyDbProvider(_dbProvider, false);
            var debugBridge = new DebugBridge(_configProvider, debugDbProvider, tracer, debugChain.Processor);

            EthModule module = new EthModule(_jsonSerializer, _configProvider, _logManager, blockchainBridge);

            _rpcModuleProvider.Register <IEthModule>(module);

            DebugModule debugModule = new DebugModule(_configProvider, _logManager, debugBridge, _jsonSerializer);

            _rpcModuleProvider.Register <IDebugModule>(debugModule);

            if (_sealer is CliqueSealer)
            {
                CliqueModule cliqueModule = new CliqueModule(_configProvider, _logManager, _jsonSerializer, new CliqueBridge(_blockProducer as ICliqueBlockProducer, _snapshotManager, _blockTree));
                _rpcModuleProvider.Register <ICliqueModule>(cliqueModule);
            }

            if (_initConfig.EnableUnsecuredDevWallet)
            {
                PersonalBridge personalBridge = new PersonalBridge(_wallet);
                PersonalModule personalModule = new PersonalModule(personalBridge, _configProvider, _logManager, _jsonSerializer);
                _rpcModuleProvider.Register <IPersonalModule>(personalModule);
            }

            AdminModule adminModule = new AdminModule(_configProvider, _logManager, _jsonSerializer);

            _rpcModuleProvider.Register <IAdminModule>(adminModule);

            TxPoolModule txPoolModule = new TxPoolModule(_configProvider, _logManager, _jsonSerializer, blockchainBridge);

            _rpcModuleProvider.Register <ITxPoolModule>(txPoolModule);

            if (_initConfig.NetworkEnabled && _initConfig.SynchronizationEnabled)
            {
                NetModule netModule = new NetModule(_configProvider, _logManager, _jsonSerializer, new NetBridge(_enode, _syncManager, _peerManager));
                _rpcModuleProvider.Register <INetModule>(netModule);
            }

            TraceModule traceModule = new TraceModule(_configProvider, _logManager, _jsonSerializer, tracer);

            _rpcModuleProvider.Register <ITraceModule>(traceModule);
        }
 public void TestFilterStoreGetAfterMismatch()
 {
     var env = new Environment(new DateTime(2014, 1, 1));
       var store = new FilterStore(env, capacity: 2);
       var proc1 = env.Process(TestFilterStoreGetAfterMismatch_Getter(env, store, 1));
       var proc2 = env.Process(TestFilterStoreGetAfterMismatch_Getter(env, store, 2));
       env.Process(TestFilterStoreGetAfterMismatch_Putter(env, store));
       env.Run();
       Assert.AreEqual(proc1.Value, 1);
       Assert.AreEqual(proc2.Value, 0);
 }
 private IEnumerable<Event> FilterStoreConsumerB(Environment env, FilterStore sto)
 {
     while (true) {
     yield return sto.Get(x => x == FilterStoreObjB);
     env.Log("{0}: Consume B", env.Now.Second);
     yield return env.Timeout(TimeSpan.FromSeconds(3));
       }
 }
Beispiel #35
0
        private FilterStore LoadFilters(string path)
        {
            var filterFile = Path.Combine(path, "_filter.xml");

            if (_fileAccessor.Exists(filterFile))
            {
                var       filterStore = new FilterStore();
                XDocument filterDoc   = XDocument.Parse(_fileAccessor.ReadAllText(filterFile));
                var       attrFilter  = filterDoc.Root.Element("attributeFilter");
                if (attrFilter != null && attrFilter.Attribute("apply").Value == "true")
                {
                    var attrFilterElements = attrFilter.Elements("namespaceFilter");
                    if (attrFilterElements != null)
                    {
                        filterStore.AttributeFilters = new List <AttributeFilter>();
                        foreach (var fElement in attrFilterElements)
                        {
                            AttributeFilter filter = new AttributeFilter()
                            {
                                Namespace    = fElement.Attribute("name").Value,
                                TypeFilters  = new Dictionary <string, bool>(),
                                DefaultValue = true
                            };
                            foreach (var tFiler in fElement.Elements("typeFilter"))
                            {
                                bool expose = false;
                                bool.TryParse(tFiler.Attribute("expose").Value, out expose);
                                string name = tFiler.Attribute("name").Value;
                                if (name == "*")
                                {
                                    filter.DefaultValue = expose;
                                }
                                else
                                {
                                    filter.TypeFilters[name] = expose;
                                }
                            }
                            filterStore.AttributeFilters.Add(filter);
                        }
                    }
                }
                var apiFilter = filterDoc.Root.Element("apiFilter");
                if (apiFilter != null && apiFilter.Attribute("apply").Value == "true")
                {
                    var apiFilterElements = apiFilter.Elements("namespaceFilter");
                    if (apiFilterElements != null)
                    {
                        filterStore.TypeFilters   = new List <TypeFilter>();
                        filterStore.MemberFilters = new List <MemberFilter>();
                        foreach (var fElement in apiFilterElements)
                        {
                            var nsName = fElement.Attribute("name").Value?.Trim();
                            foreach (var tElement in fElement.Elements("typeFilter"))
                            {
                                var tFilter = new TypeFilter(tElement)
                                {
                                    Namespace = nsName
                                };
                                filterStore.TypeFilters.Add(tFilter);

                                var memberFilterElements = tElement.Elements("memberFilter");
                                if (memberFilterElements != null)
                                {
                                    foreach (var mElement in memberFilterElements)
                                    {
                                        filterStore.MemberFilters.Add(new MemberFilter(mElement)
                                        {
                                            Parent = tFilter
                                        });
                                    }
                                }
                            }
                        }
                    }
                }
                return(filterStore);
            }

            return(null);
        }
 private IEnumerable<Event> TestFilterStoreGetAfterMismatch_Putter(Environment env, FilterStore store)
 {
     yield return store.Put(2);
       yield return env.Timeout(TimeSpan.FromSeconds(1));
       yield return store.Put(1);
 }
 private IEnumerable<Event> FilterStoreProducer(Environment env, FilterStore sto)
 {
     while (true) {
     yield return env.Timeout(TimeSpan.FromSeconds(4));
     yield return sto.Put(FilterStoreObjA);
     env.Log("{0}: Produce A", env.Now.Second);
     yield return env.Timeout(TimeSpan.FromSeconds(2));
     yield return sto.Put(FilterStoreObjB);
     env.Log("{0}: Produce B", env.Now.Second);
       }
 }
 private IEnumerable<Event> TestFilterCallsBestCaseProcess(FilterStore store, Func<object, bool> filter, List<string> log)
 {
     var get = store.Get(filter);
       yield return get;
       log.Add(string.Format("get {0}", get.Value));
       get = store.Get(filter);
       yield return get;
       log.Add(string.Format("get {0}", get.Value));
       get = store.Get(filter);
       yield return get;
       log.Add(string.Format("get {0}", get.Value));
 }
 private IEnumerable<Event> TestFilterCallsWorseCaseGetProcess(FilterStore store, Func<object, bool> filterLogger, List<string> log)
 {
     var req = store.Get(filterLogger);
       yield return req;
       log.Add(string.Format("get {0}", req.Value));
 }
 private IEnumerable<Event> TestFilterCallsWorstCasePutProcess(FilterStore store, List<string> log)
 {
     for (var i = 0; i < 4; i++) {
     log.Add(string.Format("put {0}", i));
     yield return store.Put(i);
       }
 }
 private IEnumerable<Event> TestFilterStoreGetAfterMismatch_Getter(Environment env, FilterStore store, int value)
 {
     yield return store.Get(x => (int)x == value);
       env.ActiveProcess.Succeed(env.Now.Second);
 }