예제 #1
0
 public async Task <T> GetAsync <T>(string endpointWithArgs)
 {
     foreach (var nodeUrl in _nodesRepository.GetNodes(NodesRepositoryFilter.OnlyActive))
     {
         var obj = await GetAsync <T>(nodeUrl, endpointWithArgs);
     }
     return(default(T));
 }
 public ActionResult GetNodes()
 {
     return(Ok(new InformationNodes()
     {
         Nodes = _nodesRepository.GetNodes(NodesRepositoryFilter.All),
     }));
 }
예제 #3
0
        private async Task NetworkDiscovery()
        {
            var nodesActive            = _nodesRepository.GetNodes(NodesRepositoryFilter.OnlyActive).ToList();
            var nodesActiveWithoutSelf = nodesActive.Where(n => !n.Contains(_nodeOptions.Value.Self)).ToList();

            if (nodesActive.Count == nodesActiveWithoutSelf.Count)
            {
                nodesActive.Add(_nodeOptions.Value.Self);
            }
            var tasks = nodesActiveWithoutSelf.Select(async(nodeUrl) =>
            {
                var timer    = DateTimeOffset.Now.ToUnixTimeSeconds();
                var result   = await _peerCommunicationService.GetAsync <InformationNodes>(nodeUrl, Endpoints.Information + "/nodes");
                var timespan = DateTimeOffset.Now.ToUnixTimeSeconds() - timer;
                ProcessResult(nodeUrl, result, timespan);
                if (result != null && result.Nodes != null && !result.Nodes.Contains(_nodeOptions.Value.Self))
                {
                    await _peerCommunicationService.SendAsync(
                        nodesActiveWithoutSelf,
                        Endpoints.Information + "/nodes",
                        new InformationNodesAdd()
                    {
                        Nodes = nodesActive
                    });
                }
            });
            await Task.WhenAll(tasks);
        }
예제 #4
0
 private async Task SendNewBlockAsync(Block createdBlock)
 {
     var nodes = _nodesRepository.GetNodes(NodesRepositoryFilter.OnlyActive);
     await _peerCommunicationService.SendAsync(nodes, Endpoints.Blockchain, createdBlock);
 }