public async Task InitNetworkProtocol() { if (_ndmInitializer == null) { throw new InvalidOperationException( $"Cannot {nameof(InitNetworkProtocol)} in NDM before preparing an NDM initializer."); } ILogger logger = _ndmApi.LogManager.GetClassLogger(); if (logger.IsInfo) { logger.Info("Initializing NDM network protocol..."); } _ndmApi.HttpClient = new DefaultHttpClient(new HttpClient(), _ndmApi.EthereumJsonSerializer, _ndmApi.LogManager); INdmConfig ndmConfig = _ndmApi.Config <INdmConfig>(); if (ndmConfig.ProxyEnabled) { _ndmApi.JsonRpcClientProxy = new JsonRpcClientProxy( _ndmApi.HttpClient, ndmConfig.JsonRpcUrlProxies, _ndmApi.LogManager); _ndmApi.EthJsonRpcClientProxy = new EthJsonRpcClientProxy(_ndmApi.JsonRpcClientProxy); } INdmCapabilityConnector capabilityConnector = await _ndmInitializer.InitAsync(_ndmApi); capabilityConnector.Init(); if (logger.IsInfo) { logger.Info("NDM network protocol initialized."); } }
public void Setup() { _protocolsManager = Substitute.For <IProtocolsManager>(); _protocolHandlerFactory = Substitute.For <IProtocolHandlerFactory>(); _accountService = Substitute.For <IAccountService>(); _logManager = NullLogManager.Instance; _providerAddress = Address.Zero; _consumerAddress = Address.Zero; _capabilityConnector = new NdmCapabilityConnector(_protocolsManager, _protocolHandlerFactory, _accountService, _logManager, _providerAddress); }
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(); }