public void Initialize()
        {
            NetworkNodeDecoder.Init();
            SetupNodeIds();

            var logManager = NullLogManager.Instance;

            //setting config to store 3 nodes in a bucket and for table to have one bucket//setting config to store 3 nodes in a bucket and for table to have one bucket

            _configurationProvider = new ConfigProvider();
            IDiscoveryConfig discoveryConfig = _configurationProvider.GetConfig <IDiscoveryConfig>();

            discoveryConfig.PongTimeout  = 50;
            discoveryConfig.BucketSize   = 3;
            discoveryConfig.BucketsCount = 1;

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

            var calculator = new NodeDistanceCalculator(discoveryConfig);

            _nodeTable = new NodeTable(calculator, discoveryConfig, logManager);
            _nodeTable.Initialize(TestItem.PublicKeyA);

            _timestamp = new Timestamp();

            var evictionManager  = new EvictionManager(_nodeTable, logManager);
            var lifecycleFactory = new NodeLifecycleManagerFactory(_nodeTable, new DiscoveryMessageFactory(_timestamp), evictionManager, new NodeStatsManager(statsConfig, logManager), discoveryConfig, logManager);

            _udpClient = Substitute.For <IMessageSender>();

            var discoveryDb = new SimpleFilePublicKeyDb("test", logManager);

            _discoveryManager = new DiscoveryManager(lifecycleFactory, _nodeTable, new NetworkStorage(discoveryDb, logManager), discoveryConfig, logManager);
            _discoveryManager.MessageSender = _udpClient;
        }
Exemple #2
0
 public DiscoveryApp(
     INodesLocator nodesLocator,
     IDiscoveryManager discoveryManager,
     INodeTable nodeTable,
     IMessageSerializationService messageSerializationService,
     ICryptoRandom cryptoRandom,
     INetworkStorage discoveryStorage,
     INetworkConfig networkConfig,
     IDiscoveryConfig discoveryConfig,
     ITimestamper timestamper,
     ILogManager logManager,
     IPerfService perfService)
 {
     _logManager                  = logManager ?? throw new ArgumentNullException(nameof(logManager));
     _logger                      = _logManager.GetClassLogger();
     _perfService                 = perfService ?? throw new ArgumentNullException(nameof(perfService));
     _discoveryConfig             = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _timestamper                 = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
     _nodesLocator                = nodesLocator ?? throw new ArgumentNullException(nameof(nodesLocator));
     _discoveryManager            = discoveryManager ?? throw new ArgumentNullException(nameof(discoveryManager));
     _nodeTable                   = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _messageSerializationService = messageSerializationService ?? throw new ArgumentNullException(nameof(messageSerializationService));
     _cryptoRandom                = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom));
     _discoveryStorage            = discoveryStorage ?? throw new ArgumentNullException(nameof(discoveryStorage));
     _networkConfig               = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
     _discoveryStorage.StartBatch();
 }
Exemple #3
0
 public NodesLocator(INodeTable?nodeTable, IDiscoveryManager?discoveryManager, IDiscoveryConfig?discoveryConfig, ILogManager?logManager)
 {
     _logger           = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _nodeTable        = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _discoveryConfig  = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _discoveryManager = discoveryManager ?? throw new ArgumentNullException(nameof(discoveryManager));
 }
Exemple #4
0
        public NodeTable(INodeDistanceCalculator nodeDistanceCalculator, IDiscoveryConfig discoveryConfig, INetworkConfig networkConfig, ILogManager logManager)
        {
            _logger          = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _networkConfig   = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
            _discoveryConfig = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));

            _nodeDistanceCalculator = nodeDistanceCalculator ?? throw new ArgumentNullException(nameof(nodeDistanceCalculator));
        }
Exemple #5
0
 public void Initialize()
 {
     _config      = new DiscoveryConfig();
     _farAddress  = new IPEndPoint(IPAddress.Parse("192.168.1.2"), 1);
     _nearAddress = new IPEndPoint(IPAddress.Parse(_config.MasterExternalIp), _config.MasterPort);
     _messageSerializationService = Build.A.SerializationService().WithDiscovery(_privateKey).TestObject;
     _timestamp = new Timestamp();
 }
Exemple #6
0
 public PeerLoader(INetworkConfig networkConfig, IDiscoveryConfig discoveryConfig, INodeStatsManager stats, INetworkStorage peerStorage, ILogManager logManager)
 {
     _logger          = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _stats           = stats ?? throw new ArgumentNullException(nameof(stats));
     _peerStorage     = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage));
     _networkConfig   = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
     _discoveryConfig = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
 }
Exemple #7
0
 public NodeLifecycleManagerFactory(INodeTable nodeTable, IDiscoveryMessageFactory discoveryMessageFactory, IEvictionManager evictionManager, INodeStatsManager nodeStatsManager, IDiscoveryConfig discoveryConfig, ILogManager logManager)
 {
     _logger                  = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _nodeTable               = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _discoveryConfig         = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _discoveryMessageFactory = discoveryMessageFactory ?? throw new ArgumentNullException(nameof(discoveryMessageFactory));
     _evictionManager         = evictionManager ?? throw new ArgumentNullException(nameof(evictionManager));
     _nodeStatsManager        = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager));
 }
 public NodeLifecycleManager(Node node, IDiscoveryManager discoveryManager, INodeTable nodeTable, IDiscoveryMessageFactory discoveryMessageFactory, IEvictionManager evictionManager, INodeStats nodeStats, IDiscoveryConfig discoveryConfig, ILogger logger)
 {
     _discoveryManager        = discoveryManager;
     _nodeTable               = nodeTable;
     _logger                  = logger;
     _discoveryConfig         = discoveryConfig;
     _discoveryMessageFactory = discoveryMessageFactory;
     _evictionManager         = evictionManager;
     NodeStats                = nodeStats;
     ManagedNode              = node;
     UpdateState(NodeLifecycleState.New);
 }
Exemple #9
0
        public void Initialize()
        {
            _config                   = new DiscoveryConfig();
            _networkConfig            = new NetworkConfig();
            _networkConfig.ExternalIp = "99.10.10.66";
            _networkConfig.LocalIp    = "10.0.0.5";

            _farAddress  = new IPEndPoint(IPAddress.Parse("192.168.1.2"), 1);
            _nearAddress = new IPEndPoint(IPAddress.Parse(_networkConfig.LocalIp), _networkConfig.DiscoveryPort);
            _messageSerializationService = Build.A.SerializationService().WithDiscovery(_privateKey).TestObject;
            _timestamper = new Timestamper();
        }
Exemple #10
0
        public NodeTable(INodeDistanceCalculator nodeDistanceCalculator, IDiscoveryConfig discoveryConfig, INetworkConfig networkConfig, ILogManager logManager)
        {
            _logger                 = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _networkConfig          = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
            _discoveryConfig        = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
            _nodeDistanceCalculator = nodeDistanceCalculator ?? throw new ArgumentNullException(nameof(nodeDistanceCalculator));

            Buckets = new NodeBucket[_discoveryConfig.BucketsCount];
            for (int i = 0; i < Buckets.Length; i++)
            {
                Buckets[i] = new NodeBucket(i, _discoveryConfig.BucketSize);
            }
        }
 public DiscoveryManager(
     INodeLifecycleManagerFactory nodeLifecycleManagerFactory,
     INodeTable nodeTable,
     INetworkStorage discoveryStorage,
     IDiscoveryConfig discoveryConfig,
     ILogManager logManager)
 {
     _logger                      = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _discoveryConfig             = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _nodeLifecycleManagerFactory = nodeLifecycleManagerFactory ?? throw new ArgumentNullException(nameof(nodeLifecycleManagerFactory));
     _nodeTable                   = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _discoveryStorage            = discoveryStorage ?? throw new ArgumentNullException(nameof(discoveryStorage));
     _nodeLifecycleManagerFactory.DiscoveryManager = this;
 }
Exemple #12
0
        public void Initialize()
        {
            _discoveryManagerMock = Substitute.For <IDiscoveryManager>();
            _discoveryConfigMock  = Substitute.For <IDiscoveryConfig>();


            NetworkNodeDecoder.Init();
            SetupNodeIds();

            var logManager = LimboLogs.Instance;

            _loggerMock = Substitute.For <ILogger>();
            //setting config to store 3 nodes in a bucket and for table to have one bucket//setting config to store 3 nodes in a bucket and for table to have one bucket

            _configurationProvider    = new ConfigProvider();
            _networkConfig.ExternalIp = "99.10.10.66";
            _networkConfig.LocalIp    = "10.0.0.5";

            IDiscoveryConfig discoveryConfig = _configurationProvider.GetConfig <IDiscoveryConfig>();

            discoveryConfig.PongTimeout  = 50;
            discoveryConfig.BucketSize   = 3;
            discoveryConfig.BucketsCount = 1;

            _ipResolverMock = Substitute.For <IIPResolver>();

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

            var calculator = new NodeDistanceCalculator(discoveryConfig);

            _nodeTable = new NodeTable(calculator, discoveryConfig, _networkConfig, logManager);
            _nodeTable.Initialize(TestItem.PublicKeyA);
            _nodeStatsMock = Substitute.For <INodeStats>();

            _timestamper = Timestamper.Default;

            var evictionManager = new EvictionManager(_nodeTable, logManager);

            _evictionManagerMock = Substitute.For <IEvictionManager>();
            var lifecycleFactory = new NodeLifecycleManagerFactory(_nodeTable, new DiscoveryMessageFactory(_timestamper), evictionManager, new NodeStatsManager(statsConfig, logManager), discoveryConfig, logManager);

            _udpClient = Substitute.For <IMessageSender>();

            var discoveryDb = new SimpleFilePublicKeyDb("Test", "test", logManager);

            _discoveryManager = new DiscoveryManager(lifecycleFactory, _nodeTable, new NetworkStorage(discoveryDb, logManager), discoveryConfig, logManager, _ipResolverMock);
            _discoveryManager.MessageSender = _udpClient;

            _discoveryManagerMock = Substitute.For <IDiscoveryManager>();
        }
 public NodeLifecycleManagerFactory(INodeTable nodeTable,
                                    IEvictionManager evictionManager,
                                    INodeStatsManager nodeStatsManager,
                                    NodeRecord self,
                                    IDiscoveryConfig discoveryConfig,
                                    ITimestamper timestamper,
                                    ILogManager?logManager)
 {
     _logger           = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _nodeTable        = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _discoveryConfig  = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _timestamper      = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
     _evictionManager  = evictionManager ?? throw new ArgumentNullException(nameof(evictionManager));
     _nodeStatsManager = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager));
     _selfNodeRecord   = self ?? throw new ArgumentNullException(nameof(self));
 }
Exemple #14
0
        public void Setup()
        {
            _discoveryManagerMock = Substitute.For <IDiscoveryManager>();
            _discoveryConfigMock  = Substitute.For <IDiscoveryConfig>();

            NetworkNodeDecoder.Init();
            SetupNodeIds();

            LimboLogs?logManager = LimboLogs.Instance;

            _loggerMock = Substitute.For <ILogger>();
            //setting config to store 3 nodes in a bucket and for table to have one bucket//setting config to store 3 nodes in a bucket and for table to have one bucket

            IConfigProvider configurationProvider = new ConfigProvider();

            _networkConfig.ExternalIp = "99.10.10.66";
            _networkConfig.LocalIp    = "10.0.0.5";

            IDiscoveryConfig discoveryConfig = configurationProvider.GetConfig <IDiscoveryConfig>();

            discoveryConfig.PongTimeout  = 50;
            discoveryConfig.BucketSize   = 3;
            discoveryConfig.BucketsCount = 1;

            NodeDistanceCalculator calculator = new(discoveryConfig);

            _nodeTable = new NodeTable(calculator, discoveryConfig, _networkConfig, logManager);
            _nodeTable.Initialize(TestItem.PublicKeyA);
            _nodeStatsMock = Substitute.For <INodeStats>();

            EvictionManager evictionManager = new(_nodeTable, logManager);

            _evictionManagerMock = Substitute.For <IEvictionManager>();
            ITimerFactory timerFactory = Substitute.For <ITimerFactory>();
            NodeLifecycleManagerFactory lifecycleFactory = new(_nodeTable, evictionManager,
                                                               new NodeStatsManager(timerFactory, logManager), new NodeRecord(), discoveryConfig, Timestamper.Default, logManager);

            IMsgSender udpClient = Substitute.For <IMsgSender>();

            SimpleFilePublicKeyDb discoveryDb = new("Test", "test", logManager);

            _discoveryManager           = new DiscoveryManager(lifecycleFactory, _nodeTable, new NetworkStorage(discoveryDb, logManager), discoveryConfig, logManager);
            _discoveryManager.MsgSender = udpClient;

            _discoveryManagerMock = Substitute.For <IDiscoveryManager>();
        }
Exemple #15
0
        private void Update()
        {
            if (_api.ChainSpec == null)
            {
                return;
            }

            IDiscoveryConfig discoveryConfig = _api.Config <IDiscoveryConfig>();

            if (discoveryConfig.Bootnodes != string.Empty)
            {
                if (_api.ChainSpec.Bootnodes.Length != 0)
                {
                    discoveryConfig.Bootnodes += "," + string.Join(",", _api.ChainSpec.Bootnodes.Select(bn => bn.ToString()));
                }
            }
            else
            {
                discoveryConfig.Bootnodes = string.Join(",", _api.ChainSpec.Bootnodes.Select(bn => bn.ToString()));
            }
        }
Exemple #16
0
 public NodeLifecycleManager(Node node,
                             IDiscoveryManager discoveryManager,
                             INodeTable nodeTable,
                             IEvictionManager evictionManager,
                             INodeStats nodeStats,
                             NodeRecord nodeRecord,
                             IDiscoveryConfig discoveryConfig,
                             ITimestamper timestamper,
                             ILogger logger)
 {
     _discoveryManager = discoveryManager ?? throw new ArgumentNullException(nameof(discoveryManager));
     _nodeTable        = nodeTable ?? throw new ArgumentNullException(nameof(nodeTable));
     _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
     _discoveryConfig  = discoveryConfig ?? throw new ArgumentNullException(nameof(discoveryConfig));
     _timestamper      = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
     _evictionManager  = evictionManager ?? throw new ArgumentNullException(nameof(evictionManager));
     _nodeRecord       = nodeRecord ?? throw new ArgumentNullException(nameof(nodeRecord));
     NodeStats         = nodeStats ?? throw new ArgumentNullException(nameof(nodeStats));
     ManagedNode       = node;
     UpdateState(NodeLifecycleState.New);
 }
Exemple #17
0
        private async Task InitPeer()
        {
            if (_ctx.DbProvider == null)
            {
                throw new StepDependencyException(nameof(_ctx.DbProvider));
            }
            if (_ctx.BlockTree == null)
            {
                throw new StepDependencyException(nameof(_ctx.BlockTree));
            }
            if (_ctx.ReceiptStorage == null)
            {
                throw new StepDependencyException(nameof(_ctx.ReceiptStorage));
            }
            if (_ctx.BlockValidator == null)
            {
                throw new StepDependencyException(nameof(_ctx.BlockValidator));
            }
            if (_ctx.SyncPeerPool == null)
            {
                throw new StepDependencyException(nameof(_ctx.SyncPeerPool));
            }
            if (_ctx.Synchronizer == null)
            {
                throw new StepDependencyException(nameof(_ctx.Synchronizer));
            }
            if (_ctx.Enode == null)
            {
                throw new StepDependencyException(nameof(_ctx.Enode));
            }
            if (_ctx.NodeKey == null)
            {
                throw new StepDependencyException(nameof(_ctx.NodeKey));
            }
            if (_ctx.MainBlockProcessor == null)
            {
                throw new StepDependencyException(nameof(_ctx.MainBlockProcessor));
            }
            if (_ctx.NodeStatsManager == null)
            {
                throw new StepDependencyException(nameof(_ctx.NodeStatsManager));
            }
            if (_ctx.KeyStore == null)
            {
                throw new StepDependencyException(nameof(_ctx.KeyStore));
            }
            if (_ctx.RpcModuleProvider == null)
            {
                throw new StepDependencyException(nameof(_ctx.RpcModuleProvider));
            }
            if (_ctx.Wallet == null)
            {
                throw new StepDependencyException(nameof(_ctx.Wallet));
            }
            if (_ctx.EthereumEcdsa == null)
            {
                throw new StepDependencyException(nameof(_ctx.EthereumEcdsa));
            }
            if (_ctx.SpecProvider == null)
            {
                throw new StepDependencyException(nameof(_ctx.SpecProvider));
            }
            if (_ctx.TxPool == null)
            {
                throw new StepDependencyException(nameof(_ctx.TxPool));
            }
            if (_ctx.EthereumJsonSerializer == null)
            {
                throw new StepDependencyException(nameof(_ctx.EthereumJsonSerializer));
            }

            /* rlpx */
            EciesCipher    eciesCipher = new EciesCipher(_ctx.CryptoRandom);
            Eip8MessagePad eip8Pad     = new Eip8MessagePad(_ctx.CryptoRandom);

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

            HandshakeService encryptionHandshakeServiceA = new HandshakeService(_ctx._messageSerializationService, eciesCipher,
                                                                                _ctx.CryptoRandom, new Ecdsa(), _ctx.NodeKey.Unprotect(), _ctx.LogManager);

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

            IDiscoveryConfig discoveryConfig = _ctx.Config <IDiscoveryConfig>();
            IInitConfig      initConfig      = _ctx.Config <IInitConfig>();

            _ctx.SessionMonitor = new SessionMonitor(_networkConfig, _ctx.LogManager);
            _ctx.RlpxPeer       = new RlpxPeer(
                _ctx._messageSerializationService,
                _ctx.NodeKey.PublicKey,
                _networkConfig.P2PPort,
                encryptionHandshakeServiceA,
                _ctx.LogManager,
                _ctx.SessionMonitor);

            await _ctx.RlpxPeer.Init();

            _ctx.StaticNodesManager = new StaticNodesManager(initConfig.StaticNodesPath, _ctx.LogManager);
            await _ctx.StaticNodesManager.InitAsync();

            var     dbName  = "PeersDB";
            IFullDb peersDb = initConfig.DiagnosticMode == DiagnosticMode.MemDb
                ? (IFullDb) new MemDb(dbName)
                : new SimpleFilePublicKeyDb(dbName, PeersDbPath.GetApplicationResourcePath(initConfig.BaseDbPath), _ctx.LogManager);

            NetworkStorage peerStorage = new NetworkStorage(peersDb, _ctx.LogManager);

            ProtocolValidator protocolValidator = new ProtocolValidator(_ctx.NodeStatsManager, _ctx.BlockTree, _ctx.LogManager);

            _ctx.ProtocolsManager = new ProtocolsManager(_ctx.SyncPeerPool, _ctx.SyncServer, _ctx.TxPool, _ctx.DiscoveryApp, _ctx._messageSerializationService, _ctx.RlpxPeer, _ctx.NodeStatsManager, protocolValidator, peerStorage, _ctx.SpecProvider, _ctx.LogManager);

            if (!(_ctx.NdmInitializer is null))
            {
                if (_ctx.WebSocketsManager == null)
                {
                    throw new StepDependencyException(nameof(_ctx.WebSocketsManager));
                }
                if (_ctx.GrpcServer == null)
                {
                    throw new StepDependencyException(nameof(_ctx.GrpcServer));
                }
                if (_ctx.NdmDataPublisher == null)
                {
                    throw new StepDependencyException(nameof(_ctx.NdmDataPublisher));
                }
                if (_ctx.NdmConsumerChannelManager == null)
                {
                    throw new StepDependencyException(nameof(_ctx.NdmConsumerChannelManager));
                }
                if (_ctx.BloomStorage == null)
                {
                    throw new StepDependencyException(nameof(_ctx.BloomStorage));
                }
                if (_ctx.ReceiptFinder == null)
                {
                    throw new StepDependencyException(nameof(_ctx.ReceiptFinder));
                }

                if (_logger.IsInfo)
                {
                    _logger.Info($"Initializing NDM...");
                }
                _ctx.HttpClient = new DefaultHttpClient(new HttpClient(), _ctx.EthereumJsonSerializer, _ctx.LogManager);
                INdmConfig ndmConfig = _ctx.Config <INdmConfig>();
                if (ndmConfig.ProxyEnabled)
                {
                    _ctx.JsonRpcClientProxy = new JsonRpcClientProxy(_ctx.HttpClient, ndmConfig.JsonRpcUrlProxies,
                                                                     _ctx.LogManager);
                    _ctx.EthJsonRpcClientProxy = new EthJsonRpcClientProxy(_ctx.JsonRpcClientProxy);
                }

                FilterStore             filterStore         = new FilterStore();
                FilterManager           filterManager       = new FilterManager(filterStore, _ctx.MainBlockProcessor, _ctx.TxPool, _ctx.LogManager);
                INdmCapabilityConnector capabilityConnector = await _ctx.NdmInitializer.InitAsync(
                    _ctx.ConfigProvider,
                    _ctx.DbProvider,
                    initConfig.BaseDbPath,
                    _ctx.BlockTree,
                    _ctx.TxPool,
                    _ctx.SpecProvider,
                    _ctx.ReceiptFinder,
                    _ctx.Wallet,
                    filterStore,
                    filterManager,
                    _ctx.Timestamper,
                    _ctx.EthereumEcdsa,
                    _ctx.RpcModuleProvider,
                    _ctx.KeyStore,
                    _ctx.EthereumJsonSerializer,
                    _ctx.CryptoRandom,
                    _ctx.Enode,
                    _ctx.NdmConsumerChannelManager,
                    _ctx.NdmDataPublisher,
                    _ctx.GrpcServer,
                    _ctx.NodeStatsManager,
                    _ctx.ProtocolsManager,
                    protocolValidator,
                    _ctx._messageSerializationService,
                    initConfig.EnableUnsecuredDevWallet,
                    _ctx.WebSocketsManager,
                    _ctx.LogManager,
                    _ctx.MainBlockProcessor,
                    _ctx.JsonRpcClientProxy,
                    _ctx.EthJsonRpcClientProxy,
                    _ctx.HttpClient,
                    _ctx.MonitoringService,
                    _ctx.BloomStorage);

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

            PeerLoader peerLoader = new PeerLoader(_networkConfig, discoveryConfig, _ctx.NodeStatsManager, peerStorage, _ctx.LogManager);

            _ctx.PeerManager = new PeerManager(_ctx.RlpxPeer, _ctx.DiscoveryApp, _ctx.NodeStatsManager, peerStorage, peerLoader, _networkConfig, _ctx.LogManager, _ctx.StaticNodesManager);
            _ctx.PeerManager.Init();
        }
        private void InitDiscovery()
        {
            if (!_initConfig.DiscoveryEnabled)
            {
                _discoveryApp = new NullDiscoveryApp();
                return;
            }

            IDiscoveryConfig discoveryConfig = _configProvider.GetConfig <IDiscoveryConfig>();

            discoveryConfig.MasterPort = _initConfig.DiscoveryPort;

            var privateKeyProvider      = new SameKeyGenerator(_nodeKey);
            var discoveryMessageFactory = new DiscoveryMessageFactory(_timestamp);
            var nodeIdResolver          = new NodeIdResolver(_ethereumEcdsa);

            IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider(
                _messageSerializationService,
                _ethereumEcdsa,
                privateKeyProvider,
                discoveryMessageFactory,
                nodeIdResolver);

            msgSerializersProvider.RegisterDiscoverySerializers();

            var nodeDistanceCalculator = new NodeDistanceCalculator(discoveryConfig);

            var nodeTable = new NodeTable(nodeDistanceCalculator,
                                          discoveryConfig,
                                          _logManager);

            var evictionManager = new EvictionManager(
                nodeTable,
                _logManager);

            var nodeLifeCycleFactory = new NodeLifecycleManagerFactory(
                nodeTable,
                discoveryMessageFactory,
                evictionManager,
                _nodeStatsManager,
                discoveryConfig,
                _logManager);

            var discoveryDb      = new SimpleFilePublicKeyDb(Path.Combine(_initConfig.BaseDbPath, DiscoveryNodesDbPath), _logManager);
            var discoveryStorage = new NetworkStorage(
                discoveryDb,
                _logManager);

            var discoveryManager = new DiscoveryManager(
                nodeLifeCycleFactory,
                nodeTable,
                discoveryStorage,
                discoveryConfig,
                _logManager);

            var nodesLocator = new NodesLocator(
                nodeTable,
                discoveryManager,
                discoveryConfig,
                _logManager);

            _discoveryApp = new DiscoveryApp(
                nodesLocator,
                discoveryManager,
                nodeTable,
                _messageSerializationService,
                _cryptoRandom,
                discoveryStorage,
                discoveryConfig,
                _timestamp,
                _logManager, _perfService);

            _discoveryApp.Initialize(_nodeKey.PublicKey);
        }
Exemple #19
0
        private void InitDiscovery()
        {
            if (_ctx.NodeStatsManager == null)
            {
                throw new StepDependencyException(nameof(_ctx.NodeStatsManager));
            }
            if (_ctx.Timestamper == null)
            {
                throw new StepDependencyException(nameof(_ctx.Timestamper));
            }
            if (_ctx.NodeKey == null)
            {
                throw new StepDependencyException(nameof(_ctx.NodeKey));
            }
            if (_ctx.CryptoRandom == null)
            {
                throw new StepDependencyException(nameof(_ctx.CryptoRandom));
            }

            if (!_ctx.Config <IInitConfig>().DiscoveryEnabled)
            {
                _ctx.DiscoveryApp = new NullDiscoveryApp();
                return;
            }

            IDiscoveryConfig discoveryConfig = _ctx.Config <IDiscoveryConfig>();

            SameKeyGenerator        privateKeyProvider      = new SameKeyGenerator(_ctx.NodeKey.Unprotect());
            DiscoveryMessageFactory discoveryMessageFactory = new DiscoveryMessageFactory(_ctx.Timestamper);
            NodeIdResolver          nodeIdResolver          = new NodeIdResolver(_ctx.EthereumEcdsa);
            IPResolver ipResolver = new IPResolver(_networkConfig, _ctx.LogManager);

            IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider(
                _ctx._messageSerializationService,
                _ctx.EthereumEcdsa,
                privateKeyProvider,
                discoveryMessageFactory,
                nodeIdResolver);

            msgSerializersProvider.RegisterDiscoverySerializers();

            NodeDistanceCalculator nodeDistanceCalculator = new NodeDistanceCalculator(discoveryConfig);

            NodeTable       nodeTable       = new NodeTable(nodeDistanceCalculator, discoveryConfig, _networkConfig, _ctx.LogManager);
            EvictionManager evictionManager = new EvictionManager(nodeTable, _ctx.LogManager);

            NodeLifecycleManagerFactory nodeLifeCycleFactory = new NodeLifecycleManagerFactory(
                nodeTable,
                discoveryMessageFactory,
                evictionManager,
                _ctx.NodeStatsManager,
                discoveryConfig,
                _ctx.LogManager);

            SimpleFilePublicKeyDb discoveryDb      = new SimpleFilePublicKeyDb("DiscoveryDB", DiscoveryNodesDbPath.GetApplicationResourcePath(_ctx.Config <IInitConfig>().BaseDbPath), _ctx.LogManager);
            NetworkStorage        discoveryStorage = new NetworkStorage(
                discoveryDb,
                _ctx.LogManager);

            DiscoveryManager discoveryManager = new DiscoveryManager(
                nodeLifeCycleFactory,
                nodeTable,
                discoveryStorage,
                discoveryConfig,
                _ctx.LogManager,
                ipResolver
                );

            NodesLocator nodesLocator = new NodesLocator(
                nodeTable,
                discoveryManager,
                discoveryConfig,
                _ctx.LogManager);

            _ctx.DiscoveryApp = new DiscoveryApp(
                nodesLocator,
                discoveryManager,
                nodeTable,
                _ctx._messageSerializationService,
                _ctx.CryptoRandom,
                discoveryStorage,
                _networkConfig,
                discoveryConfig,
                _ctx.Timestamper,
                _ctx.LogManager);

            _ctx.DiscoveryApp.Initialize(_ctx.NodeKey.PublicKey);
        }
 public NodeDistanceCalculator(IDiscoveryConfig discoveryConfig)
 {
     _maxDistance = discoveryConfig.BucketsCount;
     _bitsPerHoop = discoveryConfig.BitsPerHop;
 }