From 8f9e5a28ff70036c91b2a3f01db4b111db723264 Mon Sep 17 00:00:00 2001 From: mhchia Date: Mon, 22 Jul 2019 18:12:54 +0800 Subject: [PATCH] Temp --- libp2p/network/swarm.py | 9 +++++++++ libp2p/pubsub/pubsub.py | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libp2p/network/swarm.py b/libp2p/network/swarm.py index 7d05991..e3d037e 100644 --- a/libp2p/network/swarm.py +++ b/libp2p/network/swarm.py @@ -195,6 +195,15 @@ class Swarm(INetwork): def add_router(self, router): self.router = router + # TODO: `tear_down` + async def tear_down(self) -> None: + # pylint: disable=line-too-long + # Reference: https://github.com/libp2p/go-libp2p-swarm/blob/8be680aef8dea0a4497283f2f98470c2aeae6b65/swarm.go#L118 # noqa: E501 + pass + + # TODO: `disconnect`? + + def create_generic_protocol_handler(swarm): """ Create a generic protocol handler from the given swarm. We use swarm diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index 7afdc2a..fa04d2b 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -9,6 +9,14 @@ from typing import ( Tuple, ) +from typing import ( + Any, + Dict, + List, + Sequence, + Tuple, +) + from lru import LRU from libp2p.host.host_interface import ( @@ -319,3 +327,19 @@ class Pubsub: for _, stream in self.peers.items(): # Write message to stream await stream.write(rpc_msg) + + def list_peers(self, topic_id: str) -> Tuple[ID]: + return + + def publish(self, topic_id: str, data: bytes) -> None: + # TODO: Create pb message + # TODO: Sign with our signing key + # TODO: `p.pushMsg(p.host.ID(), msg)` + # TODO: - Check if the source is in the blacklist. If yes, reject. + # TODO: - Check if the `from` is in the blacklist. If yes, reject. + # TODO: - Check if the message is seen. If yes, reject it. + # TODO: - Validate the message. If failed, reject it. + # TODO: - Mark as seen and `publishMessage` + # TODO: - Notify the subscribers + # TODO: - Router.Publish + return