Esempio n. 1
0
        /// <summary>
        /// Decreases the quality score of the peer node.
        /// <para>This function is called when something goes wrong with the peer.</para>
        /// <para>If the score reaches the minimal value, the tasks assigned for the node are released.</para>
        /// </summary>
        /// <param name="chainedHeader>Block the node wanted to download, but something went wrong during the process.</param>
        protected void OnStalling(ChainedHeader chainedHeader)
        {
            this.logger.LogTrace("({0}:'{1}')", nameof(chainedHeader), chainedHeader.HashBlock);
            BlockPullerBehavior behavior = null;

            lock (this.lockObject)
            {
                this.assignedBlockTasks.TryGetValue(chainedHeader.HashBlock, out behavior);
            }

            if (behavior != null)
            {
                double penalty = -1;
                this.logger.LogTrace("Block '{0}' assigned to peer {1:x}, penalty is {2}.", chainedHeader.HashBlock, behavior.GetHashCode(), penalty);

                behavior.UpdateQualityScore(penalty);
                if (Math.Abs(behavior.QualityScore - QualityScore.MinScore) < 0.00001)
                {
                    behavior.ReleaseAll(false);
                    this.AssignPendingVectors();
                }
            }
            else
            {
                this.logger.LogTrace("Block '{0}' not assigned to any peer.", chainedHeader.HashBlock);
                this.AssignPendingVectors();
            }

            this.logger.LogTrace("(-)");
        }
Esempio n. 2
0
        /// <summary>
        /// Decreases the quality score of the peer node.
        /// <para>This function is called when something goes wrong with the peer.</para>
        /// <para>If the score reaches the minimal value, the tasks assigned for the node are released.</para>
        /// </summary>
        /// <param name="chainedBlock">Block the node wanted to download, but something went wrong during the process.</param>
        protected void OnStalling(ChainedBlock chainedBlock)
        {
            this.logger.LogTrace($"({nameof(chainedBlock)}.{nameof(chainedBlock.HashBlock)}:'{chainedBlock.HashBlock}')");
            BlockPullerBehavior behavior = null;

            lock (this.lockObject)
            {
                this.assignedBlockTasks.TryGetValue(chainedBlock.HashBlock, out behavior);
            }

            if (behavior != null)
            {
                double penalty = this.peerQuality.CalculateNextBlockTimeoutQualityPenalty();
                this.logger.LogTrace($"Block '{chainedBlock.HashBlock}' assigned to '{behavior.GetHashCode():x}', penalty is {penalty}.");

                behavior.UpdateQualityScore(penalty);
                if (Math.Abs(behavior.QualityScore - QualityScore.MinScore) < 0.00001)
                {
                    behavior.ReleaseAll();
                    this.AssignPendingVectors();
                }
            }
            else
            {
                this.logger.LogTrace($"Block '{chainedBlock.HashBlock}' not assigned to any peer.");
                this.AssignPendingVectors();
            }

            this.logger.LogTrace("(-)");
        }
        protected void OnStalling(ChainedBlock chainedBlock)
        {
            BlockPullerBehavior behavior = null;

            if (this.map.TryGetValue(chainedBlock.HashBlock, out behavior))
            {
                behavior.QualityScore = Math.Max(MinQualityScore, behavior.QualityScore - 1);
                if (behavior.QualityScore == MinQualityScore)
                {
                    // TODO: this does not necessarily mean the node is slow
                    // the best way is to check the nodes download speed, how
                    // many kb/s the node for the node download speed.
                    behavior.ReleaseAll();
                    AssignPendingVectors();
                }
            }
            else
            {
                AssignPendingVectors();
            }
        }