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 (
Multiaddr,
)
import trio
from libp2p.abc import (
IHost,
@ -175,7 +176,7 @@ async def push_identify_to_peers(
observed_multiaddr: Optional[Multiaddr] = 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.
"""
@ -183,6 +184,7 @@ async def push_identify_to_peers(
# Get all connected peers
peer_ids = set(host.get_peerstore().peer_ids())
# Push to each peer
for peer_id in peer_ids:
await push_identify_to_peer(host, peer_id, observed_multiaddr)
# Push to each peer in parallel using a trio.Nursery
async with trio.open_nursery() as nursery:
for peer_id in peer_ids:
nursery.start_soon(push_identify_to_peer, host, peer_id, observed_multiaddr)