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(); }
public void SetUp() { _networkConfig = new NetworkConfig(); _statsManager = Substitute.For <INodeStatsManager>(); _peerStorage = Substitute.For <INetworkStorage>(); _loader = new PeerLoader(_networkConfig, _statsManager, _peerStorage, LimboLogs.Instance); }
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(); }
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(), _stats, _storage, LimboLogs.Instance); _networkConfig = new NetworkConfig(); _networkConfig.PeersPersistenceInterval = 50; _peerManager = new PeerManager(_rlpxPeer, _discoveryApp, _stats, _storage, _peerLoader, _networkConfig, LimboLogs.Instance); }
public Context() { RlpxPeer = new RlpxMock(Sessions); DiscoveryApp = Substitute.For <IDiscoveryApp>(); Stats = new NodeStatsManager(LimboLogs.Instance); Storage = new InMemoryStorage(); PeerLoader = new PeerLoader(new NetworkConfig(), new DiscoveryConfig(), Stats, Storage, LimboLogs.Instance); NetworkConfig = new NetworkConfig(); NetworkConfig.ActivePeersMaxCount = 25; NetworkConfig.PeersPersistenceInterval = 50; StaticNodesManager = Substitute.For <IStaticNodesManager>(); PeerManager = new PeerManager(RlpxPeer, DiscoveryApp, Stats, Storage, PeerLoader, NetworkConfig, LimboLogs.Instance, StaticNodesManager); }
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 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(); }