2022-11-04 10:52:27 +01:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
import
|
|
|
|
chronos,
|
2023-02-13 15:22:24 +01:00
|
|
|
chronicles
|
2022-06-10 13:30:51 +02:00
|
|
|
import
|
2023-02-13 15:22:24 +01:00
|
|
|
../../../../waku/v2/protocol/waku_relay,
|
|
|
|
../../../../waku/v2/protocol/waku_message,
|
|
|
|
../../../../waku/v2/node/message_cache
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2022-08-30 15:57:45 +02:00
|
|
|
export message_cache
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
2022-08-30 15:57:45 +02:00
|
|
|
##### TopicCache
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2022-08-30 15:57:45 +02:00
|
|
|
type TopicCacheResult*[T] = MessageCacheResult[T]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2022-11-09 15:00:11 +01:00
|
|
|
type TopicCache* = MessageCache[PubSubTopic]
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
|
2022-08-30 15:57:45 +02:00
|
|
|
##### Message handler
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-02-13 15:22:24 +01:00
|
|
|
type TopicCacheMessageHandler* = SubscriptionHandler
|
2022-06-10 13:30:51 +02:00
|
|
|
|
|
|
|
proc messageHandler*(cache: TopicCache): TopicCacheMessageHandler =
|
|
|
|
|
2023-02-13 15:22:24 +01:00
|
|
|
let handler = proc(pubsubTopic: string, msg: WakuMessage): Future[void] {.async, closure.} =
|
|
|
|
cache.addMessage(PubSubTopic(pubsubTopic), msg)
|
2022-06-10 13:30:51 +02:00
|
|
|
|
2023-02-13 15:22:24 +01:00
|
|
|
handler
|