Example #1
0
        public int RequestForNewPiece()
        {
            int piece = 0, offset = 0, length = 0;

            if (!CurrentFile.GetNextMissingPiece(ref piece, ref offset, ref length))
            {
                return(-1);
            }

            if (!DifferenceBitField.GetPiece(piece))
            {
#if DEBUG
                Console.WriteLine("Cutting connection.. Peer does not have the piece");
#endif
                return(-1); //does not have the piece
            }

#if DEBUG
            Console.WriteLine("Requesting for piece: {0}", piece);
#endif

            byte[] pieceRequest = PacketGenerator.Request(piece, offset, length);
            Send(pieceRequest);
            State = PeerState.DOWNLOADING;

            return(piece);
        }