Files
Igor Sirotin e42d217c59 refactor: kernel.Node owns the node, MessagingClient exposes it (#122)
* refactor: make kernel.Node the single owner of the node context

The Kernel API and the Messaging API each built their own node and kept
the FFI handle private, so a MessagingClient had no way to reach store
queries, peers or metrics. The C library has one context serving both
tiers, so this was only a Go ownership problem.

kernel.Node now owns that context, and the kernel protocols hang off it
as facades: Relay(), Store(), Peers(), Discovery(), plus Messaging() for
the stable tier. MessagingClient drives a Node and hands it over with
Node(), mirroring the Nim MessagingClient's public waku field.

* refactor: address review on the Node facades

Move the Messaging API back out of pkg/kernel: ffi.Handle becomes a
defined type in the internal package, so kernel can hand the context to
pkg/messaging through kernel.Handle without the kernel layer knowing the
tier exists, and without the type being nameable outside this module.

Split Discovery into DiscV5, PeerExchange and DNSDiscovery, group the
node's identity and health under Debug(), and give every facade a pointer
receiver. Drop the node name, the per-operation logging that duplicates
what the library already writes, and GetFreePortIfNeeded — port 0 already
means "let the OS pick".

Heavy kernel tests now mark themselves with requiresNode and skip under
-short, so the gate runs `go test -short ./...` instead of naming tests
in a regexp.

* refactor: keep the Messaging API where it was

Restore messaging_client.go to its shape before this PR: Subscribe,
Unsubscribe and Send go back on MessagingClient, and the package imports
internal/ffi for the handle rather than reaching the calls through the
kernel. The only change left is what owning a kernel.Node requires — the
node holds the lifecycle and the listeners, and Node() exposes it.

* fix: keep allocating test ports, and move that out of the library

Removing GetFreePortIfNeeded also removed the allocation StartWakuNode
did, and the library does not treat a zero DiscV5 UDP port as "pick one":
every node tried the same default and all but the first failed to bind.

StartWakuNode is test scaffolding, so it moves to the test helpers along
with the port allocation. Neither is part of the package surface now.

* chore: go mod tidy

* refactor: let the library pick the ports, and address review

TcpPort and Discv5UdpPort were `omitempty`, so a zero port was dropped
from the JSON entirely and the library applied its own default of 9000 —
every node bound the same port and all but the first failed. With the
zero emitted, the library's auto-port retry picks a free one per node,
which is what "port 0 means port 0" needs to work. The test-side port
allocation is gone with it.

Also: Handle moves to its own file with a Valid method and the reasoning
for not aliasing unsafe.Pointer, logInfo is back alongside the other
levels, and the single-field facade structs are spelled out.
2026-08-26 00:12:01 +01:00

32 lines
1.0 KiB
Go

package messaging
import "github.com/logos-messaging/logos-delivery-go-bindings/pkg/kernel"
// The node configuration lives with the node itself, in pkg/kernel: a client
// and the kernel protocols configure one and the same node. These aliases keep
// it spellable from here.
type (
// Mode selects how much of the stack a node runs.
Mode = kernel.Mode
// Overrides is a bag of per-field configuration overrides.
Overrides = kernel.Overrides
// Config is a node's configuration.
Config = kernel.Config
)
const (
// ModeCore runs a full node: relay plus the service protocols.
ModeCore = kernel.ModeCore
// ModeEdge runs a light client: lightpush, filter and store clients.
ModeEdge = kernel.ModeEdge
)
// 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 = kernel.PresetTWN
PresetLogosDev = kernel.PresetLogosDev
PresetLogosTest = kernel.PresetLogosTest
PresetStatusProd = kernel.PresetStatusProd
)