logos-delivery/logos_delivery/messaging/messaging_client.nim
Ivan FB 4dfe72e12f
messaging & channels: per-layer api/ folders + concentrator
Extract the messaging (send/subscription) and reliable-channel
(lifecycle/send) operations into their own api/ folders with events moved to
the owning layer, thin messaging_client and reliable_channel_manager, and add
the LogosDelivery concentrator that aggregates the per-layer APIs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 04:17:49 +02:00

52 lines
1.8 KiB
Nim

## Messaging layer core: the `MessagingClient` type plus its construction and
## lifecycle. The public operations (subscribe / unsubscribe / send) live in
## `messaging/api.nim`.
import results, chronos
import
logos_delivery/waku/node/waku_node,
logos_delivery/messaging/delivery_service/[recv_service, send_service]
type
MessagingClientConf* = object
## Per-layer config object for the messaging API.
## Kept intentionally minimal for now; the full config surface lands in a
## follow-up PR. Today it only carries the p2p reliability toggle.
useP2PReliability*: bool
MessagingClient* = ref object
node*: WakuNode ## Waku core driven by this layer; read by `messaging/api.nim`.
sendService*: SendService
recvService*: RecvService
started: bool
proc new*(
T: type MessagingClient, conf: MessagingClientConf, node: WakuNode
): Result[T, string] =
## The messaging layer chains onto Waku: it drives the underlying
## `WakuNode` (Waku's core) for transport while exposing its own send/recv API.
let sendService = ?SendService.new(conf.useP2PReliability, node)
let recvService = RecvService.new(node)
ok(T(node: node, sendService: sendService, recvService: recvService))
proc start*(self: MessagingClient): Result[void, string] =
if self.started:
return ok()
self.recvService.startRecvService()
self.sendService.startSendService()
self.started = true
ok()
proc stop*(self: MessagingClient) {.async.} =
if not self.started:
return
await self.sendService.stopSendService()
await self.recvService.stopRecvService()
self.started = false
proc checkApiAvailability*(self: MessagingClient): Result[void, string] =
## Shared guard for the api operation module.
if self.isNil():
return err("MessagingClient is not initialized")
return ok()