Ivan FB 46666044f2
channels_api: reliable-channel FFI (create/send/close + events)
Add library/channels_api over the reliable-channel logic: channel_create
returns a {.ffiHandle.} ReliableChannelHandle, channel_send/channel_close
operate on it, and the channel message received/sent/error events are fed by
the channel-layer broker events. Wire them into the FFI root.

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

34 lines
1.1 KiB
Nim

## Reliable-channel events: per-channel message received / sent / errored,
## fed by the channel-layer broker events.
proc onChannelMessageReceived*(
channelId: string, senderId: string, payload: seq[byte]
) {.ffiEvent: "on_channel_message_received".}
proc onChannelMessageSent*(
channelId: string, requestId: string
) {.ffiEvent: "on_channel_message_sent".}
proc onChannelMessageError*(
channelId: string, requestId: string, error: string
) {.ffiEvent: "on_channel_message_error".}
proc listenChannelEvents(self: LogosDelivery) =
let brokerCtx = self.waku.brokerCtx
discard ChannelMessageReceivedEvent.listen(
brokerCtx,
proc(e: ChannelMessageReceivedEvent) {.async: (raises: []).} =
onChannelMessageReceived(string(e.channelId), $e.senderId, e.payload),
)
discard ChannelMessageSentEvent.listen(
brokerCtx,
proc(e: ChannelMessageSentEvent) {.async: (raises: []).} =
onChannelMessageSent(string(e.channelId), $e.requestId),
)
discard ChannelMessageErrorEvent.listen(
brokerCtx,
proc(e: ChannelMessageErrorEvent) {.async: (raises: []).} =
onChannelMessageError(string(e.channelId), $e.requestId, e.error),
)