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);
        }
Exemple #2
0
 private IEnumerable <Block> GetNextBlockFromNodes(string headBlockHash)
 {
     foreach (var node in _nodesRepository.GetNodes(NodesRepositoryFilter.OnlyActive))
     {
         var headBlockHashEncoded = WebUtility.UrlEncode(headBlockHash);
         var block = _peerCommunicationService.GetAsync <Block>(node, Endpoints.Blockchain + "/next/" + headBlockHashEncoded);
         if (block != null && block.Result != null)
         {
             yield return(block.Result);
         }
     }
 }