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
    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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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