async def test_ipv8_component_dht_disabled(tribler_config): tribler_config.ipv8.enabled = True tribler_config.dht.enabled = True async with Session(tribler_config, [KeyComponent(), Ipv8Component()]).start(): comp = Ipv8Component.instance() assert comp.dht_discovery_community
async def test_ipv8_component_discovery_community_enabled(tribler_config): tribler_config.ipv8.enabled = True tribler_config.gui_test_mode = False tribler_config.discovery_community.enabled = True async with Session(tribler_config, [KeyComponent(), Ipv8Component()]).start(): comp = Ipv8Component.instance() assert comp._peer_discovery_community
async def test_ipv8_component(tribler_config): async with Session(tribler_config, [KeyComponent(), Ipv8Component()]).start(): comp = Ipv8Component.instance() assert comp.started_event.is_set() and not comp.failed assert comp.ipv8 assert comp.peer assert not comp.dht_discovery_community assert comp._task_manager assert not comp._peer_discovery_community
async def test_rest_component(tribler_config): components = [ KeyComponent(), RESTComponent(), Ipv8Component(), LibtorrentComponent(), ResourceMonitorComponent(), BandwidthAccountingComponent(), GigaChannelComponent(), TagComponent(), SocksServersComponent(), MetadataStoreComponent() ] async with Session(tribler_config, components).start(): # Test REST component starts normally comp = RESTComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.rest_manager # Test report callback works # mock callbacks comp._events_endpoint.on_tribler_exception = MagicMock() # try to call report_callback from core_exception_handler and assert # that corresponding methods in events_endpoint and state_endpoint have been called error = ReportedError(type='', text='text', event={}) comp._core_exception_handler.report_callback(error) comp._events_endpoint.on_tribler_exception.assert_called_with(error)
async def test_tunnels_component(tribler_config): components = [Ipv8Component(), KeyComponent(), TunnelsComponent()] async with Session(tribler_config, components).start(): comp = TunnelsComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.community assert comp._ipv8_component
async def test_popularity_component(tribler_config): components = [SocksServersComponent(), LibtorrentComponent(), TorrentCheckerComponent(), TagComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), PopularityComponent()] async with Session(tribler_config, components).start(): comp = PopularityComponent.instance() assert comp.community assert comp._ipv8_component
def tribler_started(self): async def signal_handler(sig): print(f"Received shut down signal {sig}") # noqa: T001 await self.stop() signal.signal(signal.SIGINT, lambda sig, _: ensure_future(signal_handler(sig))) signal.signal(signal.SIGTERM, lambda sig, _: ensure_future(signal_handler(sig))) tunnel_community = TunnelsComponent.instance().community self.register_task("bootstrap", tunnel_community.bootstrap, interval=30) # Remove all logging handlers root_logger = logging.getLogger() handlers = root_logger.handlers for handler in handlers: root_logger.removeHandler(handler) logging.getLogger().setLevel(logging.ERROR) ipv8 = Ipv8Component.instance().ipv8 new_strategies = [] with ipv8.overlay_lock: for strategy, target_peers in ipv8.strategies: if strategy.overlay == tunnel_community: new_strategies.append((strategy, -1)) else: new_strategies.append((strategy, target_peers)) ipv8.strategies = new_strategies
async def test_gigachannel_manager_component(tribler_config): components = [Ipv8Component(), TagComponent(), SocksServersComponent(), KeyComponent(), MetadataStoreComponent(), LibtorrentComponent(), GigachannelManagerComponent()] async with Session(tribler_config, components).start(): comp = GigachannelManagerComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.gigachannel_manager
def components_gen(): yield KeyComponent() yield RESTComponent() yield Ipv8Component() yield ResourceMonitorComponent() yield BandwidthAccountingComponent() yield SocksServersComponent() yield TunnelsComponent()
async def test_bandwidth_accounting_component(tribler_config): components = [ KeyComponent(), Ipv8Component(), BandwidthAccountingComponent() ] async with Session(tribler_config, components).start(): comp = BandwidthAccountingComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.community assert comp._ipv8_component
async def test_payout_component(tribler_config): components = [ BandwidthAccountingComponent(), KeyComponent(), Ipv8Component(), PayoutComponent() ] async with Session(tribler_config, components).start(): comp = PayoutComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.payout_manager
def circuit_removed(self, circuit, additional_info): ipv8 = Ipv8Component.instance().ipv8 ipv8.network.remove_by_address(circuit.peer.address) if self.log_circuits: with open( os.path.join(self.session.config.state_dir, "circuits.log"), 'a') as out_file: duration = time.time() - circuit.creation_time out_file.write("%d,%f,%d,%d,%s\n" % (circuit.circuit_id, duration, circuit.bytes_up, circuit.bytes_down, additional_info))
async def test_metadata_store_component(tribler_config): components = [ TagComponent(), Ipv8Component(), KeyComponent(), MetadataStoreComponent() ] async with Session(tribler_config, components).start(): comp = MetadataStoreComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.mds
def __init__(self, working_dir, config_path): super().__init__(Service.create_config(working_dir, config_path), working_dir=working_dir, components=[ Ipv8Component(), KeyComponent(), RESTComponent(), TunnelsComponent() ]) TaskManager.__init__(self) self.results = [] self.output_file = 'speed_test_exit.txt'
async def test_tunnels_component(tribler_config): components = [Ipv8Component(), KeyComponent(), TunnelsComponent()] session = Session(tribler_config, components) with session: await session.start() comp = TunnelsComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.community assert comp._ipv8_component await session.shutdown()
async def test_tag_component(tribler_config): session = Session( tribler_config, [KeyComponent(), Ipv8Component(), TagComponent()]) with session: comp = TagComponent.instance() await session.start() assert comp.started_event.is_set() and not comp.failed assert comp.community await session.shutdown()
async def test_torrent_checker_component(tribler_config): components = [ SocksServersComponent(), LibtorrentComponent(), KeyComponent(), Ipv8Component(), TagComponent(), MetadataStoreComponent(), TorrentCheckerComponent() ] async with Session(tribler_config, components).start(): comp = TorrentCheckerComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.torrent_checker
def __init__(self, source_dir, working_dir): super().__init__(TriblerConfig(state_dir=working_dir), working_dir=working_dir, components=[ RESTComponent(), KeyComponent(), SocksServersComponent(), LibtorrentComponent(), Ipv8Component(), MetadataStoreComponent(), GigachannelManagerComponent(), GigaChannelComponent() ]) self.source_dir = Path(source_dir)
def __init__(self, timeout_in_sec, working_dir): super().__init__(config=TriblerConfig(state_dir=working_dir), timeout_in_sec=timeout_in_sec, working_dir=working_dir, components=[ SocksServersComponent(), LibtorrentComponent(), TorrentCheckerComponent(), MetadataStoreComponent(), KeyComponent(), RESTComponent(), Ipv8Component(), ObservablePopularityComponent() ])
async def test_giga_channel_component(tribler_config): tribler_config.ipv8.enabled = True tribler_config.libtorrent.enabled = True tribler_config.chant.enabled = True components = [TagComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), GigaChannelComponent()] session = Session(tribler_config, components) with session: await session.start() comp = GigaChannelComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.community assert comp._ipv8_component await session.shutdown()
async def test_metadata_store_component(tribler_config): components = [ TagComponent(), Ipv8Component(), KeyComponent(), MetadataStoreComponent() ] session = Session(tribler_config, components) with session: comp = MetadataStoreComponent.instance() await session.start() assert comp.started_event.is_set() and not comp.failed assert comp.mds await session.shutdown()
async def test_payout_component(tribler_config): components = [ BandwidthAccountingComponent(), KeyComponent(), Ipv8Component(), PayoutComponent() ] session = Session(tribler_config, components) with session: await session.start() comp = PayoutComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.payout_manager await session.shutdown()
def __init__(self, working_dir, config_path): super().__init__(Service.create_config(working_dir, config_path), working_dir=working_dir, components=[ Ipv8Component(), KeyComponent(), RESTComponent(), TunnelsComponent() ]) TaskManager.__init__(self) self.swarm = None self.start = time.time() self.results = [] self.register_task('monitor_swarm', self.monitor_swarm, interval=5) self.register_task('_graceful_shutdown', self._graceful_shutdown, delay=EXPERIMENT_RUN_TIME)
def components_gen(config: TriblerConfig): """This function defines components that will be used in Tibler """ yield ReporterComponent() if config.api.http_enabled or config.api.https_enabled: yield RESTComponent() if config.chant.enabled or config.torrent_checking.enabled: yield MetadataStoreComponent() if config.ipv8.enabled: yield Ipv8Component() yield KeyComponent() yield TagComponent() if config.libtorrent.enabled: yield LibtorrentComponent() if config.ipv8.enabled and config.chant.enabled: yield GigaChannelComponent() if config.ipv8.enabled: yield BandwidthAccountingComponent() if config.resource_monitor.enabled: yield ResourceMonitorComponent() # The components below are skipped if config.gui_test_mode == True if config.gui_test_mode: return if config.libtorrent.enabled: yield SocksServersComponent() if config.torrent_checking.enabled: yield TorrentCheckerComponent() if config.ipv8.enabled and config.torrent_checking.enabled and config.popularity_community.enabled: yield PopularityComponent() if config.ipv8.enabled and config.tunnel_community.enabled: yield TunnelsComponent() if config.ipv8.enabled: yield PayoutComponent() if config.watch_folder.enabled: yield WatchFolderComponent() if config.general.version_checker_enabled: yield VersionCheckComponent() if config.chant.enabled and config.chant.manager_enabled and config.libtorrent.enabled: yield GigachannelManagerComponent()
async def crawler_session(session_config: TriblerConfig): session = Session(session_config, [KeyComponent(), Ipv8Component(), BandwidthAccountingComponent(crawler_mode=True)]) signal.signal(signal.SIGTERM, lambda signum, stack: session.shutdown_event.set) async with session.start(): await session.shutdown_event.wait()
async def test_tag_component(tribler_config): components = [MetadataStoreComponent(), KeyComponent(), Ipv8Component(), TagComponent()] async with Session(tribler_config, components).start(): comp = TagComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.community