Ivan FB 18e17d2ddd
refactor: extract messaging client into top-level messaging folder
Move messaging_client.nim and the delivery_service machinery (send/recv
services, processors, not_delivered_storage) out of waku/ and waku/node/
into a dedicated top-level messaging/ folder.

The delivery services are a messaging-layer concern built on top of the
node, not part of node core, so a sibling folder makes that boundary
explicit. Shared message types (waku/api/types) and the node-owned
subscription_manager are left in place to avoid churn on widely-imported
modules.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 00:37:34 +02:00

54 lines
1.6 KiB
Nim

import chronicles, chronos, results
import waku/factory/waku
import messaging/messaging_client
import waku/[requests/health_requests, waku_core, waku_node]
import messaging/delivery_service/send_service
import waku/node/subscription_manager
import libp2p/peerid
import ../../tools/confutils/cli_args
import ./[api_conf, types]
export cli_args
logScope:
topics = "api"
proc createNode*(conf: WakuNodeConf): Future[Result[Waku, string]] {.async.} =
let wakuConf = conf.toWakuConf().valueOr:
return err("Failed to handle the configuration: " & error)
## We are not defining app callbacks at node creation
let wakuRes = (await Waku.new(wakuConf)).valueOr:
error "waku initialization failed", error = error
return err("Failed setting up Waku: " & $error)
return ok(wakuRes)
proc checkApiAvailability(w: Waku): Result[void, string] =
if w.isNil():
return err("Waku node is not initialized")
# TODO: Conciliate request-bouncing health checks here with unit testing.
# (For now, better to just allow all sends and rely on retries.)
return ok()
proc subscribe*(
w: Waku, contentTopic: ContentTopic
): Future[Result[void, string]] {.async.} =
?checkApiAvailability(w)
return w.node.subscriptionManager.subscribe(contentTopic)
proc unsubscribe*(w: Waku, contentTopic: ContentTopic): Result[void, string] =
?checkApiAvailability(w)
return w.node.subscriptionManager.unsubscribe(contentTopic)
proc send*(
w: Waku, envelope: MessageEnvelope
): Future[Result[RequestId, string]] {.async.} =
?checkApiAvailability(w)
return await w.messagingClient.send(envelope)