From ae16909f792deb2eb03b2e64a52c7130a509e17b Mon Sep 17 00:00:00 2001 From: sukhman Date: Mon, 2 Jun 2025 22:42:45 +0530 Subject: [PATCH] Test: Connected Peers Receive Pushes --- libp2p/identity/identify_push/identify_push.py | 2 +- .../identity/identify_push/test_identify_push.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libp2p/identity/identify_push/identify_push.py b/libp2p/identity/identify_push/identify_push.py index b6034956..7a9c10a9 100644 --- a/libp2p/identity/identify_push/identify_push.py +++ b/libp2p/identity/identify_push/identify_push.py @@ -40,7 +40,7 @@ logger = logging.getLogger(__name__) ID_PUSH = TProtocol("/ipfs/id/push/1.0.0") PROTOCOL_VERSION = "ipfs/0.1.0" AGENT_VERSION = get_agent_version() -LIMIT = trio.CapacityLimiter(10) +LIMIT = trio.Semaphore(10) def identify_push_handler_for(host: IHost) -> StreamHandlerFn: diff --git a/tests/core/identity/identify_push/test_identify_push.py b/tests/core/identity/identify_push/test_identify_push.py index 1b875e6f..ac06f599 100644 --- a/tests/core/identity/identify_push/test_identify_push.py +++ b/tests/core/identity/identify_push/test_identify_push.py @@ -175,6 +175,7 @@ async def test_identify_push_to_peers(security_protocol): host_c = new_host(key_pair=key_pair_c) # Set up the identify/push handlers + host_a.set_stream_handler(ID_PUSH, identify_push_handler_for(host_a)) host_b.set_stream_handler(ID_PUSH, identify_push_handler_for(host_b)) host_c.set_stream_handler(ID_PUSH, identify_push_handler_for(host_c)) @@ -203,6 +204,20 @@ async def test_identify_push_to_peers(security_protocol): # Check that the peer is in the peerstore assert peer_id_a in peerstore_c.peer_ids() + + # Test for push_identify to only connected peers and not all peers in peerstore + # Disconnect a from c. + await host_c.disconnect(host_a.get_id()) + # + await push_identify_to_peers(host_c) + + # Wait a bit for the push to complete + await trio.sleep(0.1) + + # Check that host_a's peerstore has not been updated with host_c's information + assert(host_c.get_id() not in host_a.get_peerstore().peer_ids()) + # Check that host_b's peerstore has been updated with host_c's information + assert(host_c.get_id() in host_b.get_peerstore().peer_ids()) @pytest.mark.trio