OctoTorrent.Client.InitialSeedUnchoker.ReceivedHave C# (CSharp) Méthode

ReceivedHave() public méthode

public ReceivedHave ( PeerId peer, int pieceIndex ) : void
peer PeerId
pieceIndex int
Résultat 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

 protected override void HandleHaveMessage(PeerId id, HaveMessage message)
 {
     base.HandleHaveMessage(id, message);
     _unchoker.ReceivedHave(id, message.PieceIndex);
 }