mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-26 14:33:27 +00:00
Each layer now separates its constructible core from its public surface:
- core module (waku.nim / messaging_client.nim /
reliable_channel_manager.nim): the type plus new/start/stop and the
private construction helpers.
- api/ folder: one module per differentiated set of operations
(waku: topics/relay/filter/lightpush/store/peer_manager/discovery/
debug/health) plus an events surface.
The waku api is reshaped to be the complete operation surface the C
bindings need, so the library no longer reaches into node internals:
relayPublish returns the message hash, relaySubscribe takes an optional
handler, filter/lightpush auto-select the service peer, connectedPeersInfo
returns structured data, pingPeer honours the timeout, plus
relayNumPeersInMesh / relayNumConnectedPeers / isOnline. library/ is now a
thin C-ABI shim: each {.ffi.} proc only marshals cstring/JSON/callbacks and
delegates to ctx.myLib[].waku.<op> (or messagingClient.<op>).
app_callbacks re-exports the modules defining its handler types, which the
included FFI files previously relied on by leakage.
Events move next to the surface that owns them, with each dependency kept
pointing the right way:
- waku/events/ relocated under waku/api/events/.
- channel events live in channels/api/events.nim.
- the four messaging-level message events move to messaging/api/events;
MessageSeenEvent stays in waku because it is emitted by waku core, so
moving it would make waku depend on the messaging layer.
- delivery_events renamed to filter_subscribe_events to match the
OnFilterSubscribe/Unsubscribe events it actually declares.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
1.8 KiB
Nim
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()
|