mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 23:51:07 +00:00
feat: push identify-push info in pararrel
This commit is contained in:
@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user