Ivan FB cb340f7ce3
messaging: drive delivery services through the Waku kernel
`SendService`/`RecvService` took a raw `WakuNode` and reached into its
internals (`wakuStoreClient`, `subscriptionManager`, `peerManager`),
which breaks the layering: the messaging layer should depend on the Waku
kernel, not the node.

Widen the Waku api surface with the operations these services need
(`storeQueryToAny`, `isStoreMounted`, `hasStorePeer`, `isContentSubscribed`,
`subscribedContentTopics`) and switch both services to hold `Waku` and
call that surface instead. The send-processor chain still pulls raw
publish handles (relay/lightpush/RLN/peer manager) from `waku.node`,
since the kernel API does not expose publishing primitives yet; this is
isolated to the constructor and flagged with a comment.

Also make `MessagingClient.new` return explicitly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-30 13:47:36 +02:00

55 lines
1.8 KiB
Nim

## Waku layer API — store (historical query) operations.
{.push raises: [].}
import std/options
import results, chronos, chronicles
import logos_delivery/waku/waku
import
logos_delivery/waku/
[waku_core, node/waku_node, node/peer_manager, waku_store/common, waku_store/client]
proc isStoreMounted*(self: Waku): bool =
## True if a store client is mounted (the node can run store queries).
return not self.node.wakuStoreClient.isNil()
proc hasStorePeer*(self: Waku): bool =
## True if at least one store service peer is available to query.
return self.node.peerManager.selectPeer(WakuStoreCodec).isSome()
proc storeQueryToAny*(
self: Waku, request: StoreQueryRequest
): Future[Result[StoreQueryResponse, string]] {.async.} =
## Runs a store query against any available store peer (retries across peers).
try:
if self.node.wakuStoreClient.isNil():
return err("wakuStoreClient is not mounted")
let queryResponse = (await self.node.wakuStoreClient.queryToAny(request)).valueOr:
return err($error)
return ok(queryResponse)
except CatchableError as e:
return err(e.msg)
proc storeQuery*(
self: Waku, request: StoreQueryRequest, peer: string, timeoutMs: int
): Future[Result[StoreQueryResponse, string]] {.async.} =
try:
if self.node.wakuStoreClient.isNil():
return err("wakuStoreClient is not mounted")
let remotePeer = parsePeerInfo(peer).valueOr:
return err("storeQuery failed to parse peer addr: " & $error)
let queryFut = self.node.wakuStoreClient.query(request, remotePeer)
if not await queryFut.withTimeout(timeoutMs.milliseconds):
return err("storeQuery timed out")
let queryResponse = queryFut.read().valueOr:
return err("storeQuery failed: " & $error)
return ok(queryResponse)
except CatchableError as e:
return err(e.msg)