logos-messaging-nim/logos_delivery/api/messaging_client_api.nim
Ivan FB b7d1cb8872
api: define layer contracts with concept, not RootObj inheritance
The IMessagingClient / IKernel / IReliableChannelManager base types were
inheritance-as-documentation: nothing dispatched over them and no impl ever
overrode their base `method`s (the ops live in `*/api/*` as plain procs). The
`method`s only returned "not implemented" at runtime and, crucially, were never
checked against the real surface -- so IKernel had silently drifted from `Waku`
(relayPublish returned int not string; filter/lightpush still carried a `peer`
param; connectedPeersInfo returned seq[string]).

Replace each base type with a structural Nim `concept` matched against the real
implementation, and assert conformance once in the concentrator
(`doAssert Waku is KernelApi`, etc.) where every impl and its op modules are in
scope. This is zero-cost, drops the dead vtables, and makes each layer's true
surface a single compiler-checked source of truth.

Move `PeerConnInfo` from `waku/api/peer_manager` into `api/types` (alongside the
other api-boundary data types) so `KernelApi` can name it without an import
cycle -- otherwise `connectedPeersInfo` could not be part of the contract.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 14:30:08 +02:00

39 lines
1.1 KiB
Nim

import chronos, results
import brokers/event_broker
import logos_delivery/api/types as api_types
import logos_delivery/waku/waku_core/message
export event_broker, api_types
EventBroker:
# Event emitted when a message is sent to the network
type MessageSentEvent* = object
requestId*: RequestId
messageHash*: string
EventBroker:
# Event emitted when a message send operation fails
type MessageErrorEvent* = object
requestId*: RequestId
messageHash*: string
error*: string
EventBroker:
# Confirmation that a message has been correctly delivered to some neighbouring nodes.
type MessagePropagatedEvent* = object
requestId*: RequestId
messageHash*: string
EventBroker:
# Event emitted when a message is received via Waku
type MessageReceivedEvent* = object
messageHash*: string
message*: WakuMessage
# Structural API contract for a messaging client (ops in `messaging/api/*`).
type MessagingApi* = concept c
subscribe(c, ContentTopic) is Future[Result[void, string]]
unsubscribe(c, ContentTopic) is Result[void, string]
send(c, MessageEnvelope) is Future[Result[RequestId, string]]