public void NoTrackersTest() { BEncodedDictionary dict = creator.Create("TorrentName", files); Torrent t = Torrent.Load(dict); Assert.AreEqual(0, t.AnnounceUrls.Count, "#1"); }
public void StartUp() { DateTime current = new DateTime(2006, 7, 1, 5, 5, 5); DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = current - epochStart; creationTime = (long)span.TotalSeconds; Console.WriteLine($"{creationTime}Creation seconds"); torrentInfo = new BEncodedDictionary { { "announce", new BEncodedString("http://myannouceurl/announce") }, { "creation date", new BEncodedNumber(creationTime) }, { "nodes", new BEncodedList() }, //FIXME: What is this? { "comment.utf-8", new BEncodedString("my big long comment") }, { "comment", new BEncodedString("my big long comment") }, { "azureus_properties", new BEncodedDictionary() }, //FIXME: What is this? { "created by", new BEncodedString($"MonoTorrent/{VersionInfo.ClientVersion}") }, { "encoding", new BEncodedString("UTF-8") }, { "info", CreateInfoDict() }, { "private", new BEncodedString("1") }, { "url-list", new BEncodedList() { new BEncodedString("https://example.com/8/items/"), new BEncodedString("/8/items/"), // this should be ignored on loading } } }; torrent = Torrent.Load(torrentInfo); }
public void StartUp() { DateTime current = new DateTime(2006, 7, 1, 5, 5, 5); DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = current - epochStart; creationTime = (long)span.TotalSeconds; torrentInfo = new BEncodedDictionary { { "announce", new BEncodedString("http://myannouceurl/announce") }, { "creation date", new BEncodedNumber(creationTime) }, { "nodes", new BEncodedList() }, //FIXME: What is this? { "comment.utf-8", new BEncodedString("my big long comment") }, { "comment", new BEncodedString("my big long comment") }, { "azureus_properties", new BEncodedDictionary() }, //FIXME: What is this? { "created by", new BEncodedString($"MonoTorrent/{GitInfoHelper.ClientVersion}") }, { "encoding", new BEncodedString("UTF-8") }, { "info", CreateInfoDict() }, { "private", new BEncodedString("1") }, { "url-list", new BEncodedList() { new BEncodedString("https://example.com/8/items/"), new BEncodedString("/8/items/"), // this should be ignored on loading } } }; torrent = Torrent.Load(torrentInfo); // People using monotorrent should only see V1 torrent infohashes (for now). Assert.IsNotNull(torrent.InfoHashes.V1); Assert.IsNull(torrent.InfoHashes.V2); }
public void LargeMultiTorrent() { string name1 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); string name2 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); string name3 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); string name4 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); string name5 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); files = new List <TorrentFile>(new TorrentFile[] { new TorrentFile(name1, (long)(PieceLength * 200.30), 0, 1), new TorrentFile(name2, (long)(PieceLength * 42000.5), 1, 3), new TorrentFile(name3, (long)(PieceLength * 300.17), 3, 12), new TorrentFile(name4, (long)(PieceLength * 100.22), 12, 15), new TorrentFile(name5, (long)(PieceLength * 600.94), 15, 15), }); Torrent torrent = Torrent.Load(creator.Create("BaseDir", files)); Assert.AreEqual(5, torrent.Files.Length, "#1"); Assert.AreEqual(name1, torrent.Files[0].Path, "#2"); Assert.AreEqual(name2, torrent.Files[1].Path, "#3"); Assert.AreEqual(name3, torrent.Files[2].Path, "#4"); Assert.AreEqual(name4, torrent.Files[3].Path, "#5"); Assert.AreEqual(name5, torrent.Files[4].Path, "#6"); }
public void FixtureSetup() { Torrent.SupportsV2Torrents = true; HybridTorrent = Torrent.Load(HybridTorrentPath); V2OnlyTorrent = Torrent.Load(V2OnlyTorrentPath); Torrent.SupportsV2Torrents = false; }
public async Task LargeMultiTorrent() { string name1 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File1"); string name2 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File2"); string name3 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File3"); string name4 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File4"); string name5 = Path.Combine(Path.Combine("Dir1", "SDir1"), "File5"); files = new List <TorrentCreator.InputFile> { new TorrentCreator.InputFile(name1, (long)(PieceLength * 200.30)), new TorrentCreator.InputFile(name2, (long)(PieceLength * 42000.5)), new TorrentCreator.InputFile(name3, (long)(PieceLength * 300.17)), new TorrentCreator.InputFile(name4, (long)(PieceLength * 100.22)), new TorrentCreator.InputFile(name5, (long)(PieceLength * 600.94)), }; Torrent torrent = Torrent.Load(await creator.CreateAsync("BaseDir", files)); Assert.AreEqual(5, torrent.Files.Count, "#1"); Assert.AreEqual(name1, torrent.Files[0].Path, "#2"); Assert.AreEqual(name2, torrent.Files[1].Path, "#3"); Assert.AreEqual(name3, torrent.Files[2].Path, "#4"); Assert.AreEqual(name4, torrent.Files[3].Path, "#5"); Assert.AreEqual(name5, torrent.Files[4].Path, "#6"); }
public async Task NoTrackersTest() { BEncodedDictionary dict = await creator.CreateAsync("TorrentName", files); Torrent t = Torrent.Load(dict); Assert.AreEqual(0, t.AnnounceUrls.Count, "#1"); }
public void NodesIsNotAList() { var dict = torrent.ToDictionary(); dict["nodes"] = new BEncodedString("192.168.0.1:12345"); torrent = Torrent.Load(dict); Assert.IsNull(torrent.Nodes, "#1"); }
public void LoadingFileTreesFailsWhenBEP52Unsupported() { Torrent.SupportsV2Torrents = false; var dict = (BEncodedDictionary)BEncodedValue.Decode(Encoding.UTF8.GetBytes("d4:infod9:file treed4:dir1d4:dir2d9:fileA.txtd0:d6:lengthi1024e11:pieces root32:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeeeee12:piece lengthi16382eee")); Assert.Throws <TorrentException> (() => Torrent.Load(dict)); }
public async Task AnnounceUrl_None() { BEncodedDictionary dict = await creator.CreateAsync("TorrentName", files); Torrent t = Torrent.Load(dict); Assert.IsFalse(dict.ContainsKey("announce-list")); Assert.IsFalse(dict.ContainsKey("announce")); }
public void V1InfoHashOnly() { (bool before1, bool before2) = (Torrent.SupportsV1V2Torrents, Torrent.SupportsV2Torrents); (Torrent.SupportsV1V2Torrents, Torrent.SupportsV2Torrents) = (true, true); try { Assert.IsNull(Torrent.Load(torrentInfo).InfoHashes.V2); } finally { (Torrent.SupportsV1V2Torrents, Torrent.SupportsV2Torrents) = (before1, before2); } }
public void InvalidPath() { var files = ((BEncodedDictionary)torrentInfo["info"])["files"] as BEncodedList; var newFile = new BEncodedDictionary(); var path = new BEncodedList(new BEncodedString[] { "test", "..", "bar" }); newFile["path"] = path; newFile["length"] = (BEncodedNumber)15251; files.Add(newFile); Assert.Throws <ArgumentException> (() => Torrent.Load(torrentInfo)); }
public void CreateSingleFromFolder() { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); BEncodedDictionary dict = creator.Create(new TorrentFileSource(assembly.Location)); Torrent t = Torrent.Load(dict); Assert.AreEqual(1, t.Files.Count, "#1"); Assert.AreEqual(Path.GetFileName(assembly.Location), t.Name, "#2"); Assert.AreEqual(Path.GetFileName(assembly.Location), t.Files[0].Path, "#3"); // Create it again creator.Create(new TorrentFileSource(assembly.Location)); }
public void LoadSingleFile() { var torrent = Torrent.Load(Encoding.UTF8.GetBytes("d4:infod9:file treed4:dir1d4:dir2d9:fileA.txtd0:d6:lengthi1024e11:pieces root32:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaeeeee12:piece lengthi32768eee")); var file = torrent.Files.Single(); Assert.AreEqual(Path.Combine("dir1", "dir2", "fileA.txt"), file.Path); Assert.AreEqual(0, file.StartPieceIndex); Assert.AreEqual(0, file.EndPieceIndex); Assert.AreEqual(0, file.OffsetInTorrent); var hash = Enumerable.Repeat((byte)'a', 32).ToArray().AsMemory(); Assert.IsTrue(hash.Span.SequenceEqual(file.PiecesRoot.Span)); }
public void CreateMultiTest() { foreach (var v in announces) { creator.Announces.Add(v); } BEncodedDictionary dict = creator.Create("TorrentName", files); Torrent torrent = Torrent.Load(dict); VerifyCommonParts(torrent); for (int i = 0; i < torrent.Files.Length; i++) { Assert.IsTrue(files.Exists(delegate(TorrentFile f) { return(f.Equals(torrent.Files[i])); })); } }
public async Task CreateMultiTest() { foreach (var v in announces) { creator.Announces.Add(v); } BEncodedDictionary dict = await creator.CreateAsync("TorrentName", files); Torrent torrent = Torrent.Load(dict); VerifyCommonParts(torrent); for (int i = 0; i < torrent.Files.Count; i++) { Assert.IsTrue(files.Exists(f => f.Path.Equals(torrent.Files[i].Path))); } }
public async Task CreateSingleTest() { foreach (var v in announces) { creator.Announces.Add(v); } var f = new TorrentCreator.InputFile(Path.GetFileName(files[0].Path), files[0].Length); BEncodedDictionary dict = await creator.CreateAsync(f.Path, new List <TorrentCreator.InputFile> (new[] { f })); Torrent torrent = Torrent.Load(dict); VerifyCommonParts(torrent); Assert.AreEqual(1, torrent.Files.Count, "#1"); Assert.AreEqual(f.Path, torrent.Files[0].Path, "#2"); }
public void CreateSingleTest() { foreach (var v in announces) { creator.Announces.Add(v); } TorrentFile f = new TorrentFile(Path.GetFileName(files[0].Path), files[0].Length, files[0].StartPieceIndex, files[0].EndPieceIndex); BEncodedDictionary dict = creator.Create(f.Path, new List <TorrentFile> (new TorrentFile[] { f })); Torrent torrent = Torrent.Load(dict); VerifyCommonParts(torrent); Assert.AreEqual(1, torrent.Files.Length, "#1"); Assert.AreEqual(f, torrent.Files[0], "#2"); }
public void StartUp() { DateTime current = new DateTime(2006, 7, 1, 5, 5, 5); DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0); TimeSpan span = current - epochStart; creationTime = (long)span.TotalSeconds; Console.WriteLine(creationTime.ToString() + "Creation seconds"); BEncodedDictionary torrentInfo = new BEncodedDictionary(); torrentInfo.Add("announce", new BEncodedString("http://myannouceurl/announce")); torrentInfo.Add("creation date", new BEncodedNumber(creationTime)); torrentInfo.Add("nodes", new BEncodedList()); //FIXME: What is this? torrentInfo.Add("comment.utf-8", new BEncodedString("my big long comment")); torrentInfo.Add("comment", new BEncodedString("my big long comment")); torrentInfo.Add("azureus_properties", new BEncodedDictionary()); //FIXME: What is this? torrentInfo.Add("created by", new BEncodedString("MonoTorrent/" + VersionInfo.ClientVersion)); torrentInfo.Add("encoding", new BEncodedString("UTF-8")); torrentInfo.Add("info", CreateInfoDict()); torrentInfo.Add("private", new BEncodedString("1")); torrent = Torrent.Load(torrentInfo); }
public Torrent ToTorrent() { return(Torrent.Load(ToDictionary())); }
public void NodesIsNotAList() { torrentInfo["nodes"] = new BEncodedString("192.168.0.1:12345"); torrent = Torrent.Load(torrentInfo); Assert.AreEqual(0, torrent.Nodes.Count, "#1"); }
public void NodesIsNotAList() { torrentInfo["nodes"] = new BEncodedString("192.168.0.1:12345"); torrent = Torrent.Load(torrentInfo); Assert.IsNull(torrent.Nodes, "#1"); }