Ivan FB b95a74c600
messaging: depend on the Waku kernel, not the raw WakuNode
MessagingClient sat one layer below where the documented layering
(Waku <- MessagingClient <- ReliableChannelManager) places it: it took a
raw WakuNode and reached around the Waku kernel to its internals. Make the
messaging layer hold the Waku kernel and read `waku.node` from there, so the
declared dependency matches the layering and the layer holds the kernel handle
it will later route through.

The health-monitor test hand-builds a WakuNode, so it now wraps it in a
minimal Waku (conf/stateInfo only satisfy {.requiresInit.}; the messaging
path reads neither).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 11:56:47 +02:00

39 lines
1.5 KiB
Nim

## Messaging layer API — send operation.
import results, chronos, chronicles
import logos_delivery/api/types
import logos_delivery/messaging/messaging_client
import logos_delivery/waku/waku
import logos_delivery/waku/node/[waku_node, subscription_manager]
import logos_delivery/messaging/delivery_service/send_service
import logos_delivery/messaging/delivery_service/send_service/delivery_task
proc send*(
self: MessagingClient, envelope: MessageEnvelope
): Future[Result[RequestId, string]] {.async.} =
## High-level messaging API send. Auto-subscribes to the content topic
## (so the local node sees its own gossipsub broadcast), builds a
## `DeliveryTask`, and hands it to the send service. Returns the request
## id the caller can correlate with `MessageSentEvent` / `MessageErrorEvent`.
?self.checkApiAvailability()
let isSubbed = self.waku.node.subscriptionManager.isSubscribed(
envelope.contentTopic
).valueOr(false)
if not isSubbed:
info "Auto-subscribing to topic on send", contentTopic = envelope.contentTopic
self.waku.node.subscriptionManager.subscribe(envelope.contentTopic).isOkOr:
warn "Failed to auto-subscribe", error = error
return err("Failed to auto-subscribe before sending: " & error)
let requestId = RequestId.new(self.waku.node.rng)
let deliveryTask = DeliveryTask.new(
requestId, envelope, self.waku.node.brokerCtx
).valueOr:
return err("MessagingClient.send: Failed to create delivery task: " & error)
asyncSpawn self.sendService.send(deliveryTask)
return ok(requestId)