def upgrade_state_dir(root_state_dir: Path, update_status_callback=None, interrupt_upgrade_event=None): # Before any upgrade, prepare a separate state directory for the update version so it does not # affect the older version state directory. This allows for safe rollback. version_history = VersionHistory(root_state_dir) version_history.fork_state_directory_if_necessary() version_history.save_if_necessary() state_dir = version_history.code_version.directory if not state_dir.exists(): return config = TriblerConfig.load(file=state_dir / CONFIG_FILE_NAME, state_dir=state_dir, reset_config_on_error=True) channels_dir = config.chant.get_path_as_absolute('channels_dir', config.state_dir) primary_private_key_path = config.state_dir / KeyComponent.get_private_key_filename( config) primary_public_key_path = config.state_dir / config.trustchain.ec_keypair_pubfilename primary_key = KeyComponent.load_or_create(primary_private_key_path, primary_public_key_path) upgrader = TriblerUpgrader(state_dir, channels_dir, primary_key, update_status_callback=update_status_callback, interrupt_upgrade_event=interrupt_upgrade_event) upgrader.run()
def test_load(tmp_path): private_key_path = tmp_path / 'private' public_key_path = tmp_path / 'public' key1 = KeyComponent.load_or_create(private_key_path, public_key_path) key2 = KeyComponent.load_or_create(private_key_path, public_key_path) assert key1.key_to_bin() == key2.key_to_bin()
async def test_get_private_key_filename(tribler_config): private_key_file_name = KeyComponent.get_private_key_filename( tribler_config) tribler_config.general.testnet = True testnet_private_key_file_name = KeyComponent.get_private_key_filename( tribler_config) assert private_key_file_name != testnet_private_key_file_name
async def test_masterkey_component(tribler_config): session = Session(tribler_config, [KeyComponent()]) with session: comp = KeyComponent.instance() await session.start() assert comp.primary_key await session.shutdown()
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
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_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
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
def components_gen(): yield KeyComponent() yield RESTComponent() yield Ipv8Component() yield ResourceMonitorComponent() yield BandwidthAccountingComponent() yield SocksServersComponent() yield TunnelsComponent()
def test_create_no_public_key(tmp_path): private_key_path = tmp_path / 'private' assert not private_key_path.exists() key = KeyComponent.load_or_create(private_key_path) assert key assert private_key_path.exists()
async def test_reporter_component(tribler_config): components = [KeyComponent(), ReporterComponent()] session = Session(tribler_config, components) with session: await session.start() comp = ReporterComponent.instance() assert comp.started_event.is_set() and not comp.failed await session.shutdown()
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_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_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
async def test_watch_folder_component(tribler_config): components = [ KeyComponent(), SocksServersComponent(), LibtorrentComponent(), WatchFolderComponent() ] async with Session(tribler_config, components).start(): comp = WatchFolderComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.watch_folder
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
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()
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_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_libtorrent_component(tribler_config): components = [ KeyComponent(), SocksServersComponent(), LibtorrentComponent() ] session = Session(tribler_config, components) with session: await session.start() comp = LibtorrentComponent.instance() assert comp.started_event.is_set() and not comp.failed assert comp.download_manager await session.shutdown()
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_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()
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()
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()