mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-27 20:10:02 +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>
35 lines
1.0 KiB
Nim
35 lines
1.0 KiB
Nim
import std/[json, strformat]
|
|
import chronicles, chronos, results, ffi
|
|
import
|
|
logos_delivery,
|
|
logos_delivery/waku/waku_core/message,
|
|
logos_delivery/waku/waku_core/topics/pubsub_topic,
|
|
library/events/json_message_event,
|
|
library/declare_lib
|
|
|
|
proc waku_lightpush_publish(
|
|
ctx: ptr FFIContext[LogosDelivery],
|
|
callback: FFICallBack,
|
|
userData: pointer,
|
|
pubSubTopic: cstring,
|
|
jsonWakuMessage: cstring,
|
|
) {.ffi.} =
|
|
var jsonMessage: JsonMessage
|
|
try:
|
|
let jsonContent = parseJson($jsonWakuMessage)
|
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
|
raise newException(JsonParsingError, $error)
|
|
except JsonParsingError as exc:
|
|
return err(fmt"Error parsing json message: {exc.msg}")
|
|
|
|
let msg = json_message_event.toWakuMessage(jsonMessage).valueOr:
|
|
return err("Problem building the WakuMessage: " & $error)
|
|
|
|
let msgHashHex = (
|
|
await ctx.myLib[].waku.lightpushPublish(PubsubTopic($pubSubTopic), msg)
|
|
).valueOr:
|
|
error "PUBLISH failed", error = error
|
|
return err(error)
|
|
|
|
return ok(msgHashHex)
|