feat: push identify-push info in pararrel

This commit is contained in:
acul71
2025-04-29 01:15:46 +00:00
committed by Paul Robinson
parent 1213710af3
commit 4ad6975ef1

View File

@ -6,6 +6,7 @@ from typing import (
from multiaddr import ( from multiaddr import (
Multiaddr, Multiaddr,
) )
import trio
from libp2p.abc import ( from libp2p.abc import (
IHost, IHost,
@ -175,7 +176,7 @@ async def push_identify_to_peers(
observed_multiaddr: Optional[Multiaddr] = None, observed_multiaddr: Optional[Multiaddr] = None,
) -> None: ) -> None:
""" """
Push an identify message to multiple peers. Push an identify message to multiple peers in parallel.
If peer_ids is None, push to all connected peers. If peer_ids is None, push to all connected peers.
""" """
@ -183,6 +184,7 @@ async def push_identify_to_peers(
# Get all connected peers # Get all connected peers
peer_ids = set(host.get_peerstore().peer_ids()) peer_ids = set(host.get_peerstore().peer_ids())
# Push to each peer # Push to each peer in parallel using a trio.Nursery
for peer_id in peer_ids: async with trio.open_nursery() as nursery:
await push_identify_to_peer(host, peer_id, observed_multiaddr) for peer_id in peer_ids:
nursery.start_soon(push_identify_to_peer, host, peer_id, observed_multiaddr)