diff --git a/libp2p/muxers/muxer.nim b/libp2p/muxers/muxer.nim index b6028bc..9662ac8 100644 --- a/libp2p/muxers/muxer.nim +++ b/libp2p/muxers/muxer.nim @@ -22,42 +22,26 @@ type streamHandler*: StreamHandler connection*: Connection - MuxerCreator* = proc(conn: Connection): Muxer {.gcsafe, closure.} + # user provider proc that returns a constructed Muxer + MuxerConstructor* = proc(conn: Connection): Muxer {.gcsafe, closure.} + # this wraps a creator proc that knows how to make muxers MuxerProvider* = ref object of LPProtocol - newMuxer*: MuxerCreator - streamHandler*: StreamHandler - muxerHandler*: MuxerHandler + newMuxer*: MuxerConstructor + streamHandler*: StreamHandler # triggered every time there is a new stream, called for any muxer instance + muxerHandler*: MuxerHandler # triggered every time there is a new muxed connection created +# muxer interface method newStream*(m: Muxer, name: string = ""): Future[Connection] {.base, async, gcsafe.} = discard method close*(m: Muxer) {.base, async, gcsafe.} = discard method handle*(m: Muxer): Future[void] {.base, async, gcsafe.} = discard -method `streamHandler=`*(m: Muxer, handler: StreamHandler) {.base, gcsafe.} = - m.streamHandler = handler -proc newMuxerProvider*(creator: MuxerCreator, codec: string): MuxerProvider {.gcsafe.} = +proc newMuxerProvider*(creator: MuxerConstructor, codec: string): MuxerProvider {.gcsafe.} = new result result.newMuxer = creator result.codec = codec result.init() -method `streamHandler=`*(m: MuxerProvider, handler: StreamHandler) {.base, gcsafe.} = - ## new stream (channels) handler - ## - ## triggered every time there is a new - ## stream (channel) oppened over a muxed - ## connection - ## - m.streamHandler = handler - -method `muxerHandler=`*(m: MuxerProvider, handler: MuxerHandler) {.base, gcsafe.} = - ## new muxer (muxed connections) handler - ## - ## triggered every time there is a new muxed - ## connection created - ## - m.muxerHandler = handler - method init(c: MuxerProvider) = proc handler(conn: Connection, proto: string) {.async, gcsafe, closure.} = let muxer = c.newMuxer(conn)