async def test_connection_tracker_server_and_client(event_loop, event_bus):
    tracker = MemoryConnectionTracker()
    remote_a = NodeFactory()
    tracker.record_blacklist(remote_a, 60, "testing")

    assert await tracker.should_connect_to(remote_a) is False

    service = ConnectionTrackerServer(event_bus, tracker)

    # start the server
    asyncio.ensure_future(service.run(), loop=event_loop)
    await service.events.started.wait()

    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(ShouldConnectToPeerRequest)
    # ensure we can read from the tracker over the event bus
    assert await bus_tracker.should_connect_to(remote_a) is False

    # ensure we can write to the tracker over the event bus
    remote_b = NodeFactory()

    assert await bus_tracker.should_connect_to(remote_b) is True

    bus_tracker.record_blacklist(remote_b, 60, "testing")
    # let the underlying broadcast_nowait execute
    await asyncio.sleep(0.01)

    assert await bus_tracker.should_connect_to(remote_b) is False
    assert await tracker.should_connect_to(remote_b) is False
async def test_connection_tracker_server_and_client(event_loop, event_bus):
    tracker = MemoryConnectionTracker()
    remote_a = NodeFactory()
    await tracker.record_blacklist(remote_a, 60, "testing")

    assert await tracker.should_connect_to(remote_a) is False

    service = ConnectionTrackerServer(event_bus, tracker)

    # start the server
    asyncio.ensure_future(service.run(), loop=event_loop)
    await service.events.started.wait()

    config = BroadcastConfig(filter_endpoint=NETWORKING_EVENTBUS_ENDPOINT)
    bus_tracker = ConnectionTrackerClient(event_bus, config=config)

    # ensure we can read from the tracker over the event bus
    assert await bus_tracker.should_connect_to(remote_a) is False

    # ensure we can write to the tracker over the event bus
    remote_b = NodeFactory()

    assert await bus_tracker.should_connect_to(remote_b) is True

    await bus_tracker.record_blacklist(remote_b, 60, "testing")

    assert await bus_tracker.should_connect_to(remote_b) is False
    assert await tracker.should_connect_to(remote_b) is False
Пример #3
0
 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()
Пример #4
0
 def setup_connection_tracker(self) -> BaseConnectionTracker:
     if self.has_event_bus:
         return ConnectionTrackerClient(self.get_event_bus())
     else:
         return NoopConnectionTracker()