mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-03 22:43:09 +00:00
fix/libp2p-protocol-inheritance (#173)
This commit is contained in:
parent
fe5c0a9ce8
commit
bcae93300a
@ -74,25 +74,22 @@ proc init*(T: type MessagePush, buffer: seq[byte]): ProtoResult[T] =
|
|||||||
|
|
||||||
ok(push)
|
ok(push)
|
||||||
|
|
||||||
proc init*(T: type WakuFilter): T =
|
method init*(wf: WakuFilter) =
|
||||||
var ws = WakuFilter(subscribers: newSeq[Subscriber](0))
|
|
||||||
|
|
||||||
# From my understanding we need to set up filters,
|
|
||||||
# then on every message received we need the handle function to send it to the connection
|
|
||||||
# if the peer subscribed.
|
|
||||||
|
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
var message = await conn.readLp(64*1024)
|
var message = await conn.readLp(64*1024)
|
||||||
var res = FilterRequest.init(message)
|
var res = FilterRequest.init(message)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
return
|
return
|
||||||
|
|
||||||
ws.subscribers.add(Subscriber(connection: conn, filter: res.value))
|
wf.subscribers.add(Subscriber(connection: conn, filter: res.value))
|
||||||
# @TODO THIS IS A VERY ROUGH EXPERIMENT
|
# @TODO THIS IS A VERY ROUGH EXPERIMENT
|
||||||
|
|
||||||
ws.handler = handle
|
wf.handler = handle
|
||||||
ws.codec = WakuFilterCodec
|
wf.codec = WakuFilterCodec
|
||||||
result = ws
|
|
||||||
|
proc init*(T: type WakuFilter): T =
|
||||||
|
new result
|
||||||
|
result.init()
|
||||||
|
|
||||||
proc subscription*(proto: WakuFilter): MessageNotificationSubscription =
|
proc subscription*(proto: WakuFilter): MessageNotificationSubscription =
|
||||||
## Returns a Filter for the specific protocol
|
## Returns a Filter for the specific protocol
|
||||||
|
|||||||
@ -61,9 +61,7 @@ proc query(w: WakuStore, query: HistoryQuery): HistoryResponse =
|
|||||||
if msg.contentTopic in query.topics:
|
if msg.contentTopic in query.topics:
|
||||||
result.messages.insert(msg)
|
result.messages.insert(msg)
|
||||||
|
|
||||||
proc init*(T: type WakuStore): T =
|
method init*(ws: WakuStore) =
|
||||||
var ws = WakuStore()
|
|
||||||
|
|
||||||
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
|
||||||
var message = await conn.readLp(64*1024)
|
var message = await conn.readLp(64*1024)
|
||||||
var rpc = HistoryQuery.init(message)
|
var rpc = HistoryQuery.init(message)
|
||||||
@ -78,7 +76,10 @@ proc init*(T: type WakuStore): T =
|
|||||||
|
|
||||||
ws.handler = handle
|
ws.handler = handle
|
||||||
ws.codec = WakuStoreCodec
|
ws.codec = WakuStoreCodec
|
||||||
result = ws
|
|
||||||
|
proc init*(T: type WakuStore): T =
|
||||||
|
new result
|
||||||
|
result.init()
|
||||||
|
|
||||||
proc subscription*(proto: WakuStore): MessageNotificationSubscription =
|
proc subscription*(proto: WakuStore): MessageNotificationSubscription =
|
||||||
## The filter function returns the pubsub filter for the node.
|
## The filter function returns the pubsub filter for the node.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user