From 3568b073fd5f59f100e0c11b79cdb7cb172a2457 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni Date: Tue, 23 Jun 2020 11:48:11 +0900 Subject: [PATCH] allow multiple codecs per protocol (without breaking things) --- libp2p/protocols/protocol.nim | 11 ++++++++++- libp2p/protocols/pubsub/pubsub.nim | 1 + libp2p/protocols/secure/secure.nim | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libp2p/protocols/protocol.nim b/libp2p/protocols/protocol.nim index 30e1c36c0..79badf3d0 100644 --- a/libp2p/protocols/protocol.nim +++ b/libp2p/protocols/protocol.nim @@ -16,7 +16,16 @@ type Future[void] {.gcsafe, closure.} LPProtocol* = ref object of RootObj - codec*: string + codecs*: seq[string] handler*: LPProtoHandler ## this handler gets invoked by the protocol negotiator method init*(p: LPProtocol) {.base, gcsafe.} = discard + +func codec*(p: LPProtocol): string = + assert(p.codecs.len > 0, "Codecs sequence was empty!") + p.codecs[0] + +func `codec=`*(p: LPProtocol, codec: string) = + # always insert as first codec + # if we use this abstraction + p.codecs.insert(codec, 0) diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index c893892cf..08167ec6e 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -18,6 +18,7 @@ import metrics export PubSubPeer export PubSubObserver +export protocol logScope: topics = "pubsub" diff --git a/libp2p/protocols/secure/secure.nim b/libp2p/protocols/secure/secure.nim index a12c35f97..3b9e16524 100644 --- a/libp2p/protocols/secure/secure.nim +++ b/libp2p/protocols/secure/secure.nim @@ -14,6 +14,8 @@ import ../protocol, ../../stream/connection, ../../peerinfo +export protocol + logScope: topics = "secure"