コード例 #1
0
ファイル: net.py プロジェクト: manimech315/trinity
 async def peerCount(self) -> str:
     """
     Return the number of peers that are currently connected to the node
     """
     response = await self.event_bus.request(
         PeerCountRequest(), TO_NETWORKING_BROADCAST_CONFIG)
     return hex(response.peer_count)
コード例 #2
0
 async def _periodically_report_stats(self) -> None:
     while self.manager.is_running:
         try:
             response = await asyncio.wait_for(self.event_bus.request(
                 PeerCountRequest()),
                                               timeout=1.0)
             self.logger.info("CONNECTED PEERS: %s", response.peer_count)
         except asyncio.TimeoutError:
             self.logger.warning("TIMEOUT: Waiting on PeerPool to boot")
         await asyncio.sleep(5)
コード例 #3
0
async def test_event_bus_requests_against_peer_pool(request, event_loop,
                                                    event_bus):

    alice, bob = await get_directly_linked_peers(request, event_loop)
    peer_pool = ParagonMockPeerPoolWithConnectedPeers([alice, bob])
    await make_peer_pool_answer_event_bus_requests(
        event_bus, peer_pool, handler_type=ParagonPeerPoolEventServer)

    res = await event_bus.request(PeerCountRequest())

    assert res.peer_count == 2
コード例 #4
0
async def test_event_bus_requests_against_peer_pool(request, event_loop,
                                                    event_bus):
    async with ParagonPeerPairFactory() as (alice, bob):
        peer_pool = ParagonMockPeerPoolWithConnectedPeers([alice, bob])
        async with run_peer_pool_event_server(event_bus, peer_pool):

            await event_bus.wait_until_any_endpoint_subscribed_to(
                PeerCountRequest)

            res = await event_bus.request(PeerCountRequest())

            assert res.peer_count == 2
コード例 #5
0
async def test_event_bus_requests_against_peer_pool(request, event_loop,
                                                    event_bus):

    alice, bob = await get_directly_linked_peers(request, event_loop)
    peer_pool = ParagonMockPeerPoolWithConnectedPeers([alice, bob])
    async with run_peer_pool_event_server(event_bus, peer_pool):

        await event_bus.wait_until_any_connection_subscribed_to(
            PeerCountRequest)

        res = await event_bus.request(PeerCountRequest())

        assert res.peer_count == 2
コード例 #6
0
    async def get_node_stats(self) -> EthstatsData:
        """Getter for data that should be sent periodically."""
        try:
            peer_count = (await asyncio.wait_for(self.event_bus.request(
                PeerCountRequest(),
                TO_NETWORKING_BROADCAST_CONFIG,
            ),
                                                 timeout=1)).peer_count
        except asyncio.TimeoutError:
            self.logger.warning(
                "Timeout: PeerPool did not answer PeerCountRequest")
            peer_count = 0

        return {
            'active': True,
            'uptime': 100,
            'peers': peer_count,
        }