Пример #1
0
        public void StartEndIndices4()
        {
            const int pieceLength = 32 * 32;
            var       files       = new[]
            {
                new TorrentFile("File0", pieceLength - 10),
                new TorrentFile("File1", 11)
            };
            var t = TestRig.CreateMultiFile(files, pieceLength).Torrent;

            Assert.AreEqual(0, t.Files[0].StartPieceIndex, "#1");
            Assert.AreEqual(0, t.Files[0].EndPieceIndex, "#2");

            Assert.AreEqual(0, t.Files[1].StartPieceIndex, "#3");
            Assert.AreEqual(1, t.Files[1].EndPieceIndex, "#4");
        }
Пример #2
0
        public virtual void Setup()
        {
            // Yes, this is horrible. Deal with it.
            rig   = TestRig.CreateMultiFile();
            peers = new List <PeerId>();

            manager = new PieceManager();
            manager.ChangePicker((standardPicker = new StandardPicker()), rig.Manager.Bitfield, rig.Manager.Torrent.Files);
            this.picker = manager.Picker;

            peer = new PeerId(new Peer(new string('a', 20), new Uri("ipv4://BLAH")), rig.Manager, NullConnection.Incoming);
            for (int i = 0; i < 20; i++)
            {
                PeerId p = new PeerId(new Peer(new string(i.ToString()[0], 20), new Uri("ipv4://" + i)), rig.Manager, NullConnection.Incoming);
                p.SupportsFastPeer = true;
                peers.Add(p);
            }
        }
Пример #3
0
        public async Task Setup(bool metadataMode, bool multiFile = false, bool metadataOnly = false)
        {
            pair = new ConnectionPair().WithTimeout();
            rig  = multiFile ? TestRig.CreateMultiFile(32768, metadataMode) : TestRig.CreateSingleFile(1024 * 1024 * 1024, 32768, metadataMode);
            rig.RecreateManager().Wait();

            rig.Manager.HashChecked = true;
            await rig.Manager.StartAsync(metadataOnly);

            rig.AddConnection(pair.Outgoing);

            var    connection = pair.Incoming;
            PeerId id         = new PeerId(new Peer("", connection.Uri), connection, rig.Manager.Bitfield?.Clone().SetAll(false));

            var result = await EncryptorFactory.CheckIncomingConnectionAsync(id.Connection, id.Peer.AllowedEncryption, new[] { rig.Manager.InfoHash });

            decryptor = id.Decryptor = result.Decryptor;
            encryptor = id.Encryptor = result.Encryptor;
        }
Пример #4
0
        public async Task Setup(bool metadataMode, bool multiFile = false, bool metadataOnly = false)
        {
            pair = new ConnectionPair().WithTimeout();
            rig  = multiFile ? TestRig.CreateMultiFile(32768, metadataMode) : TestRig.CreateSingleFile(Piece.BlockSize * 27, Piece.BlockSize * 2, metadataMode);
            rig.RecreateManager().Wait();

            // Mark the torrent as hash check complete with no data downloaded
            if (rig.Manager.HasMetadata)
            {
                rig.Manager.LoadFastResume(new FastResume(rig.Manager.InfoHash, rig.Manager.Bitfield.Clone().SetAll(false), rig.Manager.Bitfield.Clone().SetAll(false)));
            }
            await rig.Manager.StartAsync(metadataOnly);

            rig.AddConnection(pair.Outgoing);

            var    connection = pair.Incoming;
            PeerId id         = new PeerId(new Peer("", connection.Uri), connection, rig.Manager.Bitfield?.Clone().SetAll(false));

            var result = await EncryptorFactory.CheckIncomingConnectionAsync(id.Connection, id.Peer.AllowedEncryption, new[] { rig.Manager.InfoHash });

            decryptor = id.Decryptor = result.Decryptor;
            encryptor = id.Encryptor = result.Encryptor;
        }
Пример #5
0
        public void StartEndIndices()
        {
            const int pieceLength = 32 * 32;

            var files = new[]
            {
                new TorrentFile("File0", 0),
                new TorrentFile("File1", pieceLength),
                new TorrentFile("File2", 0),
                new TorrentFile("File3", pieceLength - 1),
                new TorrentFile("File4", 1),
                new TorrentFile("File5", 236),
                new TorrentFile("File6", pieceLength * 7)
            };
            var t = TestRig.CreateMultiFile(files, pieceLength).Torrent;

            Assert.AreEqual(0, t.Files[0].StartPieceIndex, "#0a");
            Assert.AreEqual(0, t.Files[0].EndPieceIndex, "#0b");

            Assert.AreEqual(0, t.Files[1].StartPieceIndex, "#1");
            Assert.AreEqual(0, t.Files[1].EndPieceIndex, "#2");

            Assert.AreEqual(0, t.Files[2].StartPieceIndex, "#3");
            Assert.AreEqual(0, t.Files[2].EndPieceIndex, "#4");

            Assert.AreEqual(1, t.Files[3].StartPieceIndex, "#5");
            Assert.AreEqual(1, t.Files[3].EndPieceIndex, "#6");

            Assert.AreEqual(1, t.Files[4].StartPieceIndex, "#7");
            Assert.AreEqual(1, t.Files[4].EndPieceIndex, "#8");

            Assert.AreEqual(2, t.Files[5].StartPieceIndex, "#9");
            Assert.AreEqual(2, t.Files[5].EndPieceIndex, "#10");

            Assert.AreEqual(2, t.Files[6].StartPieceIndex, "#11");
            Assert.AreEqual(9, t.Files[6].EndPieceIndex, "#12");
        }
Пример #6
0
 public void FixtureSetup()
 {
     rig = TestRig.CreateMultiFile();
 }
Пример #7
0
 public void FixtureSetup()
 {
     rig = TestRig.CreateMultiFile();
     id  = new PeerId(new Peer(new string('a', 20), new Uri("ipv4://BLAH")), rig.Manager, NullConnection.Incoming);
     id.BitField.SetAll(true);
 }