Beispiel #1
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>();

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

            await _rlpxPeer.Init();

            var peerStorage = new NetworkStorage(PeersDbPath, networkConfig, _logManager, _perfService);

            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, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager);
            _peerManager.Init();
        }
Beispiel #2
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));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Signer(), _nodeKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth62 */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            /* eth63 */
            _messageSerializationService.Register(new GetNodeDataMessageSerializer());
            _messageSerializationService.Register(new NodeDataMessageSerializer());
            _messageSerializationService.Register(new GetReceiptsMessageSerializer());
            _messageSerializationService.Register(new ReceiptsMessageSerializer());

            var             networkConfig  = _configProvider.GetConfig <INetworkConfig>();
            ISessionMonitor sessionMonitor = new SessionMonitor(networkConfig, _logManager);

            _rlpxPeer = new RlpxPeer(
                _nodeKey.PublicKey,
                _initConfig.P2PPort,
                encryptionHandshakeServiceA,
                _logManager,
                _perfService,
                sessionMonitor);

            await _rlpxPeer.Init();


            var peerStorage = new NetworkStorage(PeersDbPath, networkConfig, _logManager, _perfService);

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

            _protocolsManager = new ProtocolsManager(_syncManager, _transactionPool, _discoveryApp, _messageSerializationService, _rlpxPeer, _nodeStatsManager, protocolValidator, peerStorage, _perfService, _logManager);
            PeerLoader peerLoader = new PeerLoader(networkConfig, _nodeStatsManager, peerStorage, _logManager);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _nodeStatsManager, peerStorage, peerLoader, networkConfig, _logManager);
            _peerManager.Init();
        }
Beispiel #3
0
        private static void Start()
        {
            var privateKeyProvider = new PrivateKeyProvider(PrivateKey);
            var config             = new DiscoveryConfigurationProvider(new NetworkHelper(Logger));
            var signer             = new Signer();
            var cryptoRandom       = new CryptoRandom();
            var configProvider     = new ConfigurationProvider();

            var nodeFactory = new NodeFactory();
            var calculator  = new NodeDistanceCalculator(config);

            var nodeTable = new NodeTable(config, nodeFactory, new FileKeyStore(configProvider, new JsonSerializer(Logger), new AesEncrypter(configProvider, Logger), cryptoRandom, Logger), Logger, calculator);

            var evictionManager  = new EvictionManager(nodeTable, Logger);
            var lifecycleFactory = new NodeLifecycleManagerFactory(nodeFactory, nodeTable, Logger, config, new DiscoveryMessageFactory(config), evictionManager);

            var discoveryManager = new DiscoveryManager(Logger, config, lifecycleFactory, nodeFactory, nodeTable);

            var nodesLocator           = new NodesLocator(nodeTable, discoveryManager, config, Logger);
            var discoveryMesageFactory = new DiscoveryMessageFactory(config);
            var nodeIdResolver         = new NodeIdResolver(signer);

            var pingSerializer      = new PingMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var pongSerializer      = new PongMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var findNodeSerializer  = new FindNodeMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);
            var neighborsSerializer = new NeighborsMessageSerializer(signer, privateKeyProvider, discoveryMesageFactory, nodeIdResolver, nodeFactory);

            var messageSerializationService = new MessageSerializationService();

            messageSerializationService.Register(pingSerializer);
            messageSerializationService.Register(pongSerializer);
            messageSerializationService.Register(findNodeSerializer);
            messageSerializationService.Register(neighborsSerializer);


            //P2P initialization
            IMessagePad eip8Pad = new Eip8MessagePad(cryptoRandom);

            messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            messageSerializationService.Register(new HelloMessageSerializer());
            messageSerializationService.Register(new DisconnectMessageSerializer());
            messageSerializationService.Register(new Nethermind.Network.P2P.PingMessageSerializer());
            messageSerializationService.Register(new Nethermind.Network.P2P.PongMessageSerializer());
            messageSerializationService.Register(new StatusMessageSerializer());
            IEciesCipher eciesCipher = new EciesCipher(cryptoRandom);
            IEncryptionHandshakeService encryptionHandshakeService = new EncryptionHandshakeService(messageSerializationService, eciesCipher, cryptoRandom, signer, PrivateKey, Logger);
            var p2pManager = new P2PManager(encryptionHandshakeService, Logger, messageSerializationService, Substitute.For <ISynchronizationManager>());

            //Connect discovery with P2P
            discoveryManager.RegisterDiscoveryListener(p2pManager);

            _discoveryApp = new DiscoveryApp(config, nodesLocator, Logger, discoveryManager, nodeFactory, nodeTable, messageSerializationService, cryptoRandom);
            _discoveryApp.Start(PrivateKey.PublicKey);
        }
Beispiel #4
0
        public void Adds_at_most_300_bytes()
        {
            byte[] message             = { 1 };
            int    lengthBeforePadding = message.Length;

            TestRandom testRandom = new TestRandom(i => i - 1, i => new byte[i]);

            Eip8MessagePad pad = new Eip8MessagePad(testRandom);

            message = pad.Pad(message);

            Assert.AreEqual(lengthBeforePadding + 300, message.Length, "incorrect length");
            Assert.AreEqual(message[0], 1, "first byte touched");
        }
Beispiel #5
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));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher,
                                                                             _cryptoRandom, new Signer(), _privateKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            _rlpxPeer = new RlpxPeer(new NodeId(_privateKey.PublicKey), _initConfig.P2PPort,
                                     _syncManager,
                                     _messageSerializationService,
                                     encryptionHandshakeServiceA,
                                     _nodeStatsProvider,
                                     _logManager, _perfService);

            await _rlpxPeer.Init();

            var peerStorage = new NetworkStorage(PeersDbPath, _configProvider.GetConfig <INetworkConfig>(), _logManager, _perfService);

            _peerManager = new PeerManager(_rlpxPeer, _discoveryManager, _syncManager, _nodeStatsProvider, peerStorage,
                                           _nodeFactory, _configProvider, _perfService, _logManager);
            _peerManager.Init(_initConfig.DiscoveryEnabled);
        }
Beispiel #6
0
        private async Task InitNet(int listenPort)
        {
            /* tools */
            _messageSerializationService = new MessageSerializationService();
            _cryptoRandom = new CryptoRandom();
            _signer       = new Signer();

            /* rlpx */
            var eciesCipher = new EciesCipher(_cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(_cryptoRandom);

            _messageSerializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            _messageSerializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(_messageSerializationService, eciesCipher, _cryptoRandom, _signer, _privateKey, _logManager);

            /* p2p */
            _messageSerializationService.Register(new HelloMessageSerializer());
            _messageSerializationService.Register(new DisconnectMessageSerializer());
            _messageSerializationService.Register(new PingMessageSerializer());
            _messageSerializationService.Register(new PongMessageSerializer());

            /* eth */
            _messageSerializationService.Register(new StatusMessageSerializer());
            _messageSerializationService.Register(new TransactionsMessageSerializer());
            _messageSerializationService.Register(new GetBlockHeadersMessageSerializer());
            _messageSerializationService.Register(new NewBlockHashesMessageSerializer());
            _messageSerializationService.Register(new GetBlockBodiesMessageSerializer());
            _messageSerializationService.Register(new BlockHeadersMessageSerializer());
            _messageSerializationService.Register(new BlockBodiesMessageSerializer());
            _messageSerializationService.Register(new NewBlockMessageSerializer());

            _logger.Info("Initializing server...");
            _localPeer = new RlpxPeer(new NodeId(_privateKey.PublicKey), listenPort, encryptionHandshakeServiceA, _messageSerializationService, _syncManager, _logManager);
            await _localPeer.Init();

            var localIp = _networkHelper.GetLocalIp();

            _logger.Info($"Node is up and listening on {localIp}:{listenPort}... press ENTER to exit");
            _logger.Info($"enode://{_privateKey.PublicKey}@{localIp}:{listenPort}");
        }
Beispiel #7
0
        private static async Task InitNet(ChainSpec chainSpec)
        {
            /* tools */
            var serializationService = new MessageSerializationService();
            var cryptoRandom         = new CryptoRandom();
            var signer = new Signer();

            /* rlpx */
            var eciesCipher = new EciesCipher(cryptoRandom);
            var eip8Pad     = new Eip8MessagePad(cryptoRandom);

            serializationService.Register(new AuthEip8MessageSerializer(eip8Pad));
            serializationService.Register(new AckEip8MessageSerializer(eip8Pad));
            var encryptionHandshakeServiceA = new EncryptionHandshakeService(serializationService, eciesCipher, cryptoRandom, signer, _privateKey, NetworkLogger);

            /* p2p */
            serializationService.Register(new HelloMessageSerializer());
            serializationService.Register(new DisconnectMessageSerializer());
            serializationService.Register(new PingMessageSerializer());
            serializationService.Register(new PongMessageSerializer());

            /* eth */
            serializationService.Register(new StatusMessageSerializer());
            serializationService.Register(new TransactionsMessageSerializer());
            serializationService.Register(new GetBlockHeadersMessageSerializer());
            serializationService.Register(new NewBlockHashesMessageSerializer());
            serializationService.Register(new GetBlockBodiesMessageSerializer());
            serializationService.Register(new BlockHeadersMessageSerializer());
            serializationService.Register(new BlockBodiesMessageSerializer());
            serializationService.Register(new NewBlockMessageSerializer());

            NetworkLogger.Info("Initializing server...");
            var localPeer = new RlpxPeer(_privateKey.PublicKey, _listenPort, encryptionHandshakeServiceA, serializationService, _syncManager, NetworkLogger);
            await localPeer.Init();

            // https://stackoverflow.com/questions/6803073/get-local-ip-address?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
            string localIp;

            using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
            {
                socket.Connect("8.8.8.8", 65530);
                IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
                Debug.Assert(endPoint != null, "null endpoint when connecting a UDP socket");
                localIp = endPoint.Address.ToString();
            }

            NetworkLogger.Info($"Node is up and listening on {localIp}:{_listenPort}... press ENTER to exit");
            NetworkLogger.Info($"enode://{_privateKey.PublicKey.ToString(false)}@{localIp}:{_listenPort}");

            foreach (Bootnode bootnode in chainSpec.Bootnodes)
            {
                NetworkLogger.Info($"Connecting to {bootnode.Description} @ {bootnode.Host}:{bootnode.Port}");
                await localPeer.ConnectAsync(bootnode.PublicKey, bootnode.Host, bootnode.Port);

                NetworkLogger.Info("Testnet connected...");
            }

            Console.ReadLine();
            NetworkLogger.Info("Shutting down...");
            NetworkLogger.Info("Stopping sync manager...");
            await _syncManager.StopAsync();

            NetworkLogger.Info("Stopping blockchain processor...");
            await _blockchainProcessor.StopAsync();

            NetworkLogger.Info("Stopping local peer...");
            await localPeer.Shutdown();

            NetworkLogger.Info("Goodbye...");
        }
Beispiel #8
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();
        }
Beispiel #9
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();
        }