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;
}
}
}