Example #1
0
 protected override void HandleRequest(RequestMessage request, PeerState peer)
 {
     if (!peer.IsChoked && request.Length <= Global.Instance.BlockSize)
     {
         BlockManager.GetBlock(new byte[request.Length], request.Index, request.Offset, request.Length, BlockRead, peer);
     }
 }
Example #2
0
        private void StartTask()
        {
            if (!Directory.Exists(BlockManager.MainDirectory))
            {
                Stop(true);
                OnHashingComplete();
                return;
            }
            pieceBuffer     = new byte[Metadata.PieceLength];
            remainingPieces = Metadata.PieceCount;
            int lastPieceLength = (int)(Metadata.TotalLength - (Metadata.PieceLength * (Metadata.PieceCount - 1)));

            //цикъл за проверка всеки блок (без последния, който може да бъде с произволен размер)
            for (int i = 0; i < Metadata.PieceCount - 1; i++)
            {
                if (Stopping)
                {
                    return;
                }
                try
                {   //асинхронна заявка за прочитане на блок от файловата система
                    BlockManager.GetBlock(pieceBuffer, i, 0, Metadata.PieceLength, PieceRead, i);
                }
                catch { }
            }
            try
            {   //обработка на последния блок
                BlockManager.GetBlock(pieceBuffer, Metadata.PieceCount - 1, 0, lastPieceLength, PieceRead, Metadata.PieceCount - 1);
            }
            catch { }
        }