mirror of https://github.com/waku-org/nwaku.git
updating available procs in golang example (#3137)
This commit is contained in:
parent
d098b93d9d
commit
dbf02226cd
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#cgo LDFLAGS: -L../../build/ -lwaku -lnegentropy -Wl,--allow-multiple-definition
|
#cgo LDFLAGS: -L../../build/ -lwaku -lnegentropy
|
||||||
#cgo LDFLAGS: -L../../ -Wl,-rpath,../../
|
#cgo LDFLAGS: -L../../ -Wl,-rpath,../../
|
||||||
|
|
||||||
#include "../../library/libwaku.h"
|
#include "../../library/libwaku.h"
|
||||||
|
@ -16,17 +16,17 @@ package main
|
||||||
size_t len;
|
size_t len;
|
||||||
} Resp;
|
} Resp;
|
||||||
|
|
||||||
void* allocResp() {
|
static void* allocResp() {
|
||||||
return calloc(1, sizeof(Resp));
|
return calloc(1, sizeof(Resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeResp(void* resp) {
|
static void freeResp(void* resp) {
|
||||||
if (resp != NULL) {
|
if (resp != NULL) {
|
||||||
free(resp);
|
free(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* getMyCharPtr(void* resp) {
|
static char* getMyCharPtr(void* resp) {
|
||||||
if (resp == NULL) {
|
if (resp == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ package main
|
||||||
return m->msg;
|
return m->msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getMyCharLen(void* resp) {
|
static size_t getMyCharLen(void* resp) {
|
||||||
if (resp == NULL) {
|
if (resp == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ package main
|
||||||
return m->len;
|
return m->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRet(void* resp) {
|
static int getRet(void* resp) {
|
||||||
if (resp == NULL) {
|
if (resp == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ package main
|
||||||
}
|
}
|
||||||
|
|
||||||
// resp must be set != NULL in case interest on retrieving data from the callback
|
// resp must be set != NULL in case interest on retrieving data from the callback
|
||||||
void callback(int ret, char* msg, size_t len, void* resp) {
|
static void callback(int ret, char* msg, size_t len, void* resp) {
|
||||||
if (resp != NULL) {
|
if (resp != NULL) {
|
||||||
Resp* m = (Resp*) resp;
|
Resp* m = (Resp*) resp;
|
||||||
m->ret = ret;
|
m->ret = ret;
|
||||||
|
@ -69,32 +69,41 @@ package main
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
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
|
||||||
return waku_new(configJson, (WakuCallBack) callback, resp);
|
void* ret = waku_new(configJson, (WakuCallBack) callback, resp);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuStart(void* ctx, void* resp) {
|
static void cGoWakuStart(void* wakuCtx, void* resp) {
|
||||||
WAKU_CALL(waku_start(ctx, (WakuCallBack) callback, resp));
|
WAKU_CALL(waku_start(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuStop(void* ctx, void* resp) {
|
static void cGoWakuStop(void* wakuCtx, void* resp) {
|
||||||
WAKU_CALL(waku_stop(ctx, (WakuCallBack) callback, resp));
|
WAKU_CALL(waku_stop(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuDestroy(void* ctx, void* resp) {
|
static void cGoWakuDestroy(void* wakuCtx, void* resp) {
|
||||||
WAKU_CALL(waku_destroy(ctx, (WakuCallBack) callback, resp));
|
WAKU_CALL(waku_destroy(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuVersion(void* ctx, void* resp) {
|
static void cGoWakuStartDiscV5(void* wakuCtx, void* resp) {
|
||||||
WAKU_CALL(waku_version(ctx, (WakuCallBack) callback, resp));
|
WAKU_CALL(waku_start_discv5(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuSetEventCallback(void* ctx) {
|
static void cGoWakuStopDiscV5(void* wakuCtx, void* resp) {
|
||||||
// The 'globalEventCallback' Go function is shared amongst all possible WakuNode instances.
|
WAKU_CALL(waku_stop_discv5(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuVersion(void* wakuCtx, void* resp) {
|
||||||
|
WAKU_CALL(waku_version(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuSetEventCallback(void* wakuCtx) {
|
||||||
|
// The 'globalEventCallback' Go function is shared amongst all possible Waku instances.
|
||||||
|
|
||||||
// Given that the 'globalEventCallback' is shared, we pass again the
|
// Given that the 'globalEventCallback' is shared, we pass again the
|
||||||
// ctx instance but in this case is needed to pick up the correct method
|
// wakuCtx instance but in this case is needed to pick up the correct method
|
||||||
// that will handle the event.
|
// that will handle the event.
|
||||||
|
|
||||||
// In other words, for every call the libwaku makes to globalEventCallback,
|
// In other words, for every call the libwaku makes to globalEventCallback,
|
||||||
|
@ -103,17 +112,17 @@ package main
|
||||||
|
|
||||||
// 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(ctx, (WakuCallBack) globalEventCallback, ctx);
|
waku_set_event_callback(wakuCtx, (WakuCallBack) globalEventCallback, wakuCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuContentTopic(void* ctx,
|
static void cGoWakuContentTopic(void* wakuCtx,
|
||||||
char* appName,
|
char* appName,
|
||||||
int appVersion,
|
int appVersion,
|
||||||
char* contentTopicName,
|
char* contentTopicName,
|
||||||
char* encoding,
|
char* encoding,
|
||||||
void* resp) {
|
void* resp) {
|
||||||
|
|
||||||
WAKU_CALL( waku_content_topic(ctx,
|
WAKU_CALL( waku_content_topic(wakuCtx,
|
||||||
appName,
|
appName,
|
||||||
appVersion,
|
appVersion,
|
||||||
contentTopicName,
|
contentTopicName,
|
||||||
|
@ -122,21 +131,21 @@ package main
|
||||||
resp) );
|
resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuPubsubTopic(void* ctx, char* topicName, void* resp) {
|
static void cGoWakuPubsubTopic(void* wakuCtx, char* topicName, void* resp) {
|
||||||
WAKU_CALL( waku_pubsub_topic(ctx, topicName, (WakuCallBack) callback, resp) );
|
WAKU_CALL( waku_pubsub_topic(wakuCtx, topicName, (WakuCallBack) callback, resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuDefaultPubsubTopic(void* ctx, void* resp) {
|
static void cGoWakuDefaultPubsubTopic(void* wakuCtx, void* resp) {
|
||||||
WAKU_CALL (waku_default_pubsub_topic(ctx, (WakuCallBack) callback, resp));
|
WAKU_CALL (waku_default_pubsub_topic(wakuCtx, (WakuCallBack) callback, resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuRelayPublish(void* ctx,
|
static void cGoWakuRelayPublish(void* wakuCtx,
|
||||||
const char* pubSubTopic,
|
const char* pubSubTopic,
|
||||||
const char* jsonWakuMessage,
|
const char* jsonWakuMessage,
|
||||||
int timeoutMs,
|
int timeoutMs,
|
||||||
void* resp) {
|
void* resp) {
|
||||||
|
|
||||||
WAKU_CALL (waku_relay_publish(ctx,
|
WAKU_CALL (waku_relay_publish(wakuCtx,
|
||||||
pubSubTopic,
|
pubSubTopic,
|
||||||
jsonWakuMessage,
|
jsonWakuMessage,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
|
@ -144,38 +153,120 @@ package main
|
||||||
resp));
|
resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuRelaySubscribe(void* ctx, char* pubSubTopic, void* resp) {
|
static void cGoWakuRelaySubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
|
||||||
|
WAKU_CALL ( waku_relay_subscribe(wakuCtx,
|
||||||
WAKU_CALL ( waku_relay_subscribe(ctx,
|
|
||||||
pubSubTopic,
|
pubSubTopic,
|
||||||
(WakuCallBack) callback,
|
(WakuCallBack) callback,
|
||||||
resp) );
|
resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuRelayUnsubscribe(void* ctx, char* pubSubTopic, void* resp) {
|
static void cGoWakuRelayUnsubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
|
||||||
|
|
||||||
WAKU_CALL ( waku_relay_unsubscribe(ctx,
|
WAKU_CALL ( waku_relay_unsubscribe(wakuCtx,
|
||||||
pubSubTopic,
|
pubSubTopic,
|
||||||
(WakuCallBack) callback,
|
(WakuCallBack) callback,
|
||||||
resp) );
|
resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuConnect(void* ctx, char* peerMultiAddr, int timeoutMs, void* resp) {
|
static void cGoWakuConnect(void* wakuCtx, char* peerMultiAddr, int timeoutMs, void* resp) {
|
||||||
WAKU_CALL( waku_connect(ctx,
|
WAKU_CALL( waku_connect(wakuCtx,
|
||||||
peerMultiAddr,
|
peerMultiAddr,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
(WakuCallBack) callback,
|
(WakuCallBack) callback,
|
||||||
resp) );
|
resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuListenAddresses(void* ctx, void* resp) {
|
static void cGoWakuDialPeerById(void* wakuCtx,
|
||||||
WAKU_CALL (waku_listen_addresses(ctx, (WakuCallBack) callback, resp) );
|
char* peerId,
|
||||||
|
char* protocol,
|
||||||
|
int timeoutMs,
|
||||||
|
void* resp) {
|
||||||
|
|
||||||
|
WAKU_CALL( waku_dial_peer_by_id(wakuCtx,
|
||||||
|
peerId,
|
||||||
|
protocol,
|
||||||
|
timeoutMs,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cGoWakuGetMyENR(void* ctx, void* resp) {
|
static void cGoWakuDisconnectPeerById(void* wakuCtx, char* peerId, void* resp) {
|
||||||
|
WAKU_CALL( waku_disconnect_peer_by_id(wakuCtx,
|
||||||
|
peerId,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuListenAddresses(void* wakuCtx, void* resp) {
|
||||||
|
WAKU_CALL (waku_listen_addresses(wakuCtx, (WakuCallBack) callback, resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuGetMyENR(void* ctx, void* resp) {
|
||||||
WAKU_CALL (waku_get_my_enr(ctx, (WakuCallBack) callback, resp) );
|
WAKU_CALL (waku_get_my_enr(ctx, (WakuCallBack) callback, resp) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cGoWakuGetMyPeerId(void* ctx, void* resp) {
|
||||||
|
WAKU_CALL (waku_get_my_peerid(ctx, (WakuCallBack) callback, resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuListPeersInMesh(void* ctx, char* pubSubTopic, void* resp) {
|
||||||
|
WAKU_CALL (waku_relay_get_num_peers_in_mesh(ctx, pubSubTopic, (WakuCallBack) callback, resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuGetNumConnectedPeers(void* ctx, char* pubSubTopic, void* resp) {
|
||||||
|
WAKU_CALL (waku_relay_get_num_connected_peers(ctx, pubSubTopic, (WakuCallBack) callback, resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuGetPeerIdsFromPeerStore(void* wakuCtx, void* resp) {
|
||||||
|
WAKU_CALL (waku_get_peerids_from_peerstore(wakuCtx, (WakuCallBack) callback, resp) );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuLightpushPublish(void* wakuCtx,
|
||||||
|
const char* pubSubTopic,
|
||||||
|
const char* jsonWakuMessage,
|
||||||
|
void* resp) {
|
||||||
|
|
||||||
|
WAKU_CALL (waku_lightpush_publish(wakuCtx,
|
||||||
|
pubSubTopic,
|
||||||
|
jsonWakuMessage,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuStoreQuery(void* wakuCtx,
|
||||||
|
const char* jsonQuery,
|
||||||
|
const char* peerAddr,
|
||||||
|
int timeoutMs,
|
||||||
|
void* resp) {
|
||||||
|
|
||||||
|
WAKU_CALL (waku_store_query(wakuCtx,
|
||||||
|
jsonQuery,
|
||||||
|
peerAddr,
|
||||||
|
timeoutMs,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuPeerExchangeQuery(void* wakuCtx,
|
||||||
|
uint64_t numPeers,
|
||||||
|
void* resp) {
|
||||||
|
|
||||||
|
WAKU_CALL (waku_peer_exchange_request(wakuCtx,
|
||||||
|
numPeers,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cGoWakuGetPeerIdsByProtocol(void* wakuCtx,
|
||||||
|
const char* protocol,
|
||||||
|
void* resp) {
|
||||||
|
|
||||||
|
WAKU_CALL (waku_get_peerids_by_protocol(wakuCtx,
|
||||||
|
protocol,
|
||||||
|
(WakuCallBack) callback,
|
||||||
|
resp));
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue