Exemple #1
0
        public void Initialize()
        {
            _logManager            = new OneLoggerLogManager(new SimpleConsoleLogger());
            _configurationProvider = new JsonConfigProvider();
            ((NetworkConfig)_configurationProvider.GetConfig <NetworkConfig>()).DbBasePath = Path.Combine(Path.GetTempPath(), "PeerManagerTests");
            if (!Directory.Exists(_configurationProvider.GetConfig <NetworkConfig>().DbBasePath))
            {
                Directory.CreateDirectory(_configurationProvider.GetConfig <NetworkConfig>().DbBasePath);
            }
            _nodeFactory = new NodeFactory();
            _localPeer   = new TestRlpxPeer();
            var keyProvider = new PrivateKeyProvider(new CryptoRandom());
            var key         = keyProvider.PrivateKey.PublicKey;

            _synchronizationManager = Substitute.For <ISynchronizationManager>();

            var nodeTable = new NodeTable(_nodeFactory, Substitute.For <IKeyStore>(), new NodeDistanceCalculator(_configurationProvider), _configurationProvider, _logManager);

            nodeTable.Initialize(new NodeId(key));

            _discoveryManager = new DiscoveryManager(new NodeLifecycleManagerFactory(_nodeFactory, nodeTable, new DiscoveryMessageFactory(_configurationProvider), Substitute.For <IEvictionManager>(), new NodeStatsProvider(_configurationProvider), _configurationProvider, _logManager), _nodeFactory, nodeTable, new DiscoveryStorage(_configurationProvider, _nodeFactory, _logManager, new PerfService(_logManager)), _configurationProvider, _logManager);
            _discoveryManager.MessageSender = Substitute.For <IMessageSender>();

            _peerManager = new PeerManager(_localPeer, _discoveryManager, _synchronizationManager, new NodeStatsProvider(_configurationProvider), new PeerStorage(_configurationProvider, _nodeFactory, _logManager, new PerfService(_logManager)), _nodeFactory, _configurationProvider, new PerfService(_logManager), _logManager);
        }
Exemple #2
0
        public void Initialize()
        {
            NetworkNodeDecoder.Init();
            _timestamp             = new Timestamp();
            _logManager            = new OneLoggerLogManager(new SimpleConsoleLogger());
            _configurationProvider = new ConfigProvider();
            INetworkConfig networkConfig = _configurationProvider.GetConfig <INetworkConfig>();

            networkConfig.DbBasePath = Path.Combine(Path.GetTempPath(), "PeerManagerTests");
            networkConfig.IsActivePeerTimerEnabled      = false;
            networkConfig.IsDiscoveryNodesPersistenceOn = false;
            networkConfig.IsPeersPersistenceOn          = false;

            if (!Directory.Exists(networkConfig.DbBasePath))
            {
                Directory.CreateDirectory(networkConfig.DbBasePath);
            }

            var   syncManager  = Substitute.For <ISynchronizationManager>();
            Block genesisBlock = Build.A.Block.Genesis.TestObject;

            syncManager.Head.Returns(genesisBlock.Header);
            syncManager.Genesis.Returns(genesisBlock.Header);

            _nodeFactory = new NodeFactory(LimboLogs.Instance);
            _localPeer   = new TestRlpxPeer();
            var keyProvider = new PrivateKeyGenerator(new CryptoRandom());
            var key         = keyProvider.Generate().PublicKey;

            _synchronizationManager = Substitute.For <ISynchronizationManager>();

            IStatsConfig statsConfig = _configurationProvider.GetConfig <IStatsConfig>();
            var          nodeTable   = new NodeTable(_nodeFactory, Substitute.For <IKeyStore>(), new NodeDistanceCalculator(networkConfig), networkConfig, _logManager);

            nodeTable.Initialize(new NodeId(key));

            _discoveryManager = new DiscoveryManager(new NodeLifecycleManagerFactory(_nodeFactory, nodeTable, new DiscoveryMessageFactory(networkConfig, _timestamp), Substitute.For <IEvictionManager>(), new NodeStatsProvider(_configurationProvider.GetConfig <IStatsConfig>(), _nodeFactory, _logManager, true), networkConfig, _logManager), _nodeFactory, nodeTable, new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)), networkConfig, _logManager);
            _discoveryManager.MessageSender = Substitute.For <IMessageSender>();
            _transactionPool = NullTransactionPool.Instance;
            _blockTree       = Substitute.For <IBlockTree>();
            var app = new DiscoveryApp(new NodesLocator(nodeTable, _discoveryManager, _configurationProvider, _logManager), _discoveryManager, _nodeFactory, nodeTable, Substitute.For <IMessageSerializationService>(), new CryptoRandom(), Substitute.For <INetworkStorage>(), networkConfig, _logManager, new PerfService(_logManager));

            app.Initialize(key);

            var sessionLogger = new PeerSessionLogger(_logManager, _configurationProvider, new PerfService(_logManager));

            sessionLogger.Init(Path.GetTempPath());
            var networkStorage = new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager));

            _peerManager = new PeerManager(_localPeer, app, _synchronizationManager, new NodeStatsProvider(statsConfig, _nodeFactory, _logManager, true), networkStorage, _nodeFactory, _configurationProvider, new PerfService(_logManager), _transactionPool, _logManager, sessionLogger);
            _peerManager.Init(true);
        }
Exemple #3
0
        public async Task Initialize()
        {
            _logManager            = new OneLoggerLogManager(new SimpleConsoleLogger());
            _configurationProvider = new JsonConfigProvider();
            ((NetworkConfig)_configurationProvider.GetConfig <INetworkConfig>()).DbBasePath = Path.Combine(Path.GetTempPath(), "PeerManagerTests");
            if (!Directory.Exists(_configurationProvider.GetConfig <INetworkConfig>().DbBasePath))
            {
                Directory.CreateDirectory(_configurationProvider.GetConfig <INetworkConfig>().DbBasePath);
            }

            var serializationService = Build.A.SerializationService().WithEncryptionHandshake().WithP2P().WithEth().TestObject;

            var   syncManager  = Substitute.For <ISynchronizationManager>();
            Block genesisBlock = Build.A.Block.Genesis.TestObject;

            syncManager.Head.Returns(genesisBlock.Header);
            syncManager.Genesis.Returns(genesisBlock.Header);

            _nodeFactory = new NodeFactory();
            _localPeer   = new TestRlpxPeer();
            var keyProvider = new PrivateKeyProvider(new CryptoRandom());
            var key         = keyProvider.PrivateKey.PublicKey;

            _synchronizationManager = Substitute.For <ISynchronizationManager>();

            var nodeTable = new NodeTable(_nodeFactory, Substitute.For <IKeyStore>(), new NodeDistanceCalculator(_configurationProvider), _configurationProvider, _logManager);

            nodeTable.Initialize(new NodeId(key));

            INetworkConfig networkConfig = _configurationProvider.GetConfig <INetworkConfig>();
            IStatsConfig   statsConfig   = _configurationProvider.GetConfig <IStatsConfig>();

            _discoveryManager = new DiscoveryManager(new NodeLifecycleManagerFactory(_nodeFactory, nodeTable, new DiscoveryMessageFactory(_configurationProvider), Substitute.For <IEvictionManager>(), new NodeStatsProvider(_configurationProvider.GetConfig <IStatsConfig>(), _nodeFactory, _logManager), _configurationProvider, _logManager), _nodeFactory, nodeTable, new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)), _configurationProvider, _logManager);
            _discoveryManager.MessageSender = Substitute.For <IMessageSender>();

            var networkStorage = new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager));

            _peerManager = new PeerManager(_localPeer, _discoveryManager, _synchronizationManager, new NodeStatsProvider(statsConfig, _nodeFactory, _logManager), networkStorage, _nodeFactory, _configurationProvider, new PerfService(_logManager), _logManager);
            _peerManager.Init(true);
        }