diff --git a/examples/chat/chat.py b/examples/chat/chat.py index 9c55687..0ac6e78 100755 --- a/examples/chat/chat.py +++ b/examples/chat/chat.py @@ -1,8 +1,8 @@ +import argparse import asyncio import sys import urllib.request -import click import multiaddr from libp2p import new_node @@ -52,9 +52,9 @@ async def run(port, destination): (int(port) + 1, external_ip, port, host.get_id().pretty())) print("\nWaiting for incoming connection\n\n") - else: # its the client - m = multiaddr.Multiaddr(destination) - info = info_from_p2p_addr(m) + else: # its the client + maddr = multiaddr.Multiaddr(destination) + info = info_from_p2p_addr(maddr) # Associate the peer with local ip address await host.connect(info) @@ -67,22 +67,37 @@ async def run(port, destination): print("Connected to peer %s" % info.addrs[0]) -@click.command() -@click.option('--port', '-p', help='source port number', default=8000) -@click.option('--destination', '-d', help="Destination multiaddr string") -@click.option('--help', is_flag=True, default=False, help='display help') -# @click.option('--debug', is_flag=True, default=False, help='Debug generates the same node ID on every execution') -def main(port, destination, help): - - if help: - print("This program demonstrates a simple p2p chat application using libp2p\n\n") - print("Usage: Run './chat -p ' where can be any port number.") - print("Now run './chat -p -d ' where is multiaddress of previous listener host.") - return +def main(): + description = """ + This program demonstrates a simple p2p chat application using libp2p. + To use it, first run 'python ./chat -p ', where is the port number. + Then, run another host with 'python ./chat -p -d ', + where is the multiaddress of the previous listener host. + """ + example_maddr = "/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q" + parser = argparse.ArgumentParser(description=description) + parser.add_argument( + "--debug", + action='store_true', + help='generate the same node ID on every execution', + ) + parser.add_argument( + "-p", + "--port", + default=8000, + help="source port number", + ) + parser.add_argument( + "-d", + "--destination", + type=str, + help=f"destination multiaddr string, e.g. {example_maddr}", + ) + args = parser.parse_args() loop = asyncio.get_event_loop() try: - asyncio.ensure_future(run(port, destination)) + asyncio.ensure_future(run(args.port, args.destination)) loop.run_forever() except KeyboardInterrupt: pass diff --git a/setup.py b/setup.py index bc8cefb..36d99a4 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,6 @@ setuptools.setup( classifiers=classifiers, install_requires=[ "pycryptodome>=3.8.2,<4.0.0", - "click>=7.0,<8.0", "base58>=1.0.3,<2.0.0", "pymultihash>=0.8.2", "multiaddr>=0.0.8,<0.1.0",