async def setup_tunnel_seeder(self, hops): """ Setup the seeder. """ from tribler_core.session import Session self.seed_config = self.config.copy() self.seed_config._state_dir = self.getRootStateDir(2) self.seed_config.set_libtorrent_enabled(hops == 0) self.seed_config.set_tunnel_community_socks5_listen_ports( self.get_ports(5)) if self.session2 is None: self.session2 = Session(self.seed_config) self.session2.upgrader_enabled = False await self.session2.start() tdef = TorrentDef() tdef.add_content(TESTS_DATA_DIR / "video.avi") tdef.set_tracker("http://localhost/announce") torrentfn = self.session2.config.get_state_dir() / "gen.torrent" tdef.save(torrent_filepath=torrentfn) self.seed_tdef = tdef if hops > 0: # Safe seeding enabled self.tunnel_community_seeder = await self.load_tunnel_community_in_session( self.session2, start_lt=True) self.tunnel_community_seeder.build_tunnels(hops) else: await self.sanitize_network(self.session2) dscfg = DownloadConfig() dscfg.set_dest_dir( TESTS_DATA_DIR) # basedir of the file we are seeding dscfg.set_hops(hops) d = self.session2.dlmgr.start_download(tdef=tdef, config=dscfg) d.set_state_callback(self.seeder_state_callback)
def test_tdef(state_dir): tdef = TorrentDef() sourcefn = TESTS_DATA_DIR / 'video.avi' tdef.add_content(sourcefn) tdef.set_tracker("http://localhost/announce") torrentfn = state_dir / "gen.torrent" tdef.save(torrentfn) return tdef
def create_tdef(self): """ create and save torrent definition used in this test file """ tdef = TorrentDef() sourcefn = TESTS_DATA_DIR / 'video.avi' tdef.add_content(sourcefn) tdef.set_tracker("http://localhost/announce") torrentfn = self.session.config.get_state_dir() / "gen.torrent" tdef.save(torrentfn) return tdef
async def test_multifile_torrent(self): # Achtung! This test is completely and utterly broken, as is the whole libtorrent wrapper! # Don't try to understand it, it is a legacy thing! tdef = TorrentDef() tdef.add_content(TESTS_DATA_DIR / "video.avi") tdef.set_tracker("http://tribler.org/announce") tdef.save() fake_handler = MockObject() fake_handler.is_valid = lambda: True fake_handler.status = lambda: fake_status fake_handler.set_share_mode = lambda _: None fake_handler.set_priority = lambda _: None fake_handler.set_sequential_download = lambda _: None fake_handler.resume = lambda: None fake_handler.set_max_connections = lambda _: None fake_handler.apply_ip_filter = lambda _: None fake_handler.save_resume_data = lambda: None fake_status = MockObject() fake_status.share_mode = False dl = Download(self.session, tdef) dl.set_selected_files = lambda: None dl.future_added = succeed(fake_handler) # Create a dummy download config dl.config = DownloadConfig() dl.config.set_engineresumedata({ b"save_path": path_util.abspath(self.state_dir), b"info-hash": b'\x00' * 20 }) dl.setup() dl.config.set_engineresumedata({ b"save_path": path_util.abspath(self.state_dir), b"info-hash": b'\x00' * 20 }) dl.setup() dl.config.set_engineresumedata({ b"save_path": "some_local_dir", b"info-hash": b'\x00' * 20 }) dl.setup() await dl.shutdown()
def test_set_tracker(self): t = TorrentDef() self.assertFalse(t.get_trackers_as_single_tuple()) t.set_tracker("http://tracker.org") self.assertEqual(t.get_trackers_as_single_tuple(), ('http://tracker.org', ))
def test_set_tracker_strip_slash(self): t = TorrentDef() t.set_tracker("http://tracker.org/") self.assertEqual(t.torrent_parameters[b'announce'], "http://tracker.org")
def test_set_tracker_invalid_url(self): t = TorrentDef() t.set_tracker("http/tracker.org")