adapt nwaku.go to latest nim-ffi ctx callback and userData go first

This commit is contained in:
Ivan Folgueira Bande 2025-12-12 17:41:02 +01:00
parent 31fb882511
commit 8c92ab1daf
No known key found for this signature in database
GPG Key ID: 3C117481F89E24A7

View File

@ -55,32 +55,32 @@ package waku
static void* cGoWakuNew(const char* configJson, void* resp) { static void* cGoWakuNew(const char* configJson, void* resp) {
// We pass NULL because we are not interested in retrieving data from this callback // We pass NULL because we are not interested in retrieving data from this callback
void* ret = waku_new(configJson, (WakuCallBack) WakuGoCallback, resp); void* ret = waku_new(configJson, (FFICallBack) WakuGoCallback, resp);
return ret; return ret;
} }
static void cGoWakuStart(void* wakuCtx, void* resp) { static void cGoWakuStart(void* wakuCtx, void* resp) {
waku_start(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_start(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuStop(void* wakuCtx, void* resp) { static void cGoWakuStop(void* wakuCtx, void* resp) {
waku_stop(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_stop(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuDestroy(void* wakuCtx, void* resp) { static void cGoWakuDestroy(void* wakuCtx, void* resp) {
waku_destroy(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_destroy(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuStartDiscV5(void* wakuCtx, void* resp) { static void cGoWakuStartDiscV5(void* wakuCtx, void* resp) {
waku_start_discv5(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_start_discv5(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuStopDiscV5(void* wakuCtx, void* resp) { static void cGoWakuStopDiscV5(void* wakuCtx, void* resp) {
waku_stop_discv5(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_stop_discv5(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuVersion(void* wakuCtx, void* resp) { static void cGoWakuVersion(void* wakuCtx, void* resp) {
waku_version(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_version(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuSetEventCallback(void* wakuCtx) { static void cGoWakuSetEventCallback(void* wakuCtx) {
@ -96,7 +96,7 @@ package waku
// This technique is needed because cgo only allows to export Go functions and not methods. // This technique is needed because cgo only allows to export Go functions and not methods.
waku_set_event_callback(wakuCtx, (WakuCallBack) wakuGlobalEventCallback, wakuCtx); set_event_callback(wakuCtx, (FFICallBack) wakuGlobalEventCallback, wakuCtx);
} }
static void cGoWakuContentTopic(void* wakuCtx, static void cGoWakuContentTopic(void* wakuCtx,
@ -107,20 +107,21 @@ package waku
void* resp) { void* resp) {
waku_content_topic(wakuCtx, waku_content_topic(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
appName, appName,
appVersion, appVersion,
contentTopicName, contentTopicName,
encoding, encoding
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuPubsubTopic(void* wakuCtx, char* topicName, void* resp) { static void cGoWakuPubsubTopic(void* wakuCtx, char* topicName, void* resp) {
waku_pubsub_topic(wakuCtx, topicName, (WakuCallBack) WakuGoCallback, resp); waku_pubsub_topic(wakuCtx, (FFICallBack) WakuGoCallback, resp, topicName);
} }
static void cGoWakuDefaultPubsubTopic(void* wakuCtx, void* resp) { static void cGoWakuDefaultPubsubTopic(void* wakuCtx, void* resp) {
waku_default_pubsub_topic(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_default_pubsub_topic(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuRelayPublish(void* wakuCtx, static void cGoWakuRelayPublish(void* wakuCtx,
@ -130,43 +131,48 @@ package waku
void* resp) { void* resp) {
waku_relay_publish(wakuCtx, waku_relay_publish(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
pubSubTopic, pubSubTopic,
jsonWakuMessage, jsonWakuMessage,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuRelaySubscribe(void* wakuCtx, char* pubSubTopic, void* resp) { static void cGoWakuRelaySubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
waku_relay_subscribe(wakuCtx, waku_relay_subscribe(wakuCtx,
pubSubTopic, (FFICallBack) WakuGoCallback,
(WakuCallBack) WakuGoCallback, resp,
resp); pubSubTopic
);
} }
static void cGoWakuRelayAddProtectedShard(void* wakuCtx, int clusterId, int shardId, char* publicKey, void* resp) { static void cGoWakuRelayAddProtectedShard(void* wakuCtx, int clusterId, int shardId, char* publicKey, void* resp) {
waku_relay_add_protected_shard(wakuCtx, waku_relay_add_protected_shard(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
clusterId, clusterId,
shardId, shardId,
publicKey, publicKey
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuRelayUnsubscribe(void* wakuCtx, char* pubSubTopic, void* resp) { static void cGoWakuRelayUnsubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
waku_relay_unsubscribe(wakuCtx, waku_relay_unsubscribe(wakuCtx,
pubSubTopic, (FFICallBack) WakuGoCallback,
(WakuCallBack) WakuGoCallback, resp,
resp); pubSubTopic
);
} }
static void cGoWakuConnect(void* wakuCtx, char* peerMultiAddr, int timeoutMs, void* resp) { static void cGoWakuConnect(void* wakuCtx, char* peerMultiAddr, int timeoutMs, void* resp) {
waku_connect(wakuCtx, waku_connect(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
peerMultiAddr, peerMultiAddr,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuDialPeer(void* wakuCtx, static void cGoWakuDialPeer(void* wakuCtx,
@ -176,11 +182,12 @@ package waku
void* resp) { void* resp) {
waku_dial_peer(wakuCtx, waku_dial_peer(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
peerMultiAddr, peerMultiAddr,
protocol, protocol,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuDialPeerById(void* wakuCtx, static void cGoWakuDialPeerById(void* wakuCtx,
@ -190,68 +197,70 @@ package waku
void* resp) { void* resp) {
waku_dial_peer_by_id(wakuCtx, waku_dial_peer_by_id(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
peerId, peerId,
protocol, protocol,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuDisconnectPeerById(void* wakuCtx, char* peerId, void* resp) { static void cGoWakuDisconnectPeerById(void* wakuCtx, char* peerId, void* resp) {
waku_disconnect_peer_by_id(wakuCtx, waku_disconnect_peer_by_id(wakuCtx,
peerId, (FFICallBack) WakuGoCallback,
(WakuCallBack) WakuGoCallback, resp,
resp); peerId
);
} }
static void cGoWakuDisconnectAllPeers(void* wakuCtx, void* resp) { static void cGoWakuDisconnectAllPeers(void* wakuCtx, void* resp) {
waku_disconnect_all_peers(wakuCtx, waku_disconnect_all_peers(wakuCtx,
(WakuCallBack) WakuGoCallback, (FFICallBack) WakuGoCallback,
resp); resp);
} }
static void cGoWakuListenAddresses(void* wakuCtx, void* resp) { static void cGoWakuListenAddresses(void* wakuCtx, void* resp) {
waku_listen_addresses(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_listen_addresses(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuGetMyENR(void* ctx, void* resp) { static void cGoWakuGetMyENR(void* ctx, void* resp) {
waku_get_my_enr(ctx, (WakuCallBack) WakuGoCallback, resp); waku_get_my_enr(ctx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuGetMyPeerId(void* ctx, void* resp) { static void cGoWakuGetMyPeerId(void* ctx, void* resp) {
waku_get_my_peerid(ctx, (WakuCallBack) WakuGoCallback, resp); waku_get_my_peerid(ctx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuPingPeer(void* ctx, char* peerAddr, int timeoutMs, void* resp) { static void cGoWakuPingPeer(void* ctx, char* peerAddr, int timeoutMs, void* resp) {
waku_ping_peer(ctx, peerAddr, timeoutMs, (WakuCallBack) WakuGoCallback, resp); waku_ping_peer(ctx, (FFICallBack) WakuGoCallback, resp, peerAddr, timeoutMs);
} }
static void cGoWakuGetPeersInMesh(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuGetPeersInMesh(void* ctx, char* pubSubTopic, void* resp) {
waku_relay_get_peers_in_mesh(ctx, pubSubTopic, (WakuCallBack) WakuGoCallback, resp); waku_relay_get_peers_in_mesh(ctx, (FFICallBack) WakuGoCallback, resp, pubSubTopic);
} }
static void cGoWakuGetNumPeersInMesh(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuGetNumPeersInMesh(void* ctx, char* pubSubTopic, void* resp) {
waku_relay_get_num_peers_in_mesh(ctx, pubSubTopic, (WakuCallBack) WakuGoCallback, resp); waku_relay_get_num_peers_in_mesh(ctx, (FFICallBack) WakuGoCallback, resp, pubSubTopic);
} }
static void cGoWakuGetNumConnectedRelayPeers(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuGetNumConnectedRelayPeers(void* ctx, char* pubSubTopic, void* resp) {
waku_relay_get_num_connected_peers(ctx, pubSubTopic, (WakuCallBack) WakuGoCallback, resp); waku_relay_get_num_connected_peers(ctx, (FFICallBack) WakuGoCallback, resp, pubSubTopic);
} }
static void cGoWakuGetConnectedRelayPeers(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuGetConnectedRelayPeers(void* ctx, char* pubSubTopic, void* resp) {
waku_relay_get_connected_peers(ctx, pubSubTopic, (WakuCallBack) WakuGoCallback, resp); waku_relay_get_connected_peers(ctx, (FFICallBack) WakuGoCallback, resp, pubSubTopic);
} }
static void cGoWakuGetConnectedPeers(void* wakuCtx, void* resp) { static void cGoWakuGetConnectedPeers(void* wakuCtx, void* resp) {
waku_get_connected_peers(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_get_connected_peers(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuGetPeerIdsFromPeerStore(void* wakuCtx, void* resp) { static void cGoWakuGetPeerIdsFromPeerStore(void* wakuCtx, void* resp) {
waku_get_peerids_from_peerstore(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_get_peerids_from_peerstore(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuGetConnectedPeersInfo(void* wakuCtx, void* resp) { static void cGoWakuGetConnectedPeersInfo(void* wakuCtx, void* resp) {
waku_get_connected_peers_info(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_get_connected_peers_info(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuLightpushPublish(void* wakuCtx, static void cGoWakuLightpushPublish(void* wakuCtx,
@ -260,10 +269,11 @@ package waku
void* resp) { void* resp) {
waku_lightpush_publish(wakuCtx, waku_lightpush_publish(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
pubSubTopic, pubSubTopic,
jsonWakuMessage, jsonWakuMessage
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuStoreQuery(void* wakuCtx, static void cGoWakuStoreQuery(void* wakuCtx,
@ -273,11 +283,12 @@ package waku
void* resp) { void* resp) {
waku_store_query(wakuCtx, waku_store_query(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
jsonQuery, jsonQuery,
peerAddr, peerAddr,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuPeerExchangeQuery(void* wakuCtx, static void cGoWakuPeerExchangeQuery(void* wakuCtx,
@ -285,9 +296,10 @@ package waku
void* resp) { void* resp) {
waku_peer_exchange_request(wakuCtx, waku_peer_exchange_request(wakuCtx,
numPeers, (FFICallBack) WakuGoCallback,
(WakuCallBack) WakuGoCallback, resp,
resp); numPeers
);
} }
static void cGoWakuGetPeerIdsByProtocol(void* wakuCtx, static void cGoWakuGetPeerIdsByProtocol(void* wakuCtx,
@ -295,9 +307,10 @@ package waku
void* resp) { void* resp) {
waku_get_peerids_by_protocol(wakuCtx, waku_get_peerids_by_protocol(wakuCtx,
protocol, (FFICallBack) WakuGoCallback,
(WakuCallBack) WakuGoCallback, resp,
resp); protocol
);
} }
static void cGoWakuDnsDiscovery(void* wakuCtx, static void cGoWakuDnsDiscovery(void* wakuCtx,
@ -307,19 +320,20 @@ package waku
void* resp) { void* resp) {
waku_dns_discovery(wakuCtx, waku_dns_discovery(wakuCtx,
(FFICallBack) WakuGoCallback,
resp,
entTreeUrl, entTreeUrl,
nameDnsServer, nameDnsServer,
timeoutMs, timeoutMs
(WakuCallBack) WakuGoCallback, );
resp);
} }
static void cGoWakuIsOnline(void* wakuCtx, void* resp) { static void cGoWakuIsOnline(void* wakuCtx, void* resp) {
waku_is_online(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_is_online(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
static void cGoWakuGetMetrics(void* wakuCtx, void* resp) { static void cGoWakuGetMetrics(void* wakuCtx, void* resp) {
waku_get_metrics(wakuCtx, (WakuCallBack) WakuGoCallback, resp); waku_get_metrics(wakuCtx, (FFICallBack) WakuGoCallback, resp);
} }
*/ */