示例#1
0
async def test_peer_pool_answers_connect_commands(event_loop, event_bus, server, receiver_remote):
    # This is the PeerPool which will accept our message and try to connect to {server}
    initiator_peer_pool = ParagonPeerPool(
        privkey=INITIATOR_PRIVKEY,
        context=ParagonContext(),
        event_bus=event_bus,
    )
    asyncio.ensure_future(initiator_peer_pool.run(), loop=event_loop)
    await initiator_peer_pool.events.started.wait()
    async with run_peer_pool_event_server(
        event_bus,
        initiator_peer_pool,
    ):

        assert len(server.peer_pool.connected_nodes) == 0

        await event_bus.wait_until_any_endpoint_subscribed_to(ConnectToNodeCommand)
        await event_bus.broadcast(
            ConnectToNodeCommand(receiver_remote),
            TO_NETWORKING_BROADCAST_CONFIG
        )

        # This test was maybe 30% flaky at 0.1 sleep
        await asyncio.sleep(0.2)

        assert len(server.peer_pool.connected_nodes) == 1

        await initiator_peer_pool.cancel()
示例#2
0
async def test_peer_pool_answers_connect_commands(event_bus, server, receiver_remote):
    # This is the PeerPool which will accept our message and try to connect to {server}
    initiator_peer_pool = ParagonPeerPool(
        privkey=INITIATOR_PRIVKEY,
        context=ParagonContext(),
        event_bus=event_bus,
    )
    async with background_asyncio_service(initiator_peer_pool) as manager:
        await manager.wait_started()
        async with run_peer_pool_event_server(event_bus, initiator_peer_pool):

            assert len(server.peer_pool.connected_nodes) == 0

            await event_bus.wait_until_any_endpoint_subscribed_to(ConnectToNodeCommand)
            await event_bus.broadcast(
                ConnectToNodeCommand(receiver_remote),
                TO_NETWORKING_BROADCAST_CONFIG
            )

            # This test was maybe 30% flaky at 0.1 sleep, so wait in a loop.
            for _ in range(5):
                await asyncio.sleep(0.1)
                if len(server.peer_pool.connected_nodes) == 1:
                    break
            else:
                assert len(server.peer_pool.connected_nodes) == 1
示例#3
0
    async def addPeer(self, uri: str) -> None:
        validate_enode_uri(uri, require_ip=True)

        await self.event_bus.broadcast(
            ConnectToNodeCommand(Node.from_uri(uri)),
            TO_NETWORKING_BROADCAST_CONFIG
        )
示例#4
0
    async def addPeer(self, node: str) -> None:
        validate_enode_uri(node, require_ip=True)

        self.event_bus.broadcast(
            ConnectToNodeCommand(node),
            TO_NETWORKING_BROADCAST_CONFIG
        )
示例#5
0
 async def _connect_to_preferred_node(self, node: NodeAPI) -> None:
     """
     Broadcast a command for peer pool to connect to a preferred node,
     and track the time of attempted connection.
     """
     self._preferred_node_tracker[node] = time.monotonic()
     await self.event_bus.broadcast(
         ConnectToNodeCommand(node),
         TO_NETWORKING_BROADCAST_CONFIG,
     )
示例#6
0
async def test_peer_pool_answers_connect_commands(event_loop, event_bus,
                                                  server):
    # This is the PeerPool which will accept our message and try to connect to {server}
    initiator_peer_pool = ParagonPeerPool(
        privkey=INITIATOR_PRIVKEY,
        context=ParagonContext(),
        event_bus=event_bus,
    )
    asyncio.ensure_future(initiator_peer_pool.run(), loop=event_loop)
    await initiator_peer_pool.events.started.wait()
    await make_peer_pool_answer_event_bus_requests(
        event_bus,
        initiator_peer_pool,
        handler_type=ParagonPeerPoolEventServer)

    assert len(server.peer_pool.connected_nodes) == 0

    event_bus.broadcast(ConnectToNodeCommand(RECEIVER_REMOTE),
                        TO_NETWORKING_BROADCAST_CONFIG)

    await asyncio.sleep(0.5)

    assert len(server.peer_pool.connected_nodes) == 1
    await initiator_peer_pool.cancel()