Example #1
0
        private void DistributeDownload(InventoryVector[] vectors, BlockPullerBehavior[] innernodes, int minHight)
        {
            if (vectors.Length == 0)
            {
                return;
            }

            // Be careful to not ask block to a node that do not have it
            // (we can check the ChainBehavior.PendingTip to know where the node is standing)
            var selectnodes = new List <BlockPullerBehavior>();

            foreach (var behavior in innernodes)
            {
                // filter nodes that are still behind
                if (behavior.BestKnownTip?.Height >= minHight)
                {
                    selectnodes.Add(behavior);
                }
            }
            innernodes = selectnodes.ToArray();

            if (innernodes.Length == 0)
            {
                foreach (var v in vectors)
                {
                    pendingInventoryVectors.Add(v.Hash);
                }
                return;
            }

            var scores     = innernodes.Select(n => n.QualityScore == MaxQualityScore ? MaxQualityScore * 2 : n.QualityScore).ToArray();
            var totalScore = scores.Sum();

            GetDataPayload[] getDatas = Nodes.Select(n => new GetDataPayload()).ToArray();
            foreach (var inv in vectors)
            {
                var index   = GetNodeIndex(scores, totalScore);
                var node    = innernodes[index];
                var getData = getDatas[index];
                if (map.TryAdd(inv.Hash, node))
                {
                    getData.Inventory.Add(inv);
                }
            }
            for (int i = 0; i < innernodes.Length; i++)
            {
                if (getDatas[i].Inventory.Count == 0)
                {
                    continue;
                }
                innernodes[i].StartDownload(getDatas[i]);
            }
        }
Example #2
0
 public override void RequestOptions(TransactionOptions transactionOptions)
 {
     if (transactionOptions == TransactionOptions.Witness)
     {
         _Requirements.RequiredServices |= NodeServices.NODE_WITNESS;
         foreach (var node in _Nodes.Select(n => n.Behaviors.Find <NodesBlockPullerBehavior>()))
         {
             if (!_Requirements.Check(node.AttachedNode.PeerVersion))
             {
                 node.ReleaseAll();
             }
         }
     }
 }