public ProtocolsManager( ISynchronizationManager synchronizationManager, ITransactionPool transactionPool, IDiscoveryApp discoveryApp, IMessageSerializationService serializationService, IRlpxPeer localPeer, INodeStatsManager nodeStatsManager, IProtocolValidator protocolValidator, INetworkStorage peerStorage, IPerfService perfService, ILogManager logManager) { _syncManager = synchronizationManager ?? throw new ArgumentNullException(nameof(synchronizationManager)); _transactionPool = transactionPool ?? throw new ArgumentNullException(nameof(transactionPool)); _discoveryApp = discoveryApp ?? throw new ArgumentNullException(nameof(discoveryApp)); _serializer = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _localPeer = localPeer ?? throw new ArgumentNullException(nameof(localPeer)); _stats = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager)); _protocolValidator = protocolValidator ?? throw new ArgumentNullException(nameof(protocolValidator)); _perfService = perfService ?? throw new ArgumentNullException(nameof(perfService)); _peerStorage = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = _logManager.GetClassLogger(); _syncManager.SyncEvent += OnSyncEvent; localPeer.SessionCreated += SessionCreated; }
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 ProtocolsManager( ISyncPeerPool syncPeerPool, ISyncServer syncServer, ITxPool txPool, IDiscoveryApp discoveryApp, IMessageSerializationService serializationService, IRlpxPeer localPeer, INodeStatsManager nodeStatsManager, IProtocolValidator protocolValidator, INetworkStorage peerStorage, ISpecProvider specProvider, ILogManager logManager) { _syncPool = syncPeerPool ?? throw new ArgumentNullException(nameof(syncPeerPool)); _syncServer = syncServer ?? throw new ArgumentNullException(nameof(syncServer)); _txPool = txPool ?? throw new ArgumentNullException(nameof(txPool)); _discoveryApp = discoveryApp ?? throw new ArgumentNullException(nameof(discoveryApp)); _serializer = serializationService ?? throw new ArgumentNullException(nameof(serializationService)); _localPeer = localPeer ?? throw new ArgumentNullException(nameof(localPeer)); _stats = nodeStatsManager ?? throw new ArgumentNullException(nameof(nodeStatsManager)); _protocolValidator = protocolValidator ?? throw new ArgumentNullException(nameof(protocolValidator)); _peerStorage = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage)); _specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider)); _logManager = logManager ?? throw new ArgumentNullException(nameof(logManager)); _logger = _logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _protocolFactories = GetProtocolFactories(); localPeer.SessionCreated += SessionCreated; }
//TODO Timer to periodically check active peers and move new to active based on max size and compatibility - stats and capabilities + update peers in synchronization manager //TODO Remove active and synch on disconnect //TODO Update Stats on disconnect, other events //TODO update runner to run discovery public PeerManager(IRlpxPeer localPeer, IDiscoveryManager discoveryManager, ISynchronizationManager synchronizationManager, INodeStatsProvider nodeStatsProvider, IPeerStorage peerStorage, INodeFactory nodeFactory, IConfigProvider configurationProvider, IPerfService perfService, ILogManager logManager) { _logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager)); _localPeer = localPeer; _configurationProvider = configurationProvider.GetConfig <NetworkConfig>(); _synchronizationManager = synchronizationManager; _nodeStatsProvider = nodeStatsProvider; _discoveryManager = discoveryManager; _perfService = perfService; _nodeFactory = nodeFactory; _isDiscoveryEnabled = _discoveryManager != null; if (_isDiscoveryEnabled) { discoveryManager.NodeDiscovered += async(s, e) => await OnNodeDiscovered(s, e); } localPeer.ConnectionInitialized += OnRemoteConnectionInitialized; synchronizationManager.SyncFailed += async(s, e) => await OnSyncFailed(s, e); _peerStorage = peerStorage; _peerStorage.StartBatch(); }
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 Context() { _channel = Substitute.For <IChannel>(); _channelHandlerContext = Substitute.For <IChannelHandlerContext>(); _pipeline = Substitute.For <IChannelPipeline>(); _channelHandlerContext.Channel.Returns(_channel); _channel.Pipeline.Returns(_pipeline); _pipeline.Get <ZeroPacketSplitter>().Returns(new ZeroPacketSplitter(LimboLogs.Instance)); _packetSender = Substitute.For <IPacketSender>(); _syncServer = Substitute.For <ISyncServer>(); _syncServer = Substitute.For <ISyncServer>(); _syncServer.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _syncServer.Head.Returns(Build.A.BlockHeader.TestObject); _txPool = Substitute.For <ITxPool>(); _pooledTxsRequestor = Substitute.For <IPooledTxsRequestor>(); _discoveryApp = Substitute.For <IDiscoveryApp>(); _serializer = new MessageSerializationService(); _localPeer = Substitute.For <IRlpxPeer>(); _localPeer.LocalPort.Returns(_localPort); _localPeer.LocalNodeId.Returns(TestItem.PublicKeyA); ITimerFactory timerFactory = Substitute.For <ITimerFactory>(); _nodeStatsManager = new NodeStatsManager(timerFactory, LimboLogs.Instance); _blockTree = Substitute.For <IBlockTree>(); _blockTree.ChainId.Returns(1ul); _blockTree.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, LimboLogs.Instance); _peerStorage = Substitute.For <INetworkStorage>(); _syncPeerPool = Substitute.For <ISyncPeerPool>(); _manager = new ProtocolsManager( _syncPeerPool, _syncServer, _txPool, _pooledTxsRequestor, _discoveryApp, _serializer, _localPeer, _nodeStatsManager, _protocolValidator, _peerStorage, MainnetSpecProvider.Instance, LimboLogs.Instance); _serializer.Register(new HelloMessageSerializer()); _serializer.Register(new StatusMessageSerializer()); _serializer.Register(new DisconnectMessageSerializer()); }
//TODO Timer to periodically check active peers and move new to active based on max size and compatibility - stats and capabilities + update peers in synchronization manager //TODO Remove active and synch on disconnect //TODO Update Stats on disconnect, other events //TODO Move Discover to Network //TODO update runner to run discovery public PeerManager(IRlpxPeer localPeer, IDiscoveryManager discoveryManager, ILogger logger, IDiscoveryConfigurationProvider configurationProvider, ISynchronizationManager synchronizationManager, INodeStatsProvider nodeStatsProvider, IPeerStorage peerStorage, IPerfService perfService) { _localPeer = localPeer; _logger = logger; _configurationProvider = configurationProvider; _synchronizationManager = synchronizationManager; _nodeStatsProvider = nodeStatsProvider; _discoveryManager = discoveryManager; _perfService = perfService; _isDiscoveryEnabled = _discoveryManager != null; if (_isDiscoveryEnabled) { discoveryManager.NodeDiscovered += async(s, e) => await OnNodeDiscovered(s, e); } localPeer.ConnectionInitialized += OnRemoteConnectionInitialized; _peerStorage = peerStorage; _peerStorage.StartBatch(); }
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); }
public PeerManager( IRlpxPeer rlpxPeer, IDiscoveryApp discoveryApp, INodeStatsManager stats, INetworkStorage peerStorage, IPeerLoader peerLoader, INetworkConfig networkConfig, ILogManager logManager) { _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)); _peerStorage = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage)); _peerLoader = peerLoader ?? throw new ArgumentNullException(nameof(peerLoader)); _peerStorage.StartBatch(); _peerComparer = new PeerComparer(_stats); }
public Context() { _channel = Substitute.For <IChannel>(); _channelHandlerContext = Substitute.For <IChannelHandlerContext>(); _pipeline = Substitute.For <IChannelPipeline>(); _channelHandlerContext.Channel.Returns(_channel); _channel.Pipeline.Returns(_pipeline); _pipeline.Get <NettyPacketSplitter>().Returns(new NettyPacketSplitter()); _packetSender = Substitute.For <IPacketSender>(); _synchronizationManager = Substitute.For <ISynchronizationManager>(); _synchronizationManager.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _synchronizationManager.Head.Returns(Build.A.BlockHeader.TestObject); _transactionPool = Substitute.For <ITransactionPool>(); _discoveryApp = Substitute.For <IDiscoveryApp>(); _serializer = new MessageSerializationService(); _localPeer = Substitute.For <IRlpxPeer>(); _localPeer.LocalPort.Returns(_localPort); _localPeer.LocalNodeId.Returns(TestItem.PublicKeyA); _nodeStatsManager = new NodeStatsManager(new StatsConfig(), LimboLogs.Instance); _blockTree = Substitute.For <IBlockTree>(); _blockTree.ChainId.Returns(1); _blockTree.Genesis.Returns(Build.A.Block.Genesis.TestObject.Header); _protocolValidator = new ProtocolValidator(_nodeStatsManager, _blockTree, LimboLogs.Instance); _peerStorage = Substitute.For <INetworkStorage>(); _perfService = new PerfService(LimboLogs.Instance); _manager = new ProtocolsManager( _synchronizationManager, _transactionPool, _discoveryApp, _serializer, _localPeer, _nodeStatsManager, _protocolValidator, _peerStorage, _perfService, LimboLogs.Instance); _serializer.Register(new HelloMessageSerializer()); _serializer.Register(new StatusMessageSerializer()); _serializer.Register(new DisconnectMessageSerializer()); }
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}"); }
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(); }