async def hidden_seeder_session(seed_config, video_tdef): seed_config.set_libtorrent_enabled(False) seeder_session = Session(seed_config) seeder_session.upgrader_enabled = False await seeder_session.start() # Also load the tunnel community in the seeder session await load_tunnel_community_in_session(seeder_session, start_lt=True) seeder_session.tunnel_community.build_tunnels(1) dscfg_seed = DownloadConfig() dscfg_seed.set_dest_dir(TESTS_DATA_DIR) dscfg_seed.set_hops(1) upload = seeder_session.dlmgr.start_download(tdef=video_tdef, config=dscfg_seed) def seeder_state_callback(ds): """ The callback of the seeder download. For now, this only logs the state of the download that's seeder and is useful for debugging purposes. """ seeder_session.tunnel_community.monitor_downloads([ds]) d = ds.get_download() print( f"seeder: {repr(d.get_def().get_name())} {dlstatus_strings[ds.get_status()]} {ds.get_progress()}" ) return 2 upload.set_state_callback(seeder_state_callback) await upload.wait_for_status(DLSTATUS_SEEDING) yield seeder_session await seeder_session.shutdown()
async def test_config_error_notification(tmpdir): """ Test if config error is notified on session startup. """ # 1. Setup corrupted config shutil.copy2(CONFIG_PATH / 'corrupt-triblerd.conf', tmpdir / 'triblerd.conf') tribler_config = TriblerConfig(tmpdir, config_file=tmpdir / 'triblerd.conf', reset_config_on_error=True) # 2. Initialize session with corrupted config, disable upgrader for simplicity. # By mocking the notifier, we can check if the notify was called with correct parameters session = Session(tribler_config) session.upgrader_enabled = False session.notifier = Mock() # 3. Start the session which should internally call the notifier. await session.start() # Notifier uses asyncio loop internally, so we must wait at least a single loop cycle await asyncio.sleep(0) # 4. There could be multiple notify calls but we are only interested in the config error # so using 'assert_any_call' here to check if the notify was called. session.notifier.notify.assert_any_call(NTFY.REPORT_CONFIG_ERROR, tribler_config.config_error) # 5. Always shutdown the session at the end. await session.shutdown()
async def channel_seeder_session(seed_config, channel_tdef): seeder_session = Session(seed_config) seeder_session.upgrader_enabled = False await seeder_session.start() dscfg_seed = DownloadConfig() dscfg_seed.set_dest_dir(TESTS_DATA_DIR / 'sample_channel') upload = seeder_session.dlmgr.start_download(tdef=channel_tdef, config=dscfg_seed) await upload.wait_for_status(DLSTATUS_SEEDING) yield seeder_session await seeder_session.shutdown()
async def get(self, exitnode=False): config = self.base_tribler_config.copy() config.set_libtorrent_enabled(False) config.set_tunnel_community_socks5_listen_ports( self.free_ports_factory(5)) config.set_state_dir(Path(self.tmpdir_factory.mktemp("session"))) session = Session(config) session.upgrader_enabled = False await session.start() self.sessions.append(session) await load_tunnel_community_in_session(session, exitnode=exitnode) return session
async def create_proxy(self, index, exitnode=False): """ Create a single proxy and load the tunnel community in the session of that proxy. """ from tribler_core.session import Session self.setUpPreSession() config = self.config.copy() config.set_libtorrent_enabled(False) config.set_tunnel_community_socks5_listen_ports(self.get_ports(5)) session = Session(config) session.upgrader_enabled = False await session.start() self.sessions.append(session) return await self.load_tunnel_community_in_session(session, exitnode=exitnode)
async def _session(tribler_config): session = Session(tribler_config) session.upgrader_enabled = False await session.start() yield session await session.shutdown()