mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
ran make lint
This commit is contained in:
committed by
Paul Robinson
parent
1549d4e5d3
commit
4620142ed1
@ -1,18 +1,26 @@
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import multiaddr
|
||||
import trio
|
||||
|
||||
from libp2p import new_host
|
||||
from libp2p.network.stream.net_stream_interface import INetStream
|
||||
from libp2p.peer.peerinfo import info_from_p2p_addr
|
||||
from libp2p.typing import TProtocol
|
||||
from libp2p import (
|
||||
new_host,
|
||||
)
|
||||
from libp2p.network.stream.net_stream_interface import (
|
||||
INetStream,
|
||||
)
|
||||
from libp2p.peer.peerinfo import (
|
||||
info_from_p2p_addr,
|
||||
)
|
||||
from libp2p.typing import (
|
||||
TProtocol,
|
||||
)
|
||||
|
||||
PING_PROTOCOL_ID = TProtocol("/ipfs/ping/1.0.0")
|
||||
PING_LENGTH = 32
|
||||
RESP_TIMEOUT = 60
|
||||
|
||||
|
||||
async def handle_ping(stream: INetStream) -> None:
|
||||
while True:
|
||||
try:
|
||||
@ -27,6 +35,7 @@ async def handle_ping(stream: INetStream) -> None:
|
||||
except:
|
||||
await stream.reset()
|
||||
|
||||
|
||||
async def send_ping(stream: INetStream) -> None:
|
||||
try:
|
||||
payload = b"\x01" * PING_LENGTH
|
||||
@ -43,6 +52,7 @@ async def send_ping(stream: INetStream) -> None:
|
||||
except Exception as e:
|
||||
print(f"error occurred : {e}")
|
||||
|
||||
|
||||
async def run(port: int, destination: str) -> None:
|
||||
localhost_ip = "127.0.0.1"
|
||||
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
|
||||
@ -71,8 +81,8 @@ async def run(port: int, destination: str) -> None:
|
||||
|
||||
await trio.sleep_forever()
|
||||
|
||||
def main() -> None:
|
||||
|
||||
def main() -> None:
|
||||
description = """
|
||||
This program demonstrates a simple p2p ping application using libp2p.
|
||||
To use it, first run 'python ping.py -p <PORT>', where <PORT> is the port number.
|
||||
@ -105,5 +115,6 @@ def main() -> None:
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user