From 827a8caba681cedf6441ecda683b89900d506e62 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 9 Sep 2019 20:14:24 -0600 Subject: [PATCH] wip: modeling floodsub --- libp2p/protocols/pubsub/floodsub.nim | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 libp2p/protocols/pubsub/floodsub.nim diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim new file mode 100644 index 000000000..11b8ef914 --- /dev/null +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -0,0 +1,53 @@ +## Nim-LibP2P +## Copyright (c) 2018 Status Research & Development GmbH +## Licensed under either of +## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) +## * MIT license ([LICENSE-MIT](LICENSE-MIT)) +## at your option. +## This file may not be copied, modified, or distributed except according to +## those terms. + +import chronos, chronicles +import ../protocol, + ../../connection + +logScope: + topic = "floodsub" + +const FloodSubCodec* = "/floodsub/1.0.0" + +type + TopicHandler* = proc(topic:string, data: seq[byte]): Future[void] {.gcsafe.} + Topic* = object + name*: string + handler*: TopicHandler + + Peer* = object + conn: Connection + topics: string + + FloodSub* = ref object of LPProtocol + topics: seq[Topic] + peers: seq[Peer] + +proc encodeRpcMsg() = discard +proc decodeRpcMsg() = discard + +method init*(f: FloodSub) = + proc handler(conn: Connection, proto: string) {.async, gcsafe.} = + discard + + f.codec = FloodSubCodec + f.handler = handler + +method subscribe*(f: FloodSub, + topic: string, + handler: TopicHandler) + {.base, async, gcsafe.} = + discard + +method publish*(f: FloodSub, topic: string) {.base, async, gcsafe.} = + discard + +proc newFloodSub*(): FloodSub = + new result