Files
Igor SirotinandClaude Opus 5 7b138bf71f feat: Messaging API (MessagingClient) (#120)
* feat(messaging): object-oriented Go mirror of the Nim MessagingClient

Adds pkg/messaging: a high-level, idiomatic Go binding for the Messaging
API, mirroring logos-delivery's Nim MessagingClient. A MessagingClient owns
a node and carries the messaging surface as methods on it — New / Start /
Stop / Close, Subscribe / Unsubscribe, Send(ctx, Envelope) (RequestID,
error) — over internal/ffi rather than exposing the raw FFI.

Events arrive on a single Events() <-chan Event with a sealed Event
interface: MessageReceivedEvent, MessageSentEvent, MessagePropagatedEvent,
MessageErrorEvent and ConnectionStatusEvent. Delivery never blocks the
library's event thread; an event is dropped when a consumer falls behind.
Config marshals to the layered configuration JSON (mode / preset /
messagingOverrides / channelsOverrides), with every field omitempty so it
can never be mistaken for the legacy flat blob.

Migrating internal/ffi to the current C ABI comes with it, because the
generated surface has moved on since the bridge was written and no longer
compiles: nim-ffi now generates the header from the {.ffi.} annotations,
argument-taking calls pass a per-call <Name>Req struct and a typed
<Name>ReplyFn, no-argument calls take a raw scalar callback, destroy is
synchronous, and the single set_event_callback has been replaced by a
per-event listener registry. The bridge now also copies every callback
string while it is still borrowed, and ignores the non-terminal
STALE_WARN progress code instead of settling the call on it.

pkg/kernel follows the same listener change, registering the three kernel
events it already consumed.

Verified against a liblogosdelivery built from logos-delivery master:
build / vet / golangci-lint / go mod tidy clean, unit tests green, and the
tagged integration test does a full create-start-subscribe-send round trip
on logos.dev, observing the message back and its propagation confirmation.

Closes #119.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CnzdnSMtHM5aLHLtDGBGR9

* review: address feedback on the MessagingClient API

- Send takes contentTopic / payload / ephemeral directly instead of an
  Envelope struct, which drops the Envelope type; ContentTopic and RequestID
  move to types.go.
- messagingEvents becomes a function returning the slice, so the set cannot
  be mutated by accident.
- Document what seals the Event interface and what that buys callers.
- Document why the received payload is decoded from a JSON integer array:
  base64 is only used on the send path and by the channel events, not by the
  messaging events.

* ci: stop golangci-lint's config verify from failing on a network timeout

golangci-lint-action runs `golangci-lint config verify` before linting, which
fetches the v2.4 JSON schema from golangci-lint.run on every run. That request
timed out on the runner and failed the gate with no lint finding behind it. An
invalid config still fails the lint run itself, so the pre-check only costs a
network dependency.

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-24 11:53:36 +01:00

48 lines
2.0 KiB
Go

package messaging
// Mode selects how much of the stack a node runs.
type Mode string
const (
// ModeCore runs a full node: relay plus the service protocols.
ModeCore Mode = "Core"
// ModeEdge runs a light client: lightpush, filter and store clients.
ModeEdge Mode = "Edge"
)
// Network presets. A preset fixes the cluster id, sharding, entry nodes and
// RLN settings for a known network, so a Config usually needs nothing else.
const (
PresetTWN = "twn" // The Waku Network
PresetLogosDev = "logos.dev" // Logos Dev Network
PresetLogosTest = "logos.test" // Logos Test Network
PresetStatusProd = "status.prod" // Status Production Network
)
// Overrides is a bag of per-field configuration overrides. Keys are node
// configuration field names or their CLI switch equivalents ("clusterId" or
// "cluster-id"); the library rejects keys it does not recognise.
type Overrides map[string]any
// Config is a MessagingClient's node configuration. It marshals to the layered
// configuration JSON that logosdelivery_create_node consumes: a network
// preset plus, optionally, overrides for the messaging and reliable-channel
// layers.
//
// Every field is omitted when empty, and that matters: the library still
// accepts a legacy flat configuration blob, and it decides between the two
// shapes by looking for bare top-level keys. A Config that emitted zero values
// would be read as a flat blob and silently ignore the layered defaults, so do
// not add fields here without `omitempty`.
type Config struct {
// Mode is the node role. Defaults to ModeCore when empty.
Mode Mode `json:"mode,omitempty"`
// Preset names the network to join, e.g. PresetLogosDev.
Preset string `json:"preset,omitempty"`
// MessagingOverrides overrides individual node configuration fields, e.g.
// {"tcp-port": 60000, "listen-address": "0.0.0.0"}.
MessagingOverrides Overrides `json:"messagingOverrides,omitempty"`
// ChannelsOverrides overrides reliable-channel configuration fields.
ChannelsOverrides Overrides `json:"channelsOverrides,omitempty"`
}