Ivan FB e59703fad7
Migrate FFI to nim-ffi v0.2.0-rc.3 (typed procs, direct params)
Rewrite the C FFI over the new per-layer APIs using nim-ffi v0.2.0 typed
{.ffiCtor.}/{.ffiDtor.}/{.ffi.}/{.ffiEvent.} + CBOR, replacing the
hand-written cstring/JSON bridge and the declare/lifecycle scaffolding.

Final API shape from the start (no intermediate request wrappers):
- every {.ffi.} proc takes its parameters directly; the macro bundles them
  into the per-proc CBOR request, so no `*Request` objects are needed
- WakuMessage rides the wire directly (its fields are CBOR-serializable)
- multi-parameter {.ffiEvent.} via the rc.3 envelope synthesis
- events are fed by internal nim-broker listeners (no AppCallbacks)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 13:14:40 +02:00

86 lines
2.9 KiB
Nim

proc relay_get_peers_in_mesh*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
let peers = (await self.waku.relayPeersInMesh(PubsubTopic(pubsubTopic))).valueOr:
return err(error)
return ok(peers.join(","))
proc relay_get_num_peers_in_mesh*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
let n = (await self.waku.relayNumPeersInMesh(PubsubTopic(pubsubTopic))).valueOr:
return err(error)
return ok($n)
proc relay_get_connected_peers*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
let peers = (await self.waku.relayConnectedPeers(PubsubTopic(pubsubTopic))).valueOr:
return err(error)
return ok(peers.join(","))
proc relay_get_num_connected_peers*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
let n = (await self.waku.relayNumConnectedPeers(PubsubTopic(pubsubTopic))).valueOr:
return err(error)
return ok($n)
proc relay_add_protected_shard*(
self: LogosDelivery, clusterId: uint16, shardId: uint16, publicKey: string
): Future[Result[string, string]] {.ffi.} =
(await self.waku.relayAddProtectedShard(clusterId, shardId, publicKey)).isOkOr:
return err(error)
return ok("")
proc relay_subscribe*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
# Just establishes the subscription; delivery flows through the global
# MessageSeenEvent listener (see the ctor in liblogosdelivery.nim).
(await self.waku.relaySubscribe(PubsubTopic(pubsubTopic))).isOkOr:
return err(error)
return ok("")
proc relay_unsubscribe*(
self: LogosDelivery, pubsubTopic: string
): Future[Result[string, string]] {.ffi.} =
(await self.waku.relayUnsubscribe(PubsubTopic(pubsubTopic))).isOkOr:
return err(error)
return ok("")
proc relay_publish*(
self: LogosDelivery, pubsubTopic: string, message: WakuMessage, timeoutMs: uint32
): Future[Result[string, string]] {.ffi.} =
## Returns the published message hash (0x-hex).
let hash = (
await self.waku.relayPublish(PubsubTopic(pubsubTopic), message, timeoutMs)
).valueOr:
return err(error)
return ok(hash)
proc relay_default_pubsub_topic*(
self: LogosDelivery
): Future[Result[string, string]] {.ffi.} =
return ok(string(self.waku.defaultPubsubTopic()))
proc relay_content_topic*(
self: LogosDelivery,
appName: string,
appVersion: uint32,
contentTopicName: string,
encoding: string,
): Future[Result[string, string]] {.ffi.} =
let contentTopic = self.waku.buildContentTopic(
appName, appVersion, contentTopicName, encoding
).valueOr:
return err(error)
return ok(string(contentTopic))
proc relay_pubsub_topic*(
self: LogosDelivery, topicName: string
): Future[Result[string, string]] {.ffi.} =
let pubsubTopic = self.waku.buildPubsubTopic(topicName).valueOr:
return err(error)
return ok(string(pubsubTopic))