diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c073e5b..fa651c9 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -17,12 +17,15 @@ jobs: # Clone the logos-delivery checkout OUTSIDE the module tree: a directory # named `vendor/` at the module root would put Go into vendor mode. LOGOS_DELIVERY_DIR: ${{ github.workspace }}/.logos-delivery - # Both kernel (libwaku) and messaging (liblogosdelivery) headers are on - # the include path so every package compiles. `-l` is deliberately NOT - # set here: each internal/ffi subpackage selects its own library via a - # `#cgo LDFLAGS` directive, so no binary links both libs (they export - # overlapping symbols until logos-delivery#3851). - CGO_CFLAGS: -I${{ github.workspace }}/.logos-delivery/library/ -I${{ github.workspace }}/.logos-delivery/liblogosdelivery/ + # TODO(revert once merged): pinned to logos-delivery#4012, which unifies + # the node lifecycle on logosdelivery_* and ships the full API in the + # single liblogosdelivery library. Point back at the default branch after + # it merges. + LOGOS_DELIVERY_REF: update-examples-ffi-node-lifecycle + # The single liblogosdelivery library exposes the full API; its headers + # live in library/. The bridge self-links -llogosdelivery via a #cgo + # directive, so no -l is set here. + CGO_CFLAGS: -I${{ github.workspace }}/.logos-delivery/library/ CGO_LDFLAGS: -L${{ github.workspace }}/.logos-delivery/build/ -Wl,-rpath,${{ github.workspace }}/.logos-delivery/build/ # Build in module mode; never use a vendor/ dir. GOFLAGS: -mod=mod @@ -39,12 +42,11 @@ jobs: go-version: "1.24" - name: Resolve logos-delivery commit - # Cache the built libraries keyed on the exact upstream commit, so the - # expensive clone + build is skipped while logos-delivery's HEAD is - # unchanged. ls-remote gives us the SHA before we clone. + # Cache the built library keyed on the exact upstream commit, so the + # expensive clone + build is skipped while the pinned ref is unchanged. id: logos-delivery-rev run: | - rev=$(git ls-remote https://github.com/logos-messaging/logos-delivery.git HEAD | cut -f1) + rev=$(git ls-remote https://github.com/logos-messaging/logos-delivery.git "$LOGOS_DELIVERY_REF" | cut -f1) echo "rev=$rev" >> "$GITHUB_OUTPUT" - name: Cache logos-delivery build @@ -56,11 +58,11 @@ jobs: - name: Clone logos-delivery if: steps.logos-delivery-cache.outputs.cache-hit != 'true' - run: git clone --depth 1 https://github.com/logos-messaging/logos-delivery.git "$LOGOS_DELIVERY_DIR" + run: git clone --depth 1 --branch "$LOGOS_DELIVERY_REF" https://github.com/logos-messaging/logos-delivery.git "$LOGOS_DELIVERY_DIR" - - name: Build libwaku + liblogosdelivery + - name: Build liblogosdelivery if: steps.logos-delivery-cache.outputs.cache-hit != 'true' - run: make -C "$LOGOS_DELIVERY_DIR" libwaku liblogosdelivery -j + run: make -C "$LOGOS_DELIVERY_DIR" liblogosdelivery -j - name: go build run: go build ./... @@ -88,9 +90,9 @@ jobs: - name: go test messaging (run) # Fast, network-free unit tests for the Messaging API + its ffi bridge. - run: go test ./pkg/messaging/... ./internal/ffi/liblogosdelivery/... + run: go test ./pkg/messaging/... ./internal/ffi/... - name: go test kernel (compile) # The kernel suite is heavy integration (runs nightly in CI.yml), so # only compile its test binaries here. - run: go test -run '^$' ./pkg/kernel/... ./internal/ffi/libwaku/... + run: go test -run '^$' ./pkg/kernel/... diff --git a/internal/ffi/doc.go b/internal/ffi/doc.go index de4ccfe..b97bf99 100644 --- a/internal/ffi/doc.go +++ b/internal/ffi/doc.go @@ -1,7 +1,7 @@ -// Package ffi groups the cgo bridges over the logos-delivery C libraries. +// Package ffi groups the cgo bridge over the logos-delivery C library. // -// Each C library gets its own subpackage (libwaku now; liblogosdelivery in a -// follow-up) so that a binary links exactly the libraries it imports — the -// two .so files carry overlapping symbols and must never be linked together -// (until logos-delivery#3851 consolidates them). +// The single liblogosdelivery library exposes the full API — the unified node +// lifecycle, the Messaging API, Reliable Channels, and the low-level Kernel +// (waku_*) tier — so a single bridge subpackage, liblogosdelivery, serves both +// pkg/messaging and pkg/kernel. package ffi diff --git a/internal/ffi/liblogosdelivery/liblogosdelivery.go b/internal/ffi/liblogosdelivery/liblogosdelivery.go index 5f91d8a..03ba2cb 100644 --- a/internal/ffi/liblogosdelivery/liblogosdelivery.go +++ b/internal/ffi/liblogosdelivery/liblogosdelivery.go @@ -1,69 +1,156 @@ -// Package liblogosdelivery is the cgo bridge over liblogosdelivery (the -// logos-delivery Messaging API C library). It owns the synchronous -// request/response callback plumbing, the shared async event callback, and the -// handle->handler registry, and exposes Go-typed primitives so the public -// messaging package stays pure Go. -// -// It links liblogosdelivery via a #cgo directive; it must never be linked into -// the same binary as the libwaku bridge (overlapping symbols) until -// logos-delivery#3851 consolidates the two libraries. +// Package liblogosdelivery is the cgo bridge over the single liblogosdelivery +// C library, which exposes the full logos-delivery API: the unified node +// lifecycle (logosdelivery_create_node/start/stop/destroy), the Messaging API +// (subscribe/unsubscribe/send), and the low-level Kernel API (waku_* — relay, +// store, lightpush, filter, discovery, peer management). It owns the +// synchronous request/callback plumbing, the shared event callback, and the +// handle registry, exposing Go-typed primitives so pkg/kernel and pkg/messaging +// stay pure Go. package liblogosdelivery /* #cgo LDFLAGS: -llogosdelivery -#include +#include #include -// logosGoCallback (sync request/response) and logosEventCallback (async events) +// wakuGoCallback (sync request/response) and wakuEventCallback (async events) // are implemented in Go and exported below. -extern void logosGoCallback(int ret, char* msg, size_t len, void* resp); -extern void logosEventCallback(int ret, char* msg, size_t len, void* userData); +extern void wakuGoCallback(int ret, char* msg, size_t len, void* resp); +extern void wakuEventCallback(int ret, char* msg, size_t len, void* userData); -// logosResp carries a single synchronous call's result back from the callback, +// wakuResp carries a single synchronous call's result back from the callback, // plus a pointer to the Go sync.WaitGroup the caller blocks on. typedef struct { int ret; char* msg; size_t len; void* wg; -} logosResp; +} wakuResp; -static void* allocLogosResp(void* wg) { - logosResp* r = (logosResp*) calloc(1, sizeof(logosResp)); +static void* allocWakuResp(void* wg) { + wakuResp* r = (wakuResp*) calloc(1, sizeof(wakuResp)); r->wg = wg; return r; } -static void freeLogosResp(void* resp) { if (resp != NULL) free(resp); } -static char* logosRespMsg(void* resp) { return resp ? ((logosResp*)resp)->msg : NULL; } -static size_t logosRespLen(void* resp) { return resp ? ((logosResp*)resp)->len : 0; } -static int logosRespRet(void* resp) { return resp ? ((logosResp*)resp)->ret : RET_ERR; } +static void freeWakuResp(void* resp) { if (resp != NULL) free(resp); } +static char* wakuRespMsg(void* resp) { return resp ? ((wakuResp*)resp)->msg : NULL; } +static size_t wakuRespLen(void* resp) { return resp ? ((wakuResp*)resp)->len : 0; } +static int wakuRespRet(void* resp) { return resp ? ((wakuResp*)resp)->ret : RET_ERR; } -// Thin wrappers binding the shared Go callback to each entry point. -static void* cGoCreateNode(const char* cfg, void* resp) { - return logosdelivery_create_node(cfg, (FFICallBack) logosGoCallback, resp); +// Thin wrappers binding the shared Go callback to each libwaku entry point. +static void* cGoWakuNew(const char* configJson, void* resp) { + return logosdelivery_create_node(configJson, (FFICallBack) wakuGoCallback, resp); } -static void cGoStartNode(void* ctx, void* resp) { - logosdelivery_start_node(ctx, (FFICallBack) logosGoCallback, resp); +static void cGoWakuStart(void* ctx, void* resp) { + logosdelivery_start_node(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoStopNode(void* ctx, void* resp) { - logosdelivery_stop_node(ctx, (FFICallBack) logosGoCallback, resp); +static void cGoWakuStop(void* ctx, void* resp) { + logosdelivery_stop_node(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoDestroyNode(void* ctx, void* resp) { - logosdelivery_destroy(ctx, (FFICallBack) logosGoCallback, resp); +static void cGoWakuDestroy(void* ctx, void* resp) { + logosdelivery_destroy(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoSubscribe(void* ctx, const char* topic, void* resp) { - logosdelivery_subscribe(ctx, (FFICallBack) logosGoCallback, resp, topic); +static void cGoWakuStartDiscV5(void* ctx, void* resp) { + waku_start_discv5(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoUnsubscribe(void* ctx, const char* topic, void* resp) { - logosdelivery_unsubscribe(ctx, (FFICallBack) logosGoCallback, resp, topic); +static void cGoWakuStopDiscV5(void* ctx, void* resp) { + waku_stop_discv5(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoSend(void* ctx, const char* msgJson, void* resp) { - logosdelivery_send(ctx, (FFICallBack) logosGoCallback, resp, msgJson); +static void cGoWakuVersion(void* ctx, void* resp) { + waku_version(ctx, (FFICallBack) wakuGoCallback, resp); } -static void cGoSetEventCallback(void* ctx) { - // ctx doubles as userData so the shared event callback can route the event - // to the right registered handler. - logosdelivery_set_event_callback(ctx, (FFICallBack) logosEventCallback, ctx); +static void cGoWakuSetEventCallback(void* ctx) { + // The ctx doubles as userData so the shared event callback can route the + // event to the right registered handler. + logosdelivery_set_event_callback(ctx, (FFICallBack) wakuEventCallback, ctx); +} +// Messaging API wrappers (stable surface, logosdelivery_*). +static void cGoLogosSubscribe(void* ctx, const char* topic, void* resp) { + logosdelivery_subscribe(ctx, (FFICallBack) wakuGoCallback, resp, topic); +} +static void cGoLogosUnsubscribe(void* ctx, const char* topic, void* resp) { + logosdelivery_unsubscribe(ctx, (FFICallBack) wakuGoCallback, resp, topic); +} +static void cGoLogosSend(void* ctx, const char* msgJson, void* resp) { + logosdelivery_send(ctx, (FFICallBack) wakuGoCallback, resp, msgJson); +} +static void cGoWakuRelayPublish(void* ctx, const char* pubSubTopic, const char* jsonWakuMessage, int timeoutMs, void* resp) { + waku_relay_publish(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic, jsonWakuMessage, timeoutMs); +} +static void cGoWakuRelaySubscribe(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_subscribe(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuRelayAddProtectedShard(void* ctx, int clusterId, int shardId, char* publicKey, void* resp) { + waku_relay_add_protected_shard(ctx, (FFICallBack) wakuGoCallback, resp, clusterId, shardId, publicKey); +} +static void cGoWakuRelayUnsubscribe(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_unsubscribe(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuConnect(void* ctx, const char* peerMultiAddr, int timeoutMs, void* resp) { + waku_connect(ctx, (FFICallBack) wakuGoCallback, resp, peerMultiAddr, timeoutMs); +} +static void cGoWakuDialPeer(void* ctx, const char* peerMultiAddr, const char* protocol, int timeoutMs, void* resp) { + waku_dial_peer(ctx, (FFICallBack) wakuGoCallback, resp, peerMultiAddr, protocol, timeoutMs); +} +static void cGoWakuDialPeerById(void* ctx, const char* peerId, const char* protocol, int timeoutMs, void* resp) { + waku_dial_peer_by_id(ctx, (FFICallBack) wakuGoCallback, resp, peerId, protocol, timeoutMs); +} +static void cGoWakuDisconnectPeerById(void* ctx, const char* peerId, void* resp) { + waku_disconnect_peer_by_id(ctx, (FFICallBack) wakuGoCallback, resp, peerId); +} +static void cGoWakuDisconnectAllPeers(void* ctx, void* resp) { + waku_disconnect_all_peers(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuListenAddresses(void* ctx, void* resp) { + waku_listen_addresses(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuGetMyENR(void* ctx, void* resp) { + waku_get_my_enr(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuGetMyPeerId(void* ctx, void* resp) { + waku_get_my_peerid(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuPingPeer(void* ctx, const char* peerAddr, int timeoutMs, void* resp) { + waku_ping_peer(ctx, (FFICallBack) wakuGoCallback, resp, peerAddr, timeoutMs); +} +static void cGoWakuGetPeersInMesh(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_get_peers_in_mesh(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuGetNumPeersInMesh(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_get_num_peers_in_mesh(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuGetNumConnectedRelayPeers(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_get_num_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuGetConnectedRelayPeers(void* ctx, const char* pubSubTopic, void* resp) { + waku_relay_get_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); +} +static void cGoWakuGetConnectedPeers(void* ctx, void* resp) { + waku_get_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuGetPeerIdsFromPeerStore(void* ctx, void* resp) { + waku_get_peerids_from_peerstore(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuGetConnectedPeersInfo(void* ctx, void* resp) { + waku_get_connected_peers_info(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuStoreQuery(void* ctx, const char* jsonQuery, const char* peerAddr, int timeoutMs, void* resp) { + waku_store_query(ctx, (FFICallBack) wakuGoCallback, resp, jsonQuery, peerAddr, timeoutMs); +} +static void cGoWakuPeerExchangeQuery(void* ctx, uint64_t numPeers, void* resp) { + waku_peer_exchange_request(ctx, (FFICallBack) wakuGoCallback, resp, numPeers); +} +static void cGoWakuGetPeerIdsByProtocol(void* ctx, const char* protocol, void* resp) { + waku_get_peerids_by_protocol(ctx, (FFICallBack) wakuGoCallback, resp, protocol); +} +static void cGoWakuDnsDiscovery(void* ctx, const char* entTreeUrl, const char* nameDnsServer, int timeoutMs, void* resp) { + waku_dns_discovery(ctx, (FFICallBack) wakuGoCallback, resp, entTreeUrl, nameDnsServer, timeoutMs); +} +static void cGoWakuIsOnline(void* ctx, void* resp) { + waku_is_online(ctx, (FFICallBack) wakuGoCallback, resp); +} +static void cGoWakuGetMetrics(void* ctx, void* resp) { + waku_get_metrics(ctx, (FFICallBack) wakuGoCallback, resp); } */ import "C" @@ -80,7 +167,7 @@ type Handle = unsafe.Pointer // RetOK is the return code callbacks report on success. const RetOK = C.RET_OK -// EventHandler receives every event liblogosdelivery emits for a node: the raw +// EventHandler receives every event libwaku emits for a node: the raw // event JSON when ret == RetOK, an error message otherwise. type EventHandler func(ret int, msg string) @@ -91,12 +178,12 @@ var ( eventHandlers = make(map[Handle]EventHandler) ) -//export logosGoCallback -func logosGoCallback(ret C.int, msg *C.char, length C.size_t, resp unsafe.Pointer) { +//export wakuGoCallback +func wakuGoCallback(ret C.int, msg *C.char, length C.size_t, resp unsafe.Pointer) { if resp == nil { return } - r := (*C.logosResp)(resp) + r := (*C.wakuResp)(resp) r.ret = ret r.msg = msg r.len = length @@ -104,8 +191,8 @@ func logosGoCallback(ret C.int, msg *C.char, length C.size_t, resp unsafe.Pointe wg.Done() } -//export logosEventCallback -func logosEventCallback(ret C.int, msg *C.char, length C.size_t, userData unsafe.Pointer) { +//export wakuEventCallback +func wakuEventCallback(ret C.int, msg *C.char, length C.size_t, userData unsafe.Pointer) { eventHandlersMu.RLock() fn := eventHandlers[userData] // userData carries the node's handle eventHandlersMu.RUnlock() @@ -114,26 +201,26 @@ func logosEventCallback(ret C.int, msg *C.char, length C.size_t, userData unsafe } } -// call runs a synchronous entry point that reports its result through the -// response callback, blocks until it completes, and returns the callback -// message (on RetOK) or an error built from it. +// call runs a synchronous libwaku entry point that reports its result +// through the response callback, blocks until it completes, and returns the +// callback message (on RetOK) or an error built from it. func call(invoke func(resp unsafe.Pointer)) (string, error) { var wg sync.WaitGroup wg.Add(1) - resp := C.allocLogosResp(unsafe.Pointer(&wg)) - defer C.freeLogosResp(resp) + resp := C.allocWakuResp(unsafe.Pointer(&wg)) + defer C.freeWakuResp(resp) invoke(resp) wg.Wait() - msg := C.GoStringN(C.logosRespMsg(resp), C.int(C.logosRespLen(resp))) - if C.logosRespRet(resp) != C.RET_OK { + msg := C.GoStringN(C.wakuRespMsg(resp), C.int(C.wakuRespLen(resp))) + if C.wakuRespRet(resp) != C.RET_OK { return "", errors.New(msg) } return msg, nil } -// New builds a node from a WakuNodeConf JSON string and returns its handle. +// New builds a node from a WakuConfig JSON string and returns its handle. // The handle must be released with Destroy. func New(configJSON string) (Handle, error) { cCfg := C.CString(configJSON) @@ -141,14 +228,14 @@ func New(configJSON string) (Handle, error) { var wg sync.WaitGroup wg.Add(1) - resp := C.allocLogosResp(unsafe.Pointer(&wg)) - defer C.freeLogosResp(resp) + resp := C.allocWakuResp(unsafe.Pointer(&wg)) + defer C.freeWakuResp(resp) - ctx := C.cGoCreateNode(cCfg, resp) + ctx := C.cGoWakuNew(cCfg, resp) wg.Wait() - if C.logosRespRet(resp) != C.RET_OK || ctx == nil { - msg := C.GoStringN(C.logosRespMsg(resp), C.int(C.logosRespLen(resp))) + if C.wakuRespRet(resp) != C.RET_OK || ctx == nil { + msg := C.GoStringN(C.wakuRespMsg(resp), C.int(C.wakuRespLen(resp))) if msg == "" { msg = "logosdelivery_create_node returned no context" } @@ -157,56 +244,270 @@ func New(configJSON string) (Handle, error) { return Handle(ctx), nil } -// SetEventHandler registers fn to receive events for the node and wires up the -// underlying C event callback. Call before Start. +// SetEventHandler registers fn to receive events for the node and wires up +// the underlying C event callback. func SetEventHandler(h Handle, fn EventHandler) { eventHandlersMu.Lock() eventHandlers[h] = fn eventHandlersMu.Unlock() - C.cGoSetEventCallback(h) + C.cGoWakuSetEventCallback(h) } -// Start starts the node's protocols and Messaging API services. +// Start starts the node. func Start(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoStartNode(h, resp) }) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStart(h, resp) }) return err } // Stop stops the node. func Stop(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoStopNode(h, resp) }) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStop(h, resp) }) return err } // Destroy releases the node context and unregisters its event handler. func Destroy(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoDestroyNode(h, resp) }) - eventHandlersMu.Lock() - delete(eventHandlers, h) - eventHandlersMu.Unlock() + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDestroy(h, resp) }) + if err == nil { + eventHandlersMu.Lock() + delete(eventHandlers, h) + eventHandlersMu.Unlock() + } return err } -// Subscribe subscribes the node to a content topic. +// Subscribe subscribes the node to a content topic (Messaging API). func Subscribe(h Handle, contentTopic string) error { cTopic := C.CString(contentTopic) defer C.free(unsafe.Pointer(cTopic)) - _, err := call(func(resp unsafe.Pointer) { C.cGoSubscribe(h, cTopic, resp) }) + _, err := call(func(resp unsafe.Pointer) { C.cGoLogosSubscribe(h, cTopic, resp) }) return err } -// Unsubscribe unsubscribes the node from a content topic. +// Unsubscribe unsubscribes the node from a content topic (Messaging API). func Unsubscribe(h Handle, contentTopic string) error { cTopic := C.CString(contentTopic) defer C.free(unsafe.Pointer(cTopic)) - _, err := call(func(resp unsafe.Pointer) { C.cGoUnsubscribe(h, cTopic, resp) }) + _, err := call(func(resp unsafe.Pointer) { C.cGoLogosUnsubscribe(h, cTopic, resp) }) return err } -// Send sends a message (JSON: {contentTopic, payload(base64), ephemeral}) and -// returns the request id used to correlate later send events. +// Send sends a Messaging API message (JSON: {contentTopic, payload(base64), +// ephemeral}) and returns the request id used to correlate later send events. func Send(h Handle, messageJSON string) (requestID string, err error) { cMsg := C.CString(messageJSON) defer C.free(unsafe.Pointer(cMsg)) - return call(func(resp unsafe.Pointer) { C.cGoSend(h, cMsg, resp) }) + return call(func(resp unsafe.Pointer) { C.cGoLogosSend(h, cMsg, resp) }) +} + +// StartDiscV5 starts DiscV5 peer discovery. +func StartDiscV5(h Handle) error { + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStartDiscV5(h, resp) }) + return err +} + +// StopDiscV5 stops DiscV5 peer discovery. +func StopDiscV5(h Handle) error { + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStopDiscV5(h, resp) }) + return err +} + +// Version returns the libwaku version string. +func Version(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuVersion(h, resp) }) +} + +// RelayPublish publishes a WakuMessage JSON on a pubsub topic and returns +// the message hash. +func RelayPublish(h Handle, pubsubTopic, messageJSON string, timeoutMs int) (string, error) { + cTopic := C.CString(pubsubTopic) + cMsg := C.CString(messageJSON) + defer C.free(unsafe.Pointer(cTopic)) + defer C.free(unsafe.Pointer(cMsg)) + return call(func(resp unsafe.Pointer) { C.cGoWakuRelayPublish(h, cTopic, cMsg, C.int(timeoutMs), resp) }) +} + +// RelaySubscribe subscribes the node to a pubsub topic. +func RelaySubscribe(h Handle, pubsubTopic string) error { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuRelaySubscribe(h, cTopic, resp) }) + return err +} + +// RelayAddProtectedShard registers the hex-encoded public key allowed to +// sign messages on a protected shard. +func RelayAddProtectedShard(h Handle, clusterID, shardID int, publicKeyHex string) error { + cPublicKey := C.CString(publicKeyHex) + defer C.free(unsafe.Pointer(cPublicKey)) + _, err := call(func(resp unsafe.Pointer) { + C.cGoWakuRelayAddProtectedShard(h, C.int(clusterID), C.int(shardID), cPublicKey, resp) + }) + return err +} + +// RelayUnsubscribe unsubscribes the node from a pubsub topic. +func RelayUnsubscribe(h Handle, pubsubTopic string) error { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuRelayUnsubscribe(h, cTopic, resp) }) + return err +} + +// Connect dials a peer multiaddress. +func Connect(h Handle, peerMultiAddr string, timeoutMs int) error { + cAddr := C.CString(peerMultiAddr) + defer C.free(unsafe.Pointer(cAddr)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuConnect(h, cAddr, C.int(timeoutMs), resp) }) + return err +} + +// DialPeer dials a peer multiaddress over a specific protocol. +func DialPeer(h Handle, peerMultiAddr, protocol string, timeoutMs int) error { + cAddr := C.CString(peerMultiAddr) + cProtocol := C.CString(protocol) + defer C.free(unsafe.Pointer(cAddr)) + defer C.free(unsafe.Pointer(cProtocol)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDialPeer(h, cAddr, cProtocol, C.int(timeoutMs), resp) }) + return err +} + +// DialPeerByID dials a known peer id over a specific protocol. +func DialPeerByID(h Handle, peerID, protocol string, timeoutMs int) error { + cPeerID := C.CString(peerID) + cProtocol := C.CString(protocol) + defer C.free(unsafe.Pointer(cPeerID)) + defer C.free(unsafe.Pointer(cProtocol)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDialPeerById(h, cPeerID, cProtocol, C.int(timeoutMs), resp) }) + return err +} + +// DisconnectPeerByID drops the connection to a peer. +func DisconnectPeerByID(h Handle, peerID string) error { + cPeerID := C.CString(peerID) + defer C.free(unsafe.Pointer(cPeerID)) + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDisconnectPeerById(h, cPeerID, resp) }) + return err +} + +// DisconnectAllPeers drops all peer connections. +func DisconnectAllPeers(h Handle) error { + _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDisconnectAllPeers(h, resp) }) + return err +} + +// ListenAddresses returns the node's listen multiaddresses as a +// comma-separated list. +func ListenAddresses(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuListenAddresses(h, resp) }) +} + +// GetMyENR returns the node's ENR record. +func GetMyENR(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetMyENR(h, resp) }) +} + +// GetMyPeerID returns the node's peer id. +func GetMyPeerID(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetMyPeerId(h, resp) }) +} + +// PingPeer pings a peer (comma-separated multiaddresses) and returns the +// round-trip time in nanoseconds. +func PingPeer(h Handle, peerAddrs string, timeoutMs int) (string, error) { + cAddr := C.CString(peerAddrs) + defer C.free(unsafe.Pointer(cAddr)) + return call(func(resp unsafe.Pointer) { C.cGoWakuPingPeer(h, cAddr, C.int(timeoutMs), resp) }) +} + +// GetPeersInMesh returns the relay mesh peer ids for a pubsub topic as a +// comma-separated list. +func GetPeersInMesh(h Handle, pubsubTopic string) (string, error) { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeersInMesh(h, cTopic, resp) }) +} + +// GetNumPeersInMesh returns the relay mesh peer count for a pubsub topic. +func GetNumPeersInMesh(h Handle, pubsubTopic string) (string, error) { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + return call(func(resp unsafe.Pointer) { C.cGoWakuGetNumPeersInMesh(h, cTopic, resp) }) +} + +// GetNumConnectedRelayPeers returns the connected relay peer count for a +// pubsub topic. +func GetNumConnectedRelayPeers(h Handle, pubsubTopic string) (string, error) { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + return call(func(resp unsafe.Pointer) { C.cGoWakuGetNumConnectedRelayPeers(h, cTopic, resp) }) +} + +// GetConnectedRelayPeers returns the connected relay peer ids for a pubsub +// topic as a comma-separated list. +func GetConnectedRelayPeers(h Handle, pubsubTopic string) (string, error) { + cTopic := C.CString(pubsubTopic) + defer C.free(unsafe.Pointer(cTopic)) + return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedRelayPeers(h, cTopic, resp) }) +} + +// GetConnectedPeers returns the connected peer ids as a comma-separated +// list. +func GetConnectedPeers(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedPeers(h, resp) }) +} + +// GetPeerIDsFromPeerStore returns the peer-store peer ids as a +// comma-separated list. +func GetPeerIDsFromPeerStore(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeerIdsFromPeerStore(h, resp) }) +} + +// GetConnectedPeersInfo returns the connected peers' info as JSON. +func GetConnectedPeersInfo(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedPeersInfo(h, resp) }) +} + +// StoreQuery runs a store query (JSON) against a peer (comma-separated +// multiaddresses) and returns the response JSON. +func StoreQuery(h Handle, queryJSON, peerAddrs string, timeoutMs int) (string, error) { + cQuery := C.CString(queryJSON) + cAddr := C.CString(peerAddrs) + defer C.free(unsafe.Pointer(cQuery)) + defer C.free(unsafe.Pointer(cAddr)) + return call(func(resp unsafe.Pointer) { C.cGoWakuStoreQuery(h, cQuery, cAddr, C.int(timeoutMs), resp) }) +} + +// PeerExchangeRequest asks peer exchange for numPeers peers and returns +// the number of received peers. +func PeerExchangeRequest(h Handle, numPeers uint64) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuPeerExchangeQuery(h, C.uint64_t(numPeers), resp) }) +} + +// GetPeerIDsByProtocol returns the peer ids supporting a protocol as a +// comma-separated list. +func GetPeerIDsByProtocol(h Handle, protocol string) (string, error) { + cProtocol := C.CString(protocol) + defer C.free(unsafe.Pointer(cProtocol)) + return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeerIdsByProtocol(h, cProtocol, resp) }) +} + +// DnsDiscovery resolves an ENR tree URL via DNS discovery and returns the +// discovered multiaddresses as a comma-separated list. +func DnsDiscovery(h Handle, enrTreeURL, nameDNSServer string, timeoutMs int) (string, error) { + cEnrTree := C.CString(enrTreeURL) + cDNSServer := C.CString(nameDNSServer) + defer C.free(unsafe.Pointer(cEnrTree)) + defer C.free(unsafe.Pointer(cDNSServer)) + return call(func(resp unsafe.Pointer) { C.cGoWakuDnsDiscovery(h, cEnrTree, cDNSServer, C.int(timeoutMs), resp) }) +} + +// IsOnline reports the node's online state ("true"/"false"). +func IsOnline(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuIsOnline(h, resp) }) +} + +// GetMetrics returns the node's metrics in Prometheus text format. +func GetMetrics(h Handle) (string, error) { + return call(func(resp unsafe.Pointer) { C.cGoWakuGetMetrics(h, resp) }) } diff --git a/internal/ffi/libwaku/libwaku.go b/internal/ffi/libwaku/libwaku.go deleted file mode 100644 index 2f5279e..0000000 --- a/internal/ffi/libwaku/libwaku.go +++ /dev/null @@ -1,475 +0,0 @@ -// Package libwaku is the cgo bridge over libwaku (the legacy Kernel API -// library): the synchronous request/callback plumbing, the global event -// callback, and the handle registry. It exposes Go-typed primitives so -// pkg/kernel stays pure Go. -package libwaku - -/* -#cgo LDFLAGS: -lwaku -#include -#include - -// wakuGoCallback (sync request/response) and wakuEventCallback (async events) -// are implemented in Go and exported below. -extern void wakuGoCallback(int ret, char* msg, size_t len, void* resp); -extern void wakuEventCallback(int ret, char* msg, size_t len, void* userData); - -// wakuResp carries a single synchronous call's result back from the callback, -// plus a pointer to the Go sync.WaitGroup the caller blocks on. -typedef struct { - int ret; - char* msg; - size_t len; - void* wg; -} wakuResp; - -static void* allocWakuResp(void* wg) { - wakuResp* r = (wakuResp*) calloc(1, sizeof(wakuResp)); - r->wg = wg; - return r; -} -static void freeWakuResp(void* resp) { if (resp != NULL) free(resp); } -static char* wakuRespMsg(void* resp) { return resp ? ((wakuResp*)resp)->msg : NULL; } -static size_t wakuRespLen(void* resp) { return resp ? ((wakuResp*)resp)->len : 0; } -static int wakuRespRet(void* resp) { return resp ? ((wakuResp*)resp)->ret : RET_ERR; } - -// Thin wrappers binding the shared Go callback to each libwaku entry point. -static void* cGoWakuNew(const char* configJson, void* resp) { - return waku_new(configJson, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuStart(void* ctx, void* resp) { - waku_start(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuStop(void* ctx, void* resp) { - waku_stop(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuDestroy(void* ctx, void* resp) { - waku_destroy(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuStartDiscV5(void* ctx, void* resp) { - waku_start_discv5(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuStopDiscV5(void* ctx, void* resp) { - waku_stop_discv5(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuVersion(void* ctx, void* resp) { - waku_version(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuSetEventCallback(void* ctx) { - // The ctx doubles as userData so the shared event callback can route the - // event to the right registered handler. - set_event_callback(ctx, (FFICallBack) wakuEventCallback, ctx); -} -static void cGoWakuRelayPublish(void* ctx, const char* pubSubTopic, const char* jsonWakuMessage, int timeoutMs, void* resp) { - waku_relay_publish(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic, jsonWakuMessage, timeoutMs); -} -static void cGoWakuRelaySubscribe(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_subscribe(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuRelayAddProtectedShard(void* ctx, int clusterId, int shardId, char* publicKey, void* resp) { - waku_relay_add_protected_shard(ctx, (FFICallBack) wakuGoCallback, resp, clusterId, shardId, publicKey); -} -static void cGoWakuRelayUnsubscribe(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_unsubscribe(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuConnect(void* ctx, const char* peerMultiAddr, int timeoutMs, void* resp) { - waku_connect(ctx, (FFICallBack) wakuGoCallback, resp, peerMultiAddr, timeoutMs); -} -static void cGoWakuDialPeer(void* ctx, const char* peerMultiAddr, const char* protocol, int timeoutMs, void* resp) { - waku_dial_peer(ctx, (FFICallBack) wakuGoCallback, resp, peerMultiAddr, protocol, timeoutMs); -} -static void cGoWakuDialPeerById(void* ctx, const char* peerId, const char* protocol, int timeoutMs, void* resp) { - waku_dial_peer_by_id(ctx, (FFICallBack) wakuGoCallback, resp, peerId, protocol, timeoutMs); -} -static void cGoWakuDisconnectPeerById(void* ctx, const char* peerId, void* resp) { - waku_disconnect_peer_by_id(ctx, (FFICallBack) wakuGoCallback, resp, peerId); -} -static void cGoWakuDisconnectAllPeers(void* ctx, void* resp) { - waku_disconnect_all_peers(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuListenAddresses(void* ctx, void* resp) { - waku_listen_addresses(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuGetMyENR(void* ctx, void* resp) { - waku_get_my_enr(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuGetMyPeerId(void* ctx, void* resp) { - waku_get_my_peerid(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuPingPeer(void* ctx, const char* peerAddr, int timeoutMs, void* resp) { - waku_ping_peer(ctx, (FFICallBack) wakuGoCallback, resp, peerAddr, timeoutMs); -} -static void cGoWakuGetPeersInMesh(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_get_peers_in_mesh(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuGetNumPeersInMesh(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_get_num_peers_in_mesh(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuGetNumConnectedRelayPeers(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_get_num_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuGetConnectedRelayPeers(void* ctx, const char* pubSubTopic, void* resp) { - waku_relay_get_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp, pubSubTopic); -} -static void cGoWakuGetConnectedPeers(void* ctx, void* resp) { - waku_get_connected_peers(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuGetPeerIdsFromPeerStore(void* ctx, void* resp) { - waku_get_peerids_from_peerstore(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuGetConnectedPeersInfo(void* ctx, void* resp) { - waku_get_connected_peers_info(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuStoreQuery(void* ctx, const char* jsonQuery, const char* peerAddr, int timeoutMs, void* resp) { - waku_store_query(ctx, (FFICallBack) wakuGoCallback, resp, jsonQuery, peerAddr, timeoutMs); -} -static void cGoWakuPeerExchangeQuery(void* ctx, uint64_t numPeers, void* resp) { - waku_peer_exchange_request(ctx, (FFICallBack) wakuGoCallback, resp, numPeers); -} -static void cGoWakuGetPeerIdsByProtocol(void* ctx, const char* protocol, void* resp) { - waku_get_peerids_by_protocol(ctx, (FFICallBack) wakuGoCallback, resp, protocol); -} -static void cGoWakuDnsDiscovery(void* ctx, const char* entTreeUrl, const char* nameDnsServer, int timeoutMs, void* resp) { - waku_dns_discovery(ctx, (FFICallBack) wakuGoCallback, resp, entTreeUrl, nameDnsServer, timeoutMs); -} -static void cGoWakuIsOnline(void* ctx, void* resp) { - waku_is_online(ctx, (FFICallBack) wakuGoCallback, resp); -} -static void cGoWakuGetMetrics(void* ctx, void* resp) { - waku_get_metrics(ctx, (FFICallBack) wakuGoCallback, resp); -} -*/ -import "C" - -import ( - "errors" - "sync" - "unsafe" -) - -// Handle is an opaque pointer to a node context owned by the C library. -type Handle = unsafe.Pointer - -// RetOK is the return code callbacks report on success. -const RetOK = C.RET_OK - -// EventHandler receives every event libwaku emits for a node: the raw -// event JSON when ret == RetOK, an error message otherwise. -type EventHandler func(ret int, msg string) - -// eventHandlers maps a node handle to the Go function that receives its -// events. The shared C event callback looks the handler up by handle. -var ( - eventHandlersMu sync.RWMutex - eventHandlers = make(map[Handle]EventHandler) -) - -//export wakuGoCallback -func wakuGoCallback(ret C.int, msg *C.char, length C.size_t, resp unsafe.Pointer) { - if resp == nil { - return - } - r := (*C.wakuResp)(resp) - r.ret = ret - r.msg = msg - r.len = length - wg := (*sync.WaitGroup)(r.wg) - wg.Done() -} - -//export wakuEventCallback -func wakuEventCallback(ret C.int, msg *C.char, length C.size_t, userData unsafe.Pointer) { - eventHandlersMu.RLock() - fn := eventHandlers[userData] // userData carries the node's handle - eventHandlersMu.RUnlock() - if fn != nil { - fn(int(ret), C.GoStringN(msg, C.int(length))) - } -} - -// call runs a synchronous libwaku entry point that reports its result -// through the response callback, blocks until it completes, and returns the -// callback message (on RetOK) or an error built from it. -func call(invoke func(resp unsafe.Pointer)) (string, error) { - var wg sync.WaitGroup - wg.Add(1) - resp := C.allocWakuResp(unsafe.Pointer(&wg)) - defer C.freeWakuResp(resp) - - invoke(resp) - wg.Wait() - - msg := C.GoStringN(C.wakuRespMsg(resp), C.int(C.wakuRespLen(resp))) - if C.wakuRespRet(resp) != C.RET_OK { - return "", errors.New(msg) - } - return msg, nil -} - -// New builds a node from a WakuConfig JSON string and returns its handle. -// The handle must be released with Destroy. -func New(configJSON string) (Handle, error) { - cCfg := C.CString(configJSON) - defer C.free(unsafe.Pointer(cCfg)) - - var wg sync.WaitGroup - wg.Add(1) - resp := C.allocWakuResp(unsafe.Pointer(&wg)) - defer C.freeWakuResp(resp) - - ctx := C.cGoWakuNew(cCfg, resp) - wg.Wait() - - if C.wakuRespRet(resp) != C.RET_OK || ctx == nil { - msg := C.GoStringN(C.wakuRespMsg(resp), C.int(C.wakuRespLen(resp))) - if msg == "" { - msg = "waku_new returned no context" - } - return nil, errors.New(msg) - } - return Handle(ctx), nil -} - -// SetEventHandler registers fn to receive events for the node and wires up -// the underlying C event callback. -func SetEventHandler(h Handle, fn EventHandler) { - eventHandlersMu.Lock() - eventHandlers[h] = fn - eventHandlersMu.Unlock() - C.cGoWakuSetEventCallback(h) -} - -// Start starts the node. -func Start(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStart(h, resp) }) - return err -} - -// Stop stops the node. -func Stop(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStop(h, resp) }) - return err -} - -// Destroy releases the node context and unregisters its event handler. -func Destroy(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDestroy(h, resp) }) - if err == nil { - eventHandlersMu.Lock() - delete(eventHandlers, h) - eventHandlersMu.Unlock() - } - return err -} - -// StartDiscV5 starts DiscV5 peer discovery. -func StartDiscV5(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStartDiscV5(h, resp) }) - return err -} - -// StopDiscV5 stops DiscV5 peer discovery. -func StopDiscV5(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuStopDiscV5(h, resp) }) - return err -} - -// Version returns the libwaku version string. -func Version(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuVersion(h, resp) }) -} - -// RelayPublish publishes a WakuMessage JSON on a pubsub topic and returns -// the message hash. -func RelayPublish(h Handle, pubsubTopic, messageJSON string, timeoutMs int) (string, error) { - cTopic := C.CString(pubsubTopic) - cMsg := C.CString(messageJSON) - defer C.free(unsafe.Pointer(cTopic)) - defer C.free(unsafe.Pointer(cMsg)) - return call(func(resp unsafe.Pointer) { C.cGoWakuRelayPublish(h, cTopic, cMsg, C.int(timeoutMs), resp) }) -} - -// RelaySubscribe subscribes the node to a pubsub topic. -func RelaySubscribe(h Handle, pubsubTopic string) error { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuRelaySubscribe(h, cTopic, resp) }) - return err -} - -// RelayAddProtectedShard registers the hex-encoded public key allowed to -// sign messages on a protected shard. -func RelayAddProtectedShard(h Handle, clusterID, shardID int, publicKeyHex string) error { - cPublicKey := C.CString(publicKeyHex) - defer C.free(unsafe.Pointer(cPublicKey)) - _, err := call(func(resp unsafe.Pointer) { - C.cGoWakuRelayAddProtectedShard(h, C.int(clusterID), C.int(shardID), cPublicKey, resp) - }) - return err -} - -// RelayUnsubscribe unsubscribes the node from a pubsub topic. -func RelayUnsubscribe(h Handle, pubsubTopic string) error { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuRelayUnsubscribe(h, cTopic, resp) }) - return err -} - -// Connect dials a peer multiaddress. -func Connect(h Handle, peerMultiAddr string, timeoutMs int) error { - cAddr := C.CString(peerMultiAddr) - defer C.free(unsafe.Pointer(cAddr)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuConnect(h, cAddr, C.int(timeoutMs), resp) }) - return err -} - -// DialPeer dials a peer multiaddress over a specific protocol. -func DialPeer(h Handle, peerMultiAddr, protocol string, timeoutMs int) error { - cAddr := C.CString(peerMultiAddr) - cProtocol := C.CString(protocol) - defer C.free(unsafe.Pointer(cAddr)) - defer C.free(unsafe.Pointer(cProtocol)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDialPeer(h, cAddr, cProtocol, C.int(timeoutMs), resp) }) - return err -} - -// DialPeerByID dials a known peer id over a specific protocol. -func DialPeerByID(h Handle, peerID, protocol string, timeoutMs int) error { - cPeerID := C.CString(peerID) - cProtocol := C.CString(protocol) - defer C.free(unsafe.Pointer(cPeerID)) - defer C.free(unsafe.Pointer(cProtocol)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDialPeerById(h, cPeerID, cProtocol, C.int(timeoutMs), resp) }) - return err -} - -// DisconnectPeerByID drops the connection to a peer. -func DisconnectPeerByID(h Handle, peerID string) error { - cPeerID := C.CString(peerID) - defer C.free(unsafe.Pointer(cPeerID)) - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDisconnectPeerById(h, cPeerID, resp) }) - return err -} - -// DisconnectAllPeers drops all peer connections. -func DisconnectAllPeers(h Handle) error { - _, err := call(func(resp unsafe.Pointer) { C.cGoWakuDisconnectAllPeers(h, resp) }) - return err -} - -// ListenAddresses returns the node's listen multiaddresses as a -// comma-separated list. -func ListenAddresses(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuListenAddresses(h, resp) }) -} - -// GetMyENR returns the node's ENR record. -func GetMyENR(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetMyENR(h, resp) }) -} - -// GetMyPeerID returns the node's peer id. -func GetMyPeerID(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetMyPeerId(h, resp) }) -} - -// PingPeer pings a peer (comma-separated multiaddresses) and returns the -// round-trip time in nanoseconds. -func PingPeer(h Handle, peerAddrs string, timeoutMs int) (string, error) { - cAddr := C.CString(peerAddrs) - defer C.free(unsafe.Pointer(cAddr)) - return call(func(resp unsafe.Pointer) { C.cGoWakuPingPeer(h, cAddr, C.int(timeoutMs), resp) }) -} - -// GetPeersInMesh returns the relay mesh peer ids for a pubsub topic as a -// comma-separated list. -func GetPeersInMesh(h Handle, pubsubTopic string) (string, error) { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeersInMesh(h, cTopic, resp) }) -} - -// GetNumPeersInMesh returns the relay mesh peer count for a pubsub topic. -func GetNumPeersInMesh(h Handle, pubsubTopic string) (string, error) { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - return call(func(resp unsafe.Pointer) { C.cGoWakuGetNumPeersInMesh(h, cTopic, resp) }) -} - -// GetNumConnectedRelayPeers returns the connected relay peer count for a -// pubsub topic. -func GetNumConnectedRelayPeers(h Handle, pubsubTopic string) (string, error) { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - return call(func(resp unsafe.Pointer) { C.cGoWakuGetNumConnectedRelayPeers(h, cTopic, resp) }) -} - -// GetConnectedRelayPeers returns the connected relay peer ids for a pubsub -// topic as a comma-separated list. -func GetConnectedRelayPeers(h Handle, pubsubTopic string) (string, error) { - cTopic := C.CString(pubsubTopic) - defer C.free(unsafe.Pointer(cTopic)) - return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedRelayPeers(h, cTopic, resp) }) -} - -// GetConnectedPeers returns the connected peer ids as a comma-separated -// list. -func GetConnectedPeers(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedPeers(h, resp) }) -} - -// GetPeerIDsFromPeerStore returns the peer-store peer ids as a -// comma-separated list. -func GetPeerIDsFromPeerStore(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeerIdsFromPeerStore(h, resp) }) -} - -// GetConnectedPeersInfo returns the connected peers' info as JSON. -func GetConnectedPeersInfo(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetConnectedPeersInfo(h, resp) }) -} - -// StoreQuery runs a store query (JSON) against a peer (comma-separated -// multiaddresses) and returns the response JSON. -func StoreQuery(h Handle, queryJSON, peerAddrs string, timeoutMs int) (string, error) { - cQuery := C.CString(queryJSON) - cAddr := C.CString(peerAddrs) - defer C.free(unsafe.Pointer(cQuery)) - defer C.free(unsafe.Pointer(cAddr)) - return call(func(resp unsafe.Pointer) { C.cGoWakuStoreQuery(h, cQuery, cAddr, C.int(timeoutMs), resp) }) -} - -// PeerExchangeRequest asks peer exchange for numPeers peers and returns -// the number of received peers. -func PeerExchangeRequest(h Handle, numPeers uint64) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuPeerExchangeQuery(h, C.uint64_t(numPeers), resp) }) -} - -// GetPeerIDsByProtocol returns the peer ids supporting a protocol as a -// comma-separated list. -func GetPeerIDsByProtocol(h Handle, protocol string) (string, error) { - cProtocol := C.CString(protocol) - defer C.free(unsafe.Pointer(cProtocol)) - return call(func(resp unsafe.Pointer) { C.cGoWakuGetPeerIdsByProtocol(h, cProtocol, resp) }) -} - -// DnsDiscovery resolves an ENR tree URL via DNS discovery and returns the -// discovered multiaddresses as a comma-separated list. -func DnsDiscovery(h Handle, enrTreeURL, nameDNSServer string, timeoutMs int) (string, error) { - cEnrTree := C.CString(enrTreeURL) - cDNSServer := C.CString(nameDNSServer) - defer C.free(unsafe.Pointer(cEnrTree)) - defer C.free(unsafe.Pointer(cDNSServer)) - return call(func(resp unsafe.Pointer) { C.cGoWakuDnsDiscovery(h, cEnrTree, cDNSServer, C.int(timeoutMs), resp) }) -} - -// IsOnline reports the node's online state ("true"/"false"). -func IsOnline(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuIsOnline(h, resp) }) -} - -// GetMetrics returns the node's metrics in Prometheus text format. -func GetMetrics(h Handle) (string, error) { - return call(func(resp unsafe.Pointer) { C.cGoWakuGetMetrics(h, resp) }) -} diff --git a/pkg/kernel/Makefile b/pkg/kernel/Makefile index 68b9104..0385c84 100644 --- a/pkg/kernel/Makefile +++ b/pkg/kernel/Makefile @@ -14,11 +14,11 @@ export LIBWAKU_HEADER_PATH ?= $(LOGOS_DELIVERY_DIR)/library export LIBWAKU_LIB_PATH ?= $(LOGOS_DELIVERY_DIR)/build export CGO_CFLAGS := -I$(LIBWAKU_HEADER_PATH)/ -export CGO_LDFLAGS := -L$(LIBWAKU_LIB_PATH)/ -lwaku -Wl,-rpath,$(LIBWAKU_LIB_PATH)/ +export CGO_LDFLAGS := -L$(LIBWAKU_LIB_PATH)/ -llogosdelivery -Wl,-rpath,$(LIBWAKU_LIB_PATH)/ # Expected files -HEADER_FILE := $(LIBWAKU_HEADER_PATH)/libwaku.h -LIB_FILES := $(wildcard $(LIBWAKU_LIB_PATH)/libwaku.*) +HEADER_FILE := $(LIBWAKU_HEADER_PATH)/liblogosdelivery.h +LIB_FILES := $(wildcard $(LIBWAKU_LIB_PATH)/liblogosdelivery.*) .PHONY: all clean prepare build test build-auto test-auto build-libwaku @@ -40,9 +40,9 @@ check-folders: echo "ERROR: Library path does not exist: $(LIBWAKU_LIB_PATH)"; exit 1; \ fi - @echo Checking for libwaku.h ... + @echo Checking for liblogosdelivery.h ... @if [ ! -f "$(HEADER_FILE)" ]; then \ - echo "ERROR: libwaku.h not found at: $(HEADER_FILE)"; exit 1; \ + echo "ERROR: liblogosdelivery.h not found at: $(HEADER_FILE)"; exit 1; \ fi @echo Checking for libwaku library file ... diff --git a/pkg/kernel/doc.go b/pkg/kernel/doc.go index a2bd914..a789efc 100644 --- a/pkg/kernel/doc.go +++ b/pkg/kernel/doc.go @@ -1,3 +1,4 @@ // Package kernel is the low-level Go wrapper over the logos-delivery Kernel API -// (libwaku): relay, store, lightpush, filter, peer management, discovery. +// (the waku_* tier of the single liblogosdelivery library): relay, store, +// lightpush, filter, peer management, discovery. package kernel diff --git a/pkg/kernel/nwaku.go b/pkg/kernel/nwaku.go index 42baeba..1d3352d 100644 --- a/pkg/kernel/nwaku.go +++ b/pkg/kernel/nwaku.go @@ -12,7 +12,7 @@ import ( "strings" "time" - "github.com/logos-messaging/logos-delivery-go-bindings/internal/ffi/libwaku" + "github.com/logos-messaging/logos-delivery-go-bindings/internal/ffi/liblogosdelivery" "github.com/logos-messaging/logos-delivery-go-bindings/pkg/kernel/timesource" "github.com/ethereum/go-ethereum/crypto" @@ -33,7 +33,7 @@ const ConnectionChangeChanBufferSize = 1024 // WakuNode represents an instance of an nwaku node type WakuNode struct { - wakuCtx libwaku.Handle + wakuCtx liblogosdelivery.Handle config *common.WakuConfig MsgChan chan common.Envelope TopicHealthChan chan topicHealth @@ -54,7 +54,7 @@ func NewWakuNode(config *common.WakuConfig, nodeName string) (*WakuNode, error) return nil, err } - n.wakuCtx, err = libwaku.New(string(jsonConfig)) + n.wakuCtx, err = liblogosdelivery.New(string(jsonConfig)) if err != nil { Error("error wakuNew for %s: %v", nodeName, err) return nil, err @@ -64,15 +64,15 @@ func NewWakuNode(config *common.WakuConfig, nodeName string) (*WakuNode, error) n.TopicHealthChan = make(chan topicHealth, TopicHealthChanBufferSize) n.ConnectionChangeChan = make(chan connectionChange, ConnectionChangeChanBufferSize) - libwaku.SetEventHandler(n.wakuCtx, n.onRawEvent) + liblogosdelivery.SetEventHandler(n.wakuCtx, n.onRawEvent) Debug("Successfully created WakuNode: %s", nodeName) return n, nil } -// onRawEvent receives every libwaku event for this node from the ffi bridge. +// onRawEvent receives every kernel event for this node from the ffi bridge. func (n *WakuNode) onRawEvent(ret int, msg string) { - if ret == libwaku.RetOK { + if ret == liblogosdelivery.RetOK { n.OnEvent(msg) return } @@ -168,7 +168,7 @@ func (n *WakuNode) GetNumConnectedRelayPeers(optPubsubTopic ...string) (int, err pubsubTopic = optPubsubTopic[0] } - numPeersStr, err := libwaku.GetNumConnectedRelayPeers(n.wakuCtx, pubsubTopic) + numPeersStr, err := liblogosdelivery.GetNumConnectedRelayPeers(n.wakuCtx, pubsubTopic) if err != nil { errMsg := "error GetNumConnectedRelayPeers: " + err.Error() Error("Failed to get number of connected relay peers for %s: %s", n.nodeName, errMsg) @@ -199,7 +199,7 @@ func (n *WakuNode) GetConnectedRelayPeers(optPubsubTopic ...string) (peer.IDSlic Debug("Fetching connected relay peers for pubsubTopic: %v, node: %v", pubsubTopic, n.nodeName) - peersStr, err := libwaku.GetConnectedRelayPeers(n.wakuCtx, pubsubTopic) + peersStr, err := liblogosdelivery.GetConnectedRelayPeers(n.wakuCtx, pubsubTopic) if err != nil { errMsg := "error GetConnectedRelayPeers: " + err.Error() Error("Failed to get connected relay peers for pubsubTopic: %v:, node: %v. %v", pubsubTopic, n.nodeName, errMsg) @@ -227,14 +227,14 @@ func (n *WakuNode) GetConnectedRelayPeers(optPubsubTopic ...string) (peer.IDSlic } func (n *WakuNode) DisconnectPeerByID(peerID peer.ID) error { - if err := libwaku.DisconnectPeerByID(n.wakuCtx, peerID.String()); err != nil { + if err := liblogosdelivery.DisconnectPeerByID(n.wakuCtx, peerID.String()); err != nil { return fmt.Errorf("error DisconnectPeerById: %w", err) } return nil } func (n *WakuNode) DisconnectAllPeers() error { - if err := libwaku.DisconnectAllPeers(n.wakuCtx); err != nil { + if err := liblogosdelivery.DisconnectAllPeers(n.wakuCtx); err != nil { return fmt.Errorf("error DisconnectAllPeers: %w", err) } return nil @@ -249,7 +249,7 @@ func (n *WakuNode) GetConnectedPeers() (peer.IDSlice, error) { Debug("Fetching connected peers for %v", n.nodeName) - peersStr, err := libwaku.GetConnectedPeers(n.wakuCtx) + peersStr, err := liblogosdelivery.GetConnectedPeers(n.wakuCtx) if err != nil { errMsg := "error GetConnectedPeers: " + err.Error() Error("Failed to get connected peers for %v: %v", n.nodeName, errMsg) @@ -285,7 +285,7 @@ func (n *WakuNode) GetPeersInMesh(pubsubTopic string) (peer.IDSlice, error) { Debug("Fetching peers in mesh peers for pubsubTopic: %v, node: %v", pubsubTopic, n.nodeName) - peersStr, err := libwaku.GetPeersInMesh(n.wakuCtx, pubsubTopic) + peersStr, err := liblogosdelivery.GetPeersInMesh(n.wakuCtx, pubsubTopic) if err != nil { errMsg := "error GetPeersInMesh: " + err.Error() Error("Failed to get peers in mesh for pubsubTopic: %v:, node: %v. %v", pubsubTopic, n.nodeName, errMsg) @@ -321,7 +321,7 @@ func (n *WakuNode) RelaySubscribe(pubsubTopic string) error { return errors.New("wakuCtx is nil") } - if err := libwaku.RelaySubscribe(n.wakuCtx, pubsubTopic); err != nil { + if err := liblogosdelivery.RelaySubscribe(n.wakuCtx, pubsubTopic); err != nil { Error("Failed to subscribe to relay on node %s, pubsubTopic: %s, error: %v", n.nodeName, pubsubTopic, err) return fmt.Errorf("error WakuRelaySubscribe: %w", err) } @@ -341,7 +341,7 @@ func (n *WakuNode) RelayAddProtectedShard(clusterId uint16, shardId uint16, pubk keyHexStr := hex.EncodeToString(crypto.FromECDSAPub(pubkey)) - if err := libwaku.RelayAddProtectedShard(n.wakuCtx, int(clusterId), int(shardId), keyHexStr); err != nil { + if err := liblogosdelivery.RelayAddProtectedShard(n.wakuCtx, int(clusterId), int(shardId), keyHexStr); err != nil { return fmt.Errorf("error WakuRelayAddProtectedShard: %w", err) } return nil @@ -359,7 +359,7 @@ func (n *WakuNode) RelayUnsubscribe(pubsubTopic string) error { } Debug("Attempting to unsubscribe from relay on node %s, pubsubTopic: %s", n.nodeName, pubsubTopic) - if err := libwaku.RelayUnsubscribe(n.wakuCtx, pubsubTopic); err != nil { + if err := liblogosdelivery.RelayUnsubscribe(n.wakuCtx, pubsubTopic); err != nil { Error("Failed to unsubscribe from relay on node %s, pubsubTopic: %s, error: %v", n.nodeName, pubsubTopic, err) return fmt.Errorf("error WakuRelayUnsubscribe: %w", err) } @@ -369,7 +369,7 @@ func (n *WakuNode) RelayUnsubscribe(pubsubTopic string) error { } func (n *WakuNode) PeerExchangeRequest(numPeers uint64) (uint64, error) { - numRecvPeersStr, err := libwaku.PeerExchangeRequest(n.wakuCtx, numPeers) + numRecvPeersStr, err := liblogosdelivery.PeerExchangeRequest(n.wakuCtx, numPeers) if err != nil { Error("PeerExchangeRequest failed: %v", err) return 0, err @@ -386,7 +386,7 @@ func (n *WakuNode) PeerExchangeRequest(numPeers uint64) (uint64, error) { func (n *WakuNode) StartDiscV5() error { Debug("Starting DiscV5 for node: %s", n.nodeName) - if err := libwaku.StartDiscV5(n.wakuCtx); err != nil { + if err := liblogosdelivery.StartDiscV5(n.wakuCtx); err != nil { errMsg := "error WakuStartDiscV5: " + err.Error() Error("Failed to start DiscV5 for node %s: %v", n.nodeName, errMsg) return errors.New(errMsg) @@ -396,7 +396,7 @@ func (n *WakuNode) StartDiscV5() error { } func (n *WakuNode) StopDiscV5() error { - if err := libwaku.StopDiscV5(n.wakuCtx); err != nil { + if err := liblogosdelivery.StopDiscV5(n.wakuCtx); err != nil { errMsg := "error WakuStopDiscV5: " + err.Error() Error("Failed to stop DiscV5 for node %s: %v", n.nodeName, errMsg) return errors.New(errMsg) @@ -406,7 +406,7 @@ func (n *WakuNode) StopDiscV5() error { } func (n *WakuNode) Version() (string, error) { - version, err := libwaku.Version(n.wakuCtx) + version, err := liblogosdelivery.Version(n.wakuCtx) if err != nil { errMsg := "error WakuVersion: " + err.Error() Error("Failed to fetch Waku version for node %s: %v", n.nodeName, errMsg) @@ -430,7 +430,7 @@ func (n *WakuNode) StoreQuery(ctx context.Context, storeRequest *common.StoreQue addrs[i] = addr.String() } - jsonResponseStr, err := libwaku.StoreQuery(n.wakuCtx, string(b), strings.Join(addrs, ","), timeoutMs) + jsonResponseStr, err := liblogosdelivery.StoreQuery(n.wakuCtx, string(b), strings.Join(addrs, ","), timeoutMs) if err != nil { return nil, fmt.Errorf("error WakuStoreQuery: %w", err) } @@ -451,7 +451,7 @@ func (n *WakuNode) RelayPublish(ctx context.Context, message *pb.WakuMessage, pu return common.MessageHash(""), err } - msgHash, err := libwaku.RelayPublish(n.wakuCtx, pubsubTopic, string(jsonMsg), timeoutMs) + msgHash, err := liblogosdelivery.RelayPublish(n.wakuCtx, pubsubTopic, string(jsonMsg), timeoutMs) if err != nil { return common.MessageHash(""), fmt.Errorf("WakuRelayPublish: %w", err) } @@ -489,7 +489,7 @@ func (n *WakuNode) RelayPublishNoCTX(pubsubTopic string, message *pb.WakuMessage func (n *WakuNode) DnsDiscovery(ctx context.Context, enrTreeUrl string, nameDnsServer string) ([]multiaddr.Multiaddr, error) { timeoutMs := getContextTimeoutMilliseconds(ctx) - nodeAddresses, err := libwaku.DnsDiscovery(n.wakuCtx, enrTreeUrl, nameDnsServer, timeoutMs) + nodeAddresses, err := liblogosdelivery.DnsDiscovery(n.wakuCtx, enrTreeUrl, nameDnsServer, timeoutMs) if err != nil { return nil, fmt.Errorf("error WakuDnsDiscovery: %w", err) } @@ -514,7 +514,7 @@ func (n *WakuNode) PingPeer(ctx context.Context, peerInfo peer.AddrInfo) (time.D timeoutMs := getContextTimeoutMilliseconds(ctx) - rttStr, err := libwaku.PingPeer(n.wakuCtx, strings.Join(addrs, ","), timeoutMs) + rttStr, err := liblogosdelivery.PingPeer(n.wakuCtx, strings.Join(addrs, ","), timeoutMs) if err != nil { return 0, fmt.Errorf("PingPeer: %w", err) } @@ -529,7 +529,7 @@ func (n *WakuNode) PingPeer(ctx context.Context, peerInfo peer.AddrInfo) (time.D func (n *WakuNode) Start() error { Debug("Starting %s", n.nodeName) - if err := libwaku.Start(n.wakuCtx); err != nil { + if err := liblogosdelivery.Start(n.wakuCtx); err != nil { errMsg := "error WakuStart: " + err.Error() Error("Failed to start %s: %s", n.nodeName, errMsg) return errors.New(errMsg) @@ -542,7 +542,7 @@ func (n *WakuNode) Start() error { func (n *WakuNode) Stop() error { Debug("Stopping %s", n.nodeName) - if err := libwaku.Stop(n.wakuCtx); err != nil { + if err := liblogosdelivery.Stop(n.wakuCtx); err != nil { errMsg := "error WakuStop: " + err.Error() Error("Failed to stop %s: %s", n.nodeName, errMsg) return errors.New(errMsg) @@ -561,7 +561,7 @@ func (n *WakuNode) Destroy() error { Debug("Destroying %v", n.nodeName) - if err := libwaku.Destroy(n.wakuCtx); err != nil { + if err := liblogosdelivery.Destroy(n.wakuCtx); err != nil { errMsg := "error WakuDestroy: " + err.Error() Error("Failed to destroy %v: %v", n.nodeName, errMsg) return errors.New(errMsg) @@ -572,7 +572,7 @@ func (n *WakuNode) Destroy() error { } func (n *WakuNode) PeerID() (peer.ID, error) { - peerIdStr, err := libwaku.GetMyPeerID(n.wakuCtx) + peerIdStr, err := liblogosdelivery.GetMyPeerID(n.wakuCtx) if err != nil { return "", err } @@ -588,7 +588,7 @@ func (n *WakuNode) PeerID() (peer.ID, error) { func (n *WakuNode) Connect(ctx context.Context, addr multiaddr.Multiaddr) error { timeoutMs := getContextTimeoutMilliseconds(ctx) - if err := libwaku.Connect(n.wakuCtx, addr.String(), timeoutMs); err != nil { + if err := liblogosdelivery.Connect(n.wakuCtx, addr.String(), timeoutMs); err != nil { return fmt.Errorf("error WakuConnect: %w", err) } return nil @@ -597,14 +597,14 @@ func (n *WakuNode) Connect(ctx context.Context, addr multiaddr.Multiaddr) error func (n *WakuNode) DialPeerByID(ctx context.Context, peerID peer.ID, protocol libp2pproto.ID) error { timeoutMs := getContextTimeoutMilliseconds(ctx) - if err := libwaku.DialPeerByID(n.wakuCtx, peerID.String(), string(protocol), timeoutMs); err != nil { + if err := liblogosdelivery.DialPeerByID(n.wakuCtx, peerID.String(), string(protocol), timeoutMs); err != nil { return fmt.Errorf("error DialPeerById: %w", err) } return nil } func (n *WakuNode) ListenAddresses() ([]multiaddr.Multiaddr, error) { - listenAddresses, err := libwaku.ListenAddresses(n.wakuCtx) + listenAddresses, err := liblogosdelivery.ListenAddresses(n.wakuCtx) if err != nil { return nil, fmt.Errorf("error WakuListenAddresses: %w", err) } @@ -622,7 +622,7 @@ func (n *WakuNode) ListenAddresses() ([]multiaddr.Multiaddr, error) { } func (n *WakuNode) ENR() (*enode.Node, error) { - enrStr, err := libwaku.GetMyENR(n.wakuCtx) + enrStr, err := liblogosdelivery.GetMyENR(n.wakuCtx) if err != nil { return nil, fmt.Errorf("error WakuGetMyENR: %w", err) } @@ -635,7 +635,7 @@ func (n *WakuNode) ENR() (*enode.Node, error) { } func (n *WakuNode) GetNumPeersInMesh(pubsubTopic string) (int, error) { - numPeersStr, err := libwaku.GetNumPeersInMesh(n.wakuCtx, pubsubTopic) + numPeersStr, err := liblogosdelivery.GetNumPeersInMesh(n.wakuCtx, pubsubTopic) if err != nil { return 0, fmt.Errorf("error GetNumPeersInMesh: %w", err) } @@ -649,7 +649,7 @@ func (n *WakuNode) GetNumPeersInMesh(pubsubTopic string) (int, error) { } func (n *WakuNode) GetPeerIDsFromPeerStore() (peer.IDSlice, error) { - peersStr, err := libwaku.GetPeerIDsFromPeerStore(n.wakuCtx) + peersStr, err := liblogosdelivery.GetPeerIDsFromPeerStore(n.wakuCtx) if err != nil { return nil, fmt.Errorf("GetPeerIdsFromPeerStore: %s", err.Error()) } @@ -672,7 +672,7 @@ func (n *WakuNode) GetPeerIDsFromPeerStore() (peer.IDSlice, error) { } func (n *WakuNode) GetConnectedPeersInfo() (common.PeersData, error) { - jsonStr, err := libwaku.GetConnectedPeersInfo(n.wakuCtx) + jsonStr, err := liblogosdelivery.GetConnectedPeersInfo(n.wakuCtx) if err != nil { return nil, fmt.Errorf("GetConnectedPeersInfo: %s", err.Error()) } @@ -691,7 +691,7 @@ func (n *WakuNode) GetConnectedPeersInfo() (common.PeersData, error) { } func (n *WakuNode) GetPeerIDsByProtocol(protocol libp2pproto.ID) (peer.IDSlice, error) { - peersStr, err := libwaku.GetPeerIDsByProtocol(n.wakuCtx, string(protocol)) + peersStr, err := liblogosdelivery.GetPeerIDsByProtocol(n.wakuCtx, string(protocol)) if err != nil { return nil, fmt.Errorf("GetPeerIdsByProtocol: error GetPeerIdsByProtocol: %s", err.Error()) } @@ -716,7 +716,7 @@ func (n *WakuNode) GetPeerIDsByProtocol(protocol libp2pproto.ID) (peer.IDSlice, func (n *WakuNode) DialPeer(ctx context.Context, peerAddr multiaddr.Multiaddr, protocol libp2pproto.ID) error { timeoutMs := getContextTimeoutMilliseconds(ctx) - if err := libwaku.DialPeer(n.wakuCtx, peerAddr.String(), string(protocol), timeoutMs); err != nil { + if err := liblogosdelivery.DialPeer(n.wakuCtx, peerAddr.String(), string(protocol), timeoutMs); err != nil { return fmt.Errorf("error DialPeer: %w", err) } return nil @@ -934,7 +934,7 @@ func (n *WakuNode) IsOnline() (bool, error) { Debug("Querying online state for %v", n.nodeName) - onlineStr, err := libwaku.IsOnline(n.wakuCtx) + onlineStr, err := liblogosdelivery.IsOnline(n.wakuCtx) if err != nil { errMsg := "error IsOnline: " + err.Error() Error("Failed to query online state for %v: %v", n.nodeName, errMsg) @@ -953,7 +953,7 @@ func (n *WakuNode) GetMetrics() (string, error) { Debug("Querying metrics for %v", n.nodeName) - metricsStr, err := libwaku.GetMetrics(n.wakuCtx) + metricsStr, err := liblogosdelivery.GetMetrics(n.wakuCtx) if err != nil { errMsg := "error GetMetrics: " + err.Error() Error("Failed to query metrics for %v: %v", n.nodeName, errMsg)