/// <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("({0}:'{1}')", nameof(chainedBlock), 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 '{0}' assigned to peer {1:x}, penalty is {2}.", chainedBlock.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.", chainedBlock.HashBlock); this.AssignPendingVectors(); } this.logger.LogTrace("(-)"); }