예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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
예제 #4
0
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()
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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
예제 #10
0
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
예제 #11
0
def components_gen():
    yield KeyComponent()
    yield RESTComponent()
    yield Ipv8Component()
    yield ResourceMonitorComponent()
    yield BandwidthAccountingComponent()
    yield SocksServersComponent()
    yield TunnelsComponent()
예제 #12
0
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()
예제 #13
0
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()
예제 #14
0
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
예제 #16
0
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
예제 #17
0
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
예제 #18
0
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
예제 #19
0
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()
예제 #20
0
 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'
예제 #21
0
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()
예제 #22
0
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
예제 #23
0
 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)
예제 #24
0
 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()
                      ])
예제 #25
0
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()
예제 #26
0
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()
예제 #27
0
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()
예제 #29
0
 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)
예제 #30
0
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()