Example #1
0
        public BlockStrategist(TorrentData data)
        {
            _blockSize   = Global.Instance.BlockSize;
            _pieceSize   = data.PieceLength;
            _totalSize   = data.Files.Sum(f => f.Length);
            _blockCount  = (int)Math.Ceiling((float)_totalSize / _blockSize);
            _pieces      = new int[data.PieceCount];
            Bitfield     = new BitArray(data.PieceCount);
            _unavailable = new BlockAddressCollection <int>();
            for (var i = 0; i < _blockCount; i++)
            {
                _unavailable.Add(i);
            }

            for (var i = 0; i < data.PieceCount - 1; i++)
            {
                _pieces[i] = data.PieceLength;
            }
            var lastLength = (int)(data.TotalLength - data.PieceLength * (data.PieceCount - 1));

            _pieces[_pieces.Length - 1] = lastLength;
        }
Example #2
0
        public BlockStrategist(TorrentData data)
        {
            this.blockSize = Global.Instance.BlockSize;
            pieceSize      = data.PieceLength;
            totalSize      = data.Files.Sum(f => f.Length);
            blockCount     = (int)Math.Ceiling((float)totalSize / blockSize);
            pieces         = new int[data.PieceCount];
            Bitfield       = new BitArray(data.PieceCount);
            unavailable    = new BlockAddressCollection <int>();
            for (int i = 0; i < blockCount; i++)
            {
                unavailable.Add(i);
            }

            for (int i = 0; i < data.PieceCount - 1; i++)
            {
                pieces[i] = data.PieceLength;
            }
            int lastLength = (int)(data.TotalLength - (data.PieceLength * (data.PieceCount - 1)));

            pieces[pieces.Length - 1] = lastLength;
        }