public PoaTestNode(string name, IPrivateKey privateKey, IPeerSettings nodeSettings, IDfsService dfsService, IEnumerable <PeerId> knownPeerIds, IFileSystem parentTestFileSystem) { Name = name; _nodeSettings = nodeSettings; _nodeDirectory = parentTestFileSystem.GetCatalystDataDir(); _dfsService = dfsService; _rpcSettings = RpcSettingsHelper.GetRpcServerSettings(nodeSettings.Port + 100); _nodePeerId = nodeSettings.PeerId; _memPool = new Mempool(new MempoolService(new InMemoryRepository <PublicEntryDao, string>())); _peerRepository = new PeerRepository(new InMemoryRepository <Peer, string>()); var peersInRepo = knownPeerIds.Select(p => new Peer { PeerId = p, IsPoaNode = true, LastSeen = DateTime.UtcNow }).ToList(); _peerRepository.Add(peersInRepo); _deltaByNumber = new DeltaByNumberRepository(new InMemoryRepository <DeltaByNumber, string>()); _containerProvider = new ContainerProvider(new[] { Constants.NetworkConfigFile(NetworkType.Devnet), Constants.SerilogJsonConfigFile } .Select(f => Path.Combine(Constants.ConfigSubFolder, f)), parentTestFileSystem, TestContext.CurrentContext); RegisterNodeDependencies(_containerProvider.ContainerBuilder, excludedModules: new List <Type> { typeof(ApiModule), typeof(RpcServerModule) } ); _containerProvider.ConfigureContainerBuilder(true, true); OverrideContainerBuilderRegistrations(); _scope = _containerProvider.Container.BeginLifetimeScope(Name); _node = _scope.Resolve <ICatalystNode>(); var keyStore = _scope.Resolve <IKeyStore>(); var keyRegistry = _scope.Resolve <IKeyRegistry>(); keyRegistry.RemoveItemFromRegistry(KeyRegistryTypes.DefaultKey); keyRegistry.AddItemToRegistry(KeyRegistryTypes.DefaultKey, privateKey); keyStore.KeyStoreEncryptAsync(privateKey, nodeSettings.NetworkType, KeyRegistryTypes.DefaultKey) .ConfigureAwait(false).GetAwaiter() .GetResult(); }
public Task DiscoveryAsync() { var copiedPath = CopyPoaFile(); var poaPeers = JsonConvert.DeserializeObject <List <PoaPeer> >(File.ReadAllText(copiedPath)); foreach (var peer in poaPeers.Select(poaPeer => new Peer { IsPoaNode = true, PeerId = poaPeer.ToPeerId() })) { //Don't add your own peer id even if you are a POA node. if (_peerSettings.PeerId == peer.PeerId) { continue; } _logger.Information( $"Adding POA Peer: {peer.PeerId.IpAddress} Public Key: {peer.PeerId.PublicKey.KeyToString()}"); if (!_peerRepository.Exists(peer.DocumentId)) { _peerRepository.Add(peer); } } return(Task.CompletedTask); }
private void PopulatePeers(int count) { for (var i = 10; i < count + 10; i++) { _peers.Add(new Peer { PeerId = PeerIdHelper.GetPeerId(i.ToString()) }); } }
private void GeneratePeers(int count) { for (var i = 0; i < count; i++) { var peer = new Peer { PeerId = PeerIdHelper.GetPeerId(port: i) }; _peerRepository.Add(peer); } }
public void Init() { _logger = Substitute.For <ILogger>(); _fakeContext = Substitute.For <IChannelHandlerContext>(); var fakeChannel = Substitute.For <IChannel>(); _fakeContext.Channel.Returns(fakeChannel); _peerRepository = new PeerRepository(new InMemoryRepository <Peer, string>()); _peerRepository.Add(GetPeerTestData()); }
public IActionResult Post([FromBody] Peer peer) { if (peer == null) { return(BadRequest("Peer is null.")); } int id = _dataRepository.Add(peer); return(CreatedAtRoute( "PeerGet", new { Id = id }, peer)); }
public Task DiscoveryAsync() { var copiedPath = CopyPoaFile(); var poaPeers = JsonConvert.DeserializeObject <List <PoaPeer> >(File.ReadAllText(copiedPath)); foreach (var peer in poaPeers.Select(poaPeer => new Peer { PeerId = poaPeer.ToPeerId() })) { _logger.Information( $"Adding POA Peer: {peer.PeerId.IpAddress} Public Key: {peer.PeerId.PublicKey.KeyToString()}"); if (!_peerRepository.Exists(peer.DocumentId)) { _peerRepository.Add(peer); } } return(Task.CompletedTask); }
/// <summary> /// Basic method to handle ping messages. /// </summary> /// <param name="pingRequest"></param> /// <param name="channelHandlerContext"></param> /// <param name="senderPeerId"></param> /// <param name="correlationId"></param> /// <returns><see cref="PingResponse"/></returns> protected override PingResponse HandleRequest(PingRequest pingRequest, IChannelHandlerContext channelHandlerContext, PeerId senderPeerId, ICorrelationId correlationId) { Guard.Argument(pingRequest, nameof(pingRequest)).NotNull(); Guard.Argument(channelHandlerContext, nameof(channelHandlerContext)).NotNull(); Guard.Argument(senderPeerId, nameof(senderPeerId)).NotNull(); Logger.Debug("message content is {0} IP: {1} PeerId: {2}", pingRequest, senderPeerId.Ip, senderPeerId); var peer = _peerRepository.Get(senderPeerId); if (peer == null) { _peerRepository.Add(new Peer { PeerId = senderPeerId, LastSeen = DateTime.UtcNow }); } return(new PingResponse()); }
private static void AddMockPeerToDbAndSetReturnExpectation(IReadOnlyList <Peer> peer, IPeerRepository repository) { repository.Add(peer); repository.GetActivePeers(Arg.Any <int>()).Returns(peer); }
private static void AddMockPeerToDbAndSetReturnExpectation(IReadOnlyList <Peer> peer, IPeerRepository store) { store.Add(peer); store.FindAll(Arg.Any <Specification <Peer> >()).Returns(peer); }
public PoaTestNode(string name, IPrivateKey privateKey, IPeerSettings nodeSettings, IEnumerable <PeerId> knownPeerIds, IFileSystem parentTestFileSystem, ITestOutputHelper output) { Name = name; _nodeSettings = nodeSettings; _nodeDirectory = parentTestFileSystem.GetCatalystDataDir().SubDirectoryInfo(Name); var nodeFileSystem = Substitute.ForPartsOf <FileSystem>(); nodeFileSystem.GetCatalystDataDir().Returns(_nodeDirectory); _rpcSettings = RpcSettingsHelper.GetRpcServerSettings(nodeSettings.Port + 100); _nodePeerId = nodeSettings.PeerId; var baseDfsFolder = Path.Combine(parentTestFileSystem.GetCatalystDataDir().FullName, "dfs"); var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("blake2b-256")); _dfs = new DevDfs(parentTestFileSystem, hashProvider, baseDfsFolder); _memPool = new Mempool(new MempoolService(new InMemoryRepository <PublicEntryDao, string>())); _peerRepository = new PeerRepository(new InMemoryRepository <Peer, string>()); var peersInRepo = knownPeerIds.Select(p => new Peer { PeerId = p }).ToList(); _peerRepository.Add(peersInRepo); _containerProvider = new ContainerProvider(new[] { Constants.NetworkConfigFile(NetworkType.Devnet), Constants.SerilogJsonConfigFile } .Select(f => Path.Combine(Constants.ConfigSubFolder, f)), parentTestFileSystem, output); Program.RegisterNodeDependencies(_containerProvider.ContainerBuilder, excludedModules: new List <Type> { typeof(ApiModule), typeof(RpcServerModule) } ); _containerProvider.ConfigureContainerBuilder(true, true); OverrideContainerBuilderRegistrations(); _scope = _containerProvider.Container.BeginLifetimeScope(Name); _node = _scope.Resolve <ICatalystNode>(); var keyStore = _scope.Resolve <IKeyStore>(); var keyRegistry = _scope.Resolve <IKeyRegistry>(); keyRegistry.RemoveItemFromRegistry(KeyRegistryTypes.DefaultKey); keyRegistry.AddItemToRegistry(KeyRegistryTypes.DefaultKey, privateKey); keyStore.KeyStoreEncryptAsync(privateKey, nodeSettings.NetworkType, KeyRegistryTypes.DefaultKey) .ConfigureAwait(false).GetAwaiter() .GetResult(); }