allow multiple codecs per protocol (without breaking things)

This commit is contained in:
Giovanni Petrantoni 2020-06-23 11:48:11 +09:00
parent ee6e545878
commit 3568b073fd
3 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,16 @@ type
Future[void] {.gcsafe, closure.} Future[void] {.gcsafe, closure.}
LPProtocol* = ref object of RootObj LPProtocol* = ref object of RootObj
codec*: string codecs*: seq[string]
handler*: LPProtoHandler ## this handler gets invoked by the protocol negotiator handler*: LPProtoHandler ## this handler gets invoked by the protocol negotiator
method init*(p: LPProtocol) {.base, gcsafe.} = discard 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)

View File

@ -18,6 +18,7 @@ import metrics
export PubSubPeer export PubSubPeer
export PubSubObserver export PubSubObserver
export protocol
logScope: logScope:
topics = "pubsub" topics = "pubsub"

View File

@ -14,6 +14,8 @@ import ../protocol,
../../stream/connection, ../../stream/connection,
../../peerinfo ../../peerinfo
export protocol
logScope: logScope:
topics = "secure" topics = "secure"