Ejemplo n.º 1
0
        public void Setup()
        {
            conn           = new ConnectionPair().WithTimeout();
            PieceWriter    = new TestWriter();
            TrackerManager = new ManualTrackerManager();

            long[] fileSizes =
            {
                Constants.BlockSize / 2,
                Constants.BlockSize * 32,
                Constants.BlockSize * 2,
                Constants.BlockSize * 13,
            };
            Manager = TestRig.CreateMultiFileManager(fileSizes, Constants.BlockSize * 2, writer: PieceWriter);
            Manager.SetTrackerManager(TrackerManager);

            Settings          = Manager.Engine.Settings;
            DiskManager       = Manager.Engine.DiskManager;
            ConnectionManager = Manager.Engine.ConnectionManager;

            Peer = new PeerId(new Peer("", new Uri("ipv4://123.123.123.123:12345"), EncryptionTypes.All), conn.Outgoing, new MutableBitField(Manager.Bitfield.Length).SetAll(true))
            {
                IsChoking    = false,
                AmInterested = true,
            };
        }
Ejemplo n.º 2
0
 public TransferTest()
 {
     pair = new ConnectionPair(55432);
     rig = TestRig.CreateMultiFile();
     rig.Manager.HashChecked = true;
     rig.Manager.Start();
 }
Ejemplo n.º 3
0
        public void Setup()
        {
            conn           = new ConnectionPair().WithTimeout();
            PieceWriter    = new TestWriter();
            TrackerManager = new ManualTrackerManager();

            int[] fileSizes =
            {
                Piece.BlockSize / 2,
                Piece.BlockSize * 32,
                Piece.BlockSize * 2,
                Piece.BlockSize * 13,
            };
            Manager = TestRig.CreateMultiFileManager(fileSizes, Piece.BlockSize * 2);
            Manager.SetTrackerManager(TrackerManager);
            Manager.Engine.DiskManager.Writer = PieceWriter;

            Settings          = Manager.Engine.Settings;
            DiskManager       = Manager.Engine.DiskManager;
            ConnectionManager = Manager.Engine.ConnectionManager;

            Peer = new PeerId(new Peer("", new Uri("ipv4://123.123.123.123:12345"), EncryptionTypes.All), conn.Outgoing, Manager.Bitfield?.Clone().SetAll(true))
            {
                ProcessingQueue = true,
                IsChoking       = false,
                AmInterested    = true,
            };
        }
 public NetworkIOTests()
 {
     if (data == null)
     {
         data = new byte[32768];
         new Random().NextBytes(data);
     }
     pair = new ConnectionPair(34567);
 }
Ejemplo n.º 5
0
        public void Setup()
        {
            pair = new ConnectionPair().WithTimeout();

            InfoHash = new InfoHash(Enumerable.Repeat((byte)255, 20).ToArray());
            SKeys    = new [] {
                new InfoHash(Enumerable.Repeat((byte)254, 20).ToArray()),
                new InfoHash(Enumerable.Repeat((byte)253, 20).ToArray()),
                InfoHash,
                new InfoHash(Enumerable.Repeat((byte)252, 20).ToArray())
            };

            IncomingId = new BEncodedString(Enumerable.Repeat((byte)'0', 20).ToArray());
            OutgoingId = new BEncodedString(Enumerable.Repeat((byte)'1', 20).ToArray());
        }
Ejemplo n.º 6
0
        public void Setup ()
        {
            conn = new ConnectionPair ().WithTimeout ();
            Settings = new EngineSettings ();
            PieceWriter = new TestWriter ();
            DiskManager = new DiskManager (Settings, PieceWriter);
            ConnectionManager = new ConnectionManager ("LocalPeerId", Settings, DiskManager);
            TrackerManager = new ManualTrackerManager ();

            long[] fileSizes = {
                Piece.BlockSize / 2,
                Piece.BlockSize * 32,
                Piece.BlockSize * 2,
                Piece.BlockSize * 13,
            };
            Manager = TestRig.CreateMultiFileManager (fileSizes, Piece.BlockSize * 2);
            Manager.SetTrackerManager (TrackerManager);
        }
Ejemplo n.º 7
0
        public void Setup()
        {
            conn = new ConnectionPair ().WithTimeout ();
            Settings = new EngineSettings ();
            DiskManager = new DiskManager (Settings, Factories.Default, new NullWriter ());
            ConnectionManager = new ConnectionManager ("LocalPeerId", Settings, Factories.Default, DiskManager);
            TrackerManager = new ManualTrackerManager ();

            long[] fileSizes = {
                Constants.BlockSize / 2,
                Constants.BlockSize * 32,
                Constants.BlockSize * 2,
                Constants.BlockSize * 13,
            };
            Manager = TestRig.CreateMultiFileManager (fileSizes, Constants.BlockSize * 2);
            Manager.SetTrackerManager (TrackerManager);
            Peer = new PeerId (new Peer ("", new Uri ("ipv4://123.123.123.123:12345"), EncryptionTypes.All), conn.Outgoing, new MutableBitField (Manager.PieceCount ()));
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            conn              = new ConnectionPair().WithTimeout();
            Settings          = new EngineSettings();
            DiskManager       = new DiskManager(Settings, new NullWriter());
            ConnectionManager = new ConnectionManager("LocalPeerId", Settings, DiskManager);
            TrackerManager    = new ManualTrackerManager();

            int[] fileSizes =
            {
                Piece.BlockSize / 2,
                Piece.BlockSize * 32,
                Piece.BlockSize * 2,
                Piece.BlockSize * 13,
            };
            Manager = TestRig.CreateMultiFileManager(fileSizes, Piece.BlockSize * 2);
            Manager.SetTrackerManager(TrackerManager);
            Peer = new PeerId(new Peer("", new Uri("ipv4://123.123.123.123:5555"), EncryptionTypes.All), conn.Outgoing, Manager.Bitfield?.Clone().SetAll(false));
        }
        public void Setup(bool metadataMode, string metadataPath)
        {
            pair = new ConnectionPair(55432);
            rig = TestRig.CreateSingleFile(1024*1024*1024, 32768, metadataMode);
            rig.MetadataPath = metadataPath;
            rig.RecreateManager();

            rig.Manager.HashChecked = true;
            rig.Manager.Start();
            rig.AddConnection(pair.Outgoing);

            var connection = pair.Incoming;
            var id = new PeerId(new Peer("", connection.Uri), rig.Manager);
            id.Connection = connection;
            byte[] data;

            EncryptorFactory.EndCheckEncryption(
                EncryptorFactory.BeginCheckEncryption(id, 68, null, null, new[] {id.TorrentManager.InfoHash}),
                out data);
            decryptor = id.Decryptor;
            encryptor = id.Encryptor;
        }
Ejemplo n.º 11
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;
        }
Ejemplo n.º 12
0
 public void Setup()
 {
     conn = new ConnectionPair(13253);
     rig.Engine.Settings.AllowedEncryption = EncryptionTypes.All;
     rig.Manager.HashChecked = true;
 }
Ejemplo n.º 13
0
        public TestManualConnection()
        {
            rig1 = new EngineTestRig("Downloads1");
            rig1.Manager.Start();
            rig2 = new EngineTestRig("Downloads2");
            rig2.Manager.Start();

            ConnectionPair p = new ConnectionPair(5151);

            rig1.AddConnection(p.Incoming);
            rig2.AddConnection(p.Outgoing);

            while (true)
            {
                Console.WriteLine("Connection 1A active: {0}", p.Incoming.Connected);
                Console.WriteLine("Connection 2A active: {0}", p.Outgoing.Connected);
                System.Threading.Thread.Sleep(1000);
            }
        }
 public TorrentManagerTest()
 {
     rig = TestRig.CreateMultiFile(new TestWriter());
     conn = new ConnectionPair(51515);
 }