public void Setup() { creator = new TestTorrentCreator(); announces = new List<List<string>>(); announces.Add(new List<string>(new string[] { "http://tier1.com/announce1", "http://tier1.com/announce2" })); announces.Add(new List<string>(new string[] { "http://tier2.com/announce1", "http://tier2.com/announce2" })); creator.Comment = Comment; creator.CreatedBy = CreatedBy; creator.PieceLength = PieceLength; creator.Publisher = Publisher; creator.PublisherUrl = PublisherUrl; creator.AddCustom(CustomKey, CustomValue); files = new List<TorrentFile>(new TorrentFile[] { new TorrentFile(Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"), (int)(PieceLength * 2.30), 0, 1), new TorrentFile(Path.Combine(Path.Combine("Dir1", "SDir1"), "File2"), (int)(PieceLength * 36.5), 1, 3), new TorrentFile(Path.Combine(Path.Combine("Dir1", "SDir2"), "File3"), (int)(PieceLength * 3.17), 3, 12), new TorrentFile(Path.Combine(Path.Combine("Dir2", "SDir1"), "File4"), (int)(PieceLength * 1.22), 12, 15), new TorrentFile(Path.Combine(Path.Combine("Dir2", "SDir2"), "File5"), (int)(PieceLength * 6.94), 15, 15), }); writer = new TestWriter(); writer.DontWrite = true; }
TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files, bool metadataMode) { this.files = files; this.savePath = savePath; this.piecelength = piecelength; this.tier = trackers; MetadataMode = metadataMode; MetadataPath = "metadataSave.torrent"; listener = new CustomListener(); engine = new ClientEngine(new EngineSettings(), listener, writer); Writer = writer; RecreateManager(); }
TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files, bool metadataMode) { this.files = files; this.savePath = savePath; this.piecelength = piecelength; this.tier = trackers; MetadataMode = metadataMode; MetadataPath = "metadataSave.torrent"; Listener = new CustomListener(); Engine = new ClientEngine(new EngineSettings(), Listener, writer); Engine.RegisterLocalPeerDiscovery(new ManualLocalPeerListener()); Writer = writer; RecreateManager().Wait(); }
TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files, bool metadataMode) { this.files = files; this.savePath = savePath; this.piecelength = piecelength; this.tier = trackers; MetadataMode = metadataMode; MetadataPath = "metadataSave.torrent"; PeerListenerFactory.Creator = endpoint => new CustomListener(); LocalPeerDiscoveryFactory.Creator = port => new ManualLocalPeerListener(); Dht.Listeners.DhtListenerFactory.Creator = endpoint => new Dht.Listeners.NullDhtListener(); Engine = new ClientEngine(new EngineSettingsBuilder { ListenPort = 12345 }.ToSettings(), writer); Writer = writer; RecreateManager().Wait(); }
public async Task DeleteBeforeHashing() { TestWriter testWriter = null; using var tmpDir = TempDir.Create(); using var engine = new ClientEngine(new EngineSettingsBuilder(EngineSettingsBuilder.CreateForTests()) { AutoSaveLoadFastResume = true, CacheDirectory = tmpDir.Path, }.ToSettings(), Factories.Default.WithPieceWriterCreator(maxOpenFiles => (testWriter = new TestWriter())) ); var first = new TaskCompletionSource <object> (); var second = new TaskCompletionSource <object> (); var torrent = TestRig.CreatePrivate(); var path = engine.Settings.GetFastResumePath(torrent.InfoHashes); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllBytes(path, new FastResume(torrent.InfoHashes, new BitField(torrent.PieceCount).SetAll(true), new BitField(torrent.PieceCount)).Encode()); var manager = await engine.AddAsync(torrent, "savedir"); testWriter.FilesThatExist = new System.Collections.Generic.List <ITorrentManagerFile> (manager.Files); Assert.IsTrue(manager.HashChecked); manager.Engine.DiskManager.GetHashAsyncOverride = (torrent, pieceIndex, dest) => { first.SetResult(null); second.Task.Wait(); new byte[20].CopyTo(dest.V1Hash); return(Task.FromResult(true)); }; var hashCheckTask = manager.HashCheckAsync(false); await first.Task.WithTimeout(); Assert.IsFalse(File.Exists(path)); second.SetResult(null); await hashCheckTask.WithTimeout(); Assert.IsTrue(File.Exists(path)); }
internal static TestRig CreateMultiFile(TestWriter writer) { return(new TestRig("", StandardPieceSize(), writer, StandardTrackers(), StandardMultiFile())); }
TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files) : this(savePath, piecelength, writer, trackers, files, false) { }
protected override PieceWriter CreateReader() { TestWriter writer = new TestWriter(); writer.DontWrite = true; return writer; }
internal static TestRig CreateMultiFile(TestWriter writer) { return new TestRig ("", StandardPieceSize (), writer, StandardTrackers (), StandardMultiFile()); }
TestRig(string savePath, int piecelength, TestWriter writer, string[][] trackers, TorrentFile[] files) : this (savePath, piecelength, writer, trackers, files, false) { }
public TestRig(string savePath, int piecelength, PieceWriter writer, bool singleFile, string[][] tier) { this.savePath = savePath; this.piecelength = piecelength; this.singleFile = singleFile; this.tier = tier; if (writer == null) writer = new TestWriter(); listener = new CustomListener(); engine = new ClientEngine(new EngineSettings(), listener, writer); RecreateManager(); }