From 01889859180360ae1e1655fbbfc07b149d0fa700 Mon Sep 17 00:00:00 2001 From: mhchia Date: Tue, 9 Jul 2019 23:29:03 +0800 Subject: [PATCH 1/7] Change `packages` in `setup` Previously, only the top level `libp2p` is included. This left only `__init__.py` in the built distribution. Use `setuptools.find_packages` with `exclude` instead, to avoid tiringly list all of the subpackages. --- setup.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index b1de125..452ea3b 100644 --- a/setup.py +++ b/setup.py @@ -2,9 +2,7 @@ import setuptools classifiers = [ - ( - "Programming Language :: Python :: %s" % version - ) + f"Programming Language :: Python :: {version}" for version in ["3.7"] ] @@ -28,6 +26,6 @@ setuptools.setup( "lru-dict>=1.1.6", "aio_timers" ], - packages=["libp2p"], + packages=setuptools.find_packages(exclude=["tests", "tests.*"]), zip_safe=False, ) From 10511d4930e97d32b4c6f4b6880f11ca2b649f41 Mon Sep 17 00:00:00 2001 From: mhchia Date: Tue, 9 Jul 2019 23:55:43 +0800 Subject: [PATCH 2/7] Clean up a bit --- libp2p/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libp2p/__init__.py b/libp2p/__init__.py index 682ae27..1434737 100644 --- a/libp2p/__init__.py +++ b/libp2p/__init__.py @@ -1,8 +1,8 @@ import asyncio -import multiaddr from Crypto.PublicKey import RSA -from libp2p.security.insecure_security import InsecureTransport + +from .security.insecure_security import InsecureTransport from .peer.peerstore import PeerStore from .peer.id import id_from_public_key from .network.swarm import Swarm From fa092505e8f515875ea860a7fe80e894eb7ed56d Mon Sep 17 00:00:00 2001 From: mhchia Date: Wed, 10 Jul 2019 00:07:58 +0800 Subject: [PATCH 3/7] Add missing "package file" --- libp2p/routing/__init__.py | 0 libp2p/transport/tcp/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 libp2p/routing/__init__.py create mode 100644 libp2p/transport/tcp/__init__.py diff --git a/libp2p/routing/__init__.py b/libp2p/routing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/libp2p/transport/tcp/__init__.py b/libp2p/transport/tcp/__init__.py new file mode 100644 index 0000000..e69de29 From c8cb375d19036a8df9202dd30b3b053dd45a193d Mon Sep 17 00:00:00 2001 From: mhchia Date: Wed, 10 Jul 2019 17:44:14 +0800 Subject: [PATCH 4/7] Make pylint happy Not sure why it fails now, but happy previously. --- libp2p/routing/interfaces.py | 2 +- libp2p/routing/kademlia/kademlia_content_router.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libp2p/routing/interfaces.py b/libp2p/routing/interfaces.py index b519a09..1f29d48 100644 --- a/libp2p/routing/interfaces.py +++ b/libp2p/routing/interfaces.py @@ -28,4 +28,4 @@ class IPeerRouting(ABC): Find specific Peer FindPeer searches for a peer with given peer_id, returns a peer.PeerInfo with relevant addresses. - """ \ No newline at end of file + """ diff --git a/libp2p/routing/kademlia/kademlia_content_router.py b/libp2p/routing/kademlia/kademlia_content_router.py index 60cf55b..ac49be8 100644 --- a/libp2p/routing/kademlia/kademlia_content_router.py +++ b/libp2p/routing/kademlia/kademlia_content_router.py @@ -11,11 +11,9 @@ class KadmeliaContentRouter(IContentRouting): """ # the DHT finds the closest peers to `key` using the `FIND_NODE` RPC # then sends a `ADD_PROVIDER` RPC with its own `PeerInfo` to each of these peers. - pass def find_provider_iter(self, cid, count): """ Search for peers who are able to provide a given key returns an iterator of peer.PeerInfo """ - pass From a7ce230d053fbfc8855432b0da68910bfd411b61 Mon Sep 17 00:00:00 2001 From: mhchia Date: Wed, 10 Jul 2019 19:33:38 +0800 Subject: [PATCH 5/7] Change params `multiaddr` to `maddr` To make pylint happy --- libp2p/transport/listener_interface.py | 4 ++-- libp2p/transport/tcp/tcp.py | 14 +++++++------- libp2p/transport/transport_interface.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libp2p/transport/listener_interface.py b/libp2p/transport/listener_interface.py index 8ef663a..174f267 100644 --- a/libp2p/transport/listener_interface.py +++ b/libp2p/transport/listener_interface.py @@ -4,10 +4,10 @@ from abc import ABC, abstractmethod class IListener(ABC): @abstractmethod - def listen(self, multiaddr): + def listen(self, maddr): """ put listener in listening mode and wait for incoming connections - :param multiaddr: multiaddr of peer + :param maddr: multiaddr of peer :return: return True if successful """ diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index f6167ce..f99b78c 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -21,13 +21,13 @@ class TCP(ITransport): self.server = None self.handler = handler_function - async def listen(self, multiaddr): + async def listen(self, maddr): """ put listener in listening mode and wait for incoming connections - :param multiaddr: multiaddr of peer + :param maddr: maddr of peer :return: return True if successful """ - _multiaddr = multiaddr + _multiaddr = maddr _multiaddr = _multiaddr.decapsulate('/p2p') coroutine = asyncio.start_server(self.handler, @@ -64,16 +64,16 @@ class TCP(ITransport): self.server = None return True - async def dial(self, multiaddr, self_id, options=None): + async def dial(self, maddr, self_id, options=None): """ dial a transport to peer listening on multiaddr - :param multiaddr: multiaddr of peer + :param maddr: multiaddr of peer :param self_id: peer_id of the dialer (to send to receiver) :param options: optional object :return: True if successful """ - host = multiaddr.value_for_protocol('ip4') - port = int(multiaddr.value_for_protocol('tcp')) + host = maddr.value_for_protocol('ip4') + port = int(maddr.value_for_protocol('tcp')) reader, writer = await asyncio.open_connection(host, port) diff --git a/libp2p/transport/transport_interface.py b/libp2p/transport/transport_interface.py index ab49c76..42acb0d 100644 --- a/libp2p/transport/transport_interface.py +++ b/libp2p/transport/transport_interface.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod class ITransport(ABC): @abstractmethod - def dial(self, multiaddr, self_id, options=None): + def dial(self, maddr, self_id, options=None): """ dial a transport to peer listening on multiaddr :param multiaddr: multiaddr of peer From 31cd520076b17e85516f63b5b90b4f15dcc00092 Mon Sep 17 00:00:00 2001 From: mhchia Date: Thu, 11 Jul 2019 17:50:36 +0800 Subject: [PATCH 6/7] Add the missing __init__.py in pb --- libp2p/pubsub/pb/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 libp2p/pubsub/pb/__init__.py diff --git a/libp2p/pubsub/pb/__init__.py b/libp2p/pubsub/pb/__init__.py new file mode 100644 index 0000000..e69de29 From edd02c498ffe0be61bdcfcff639b8f1db305c94a Mon Sep 17 00:00:00 2001 From: mhchia Date: Thu, 11 Jul 2019 20:58:03 +0800 Subject: [PATCH 7/7] Ignore pb files --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 6bf6c9f..7113484 100644 --- a/.pylintrc +++ b/.pylintrc @@ -11,7 +11,7 @@ ignore=CVS # Add files or directories matching the regex patterns to the blacklist. The # regex matches against base names, not paths. -ignore-patterns= +ignore-patterns=.*_pb2.*.py # Python code to execute, usually for sys.path manipulation such as # pygtk.require().