コード例 #1
0
 //Caller should add to the puller map
 internal void StartDownload(GetDataPayload getDataPayload)
 {
     foreach (var inv in getDataPayload.Inventory)
     {
         inv.Type = AttachedNode.AddSupportedOptions(inv.Type);
         _PendingDownloads.TryAdd(inv.Hash, inv.Hash);
     }
     AttachedNode.SendMessageAsync(getDataPayload);
 }
コード例 #2
0
        public void AskBlocks()
        {
            if (AttachedNode.State != NodeState.HandShaked)
            {
                return;
            }
            var pendingTip = AttachedNode.Behaviors.Find <ChainBehavior>().PendingTip;

            if (pendingTip == null || pendingTip.Height < AttachedNode.PeerVersion.StartHeight)
            {
                return;
            }
            if (_InFlights.Count != 0)
            {
                return;
            }
            var currentLocation = _CurrentLocation ?? new BlockLocator()
            {
                Blocks = { Chain.GetBlock(StartHeight).HashBlock }
            };;
            var currentBlock = Chain.FindFork(currentLocation);

            if (currentBlock.Height < StartHeight)
            {
                currentBlock = Chain.GetBlock(StartHeight) ?? pendingTip;
            }

            //Up to date
            if (pendingTip.HashBlock == currentBlock.HashBlock)
            {
                return;
            }

            var toDownload = pendingTip.EnumerateToGenesis().TakeWhile(b => b.HashBlock != currentBlock.HashBlock).ToArray();

            Array.Reverse(toDownload);
            var invs = toDownload.Take(10)
                       .Select(b => new InventoryVector(AttachedNode.AddSupportedOptions(InventoryType.MSG_BLOCK), b.HashBlock))
                       .Where(b => _InFlights.TryAdd(b.Hash, new Download()))
                       .ToArray();

            if (invs.Length != 0)
            {
                AttachedNode.SendMessageAsync(new GetDataPayload(invs));
                Runtime.Repository.SetIndexProgress(currentLocation);
            }
        }
コード例 #3
0
 internal void StartDownload(uint256 block)
 {
     if (_Puller._Map.TryAdd(block, this))
     {
         _PendingDownloads.TryAdd(block, block);
         AttachedNode.SendMessageAsync(new GetDataPayload(new InventoryVector(AttachedNode.AddSupportedOptions(InventoryType.MSG_BLOCK), block)));
     }
 }