mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
refactored code
This commit is contained in:
@ -6,15 +6,9 @@ import trio
|
||||
from libp2p import (
|
||||
new_host,
|
||||
)
|
||||
from libp2p.abc import (
|
||||
PeerInfo,
|
||||
)
|
||||
from libp2p.crypto.secp256k1 import (
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.discovery.events.peerDiscovery import (
|
||||
peerDiscovery,
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
@ -29,16 +23,10 @@ async def main():
|
||||
host = new_host(key_pair=key_pair, enable_mDNS=True)
|
||||
|
||||
async with host.run(listen_addrs=[listen_addr]):
|
||||
print("host peer id", host.get_id())
|
||||
|
||||
# Print discovered peers via mDNS
|
||||
print("Waiting for mDNS peer discovery events (Ctrl+C to exit)...")
|
||||
try:
|
||||
while True:
|
||||
peer_info = PeerInfo(host.get_id(), host.get_addrs())
|
||||
|
||||
await trio.sleep(1)
|
||||
await peerDiscovery.emit_peer_discovered(peer_info=peer_info)
|
||||
await trio.sleep(100)
|
||||
except KeyboardInterrupt:
|
||||
print("Exiting...")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user