コード例 #1
0
async def test_connection_tracker_server_and_client(event_loop, event_bus):
    tracker = MemoryConnectionTracker()
    remote_a = NodeFactory()
    tracker.record_blacklist(remote_a, 60, "testing")

    blacklisted_ids = await tracker.get_blacklisted()
    assert remote_a.id in blacklisted_ids

    service = ConnectionTrackerServer(event_bus, tracker)

    # start the server
    async with background_asyncio_service(service):
        config = BroadcastConfig(filter_endpoint=NETWORKING_EVENTBUS_ENDPOINT)
        bus_tracker = ConnectionTrackerClient(event_bus, config=config)

        # Give `bus_tracker` a moment to setup subscriptions
        await event_bus.wait_until_any_endpoint_subscribed_to(
            GetBlacklistedPeersRequest)
        # ensure we can read from the tracker over the event bus
        bus_blacklisted_ids = await bus_tracker.get_blacklisted()
        assert remote_a.id in bus_blacklisted_ids

        # ensure we can write to the tracker over the event bus
        remote_b = NodeFactory()
        bus_tracker.record_blacklist(remote_b, 60, "testing")
        # let the underlying broadcast_nowait execute
        await asyncio.sleep(0.01)

        bus_blacklisted_ids = await bus_tracker.get_blacklisted()
        blacklisted_ids = await tracker.get_blacklisted()
        assert remote_b.id in blacklisted_ids
        assert bus_blacklisted_ids == blacklisted_ids

        assert sorted(blacklisted_ids) == sorted([remote_a.id, remote_b.id])
コード例 #2
0
ファイル: peer.py プロジェクト: binaryflesh/trinity
 def setup_connection_tracker(self) -> BaseConnectionTracker:
     if self.has_event_bus:
         return ConnectionTrackerClient(self.get_event_bus())
     else:
         self.logger.warning(
             "No event_bus set on peer.  Connection tracking falling back to "
             "`NoopConnectionTracker`.")
         return NoopConnectionTracker()
コード例 #3
0
 def setup_connection_tracker(self) -> BaseConnectionTracker:
     if self.has_event_bus:
         return ConnectionTrackerClient(self.get_event_bus())
     else:
         return NoopConnectionTracker()