Example #1
0
 public void SetUp()
 {
     _networkConfig = new NetworkConfig();
     _statsManager  = Substitute.For <INodeStatsManager>();
     _peerStorage   = Substitute.For <INetworkStorage>();
     _loader        = new PeerLoader(_networkConfig, _statsManager, _peerStorage, LimboLogs.Instance);
 }
Example #2
0
        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;
        }
Example #3
0
        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;
        }
Example #4
0
 public PeerLoader(INetworkConfig networkConfig, INodeStatsManager stats, INetworkStorage peerStorage, ILogManager logManager)
 {
     _networkConfig = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
     _stats         = stats ?? throw new ArgumentNullException(nameof(stats));
     _peerStorage   = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage));
     _logger        = logManager.GetClassLogger();
 }
Example #5
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();
 }
        public void SetUp()
        {
            _networkConfig   = new NetworkConfig();
            _discoveryConfig = new DiscoveryConfig();
            _statsManager    = Substitute.For <INodeStatsManager>();
            _peerStorage     = Substitute.For <INetworkStorage>();
            IRlpxHost rlpxHost = Substitute.For <IRlpxHost>();

            _loader = new NodesLoader(_networkConfig, _statsManager, _peerStorage, rlpxHost, LimboLogs.Instance);
        }
 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);
 }
Example #8
0
 public NodesLoader(
     INetworkConfig networkConfig,
     INodeStatsManager stats,
     INetworkStorage peerStorage,
     IRlpxHost rlpxHost,
     ILogManager logManager)
 {
     _logger        = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _stats         = stats ?? throw new ArgumentNullException(nameof(stats));
     _peerStorage   = peerStorage ?? throw new ArgumentNullException(nameof(peerStorage));
     _rlpxHost      = rlpxHost ?? throw new ArgumentNullException(nameof(rlpxHost));
     _networkConfig = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig));
 }
Example #9
0
 public DiscoveryManager(INodeLifecycleManagerFactory nodeLifecycleManagerFactory,
                         INodeTable nodeTable,
                         INetworkStorage discoveryStorage,
                         INetworkConfig networkConfig,
                         ILogManager logManager)
 {
     _logger = logManager.GetClassLogger();
     _configurationProvider       = networkConfig;
     _nodeLifecycleManagerFactory = nodeLifecycleManagerFactory;
     _nodeTable        = nodeTable;
     _discoveryStorage = discoveryStorage;
     _nodeLifecycleManagerFactory.DiscoveryManager = this;
 }
Example #10
0
 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;
 }
            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();
                _rlpxHost           = Substitute.For <IRlpxHost>();
                _rlpxHost.LocalPort.Returns(_localPort);
                _rlpxHost.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>();
                _gossipPolicy      = Substitute.For <IGossipPolicy>();
                _manager           = new ProtocolsManager(
                    _syncPeerPool,
                    _syncServer,
                    _txPool,
                    _pooledTxsRequestor,
                    _discoveryApp,
                    _serializer,
                    _rlpxHost,
                    _nodeStatsManager,
                    _protocolValidator,
                    _peerStorage,
                    MainnetSpecProvider.Instance,
                    _gossipPolicy,
                    LimboLogs.Instance);

                _serializer.Register(new HelloMessageSerializer());
                _serializer.Register(new StatusMessageSerializer());
                _serializer.Register(new DisconnectMessageSerializer());
            }
Example #12
0
            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>();
                _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);
                _syncPeerPool      = Substitute.For <IEthSyncPeerPool>();
                _manager           = new ProtocolsManager(
                    _syncPeerPool,
                    _syncServer,
                    _txPool,
                    _discoveryApp,
                    _serializer,
                    _localPeer,
                    _nodeStatsManager,
                    _protocolValidator,
                    _peerStorage,
                    _perfService,
                    LimboLogs.Instance);

                _serializer.Register(new HelloMessageSerializer());
                _serializer.Register(new StatusMessageSerializer());
                _serializer.Register(new DisconnectMessageSerializer());
            }
Example #13
0
        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);
        }
Example #14
0
 public DiscoveryApp(
     INodesLocator nodesLocator,
     IDiscoveryManager discoveryManager,
     INodeTable nodeTable,
     IMessageSerializationService messageSerializationService,
     ICryptoRandom cryptoRandom,
     INetworkStorage discoveryStorage,
     INetworkConfig networkConfig,
     ILogManager logManager, IPerfService perfService)
 {
     _logManager                  = logManager;
     _perfService                 = perfService;
     _logger                      = _logManager.GetClassLogger();
     _networkConfig               = networkConfig;
     _nodesLocator                = nodesLocator;
     _discoveryManager            = discoveryManager;
     _nodeTable                   = nodeTable;
     _messageSerializationService = messageSerializationService;
     _cryptoRandom                = cryptoRandom;
     _discoveryStorage            = discoveryStorage;
     _discoveryStorage.StartBatch();
 }
Example #15
0
 public AIManager(INetworkStorage storage)
 {
     _storage = storage;
 }