OctoTorrent.Client.InitialSeedUnchoker.ReceivedHave C# (CSharp) Method

ReceivedHave() public method

public ReceivedHave ( PeerId peer, int pieceIndex ) : void
peer PeerId
pieceIndex int
return void
        public void ReceivedHave(PeerId peer, int pieceIndex)
        {
            bitfield[pieceIndex] = true;

            // If a peer reports they have a piece that *isn't* the peer
            // we uploaded it to, then the peer we uploaded to has shared it
            foreach (ChokeData data in peers)
            {
                if (data.CurrentPieces[pieceIndex] && data.Peer != peer)
                {
                    data.CurrentPieces[pieceIndex] = false;
                    data.SharedPieces++;
                    // Give him another piece if no-one else is waiting.
                    TryAdvertisePiece(data);
                    break;
                }
            }

            foreach (SeededPiece piece in advertisedPieces)
            {
                if (piece.Index == pieceIndex)
                {
                    advertisedPieces.Remove(piece);
                    return;
                }
            }
        }

Usage Example

示例#1
0
 protected override void HandleHaveMessage(PeerId id, HaveMessage message)
 {
     base.HandleHaveMessage(id, message);
     _unchoker.ReceivedHave(id, message.PieceIndex);
 }