Ejemplo n.º 1
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
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def components_gen():
    yield KeyComponent()
    yield RESTComponent()
    yield Ipv8Component()
    yield ResourceMonitorComponent()
    yield BandwidthAccountingComponent()
    yield SocksServersComponent()
    yield TunnelsComponent()
Ejemplo n.º 5
0
    async def on_tribler_started(self):
        info_hash = unhexlify('e24d8e65a329a59b41a532ebd4eb4a3db7cb291b')

        self.tunnel_community = TunnelsComponent.instance().community
        self.tunnel_community.join_swarm(info_hash,
                                         EXPERIMENT_NUM_HOPS,
                                         seeding=False,
                                         callback=self.on_circuit_ready)
Ejemplo n.º 6
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'
Ejemplo n.º 7
0
 async def on_tribler_started(self):
     index = 0
     while index < EXPERIMENT_NUM_CIRCUITS:
         community = TunnelsComponent.instance().community
         circuit = community.create_circuit(EXPERIMENT_NUM_HOPS)
         if circuit and (await circuit.ready):
             index += 1
             self.results += await self.run_speed_test(ORIGINATOR, circuit, index, EXPERIMENT_NUM_MB)
             self.results += await self.run_speed_test(EXIT_NODE, circuit, index, EXPERIMENT_NUM_MB)
             self.logger.info(f"Remove circuit: {index}/{EXPERIMENT_NUM_CIRCUITS}")
             community.remove_circuit(circuit.circuit_id)
         else:
             await asyncio.sleep(1)
     self._graceful_shutdown()
Ejemplo n.º 8
0
 async def run_speed_test(self, direction, circuit, index, size):
     request_size = 0 if direction == ORIGINATOR else 1024
     response_size = 1024 if direction == ORIGINATOR else 0
     num_requests = size * 1024
     task = asyncio.create_task(run_speed_test(TunnelsComponent.instance().community, circuit, request_size,
                                               response_size, num_requests, window=50))
     results = []
     prev_transferred = ts = 0
     while not task.done():
         cur_transferred = circuit.bytes_down if direction == ORIGINATOR else circuit.bytes_up
         results.append((ts, index, direction, (cur_transferred - prev_transferred) / 1024))
         prev_transferred = cur_transferred
         ts += 1
         await asyncio.sleep(1)
     return results
Ejemplo n.º 9
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)
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
    async def start(self, options):
        config = make_config(options)
        components = list(components_gen())
        session = self.session = Session(config, components)
        session.set_as_default()

        self.log_circuits = options.log_circuits
        session.notifier.add_observer(NTFY.TUNNEL_REMOVE, self.circuit_removed)

        await session.start()

        with session:
            if options.log_rejects:
                tunnels_component = TunnelsComponent.instance()
                tunnels_community = tunnels_component.community
                # We set this after Tribler has started since the tunnel_community won't be available otherwise
                tunnels_community.reject_callback = self.on_circuit_reject

        self.tribler_started()
Ejemplo n.º 12
0
 async def on_tribler_started(self):
     info_hash = unhexlify('e24d8e65a329a59b41a532ebd4eb4a3db7cb291b')
     community = TunnelsComponent.instance().community
     community.join_swarm(info_hash, 1, seeding=False)
     self.swarm = community.swarms[info_hash]
     print(f'Joining hidden swarm {hexlify(info_hash)}')  # noqa: T001