Пример #1
0
        public void Setup()
        {
            var path       = "test-static-nodes.json";
            var logManager = LimboLogs.Instance;

            _staticNodesManager = new StaticNodesManager(path, logManager);
        }
        public void Setup()
        {
            var path       = Path.Combine(TestContext.CurrentContext.WorkDirectory, "test-static-nodes.json");
            var logManager = LimboLogs.Instance;

            _staticNodesManager = new StaticNodesManager(path, logManager);
        }
Пример #3
0
        public async Task init_should_load_static_nodes_from_empty_file()
        {
            using var tempFile = TempPath.GetTempFile();
            await File.WriteAllTextAsync(tempFile.Path, string.Empty);

            _staticNodesManager = new StaticNodesManager(tempFile.Path, LimboLogs.Instance);
            await _staticNodesManager.InitAsync();

            _staticNodesManager.Nodes.Count().Should().Be(0);
        }
Пример #4
0
        public AdminModule(IBlockTree blockTree, INetworkConfig networkConfig, IPeerManager peerManager, IStaticNodesManager staticNodesManager, IEnode enode, string dataDir)
        {
            _blockTree          = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _networkConfig      = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
            _peerManager        = peerManager ?? throw new ArgumentNullException(nameof(peerManager));
            _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager));
            _enode   = enode ?? throw new ArgumentNullException(nameof(enode));
            _dataDir = dataDir ?? throw new ArgumentNullException(nameof(dataDir));

            BuildNodeInfo();
        }
Пример #5
0
 public void SetUp()
 {
     _rlpxPeer      = new RlpxMock(_sessions);
     _discoveryApp  = Substitute.For <IDiscoveryApp>();
     _stats         = new NodeStatsManager(new StatsConfig(), LimboLogs.Instance);
     _storage       = new InMemoryStorage();
     _peerLoader    = new PeerLoader(new NetworkConfig(), new DiscoveryConfig(), _stats, _storage, LimboLogs.Instance);
     _networkConfig = new NetworkConfig();
     _networkConfig.PeersPersistenceInterval = 50;
     _staticNodesManager = Substitute.For <IStaticNodesManager>();
     _peerManager        = new PeerManager(_rlpxPeer, _discoveryApp, _stats, _storage, _peerLoader, _networkConfig,
                                           LimboLogs.Instance, _staticNodesManager);
 }
Пример #6
0
        public void Setup()
        {
            _blockTree     = Build.A.BlockTree().OfChainLength(5).TestObject;
            _networkConfig = new NetworkConfig();
            IPeerManager peerManager = Substitute.For <IPeerManager>();

            peerManager.ActivePeers.Returns(new List <Peer> {
                new Peer(new Node("127.0.0.1", 30303, true))
            });

            IStaticNodesManager staticNodesManager = Substitute.For <IStaticNodesManager>();
            Enode enode = new Enode(_enodeString);

            _adminRpcModule = new AdminRpcModule(_blockTree, _networkConfig, peerManager, staticNodesManager, enode, _exampleDataDir);
            _serializer     = new EthereumJsonSerializer();
        }
        public async Task init_should_load_static_nodes_from_empty_file()
        {
            var path = Path.GetTempFileName();
            await File.WriteAllTextAsync(path, string.Empty);

            try
            {
                _staticNodesManager = new StaticNodesManager(path, LimboLogs.Instance);
                await _staticNodesManager.InitAsync();

                _staticNodesManager.Nodes.Count().Should().Be(0);
            }
            finally
            {
                File.Delete(path);
            }
        }
Пример #8
0
        public AdminRpcModule(
            IBlockTree blockTree,
            INetworkConfig networkConfig,
            IPeerPool peerPool,
            IStaticNodesManager staticNodesManager,
            IEnode enode,
            string dataDir,
            ManualPruningTrigger pruningTrigger)
        {
            _enode              = enode ?? throw new ArgumentNullException(nameof(enode));
            _dataDir            = dataDir ?? throw new ArgumentNullException(nameof(dataDir));
            _blockTree          = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
            _peerPool           = peerPool ?? throw new ArgumentNullException(nameof(peerPool));
            _networkConfig      = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
            _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager));
            _pruningTrigger     = pruningTrigger;

            BuildNodeInfo();
        }
Пример #9
0
 public PeerManager(
     IRlpxPeer rlpxPeer,
     IDiscoveryApp discoveryApp,
     INodeStatsManager stats,
     INetworkStorage peerStorage,
     IPeerLoader peerLoader,
     INetworkConfig networkConfig,
     ILogManager logManager,
     IStaticNodesManager staticNodesManager)
 {
     _logger             = logManager.GetClassLogger();
     _rlpxPeer           = rlpxPeer ?? throw new ArgumentNullException(nameof(rlpxPeer));
     _stats              = stats ?? throw new ArgumentNullException(nameof(stats));
     _discoveryApp       = discoveryApp ?? throw new ArgumentNullException(nameof(discoveryApp));
     _networkConfig      = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
     _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager));
     _peerStorage        = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage));
     _peerLoader         = peerLoader ?? throw new ArgumentNullException(nameof(peerLoader));
     _peerStorage.StartBatch();
     _peerPool = new LocalPeerPool(_logger);
 }
Пример #10
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HelloMessageSerializer)));

            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Ecdsa(), _nodeKey, _logManager);

            var networkConfig   = _configProvider.GetConfig <INetworkConfig>();
            var discoveryConfig = _configProvider.GetConfig <IDiscoveryConfig>();

            _sessionMonitor = new SessionMonitor(networkConfig, _logManager);
            _rlpxPeer       = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _sessionMonitor);

            await _rlpxPeer.Init();

            _staticNodesManager = new StaticNodesManager(_initConfig.StaticNodesPath, _logManager);
            await _staticNodesManager.InitAsync();

            var peersDb     = new SimpleFilePublicKeyDb(PeersDbPath, _logManager);
            var peerStorage = new NetworkStorage(peersDb, _logManager);

            ProtocolValidator protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, _logManager);

            _protocolsManager = new ProtocolsManager(_syncPeerPool, _syncServer, _txPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);
            PeerLoader peerLoader = new PeerLoader(networkConfig, discoveryConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager, _staticNodesManager);
            _peerManager.Init();
        }
Пример #11
0
        public void Setup()
        {
            _blockTree     = Build.A.BlockTree().OfChainLength(5).TestObject;
            _networkConfig = new NetworkConfig();
            IPeerPool peerPool = Substitute.For <IPeerPool>();
            ConcurrentDictionary <PublicKey, Peer> dict = new();

            dict.TryAdd(TestItem.PublicKeyA, new Peer(new Node(TestItem.PublicKeyA, "127.0.0.1", 30303, true)));
            peerPool.ActivePeers.Returns(dict);

            IStaticNodesManager staticNodesManager = Substitute.For <IStaticNodesManager>();
            Enode enode = new(_enodeString);

            _adminRpcModule = new AdminRpcModule(
                _blockTree,
                _networkConfig,
                peerPool,
                staticNodesManager,
                enode,
                _exampleDataDir,
                new ManualPruningTrigger());

            _serializer = new EthereumJsonSerializer();
        }
Пример #12
0
        private async Task InitPeer()
        {
            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HelloMessageSerializer)));

            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Ecdsa(), _nodeKey, _logManager);

            _messageSerializationService.Register(Assembly.GetAssembly(typeof(HiMessageSerializer)));

            var networkConfig   = _configProvider.GetConfig <INetworkConfig>();
            var discoveryConfig = _configProvider.GetConfig <IDiscoveryConfig>();

            _sessionMonitor = new SessionMonitor(networkConfig, _logManager);
            _rlpxPeer       = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _sessionMonitor);

            await _rlpxPeer.Init();

            _staticNodesManager = new StaticNodesManager(_initConfig.StaticNodesPath, _logManager);
            await _staticNodesManager.InitAsync();

            var peersDb     = new SimpleFilePublicKeyDb(Path.Combine(_initConfig.BaseDbPath, PeersDbPath), _logManager);
            var peerStorage = new NetworkStorage(peersDb, _logManager);

            ProtocolValidator protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, _logManager);

            _protocolsManager = new ProtocolsManager(_syncPeerPool, _syncServer, _txPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);

            if (!(_ndmInitializer is null))
            {
                if (_logger.IsInfo)
                {
                    _logger.Info($"Initializing NDM...");
                }
                var capabilityConnector = await _ndmInitializer.InitAsync(_configProvider, _dbProvider,
                                                                          _initConfig.BaseDbPath, _blockProcessor, _blockTree, _txPool, _txPoolInfoProvider, _specProvider,
                                                                          _receiptStorage, _wallet, _timestamp, _ethereumEcdsa, _rpcModuleProvider, _keyStore, _jsonSerializer,
                                                                          _cryptoRandom, _enode, _ndmConsumerChannelManager, _ndmDataPublisher, _grpcService,
                                                                          _nodeStatsManager, _protocolsManager, protocolValidator, _messageSerializationService,
                                                                          _initConfig.EnableUnsecuredDevWallet, _logManager);

                capabilityConnector.Init();
                if (_logger.IsInfo)
                {
                    _logger.Info($"NDM initialized.");
                }
            }

            PeerLoader peerLoader = new PeerLoader(networkConfig, discoveryConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager, _staticNodesManager);
            _peerManager.Init();
        }
Пример #13
0
 public AdminModule(ILogManager logManager, IPeerManager peerManager, IStaticNodesManager staticNodesManager) :
     base(logManager)
 {
     _peerManager        = peerManager ?? throw new ArgumentNullException(nameof(peerManager));
     _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager));
 }
Пример #14
0
 public AdminModule(ILogManager logManager, IPeerManager peerManager, IStaticNodesManager staticNodesManager)
 {
     _logger             = logManager.GetClassLogger();
     _peerManager        = peerManager ?? throw new ArgumentNullException(nameof(peerManager));
     _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager));
 }