private void LoadTrainedGenome() { var genomePath = Application.streamingAssetsPath + "/Genome"; if (isWebGL) { NetworkStorage.Instance.DownloadGenome(genomePath, downloadedGenome => { trainedGenome = new GenomeWrapper(new Genome(downloadedGenome)); genomeDownloaded = true; if (initialized) { return; } useTrainedNetwork.SetIsOnWithoutNotify(true); SwitchNetwork(); initialized = true; }, Debug.Log); } else { trainedGenome = new GenomeWrapper(new Genome(NetworkStorage.LoadGenome(genomePath))); genomeDownloaded = true; if (initialized) { return; } useTrainedNetwork.SetIsOnWithoutNotify(true); SwitchNetwork(); initialized = true; } }
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 NetworkStorageForm(NetworkStorage storage) { InitializeComponent(); if (storage != null) { Caption = storage.StorageName; UncLocation = storage.DestinationFolder; deleteHereAllOtherBUtilImageFilesCheckbox.Checked = storage.DeleteBUtilFilesInDestinationFolderBeforeBackup; _EncryptUnderLsaCheckBox.Checked = storage.EncryptUnderLocalSystemAccount; skipIfExceedsLimitCheckBox.Checked = storage.SkipCopyingToNetworkStorageAndWriteWarningInLogIfBackupExceeds; limitSizeNumericUpDown.Value = storage.SkipCopyingToNetworkStorageLimitMb; skipIfExceedsLimitCheckBox_CheckedChanged(null, null); } // locals deleteHereAllOtherBUtilImageFilesCheckbox.Text = Translation.Current[371]; WhereToStoreBackupslabel.Text = Translation.Current[82]; this.Text = Translation.Current[453]; acceptButton.Text = Translation.Current[358]; Cancelbutton.Text = Translation.Current[359]; namelabel.Text = Translation.Current[360]; OptionsgroupBox.Text = Translation.Current[361]; _EncryptUnderLsaCheckBox.Text = Translation.Current[473]; skipIfExceedsLimitCheckBox.Text = Translation.Current[486]; requiredFieldsTextChanged(null, null); }
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(); }
static void Main() { Console.WriteLine("Welcome to MusicAI type 'help' to see documentation"); Network network = null; for (; ;) { string input = Console.ReadLine(); try { List <string> parts = input.Split(" ").ToList(); for (int i = 0; i < parts.Count; i++) { switch (parts[i].ToLower()) { case "-i": // Create new network network = new Network(int.Parse(parts[++i]), int.Parse(parts[++i]), int.Parse(parts[++i]), int.Parse(parts[++i])); Console.WriteLine("Network created."); break; case "-o": // Open and load network network = NetworkStorage.Load(parts[++i]); break; case "-s": // Save and store network NetworkStorage.Save(network, parts[++i]); break; case "-l": // Let the network learn network.Learn(parts[++i], int.Parse(parts[++i])); break; case "-x": // Use the network for output network.Execute(parts[++i], parts[++i], int.Parse(parts[++i])); break; case "help": Console.WriteLine(File.ReadAllText("Documentation.txt")); break; case "exit": return; default: Console.WriteLine("Command not recognized"); break; } } } catch (Exception e) { Console.WriteLine(e); } } }
public void SetUp() { NetworkNodeDecoder.Init(); ILogManager logManager = LimboLogs.Instance; ConfigProvider configSource = new ConfigProvider(); _tempDir = TempPath.GetTempDirectory(); var db = new SimpleFilePublicKeyDb("Test", _tempDir.Path, logManager); _storage = new NetworkStorage(db, logManager); }
public void Initialize() { NetworkNodeDecoder.Init(); _timestamp = new Timestamp(); _logManager = new OneLoggerLogManager(new SimpleConsoleLogger()); _configurationProvider = new ConfigProvider(); INetworkConfig networkConfig = _configurationProvider.GetConfig <INetworkConfig>(); networkConfig.DbBasePath = Path.Combine(Path.GetTempPath(), "PeerManagerTests"); networkConfig.IsActivePeerTimerEnabled = false; networkConfig.IsDiscoveryNodesPersistenceOn = false; networkConfig.IsPeersPersistenceOn = false; if (!Directory.Exists(networkConfig.DbBasePath)) { Directory.CreateDirectory(networkConfig.DbBasePath); } var syncManager = Substitute.For <ISynchronizationManager>(); Block genesisBlock = Build.A.Block.Genesis.TestObject; syncManager.Head.Returns(genesisBlock.Header); syncManager.Genesis.Returns(genesisBlock.Header); _nodeFactory = new NodeFactory(LimboLogs.Instance); _localPeer = new TestRlpxPeer(); var keyProvider = new PrivateKeyGenerator(new CryptoRandom()); var key = keyProvider.Generate().PublicKey; _synchronizationManager = Substitute.For <ISynchronizationManager>(); IStatsConfig statsConfig = _configurationProvider.GetConfig <IStatsConfig>(); var nodeTable = new NodeTable(_nodeFactory, Substitute.For <IKeyStore>(), new NodeDistanceCalculator(networkConfig), networkConfig, _logManager); nodeTable.Initialize(new NodeId(key)); _discoveryManager = new DiscoveryManager(new NodeLifecycleManagerFactory(_nodeFactory, nodeTable, new DiscoveryMessageFactory(networkConfig, _timestamp), Substitute.For <IEvictionManager>(), new NodeStatsProvider(_configurationProvider.GetConfig <IStatsConfig>(), _nodeFactory, _logManager, true), networkConfig, _logManager), _nodeFactory, nodeTable, new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)), networkConfig, _logManager); _discoveryManager.MessageSender = Substitute.For <IMessageSender>(); _transactionPool = NullTransactionPool.Instance; _blockTree = Substitute.For <IBlockTree>(); var app = new DiscoveryApp(new NodesLocator(nodeTable, _discoveryManager, _configurationProvider, _logManager), _discoveryManager, _nodeFactory, nodeTable, Substitute.For <IMessageSerializationService>(), new CryptoRandom(), Substitute.For <INetworkStorage>(), networkConfig, _logManager, new PerfService(_logManager)); app.Initialize(key); var sessionLogger = new PeerSessionLogger(_logManager, _configurationProvider, new PerfService(_logManager)); sessionLogger.Init(Path.GetTempPath()); var networkStorage = new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)); _peerManager = new PeerManager(_localPeer, app, _synchronizationManager, new NodeStatsProvider(statsConfig, _nodeFactory, _logManager, true), networkStorage, _nodeFactory, _configurationProvider, new PerfService(_logManager), _transactionPool, _logManager, sessionLogger); _peerManager.Init(true); }
public void SetUp() { NetworkNodeDecoder.Init(); NullLogManager logManager = NullLogManager.Instance; ConfigProvider configSource = new ConfigProvider(); _tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); _statsConfig = configSource.GetConfig <IStatsConfig>(); var db = new SimpleFilePublicKeyDb("Test", _tempDir, logManager); _storage = new NetworkStorage(db, logManager); }
public void SetUp() { NullLogManager logManager = NullLogManager.Instance; JsonConfigProvider configProvider = new JsonConfigProvider(); _tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); _networkConfig = configProvider.GetConfig <INetworkConfig>(); _networkConfig.DbBasePath = _tempDir; _statsConfig = configProvider.GetConfig <IStatsConfig>(); _nodeFactory = new NodeFactory(); _storage = new NetworkStorage("test", _networkConfig, logManager, new PerfService(logManager)); }
void SaveStorages() { List <GlobalSettings.Storage> storages = new List <GlobalSettings.Storage>(); foreach (ExternalStorage storage in Storages) { NetworkStorage networkStorage = storage as NetworkStorage; if (networkStorage != null) { storages.Add(new GlobalSettings.Storage() { UploadURL = networkStorage.UploadURL, DownloadURL = networkStorage.DownloadURL }); } } Settings.GlobalSettings.Data.Storages = storages; Settings.GlobalSettings.Save(); }
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 async Task Initialize() { _logManager = new OneLoggerLogManager(new SimpleConsoleLogger()); _configurationProvider = new JsonConfigProvider(); ((NetworkConfig)_configurationProvider.GetConfig <INetworkConfig>()).DbBasePath = Path.Combine(Path.GetTempPath(), "PeerManagerTests"); if (!Directory.Exists(_configurationProvider.GetConfig <INetworkConfig>().DbBasePath)) { Directory.CreateDirectory(_configurationProvider.GetConfig <INetworkConfig>().DbBasePath); } var serializationService = Build.A.SerializationService().WithEncryptionHandshake().WithP2P().WithEth().TestObject; var syncManager = Substitute.For <ISynchronizationManager>(); Block genesisBlock = Build.A.Block.Genesis.TestObject; syncManager.Head.Returns(genesisBlock.Header); syncManager.Genesis.Returns(genesisBlock.Header); _nodeFactory = new NodeFactory(); _localPeer = new TestRlpxPeer(); var keyProvider = new PrivateKeyProvider(new CryptoRandom()); var key = keyProvider.PrivateKey.PublicKey; _synchronizationManager = Substitute.For <ISynchronizationManager>(); var nodeTable = new NodeTable(_nodeFactory, Substitute.For <IKeyStore>(), new NodeDistanceCalculator(_configurationProvider), _configurationProvider, _logManager); nodeTable.Initialize(new NodeId(key)); INetworkConfig networkConfig = _configurationProvider.GetConfig <INetworkConfig>(); IStatsConfig statsConfig = _configurationProvider.GetConfig <IStatsConfig>(); _discoveryManager = new DiscoveryManager(new NodeLifecycleManagerFactory(_nodeFactory, nodeTable, new DiscoveryMessageFactory(_configurationProvider), Substitute.For <IEvictionManager>(), new NodeStatsProvider(_configurationProvider.GetConfig <IStatsConfig>(), _nodeFactory, _logManager), _configurationProvider, _logManager), _nodeFactory, nodeTable, new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)), _configurationProvider, _logManager); _discoveryManager.MessageSender = Substitute.For <IMessageSender>(); var networkStorage = new NetworkStorage("test", networkConfig, _logManager, new PerfService(_logManager)); _peerManager = new PeerManager(_localPeer, _discoveryManager, _synchronizationManager, new NodeStatsProvider(statsConfig, _nodeFactory, _logManager), networkStorage, _nodeFactory, _configurationProvider, new PerfService(_logManager), _logManager); _peerManager.Init(true); }
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 void InitDiscovery() { if (_ctx.NodeStatsManager == null) { throw new StepDependencyException(nameof(_ctx.NodeStatsManager)); } if (_ctx.Timestamper == null) { throw new StepDependencyException(nameof(_ctx.Timestamper)); } if (_ctx.NodeKey == null) { throw new StepDependencyException(nameof(_ctx.NodeKey)); } if (_ctx.CryptoRandom == null) { throw new StepDependencyException(nameof(_ctx.CryptoRandom)); } if (!_ctx.Config <IInitConfig>().DiscoveryEnabled) { _ctx.DiscoveryApp = new NullDiscoveryApp(); return; } IDiscoveryConfig discoveryConfig = _ctx.Config <IDiscoveryConfig>(); SameKeyGenerator privateKeyProvider = new SameKeyGenerator(_ctx.NodeKey.Unprotect()); DiscoveryMessageFactory discoveryMessageFactory = new DiscoveryMessageFactory(_ctx.Timestamper); NodeIdResolver nodeIdResolver = new NodeIdResolver(_ctx.EthereumEcdsa); IPResolver ipResolver = new IPResolver(_networkConfig, _ctx.LogManager); IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider( _ctx._messageSerializationService, _ctx.EthereumEcdsa, privateKeyProvider, discoveryMessageFactory, nodeIdResolver); msgSerializersProvider.RegisterDiscoverySerializers(); NodeDistanceCalculator nodeDistanceCalculator = new NodeDistanceCalculator(discoveryConfig); NodeTable nodeTable = new NodeTable(nodeDistanceCalculator, discoveryConfig, _networkConfig, _ctx.LogManager); EvictionManager evictionManager = new EvictionManager(nodeTable, _ctx.LogManager); NodeLifecycleManagerFactory nodeLifeCycleFactory = new NodeLifecycleManagerFactory( nodeTable, discoveryMessageFactory, evictionManager, _ctx.NodeStatsManager, discoveryConfig, _ctx.LogManager); SimpleFilePublicKeyDb discoveryDb = new SimpleFilePublicKeyDb("DiscoveryDB", DiscoveryNodesDbPath.GetApplicationResourcePath(_ctx.Config <IInitConfig>().BaseDbPath), _ctx.LogManager); NetworkStorage discoveryStorage = new NetworkStorage( discoveryDb, _ctx.LogManager); DiscoveryManager discoveryManager = new DiscoveryManager( nodeLifeCycleFactory, nodeTable, discoveryStorage, discoveryConfig, _ctx.LogManager, ipResolver ); NodesLocator nodesLocator = new NodesLocator( nodeTable, discoveryManager, discoveryConfig, _ctx.LogManager); _ctx.DiscoveryApp = new DiscoveryApp( nodesLocator, discoveryManager, nodeTable, _ctx._messageSerializationService, _ctx.CryptoRandom, discoveryStorage, _networkConfig, discoveryConfig, _ctx.Timestamper, _ctx.LogManager); _ctx.DiscoveryApp.Initialize(_ctx.NodeKey.PublicKey); }
private void InitDiscovery() { _configProvider.GetConfig <INetworkConfig>().MasterPort = _initConfig.DiscoveryPort; var privateKeyProvider = new PrivateKeyProvider(_privateKey); var discoveryMessageFactory = new DiscoveryMessageFactory(_configProvider); var nodeIdResolver = new NodeIdResolver(_signer); IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider( _messageSerializationService, _signer, privateKeyProvider, discoveryMessageFactory, nodeIdResolver, _nodeFactory); msgSerializersProvider.RegisterDiscoverySerializers(); var nodeDistanceCalculator = new NodeDistanceCalculator(_configProvider); var nodeTable = new NodeTable( _nodeFactory, _keyStore, nodeDistanceCalculator, _configProvider, _logManager); var evictionManager = new EvictionManager( nodeTable, _logManager); var nodeLifeCycleFactory = new NodeLifecycleManagerFactory( _nodeFactory, nodeTable, discoveryMessageFactory, evictionManager, _nodeStatsProvider, _configProvider, _logManager); var discoveryStorage = new NetworkStorage( DiscoveryNodesDbPath, _configProvider.GetConfig <INetworkConfig>(), _logManager, _perfService); _discoveryManager = new DiscoveryManager( nodeLifeCycleFactory, _nodeFactory, nodeTable, discoveryStorage, _configProvider, _logManager); var nodesLocator = new NodesLocator( nodeTable, _discoveryManager, _configProvider, _logManager); _discoveryApp = new DiscoveryApp( nodesLocator, _discoveryManager, _nodeFactory, nodeTable, _messageSerializationService, _cryptoRandom, discoveryStorage, _configProvider, _logManager, _perfService); _discoveryApp.Initialize(_privateKey.PublicKey); }
private void InitDiscovery() { if (!_initConfig.DiscoveryEnabled) { _discoveryApp = new NullDiscoveryApp(); return; } IDiscoveryConfig discoveryConfig = _configProvider.GetConfig <IDiscoveryConfig>(); var privateKeyProvider = new SameKeyGenerator(_nodeKey); var discoveryMessageFactory = new DiscoveryMessageFactory(_timestamper); var nodeIdResolver = new NodeIdResolver(_ethereumEcdsa); IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider( _messageSerializationService, _ethereumEcdsa, privateKeyProvider, discoveryMessageFactory, nodeIdResolver); msgSerializersProvider.RegisterDiscoverySerializers(); var nodeDistanceCalculator = new NodeDistanceCalculator(discoveryConfig); var nodeTable = new NodeTable(nodeDistanceCalculator, discoveryConfig, _networkConfig, _logManager); var evictionManager = new EvictionManager(nodeTable, _logManager); var nodeLifeCycleFactory = new NodeLifecycleManagerFactory( nodeTable, discoveryMessageFactory, evictionManager, _nodeStatsManager, discoveryConfig, _logManager); var discoveryDb = new SimpleFilePublicKeyDb("DiscoveryDB", Path.Combine(_initConfig.BaseDbPath, DiscoveryNodesDbPath), _logManager); var discoveryStorage = new NetworkStorage( discoveryDb, _logManager); var discoveryManager = new DiscoveryManager( nodeLifeCycleFactory, nodeTable, discoveryStorage, discoveryConfig, _logManager); var nodesLocator = new NodesLocator( nodeTable, discoveryManager, discoveryConfig, _logManager); _discoveryApp = new DiscoveryApp( nodesLocator, discoveryManager, nodeTable, _messageSerializationService, _cryptoRandom, discoveryStorage, _networkConfig, discoveryConfig, _timestamper, _logManager, _perfService); _discoveryApp.Initialize(_nodeKey.PublicKey); }
private void InitDiscovery() { if (!_initConfig.DiscoveryEnabled) { _discoveryApp = new NullDiscoveryApp(); return; } INetworkConfig networkConfig = _configProvider.GetConfig <INetworkConfig>(); networkConfig.MasterPort = _initConfig.DiscoveryPort; var privateKeyProvider = new SameKeyGenerator(_nodeKey); var discoveryMessageFactory = new DiscoveryMessageFactory(networkConfig, _timestamp); var nodeIdResolver = new NodeIdResolver(_ecdsa); IDiscoveryMsgSerializersProvider msgSerializersProvider = new DiscoveryMsgSerializersProvider( _messageSerializationService, _ecdsa, privateKeyProvider, discoveryMessageFactory, nodeIdResolver); msgSerializersProvider.RegisterDiscoverySerializers(); var nodeDistanceCalculator = new NodeDistanceCalculator(networkConfig); var nodeTable = new NodeTable( _keyStore, nodeDistanceCalculator, networkConfig, _logManager); var evictionManager = new EvictionManager( nodeTable, _logManager); var nodeLifeCycleFactory = new NodeLifecycleManagerFactory( nodeTable, discoveryMessageFactory, evictionManager, _nodeStatsManager, networkConfig, _logManager); var discoveryStorage = new NetworkStorage( DiscoveryNodesDbPath, networkConfig, _logManager, _perfService); var discoveryManager = new DiscoveryManager( nodeLifeCycleFactory, nodeTable, discoveryStorage, networkConfig, _logManager); var nodesLocator = new NodesLocator( nodeTable, discoveryManager, _configProvider, _logManager); _discoveryApp = new DiscoveryApp( nodesLocator, discoveryManager, nodeTable, _messageSerializationService, _cryptoRandom, discoveryStorage, networkConfig, _logManager, _perfService); _discoveryApp.Initialize(_nodeKey.PublicKey); }
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(); }