public async Task WriteSameBlockDifferentTorrents()
        {
            var data1 = new byte[] { 1, 1, 1 };
            var data2 = new byte[] { 2, 2, 2 };

            var torrent2 = TestTorrentManagerInfo.Create(
                files: torrent.TorrentInfo.Files,
                pieceLength: torrent.TorrentInfo.PieceLength,
                size: torrent.TorrentInfo.Size
                );

            var memory = new MemoryCache(new MemoryPool(), 1024, new NullWriter());
            await memory.WriteAsync(torrent, new BlockInfo (0, 0, 3), data1, false);

            await memory.WriteAsync(torrent2, new BlockInfo (0, 0, 3), data2, false);

            var readBuffer = new byte[3];
            await memory.ReadAsync(torrent, new BlockInfo (0, 0, 3), readBuffer);

            CollectionAssert.AreEqual(data1, readBuffer);

            await memory.ReadAsync(torrent2, new BlockInfo (0, 0, 3), readBuffer);

            CollectionAssert.AreEqual(data2, readBuffer);
        }
示例#2
0
 public void Setup()
 {
     checker = new PiecePickerFilterChecker(new StandardPicker());
     picker  = new RandomisedPicker(checker);
     seeder  = PeerId.CreateNull(40, true, false, true);
     picker.Initialise(TestTorrentManagerInfo.Create(pieceLength: Constants.BlockSize * 2, size: Constants.BlockSize * 2 * 40));
 }
示例#3
0
 TestTorrentManagerInfo CreateTestTorrentData()
 {
     return(TestTorrentManagerInfo.Create(
                size: 64 * 1024 * 40,
                pieceLength: 64 * 1024,
                files: TorrentFileInfo.Create(64 * 1024, 64 * 1024 * 40)
                ));
 }
        public void PieceCount()
        {
            Assert.AreEqual(2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 2 + 1, pieceLength: Constants.BlockSize * 2).TorrentInfo.PieceCount());
            Assert.AreEqual(2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4 - 1, pieceLength: Constants.BlockSize * 2).TorrentInfo.PieceCount());
            Assert.AreEqual(2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.PieceCount());
            Assert.AreEqual(3, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4 + 1, pieceLength: Constants.BlockSize * 2).TorrentInfo.PieceCount());

            Assert.AreEqual(262144, TestTorrentManagerInfo.Create(size: (long)(int.MaxValue) * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.PieceCount());
        }
        public void Setup()
        {
            var pieceLength = Constants.BlockSize * 8;
            var files       = TorrentFileInfo.Create(pieceLength, ("Relative/Path.txt", Constants.BlockSize * 5, "Full/Path/Relative/Path.txt"));

            torrent = TestTorrentManagerInfo.Create(pieceLength: pieceLength, size: files.Single().Length, files: files);

            writer = new MemoryWriter();
            cache  = new MemoryCache(new MemoryPool(), Constants.BlockSize * 4, writer);
        }
        ITorrentManagerInfo CreateTorrentInfo()
        {
            var files = TorrentFileInfo.Create(Constants.BlockSize * 8, 1024 * 1024 * 8);

            return(TestTorrentManagerInfo.Create(
                       size: files.Single().Length,
                       pieceLength: Constants.BlockSize * 8,
                       files: files
                       ));
        }
        public void BytesPerPiece()
        {
            Assert.AreEqual(Constants.BlockSize * 2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.BytesPerPiece(0));
            Assert.AreEqual(Constants.BlockSize * 2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.BytesPerPiece(1));

            Assert.AreEqual(1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4 + 1, pieceLength: Constants.BlockSize * 2).TorrentInfo.BytesPerPiece(2));
            Assert.AreEqual(Constants.BlockSize - 1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 5 - 1, pieceLength: Constants.BlockSize * 2).TorrentInfo.BytesPerPiece(2));

            Assert.AreEqual(Constants.BlockSize * 2, TestTorrentManagerInfo.Create(size: (long)(int.MaxValue) * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.BytesPerPiece(2));
        }
        public void ByteOffsetToPieceIndex()
        {
            Assert.AreEqual(0, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(0));
            Assert.AreEqual(0, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(1));
            Assert.AreEqual(0, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 2 - 1));
            Assert.AreEqual(1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 2));
            Assert.AreEqual(1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 2 + 1));
            Assert.AreEqual(1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 3 - 1));
            Assert.AreEqual(1, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 3));
            Assert.AreEqual(2, TestTorrentManagerInfo.Create(size: Constants.BlockSize * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 4));

            Assert.AreEqual(2, TestTorrentManagerInfo.Create(size: (long)(int.MaxValue) * 4, pieceLength: Constants.BlockSize * 2).TorrentInfo.ByteOffsetToPieceIndex(Constants.BlockSize * 4));
        }
        public void Setup()
        {
            buffer = new byte[100000];
            offset = 2362;
            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = 0xff;
            }

            torrentData = TestTorrentManagerInfo.Create(
                pieceLength: 16 * Constants.BlockSize,
                size: 40 * 16 * Constants.BlockSize
                );
        }
示例#10
0
        public void Setup()
        {
            var pieceLength = Constants.BlockSize * 2;
            var files       = TorrentFileInfo.Create(pieceLength,
                                                     Constants.BlockSize / 2,
                                                     Constants.BlockSize,
                                                     Constants.BlockSize + Constants.BlockSize / 2,
                                                     Constants.BlockSize * 2 + Constants.BlockSize / 2
                                                     );

            buffer = new byte[Constants.BlockSize];
            data   = TestTorrentManagerInfo.Create(
                files: files,
                size: files.Sum(f => f.Length),
                pieceLength: pieceLength
                );

            writer      = new ExceptionWriter();
            diskManager = new DiskManager(new EngineSettings(), Factories.Default, writer);
        }
示例#11
0
        static ITorrentManagerInfo CreateMultiFile()
        {
            int pieceLength = 1024 * 16 * 16;

            long[] sizes =
            {
                pieceLength * 10,
                   pieceLength * 7 + 123,
                   pieceLength * 32 + 123,
                   pieceLength * 16 + 543,
                   pieceLength * 19 + 591,
                   pieceLength * 22 + 591,
                   pieceLength * 0 + 12, // 12 byte file!
                   pieceLength * 7,
            };

            var files = TorrentFileInfo.Create(pieceLength, sizes);

            return(TestTorrentManagerInfo.Create(
                       files: files,
                       pieceLength: pieceLength,
                       size: files.Sum(t => t.Length)
                       ));
        }
        public void Setup()
        {
            int pieceCount  = 40;
            int pieceLength = 256 * 1024;

            bitfield    = new BitField(pieceCount);
            torrentData = TestTorrentManagerInfo.Create(
                files: TorrentFileInfo.Create(pieceLength, ("File", pieceLength * pieceCount, "Full/Path/File")),
                pieceLength: pieceLength,
                size: pieceLength * pieceCount
                );
            peers = new List <PeerId> ();

            picker = new StandardPicker();
            picker.Initialise(torrentData);

            peer = PeerId.CreateNull(pieceCount);
            for (int i = 0; i < 20; i++)
            {
                PeerId p = PeerId.CreateNull(pieceCount);
                p.SupportsFastPeer = true;
                peers.Add(p);
            }
        }