public async Task AddPeers_LocalPeerDiscovery_Private() { // You can't manually add peers to private torrents var editor = new TorrentEditor(rig.TorrentDict) { CanEditSecureMetadata = true, Private = true }; var manager = new TorrentManager(editor.ToTorrent(), "path", new TorrentSettings()); await rig.Engine.Register(manager); var localPeer = new ManualLocalPeerListener(); await rig.Engine.RegisterLocalPeerDiscoveryAsync(localPeer); var tcs = new TaskCompletionSource <LocalPeersAdded> (); manager.PeersFound += (o, e) => { if (e is LocalPeersAdded args) { tcs.TrySetResult(args); } }; localPeer.RaisePeerFound(manager.InfoHash, rig.CreatePeer(false).Uri); var result = await tcs.Task.WithTimeout(TimeSpan.FromSeconds(5)); Assert.AreEqual(0, result.NewPeers, "#2"); Assert.AreEqual(0, result.ExistingPeers, "#3"); Assert.AreEqual(0, manager.Peers.AvailablePeers.Count, "#4"); }
public void EditingCreatesCopy() { var d = Create ("comment", "a"); var editor = new TorrentEditor (d); editor.Comment = "b"; Assert.AreEqual ("a", d ["comment"].ToString (), "#1"); }
public async Task<TorrentManager> AddAsync (Torrent torrent, string saveDirectory, TorrentSettings settings) { await MainLoop.SwitchThread (); var editor = new TorrentEditor (new BEncodedDictionary { { "info", BEncodedValue.Decode (torrent.InfoMetadata) } }); editor.SetCustom ("name", (BEncodedString) torrent.Name); if (torrent.AnnounceUrls.Count > 0) { if (torrent.AnnounceUrls.Count == 1 && torrent.AnnounceUrls[0].Count == 1) { editor.Announce = torrent.AnnounceUrls.Single ().Single (); } else { foreach (var tier in torrent.AnnounceUrls) { var list = new List<string> (); foreach (var tracker in tier) list.Add (tracker); editor.Announces.Add (list); } } } var metadataCachePath = Settings.GetMetadataPath (torrent.InfoHashes); Directory.CreateDirectory (Path.GetDirectoryName (metadataCachePath)!); File.WriteAllBytes (metadataCachePath, editor.ToDictionary ().Encode ()); return await AddAsync (null, torrent, saveDirectory, settings); }
public async Task AddPeers_Dht_Private() { // You can't manually add peers to private torrents var editor = new TorrentEditor(rig.TorrentDict) { CanEditSecureMetadata = true, Private = true }; var manager = await rig.Engine.AddAsync(editor.ToTorrent(), "path", new TorrentSettings()); var dht = (ManualDhtEngine)rig.Engine.DhtEngine; var tcs = new TaskCompletionSource <DhtPeersAdded> (); manager.PeersFound += (o, e) => { if (e is DhtPeersAdded args) { tcs.TrySetResult(args); } }; dht.RaisePeersFound(manager.InfoHash, new[] { rig.CreatePeer(false).Peer }); var result = await tcs.Task.WithTimeout(TimeSpan.FromSeconds(5)); Assert.AreEqual(0, result.NewPeers, "#2"); Assert.AreEqual(0, result.ExistingPeers, "#3"); Assert.AreEqual(0, manager.Peers.AvailablePeers.Count, "#4"); }
public void EditingCreatesCopy() { var d = Create("comment", "a"); var editor = new TorrentEditor(d); editor.Comment = "b"; Assert.AreEqual("a", d ["comment"].ToString(), "#1"); }
public void EditComment() { var d = Create ("comment", "a"); var editor = new TorrentEditor (d); editor.Comment = "b"; d = editor.ToDictionary (); Assert.AreEqual ("b", d ["comment"].ToString (), "#1"); }
public void EditComment() { var d = Create("comment", "a"); var editor = new TorrentEditor(d); editor.Comment = "b"; d = editor.ToDictionary(); Assert.AreEqual("b", d ["comment"].ToString(), "#1"); }
public void ReplaceInfoDict() { var editor = new TorrentEditor(new BEncodedDictionary()) { CanEditSecureMetadata = false }; editor.SetCustom("info", new BEncodedDictionary()); }
public void EditProtectedProperty_NotAllowed() { var editor = new TorrentEditor(new BEncodedDictionary()) { CanEditSecureMetadata = false }; editor.PieceLength = 16; }
public void EditProtectedProperty_NotAllowed() { Assert.Throws <InvalidOperationException>(() => { var editor = new TorrentEditor(new BEncodedDictionary()) { CanEditSecureMetadata = false }; editor.PieceLength = 16; }); }
public void ReplaceInfoDict() { Assert.Throws <InvalidOperationException>(() => { var editor = new TorrentEditor(new BEncodedDictionary()) { CanEditSecureMetadata = false }; editor.SetCustom("info", new BEncodedDictionary()); }); }
internal static Torrent CreatePrivate() { var dict = CreateTorrent(16 * 1024 * 8, TorrentFile.Create(16 * 1024 * 8, ("File", 16 * 1024 * 8)), null); var editor = new TorrentEditor(dict) { CanEditSecureMetadata = true, Private = true, }; return(editor.ToTorrent()); }
internal static TorrentManager CreatePrivate() { var dict = CreateTorrent(16 * 1024 * 8, new[] { new TorrentFile("File", 16 * 1024 * 8) }, null); var editor = new TorrentEditor(dict) { CanEditSecureMetadata = true, Private = true, }; return(new TorrentManager(editor.ToTorrent(), "", new TorrentSettings())); }
public async Task ContainingDirectory_PathBusting() { // You can't manually add peers to private torrents using var rig = TestRig.CreateMultiFile(new TestWriter()); await rig.Engine.RemoveAsync(rig.Engine.Torrents[0]); var editor = new TorrentEditor(rig.TorrentDict); editor.CanEditSecureMetadata = true; editor.Name = $"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}test{Path.GetInvalidPathChars ()[0]}"; Assert.ThrowsAsync <ArgumentException> (() => rig.Engine.AddAsync(editor.ToTorrent(), "path", new TorrentSettings())); }
public void DownloadTorrent(int?torrentId) { using (var db = new OpenTrackerDbContext()) { var torrentExist = (from t in db.torrents where t.id == torrentId select t).Take(1).FirstOrDefault(); if (torrentExist == null) { Response.Write("Torrent not found."); return; } var file = string.Format("{0}.torrent", torrentExist.id); var finalTorrentPath = Path.Combine(TrackerSettings.TORRENT_DIRECTORY, file); var dictionary = (BEncodedDictionary)BEncodedValue.Decode(System.IO.File.ReadAllBytes(finalTorrentPath)); var userInformation = (from u in db.users where u.username == User.Identity.Name select u).Take(1).FirstOrDefault(); if (userInformation == null) { Response.Write("This shouldn't happen."); return; } var announceUrl = string.Format("{0}/announce/{1}", TrackerSettings.BASE_URL, userInformation.passkey); var editor = new TorrentEditor(dictionary) { Announce = announceUrl, Comment = "created by Open-Tracker.org" }; var privateTorrent = editor.ToDictionary().Encode(); var response = ControllerContext.HttpContext.Response; response.ClearHeaders(); response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}-{1}.torrent", TrackerSettings.TORRENT_NAME_PREFIX, Url.Encode(torrentExist.torrentname))); response.AddHeader("Content-Type", "application/x-bittorrent"); response.BinaryWrite(privateTorrent); response.End(); } }
public async Task ContainingDirectory_InvalidCharacters() { // You can't manually add peers to private torrents using var rig = TestRig.CreateMultiFile(new TestWriter()); await rig.Engine.RemoveAsync(rig.Engine.Torrents[0]); var editor = new TorrentEditor(rig.TorrentDict); editor.CanEditSecureMetadata = true; editor.Name = $"{Path.GetInvalidPathChars()[0]}test{Path.GetInvalidPathChars ()[0]}"; var manager = await rig.Engine.AddAsync(editor.ToTorrent(), "path", new TorrentSettings()); Assert.IsFalse(manager.ContainingDirectory.Contains(manager.Torrent.Name)); Assert.IsTrue(manager.ContainingDirectory.StartsWith(manager.SavePath)); Assert.AreEqual(Path.GetFullPath(manager.ContainingDirectory), manager.ContainingDirectory); Assert.AreEqual(Path.GetFullPath(manager.SavePath), manager.SavePath); }
//------------------------------------------------------------- public byte[] InsertAnnounce(byte[] torrentData) //------------------------------------------------------------- { MonoTorrent.Torrent torrent = MonoTorrent.Torrent.Load(torrentData); torrent.AnnounceUrls.Clear(); torrent.AnnounceUrls.Add(new RawTrackerTier(new[] { "http://" + Helper.GetHostIP().ToString() + ":" + TRACKERHTTP_PORT + "/announce", "udp://" + Helper.GetHostIP().ToString() + ":" + TRACKERUDP_PORT })); byte[] result = null; TorrentEditor torrentEditor = new TorrentEditor(torrent); torrentEditor.Announces.Clear(); torrentEditor.Announces.Add(new RawTrackerTier(new[] { "http://" + Helper.GetHostIP().ToString() + ":" + TRACKERHTTP_PORT + "/announce", "udp://" + Helper.GetHostIP().ToString() + ":" + TRACKERUDP_PORT })); var dict = torrentEditor.ToDictionary(); result = dict.Encode(); return(result); }
public void ReplaceInfoDict() { var editor = new TorrentEditor (new BEncodedDictionary ()) { CanEditSecureMetadata = false }; editor.SetCustom ("info", new BEncodedDictionary ()); }
public void EditProtectedProperty_NotAllowed() { var editor = new TorrentEditor (new BEncodedDictionary ()) { CanEditSecureMetadata = false }; editor.PieceLength = 16; }
public void EditProtectedProperty_NotAllowed() { var editor = new TorrentEditor(new BEncodedDictionary()) {CanEditSecureMetadata = false}; Assert.Throws<InvalidOperationException>(() => editor.PieceLength = 16); }
public void ReplaceInfoDict() { var editor = new TorrentEditor(new BEncodedDictionary()) {CanEditSecureMetadata = false}; Assert.Throws<InvalidOperationException>(() => editor.SetCustom("info", new BEncodedDictionary())); }