Ejemplo n.º 1
0
 /// <summary>
 /// Handles the PieceCompleted event of the PieceManager control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="PieceCompletedEventArgs"/> instance containing the event data.</param>
 private void PieceManager_PieceCompleted(object sender, PieceCompletedEventArgs e)
 {
     if (this.HandshakeState == HandshakeState.SendAndReceived)
     {
         this.EnqueueSendMessage(new HaveMessage(e.PieceIndex));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the PieceCompleted event of the PieceManager control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PieceCompletedEventArgs"/> instance containing the event data.</param>
        private void PieceManager_PieceCompleted(object sender, PieceCompletedEventArgs e)
        {
            Debug.WriteLine($"piece {e.PieceIndex} completed for torrent {this.TorrentInfo.InfoHash}");

            // persist piece
            this.persistenceManager.Put(this.TorrentInfo.Files, this.TorrentInfo.PieceLength, e.PieceIndex, e.PieceData);

            if (this.pieceManager.CompletedPercentage == 1)
            {
                this.OnTorrentSeeding(this, EventArgs.Empty);
            }
            else
            {
                this.OnTorrentLeeching(this, EventArgs.Empty);
            }
        }