2023-07-31 07:52:04 +00:00
|
|
|
{.pragma: exported, exportc, cdecl, raises: [].}
|
|
|
|
{.pragma: callback, cdecl, raises: [], gcsafe.}
|
|
|
|
{.passc: "-fPIC".}
|
|
|
|
|
2024-05-23 14:05:53 +00:00
|
|
|
when defined(linux):
|
2024-05-22 01:00:22 +00:00
|
|
|
{.passl: "-Wl,-soname,libwaku.so".}
|
|
|
|
|
2024-10-10 12:40:09 +00:00
|
|
|
import std/[json, atomics, strformat, options, atomics]
|
2024-12-02 14:56:12 +00:00
|
|
|
import chronicles, chronos, chronos/threadsync
|
2023-05-12 16:08:41 +00:00
|
|
|
import
|
2024-07-09 11:14:28 +00:00
|
|
|
waku/common/base64,
|
|
|
|
waku/waku_core/message/message,
|
|
|
|
waku/node/waku_node,
|
|
|
|
waku/waku_core/topics/pubsub_topic,
|
2024-11-29 14:31:08 +00:00
|
|
|
waku/waku_core/subscription/push_handler,
|
2024-07-09 11:14:28 +00:00
|
|
|
waku/waku_relay/protocol,
|
2023-07-31 07:52:04 +00:00
|
|
|
./events/json_message_event,
|
2023-08-02 08:45:15 +00:00
|
|
|
./waku_thread/waku_thread,
|
2023-09-18 07:21:50 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/node_lifecycle_request,
|
|
|
|
./waku_thread/inter_thread_communication/requests/peer_manager_request,
|
|
|
|
./waku_thread/inter_thread_communication/requests/protocols/relay_request,
|
2023-12-11 07:49:13 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/protocols/store_request,
|
2024-08-29 12:29:02 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/protocols/lightpush_request,
|
2024-11-29 14:31:08 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/protocols/filter_request,
|
2024-02-21 11:06:05 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/debug_node_request,
|
2024-05-21 16:37:50 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/discovery_request,
|
2024-10-24 13:07:08 +00:00
|
|
|
./waku_thread/inter_thread_communication/requests/ping_request,
|
2023-09-18 07:21:50 +00:00
|
|
|
./waku_thread/inter_thread_communication/waku_thread_request,
|
2023-12-11 07:49:13 +00:00
|
|
|
./alloc,
|
2024-12-13 16:38:16 +00:00
|
|
|
./ffi_types,
|
|
|
|
../waku/factory/app_callbacks
|
2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Wrapper around the waku node
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
### Not-exported components
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
template checkLibwakuParams*(
|
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
|
|
|
) =
|
|
|
|
ctx[].userData = userData
|
2024-05-22 01:00:22 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
if isNil(callback):
|
|
|
|
return RET_MISSING_CALLBACK
|
2024-05-22 01:00:22 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
proc handleRequest(
|
|
|
|
ctx: ptr WakuContext,
|
|
|
|
requestType: RequestType,
|
|
|
|
content: pointer,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
2024-10-09 12:12:45 +00:00
|
|
|
): cint =
|
2024-12-02 14:56:12 +00:00
|
|
|
waku_thread.sendRequestToWakuThread(ctx, requestType, content, callback, userData).isOkOr:
|
|
|
|
let msg = "libwaku error: " & $error
|
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
2024-10-11 10:57:55 +00:00
|
|
|
return RET_ERR
|
2024-09-11 16:11:59 +00:00
|
|
|
|
|
|
|
return RET_OK
|
|
|
|
|
2024-11-29 14:31:08 +00:00
|
|
|
proc onReceivedMessage(ctx: ptr WakuContext): WakuRelayHandler =
|
2024-03-15 23:08:47 +00:00
|
|
|
return proc(
|
|
|
|
pubsubTopic: PubsubTopic, msg: WakuMessage
|
|
|
|
): Future[system.void] {.async.} =
|
2024-02-13 14:22:22 +00:00
|
|
|
# Callback that hadles the Waku Relay events. i.e. messages or errors.
|
2024-02-20 20:00:03 +00:00
|
|
|
if isNil(ctx[].eventCallback):
|
2024-02-13 14:22:22 +00:00
|
|
|
error "eventCallback is nil"
|
2024-02-20 20:00:03 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if isNil(ctx[].eventUserData):
|
|
|
|
error "eventUserData is nil"
|
|
|
|
return
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
foreignThreadGc:
|
|
|
|
try:
|
|
|
|
let event = $JsonMessageEvent.new(pubsubTopic, msg)
|
2024-05-22 01:00:22 +00:00
|
|
|
cast[WakuCallBack](ctx[].eventCallback)(
|
|
|
|
RET_OK, unsafeAddr event[0], cast[csize_t](len(event)), ctx[].eventUserData
|
|
|
|
)
|
2024-12-02 14:56:12 +00:00
|
|
|
except Exception, CatchableError:
|
|
|
|
let msg = "Exception when calling 'eventCallBack': " & getCurrentExceptionMsg()
|
2024-05-22 01:00:22 +00:00
|
|
|
cast[WakuCallBack](ctx[].eventCallback)(
|
|
|
|
RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), ctx[].eventUserData
|
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
### End of not-exported components
|
|
|
|
################################################################################
|
|
|
|
|
2024-05-22 01:00:22 +00:00
|
|
|
################################################################################
|
|
|
|
### Library setup
|
|
|
|
|
|
|
|
# Every Nim library must have this function called - the name is derived from
|
|
|
|
# the `--nimMainPrefix` command line option
|
|
|
|
proc NimMain() {.importc.}
|
|
|
|
|
|
|
|
# To control when the library has been initialized
|
|
|
|
var initialized: Atomic[bool]
|
|
|
|
|
|
|
|
if defined(android):
|
|
|
|
# Redirect chronicles to Android System logs
|
|
|
|
when compiles(defaultChroniclesStream.outputs[0].writer):
|
|
|
|
defaultChroniclesStream.outputs[0].writer = proc(
|
|
|
|
logLevel: LogLevel, msg: LogOutputStr
|
|
|
|
) {.raises: [].} =
|
|
|
|
echo logLevel, msg
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
proc initializeLibrary() {.exported.} =
|
|
|
|
if not initialized.exchange(true):
|
|
|
|
NimMain() # Every Nim library needs to call `NimMain` once exactly
|
|
|
|
when declared(setupForeignThreadGc):
|
|
|
|
setupForeignThreadGc()
|
|
|
|
when declared(nimGC_setStackBottom):
|
|
|
|
var locals {.volatile, noinit.}: pointer
|
|
|
|
locals = addr(locals)
|
|
|
|
nimGC_setStackBottom(locals)
|
|
|
|
|
2024-05-22 01:00:22 +00:00
|
|
|
### End of library setup
|
|
|
|
################################################################################
|
|
|
|
|
2023-05-12 16:08:41 +00:00
|
|
|
################################################################################
|
|
|
|
### Exported procs
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_new(
|
|
|
|
configJson: cstring, callback: WakuCallback, userData: pointer
|
|
|
|
): pointer {.dynlib, exportc, cdecl.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
|
|
|
|
2023-12-15 12:32:12 +00:00
|
|
|
## Creates a new instance of the WakuNode.
|
|
|
|
if isNil(callback):
|
|
|
|
echo "error: missing callback in waku_new"
|
|
|
|
return nil
|
2023-07-07 08:53:00 +00:00
|
|
|
|
2023-09-01 06:37:02 +00:00
|
|
|
## Create the Waku thread that will keep waiting for req from the main thread.
|
2023-10-23 06:37:28 +00:00
|
|
|
var ctx = waku_thread.createWakuThread().valueOr:
|
2024-12-02 14:56:12 +00:00
|
|
|
let msg = "Error in createWakuThread: " & $error
|
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
2023-10-23 06:37:28 +00:00
|
|
|
return nil
|
|
|
|
|
2023-12-15 12:32:12 +00:00
|
|
|
ctx.userData = userData
|
2023-09-01 06:37:02 +00:00
|
|
|
|
2024-12-13 16:38:16 +00:00
|
|
|
let appCallbacks = AppCallbacks(relayHandler: onReceivedMessage(ctx))
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
let retCode = handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.LIFECYCLE,
|
2024-12-13 16:38:16 +00:00
|
|
|
NodeLifecycleRequest.createShared(
|
|
|
|
NodeLifecycleMsgType.CREATE_NODE, configJson, appCallbacks
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
|
|
|
)
|
|
|
|
|
|
|
|
if retCode == RET_ERR:
|
|
|
|
return nil
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2023-12-15 12:32:12 +00:00
|
|
|
return ctx
|
2023-07-07 08:53:00 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_destroy(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-03-07 17:53:03 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
waku_thread.destroyWakuThread(ctx).isOkOr:
|
|
|
|
let msg = "libwaku error: " & $error
|
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
|
|
|
return RET_ERR
|
|
|
|
|
|
|
|
return RET_OK
|
2024-03-07 17:53:03 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_version(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-12-02 14:56:12 +00:00
|
|
|
callback(
|
|
|
|
RET_OK,
|
|
|
|
cast[ptr cchar](WakuNodeVersionString),
|
|
|
|
cast[csize_t](len(WakuNodeVersionString)),
|
|
|
|
userData,
|
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2023-07-07 08:53:00 +00:00
|
|
|
return RET_OK
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_set_event_callback(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
) {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-02-13 14:22:22 +00:00
|
|
|
ctx[].eventCallback = cast[pointer](callback)
|
2024-02-20 20:00:03 +00:00
|
|
|
ctx[].eventUserData = userData
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_content_topic(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-03-15 23:08:47 +00:00
|
|
|
appName: cstring,
|
|
|
|
appVersion: cuint,
|
|
|
|
contentTopicName: cstring,
|
|
|
|
encoding: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2023-05-12 16:08:41 +00:00
|
|
|
# https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
let appStr = appName.alloc()
|
|
|
|
let ctnStr = contentTopicName.alloc()
|
|
|
|
let encodingStr = encoding.alloc()
|
|
|
|
|
|
|
|
let contentTopic = fmt"/{$appStr}/{appVersion}/{$ctnStr}/{$encodingStr}"
|
2024-03-15 23:08:47 +00:00
|
|
|
callback(
|
|
|
|
RET_OK, unsafeAddr contentTopic[0], cast[csize_t](len(contentTopic)), userData
|
|
|
|
)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
deallocShared(appStr)
|
|
|
|
deallocShared(ctnStr)
|
|
|
|
deallocShared(encodingStr)
|
|
|
|
|
|
|
|
return RET_OK
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_pubsub_topic(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, topicName: cstring, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc, cdecl.} =
|
2023-10-23 06:37:28 +00:00
|
|
|
# https://rfc.vac.dev/spec/36/#extern-char-waku_pubsub_topicchar-name-char-encoding
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
let topicNameStr = topicName.alloc()
|
|
|
|
|
|
|
|
let outPubsubTopic = fmt"/waku/2/{$topicNameStr}"
|
2024-03-15 23:08:47 +00:00
|
|
|
callback(
|
|
|
|
RET_OK, unsafeAddr outPubsubTopic[0], cast[csize_t](len(outPubsubTopic)), userData
|
|
|
|
)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
deallocShared(topicNameStr)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2023-07-07 08:53:00 +00:00
|
|
|
return RET_OK
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_default_pubsub_topic(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2023-05-12 16:08:41 +00:00
|
|
|
# https://rfc.vac.dev/spec/36/#extern-char-waku_default_pubsub_topic
|
2023-10-23 06:37:28 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
callback(
|
|
|
|
RET_OK,
|
|
|
|
cast[ptr cchar](DefaultPubsubTopic),
|
|
|
|
cast[csize_t](len(DefaultPubsubTopic)),
|
|
|
|
userData,
|
|
|
|
)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
return RET_OK
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_relay_publish(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubSubTopic: cstring,
|
|
|
|
jsonWakuMessage: cstring,
|
|
|
|
timeoutMs: cuint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc, cdecl.} =
|
2023-05-12 16:08:41 +00:00
|
|
|
# https://rfc.vac.dev/spec/36/#extern-char-waku_relay_publishchar-messagejson-char-pubsubtopic-int-timeoutms
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
|
|
|
let jwm = jsonWakuMessage.alloc()
|
2024-03-15 23:08:47 +00:00
|
|
|
var jsonMessage: JsonMessage
|
2023-05-12 16:08:41 +00:00
|
|
|
try:
|
2024-02-20 20:00:03 +00:00
|
|
|
let jsonContent = parseJson($jwm)
|
2024-12-10 17:52:21 +00:00
|
|
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
|
|
|
raise newException(JsonParsingError, $error)
|
2023-05-12 16:08:41 +00:00
|
|
|
except JsonParsingError:
|
2023-07-07 08:53:00 +00:00
|
|
|
deallocShared(jwm)
|
|
|
|
let msg = fmt"Error parsing json message: {getCurrentExceptionMsg()}"
|
2024-02-13 14:22:22 +00:00
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
return RET_ERR
|
2024-02-20 20:00:03 +00:00
|
|
|
finally:
|
|
|
|
deallocShared(jwm)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
2024-02-20 20:00:03 +00:00
|
|
|
let wakuMessage = jsonMessage.toWakuMessage().valueOr:
|
2024-09-09 08:45:14 +00:00
|
|
|
let msg = "Problem building the WakuMessage: " & $error
|
2024-02-13 14:22:22 +00:00
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
2023-07-07 08:53:00 +00:00
|
|
|
return RET_ERR
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2023-07-07 08:53:00 +00:00
|
|
|
let pst = pubSubTopic.alloc()
|
2024-09-11 16:11:59 +00:00
|
|
|
defer:
|
|
|
|
deallocShared(pst)
|
2023-07-07 08:53:00 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let targetPubSubTopic =
|
|
|
|
if len(pst) == 0:
|
|
|
|
DefaultPubsubTopic
|
|
|
|
else:
|
|
|
|
$pst
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.RELAY,
|
|
|
|
RelayRequest.createShared(
|
|
|
|
RelayMsgType.PUBLISH,
|
|
|
|
PubsubTopic($pst),
|
2024-11-29 14:31:08 +00:00
|
|
|
WakuRelayHandler(onReceivedMessage(ctx)),
|
2024-03-15 23:08:47 +00:00
|
|
|
wakuMessage,
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-07-31 07:52:04 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_start(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.LIFECYCLE,
|
|
|
|
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.START_NODE),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc waku_stop(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.LIFECYCLE,
|
|
|
|
NodeLifecycleRequest.createShared(NodeLifecycleMsgType.STOP_NODE),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
proc waku_relay_subscribe(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-10-23 06:37:28 +00:00
|
|
|
|
2023-07-31 07:52:04 +00:00
|
|
|
let pst = pubSubTopic.alloc()
|
2024-09-11 16:11:59 +00:00
|
|
|
defer:
|
|
|
|
deallocShared(pst)
|
2024-11-29 14:31:08 +00:00
|
|
|
var cb = onReceivedMessage(ctx)
|
2024-09-11 16:11:59 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.RELAY,
|
|
|
|
RelayRequest.createShared(
|
|
|
|
RelayMsgType.SUBSCRIBE, PubsubTopic($pst), WakuRelayHandler(cb)
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
|
|
|
proc waku_relay_unsubscribe(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-10-23 06:37:28 +00:00
|
|
|
|
2023-07-31 07:52:04 +00:00
|
|
|
let pst = pubSubTopic.alloc()
|
2024-09-11 16:11:59 +00:00
|
|
|
defer:
|
|
|
|
deallocShared(pst)
|
2023-09-18 07:21:50 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.RELAY,
|
|
|
|
RelayRequest.createShared(
|
2024-12-12 12:06:54 +00:00
|
|
|
RelayMsgType.UNSUBSCRIBE,
|
2024-03-15 23:08:47 +00:00
|
|
|
PubsubTopic($pst),
|
2024-11-29 14:31:08 +00:00
|
|
|
WakuRelayHandler(onReceivedMessage(ctx)),
|
2024-03-15 23:08:47 +00:00
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2024-08-29 12:29:02 +00:00
|
|
|
proc waku_relay_get_num_connected_peers(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
2024-08-29 12:29:02 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
|
|
|
let pst = pubSubTopic.alloc()
|
|
|
|
defer:
|
|
|
|
deallocShared(pst)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-08-29 12:29:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.RELAY,
|
|
|
|
RelayRequest.createShared(RelayMsgType.LIST_CONNECTED_PEERS, PubsubTopic($pst)),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-08-29 12:29:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc waku_relay_get_num_peers_in_mesh(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
2024-08-29 12:29:02 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
|
|
|
let pst = pubSubTopic.alloc()
|
|
|
|
defer:
|
|
|
|
deallocShared(pst)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-08-29 12:29:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.RELAY,
|
|
|
|
RelayRequest.createShared(RelayMsgType.LIST_MESH_PEERS, PubsubTopic($pst)),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-08-29 12:29:02 +00:00
|
|
|
)
|
|
|
|
|
2024-11-29 14:31:08 +00:00
|
|
|
proc waku_filter_subscribe(
|
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
contentTopics: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-11-29 14:31:08 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-11-29 14:31:08 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.FILTER,
|
|
|
|
FilterRequest.createShared(
|
|
|
|
FilterMsgType.SUBSCRIBE,
|
|
|
|
pubSubTopic,
|
|
|
|
contentTopics,
|
|
|
|
FilterPushHandler(onReceivedMessage(ctx)),
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-11-29 14:31:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc waku_filter_unsubscribe(
|
|
|
|
ctx: ptr WakuContext,
|
|
|
|
pubSubTopic: cstring,
|
|
|
|
contentTopics: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-11-29 14:31:08 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-11-29 14:31:08 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.FILTER,
|
|
|
|
FilterRequest.createShared(FilterMsgType.UNSUBSCRIBE, pubSubTopic, contentTopics),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-11-29 14:31:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
proc waku_filter_unsubscribe_all(
|
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-11-29 14:31:08 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
|
|
|
ctx,
|
|
|
|
RequestType.FILTER,
|
|
|
|
FilterRequest.createShared(FilterMsgType.UNSUBSCRIBE_ALL),
|
|
|
|
callback,
|
|
|
|
userData,
|
2024-11-29 14:31:08 +00:00
|
|
|
)
|
|
|
|
|
2024-08-29 12:29:02 +00:00
|
|
|
proc waku_lightpush_publish(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-08-29 12:29:02 +00:00
|
|
|
pubSubTopic: cstring,
|
|
|
|
jsonWakuMessage: cstring,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc, cdecl.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
|
|
|
let jwm = jsonWakuMessage.alloc()
|
|
|
|
let pst = pubSubTopic.alloc()
|
|
|
|
defer:
|
|
|
|
deallocShared(jwm)
|
|
|
|
deallocShared(pst)
|
|
|
|
|
|
|
|
var jsonMessage: JsonMessage
|
|
|
|
try:
|
|
|
|
let jsonContent = parseJson($jwm)
|
2024-12-10 17:52:21 +00:00
|
|
|
jsonMessage = JsonMessage.fromJsonNode(jsonContent).valueOr:
|
|
|
|
raise newException(JsonParsingError, $error)
|
2024-08-29 12:29:02 +00:00
|
|
|
except JsonParsingError:
|
|
|
|
let msg = fmt"Error parsing json message: {getCurrentExceptionMsg()}"
|
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
|
|
|
return RET_ERR
|
|
|
|
|
|
|
|
let wakuMessage = jsonMessage.toWakuMessage().valueOr:
|
2024-09-09 08:45:14 +00:00
|
|
|
let msg = "Problem building the WakuMessage: " & $error
|
2024-08-29 12:29:02 +00:00
|
|
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
|
|
|
return RET_ERR
|
|
|
|
|
|
|
|
let targetPubSubTopic =
|
|
|
|
if len(pst) == 0:
|
|
|
|
DefaultPubsubTopic
|
|
|
|
else:
|
|
|
|
$pst
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-08-29 12:29:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.LIGHTPUSH,
|
|
|
|
LightpushRequest.createShared(
|
|
|
|
LightpushMsgType.PUBLISH, PubsubTopic($pst), wakuMessage
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-08-29 12:29:02 +00:00
|
|
|
)
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_connect(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-03-15 23:08:47 +00:00
|
|
|
peerMultiAddr: cstring,
|
|
|
|
timeoutMs: cuint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2023-10-23 06:37:28 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
|
|
|
PeerManagementRequest.createShared(
|
|
|
|
PeerManagementMsgType.CONNECT_TO, $peerMultiAddr, chronos.milliseconds(timeoutMs)
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-05-12 16:08:41 +00:00
|
|
|
|
2024-10-15 12:32:02 +00:00
|
|
|
proc waku_disconnect_peer_by_id(
|
|
|
|
ctx: ptr WakuContext, peerId: cstring, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-15 12:32:02 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-15 12:32:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
|
|
|
PeerManagementRequest.createShared(
|
|
|
|
op = PeerManagementMsgType.DISCONNECT_PEER_BY_ID, peerId = $peerId
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-15 12:32:02 +00:00
|
|
|
)
|
|
|
|
|
2024-10-30 14:26:33 +00:00
|
|
|
proc waku_dial_peer(
|
|
|
|
ctx: ptr WakuContext,
|
|
|
|
peerMultiAddr: cstring,
|
|
|
|
protocol: cstring,
|
|
|
|
timeoutMs: cuint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-30 14:26:33 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-30 14:26:33 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
|
|
|
PeerManagementRequest.createShared(
|
|
|
|
op = PeerManagementMsgType.DIAL_PEER,
|
|
|
|
peerMultiAddr = $peerMultiAddr,
|
|
|
|
protocol = $protocol,
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-30 14:26:33 +00:00
|
|
|
)
|
|
|
|
|
2024-10-15 12:32:02 +00:00
|
|
|
proc waku_dial_peer_by_id(
|
|
|
|
ctx: ptr WakuContext,
|
|
|
|
peerId: cstring,
|
|
|
|
protocol: cstring,
|
|
|
|
timeoutMs: cuint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-15 12:32:02 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-15 12:32:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
|
|
|
PeerManagementRequest.createShared(
|
2024-10-30 14:26:33 +00:00
|
|
|
op = PeerManagementMsgType.DIAL_PEER_BY_ID, peerId = $peerId, protocol = $protocol
|
2024-10-15 12:32:02 +00:00
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-15 12:32:02 +00:00
|
|
|
)
|
|
|
|
|
2024-09-11 08:13:54 +00:00
|
|
|
proc waku_get_peerids_from_peerstore(
|
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-09-11 08:13:54 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-09-11 08:13:54 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
2024-09-20 11:23:53 +00:00
|
|
|
PeerManagementRequest.createShared(PeerManagementMsgType.GET_ALL_PEER_IDS),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 08:13:54 +00:00
|
|
|
)
|
|
|
|
|
2024-10-30 14:26:33 +00:00
|
|
|
proc waku_get_connected_peers(
|
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-30 14:26:33 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-30 14:26:33 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
|
|
|
PeerManagementRequest.createShared(PeerManagementMsgType.GET_CONNECTED_PEERS),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-30 14:26:33 +00:00
|
|
|
)
|
|
|
|
|
2024-09-11 08:13:54 +00:00
|
|
|
proc waku_get_peerids_by_protocol(
|
|
|
|
ctx: ptr WakuContext, protocol: cstring, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-09-11 08:13:54 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-09-11 08:13:54 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PEER_MANAGER,
|
2024-10-15 12:32:02 +00:00
|
|
|
PeerManagementRequest.createShared(
|
|
|
|
op = PeerManagementMsgType.GET_PEER_IDS_BY_PROTOCOL, protocol = $protocol
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 08:13:54 +00:00
|
|
|
)
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_store_query(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-08-29 12:29:02 +00:00
|
|
|
jsonQuery: cstring,
|
|
|
|
peerAddr: cstring,
|
2024-03-15 23:08:47 +00:00
|
|
|
timeoutMs: cint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-08-29 12:29:02 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.STORE,
|
2024-08-29 20:57:23 +00:00
|
|
|
JsonStoreQueryRequest.createShared(jsonQuery, peerAddr, timeoutMs),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-08-29 12:29:02 +00:00
|
|
|
)
|
2023-12-11 07:49:13 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc waku_listen_addresses(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-03-15 23:08:47 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-02-21 11:06:05 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-03-15 23:08:47 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.DEBUG,
|
|
|
|
DebugNodeRequest.createShared(DebugNodeMsgType.RETRIEVE_LISTENING_ADDRESSES),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2024-02-21 11:06:05 +00:00
|
|
|
|
2024-05-21 16:37:50 +00:00
|
|
|
proc waku_dns_discovery(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext,
|
2024-05-21 16:37:50 +00:00
|
|
|
entTreeUrl: cstring,
|
|
|
|
nameDnsServer: cstring,
|
|
|
|
timeoutMs: cint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-05-21 16:37:50 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-05-21 16:37:50 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.DISCOVERY,
|
|
|
|
DiscoveryRequest.createRetrieveBootstrapNodesRequest(
|
|
|
|
DiscoveryMsgType.GET_BOOTSTRAP_NODES, entTreeUrl, nameDnsServer, timeoutMs
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 16:11:59 +00:00
|
|
|
)
|
2024-05-21 16:37:50 +00:00
|
|
|
|
|
|
|
proc waku_discv5_update_bootnodes(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, bootnodes: cstring, callback: WakuCallBack, userData: pointer
|
2024-05-21 16:37:50 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
|
|
|
## Updates the bootnode list used for discovering new peers via DiscoveryV5
|
|
|
|
## bootnodes - JSON array containing the bootnode ENRs i.e. `["enr:...", "enr:..."]`
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-05-21 16:37:50 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-05-21 16:37:50 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.DISCOVERY,
|
|
|
|
DiscoveryRequest.createUpdateBootstrapNodesRequest(
|
|
|
|
DiscoveryMsgType.UPDATE_DISCV5_BOOTSTRAP_NODES, bootnodes
|
|
|
|
),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 16:11:59 +00:00
|
|
|
)
|
2024-05-21 16:37:50 +00:00
|
|
|
|
2024-08-22 10:01:14 +00:00
|
|
|
proc waku_get_my_enr(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-08-22 10:01:14 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-22 10:01:14 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-08-22 10:01:14 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.DEBUG,
|
|
|
|
DebugNodeRequest.createShared(DebugNodeMsgType.RETRIEVE_MY_ENR),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-08-22 10:01:14 +00:00
|
|
|
)
|
|
|
|
|
2024-10-17 16:13:00 +00:00
|
|
|
proc waku_get_my_peerid(
|
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-17 16:13:00 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-17 16:13:00 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.DEBUG,
|
|
|
|
DebugNodeRequest.createShared(DebugNodeMsgType.RETRIEVE_MY_PEER_ID),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-17 16:13:00 +00:00
|
|
|
)
|
|
|
|
|
2024-08-29 12:29:02 +00:00
|
|
|
proc waku_start_discv5(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-08-29 12:29:02 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
|
|
|
ctx,
|
|
|
|
RequestType.DISCOVERY,
|
|
|
|
DiscoveryRequest.createDiscV5StartRequest(),
|
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 16:11:59 +00:00
|
|
|
)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
|
|
|
proc waku_stop_discv5(
|
2024-08-29 20:57:23 +00:00
|
|
|
ctx: ptr WakuContext, callback: WakuCallBack, userData: pointer
|
2024-08-29 12:29:02 +00:00
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-08-29 20:57:23 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
|
|
|
ctx,
|
|
|
|
RequestType.DISCOVERY,
|
|
|
|
DiscoveryRequest.createDiscV5StopRequest(),
|
|
|
|
callback,
|
|
|
|
userData,
|
2024-09-11 16:11:59 +00:00
|
|
|
)
|
2024-08-29 12:29:02 +00:00
|
|
|
|
2024-09-11 08:13:54 +00:00
|
|
|
proc waku_peer_exchange_request(
|
|
|
|
ctx: ptr WakuContext, numPeers: uint64, callback: WakuCallBack, userData: pointer
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-09-11 08:13:54 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
|
|
|
ctx,
|
|
|
|
RequestType.DISCOVERY,
|
|
|
|
DiscoveryRequest.createPeerExchangeRequest(numPeers),
|
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-11 10:57:55 +00:00
|
|
|
)
|
2024-09-11 08:13:54 +00:00
|
|
|
|
2024-10-24 13:07:08 +00:00
|
|
|
proc waku_ping_peer(
|
|
|
|
ctx: ptr WakuContext,
|
2024-11-08 07:36:16 +00:00
|
|
|
peerAddr: cstring,
|
2024-10-24 13:07:08 +00:00
|
|
|
timeoutMs: cuint,
|
|
|
|
callback: WakuCallBack,
|
|
|
|
userData: pointer,
|
|
|
|
): cint {.dynlib, exportc.} =
|
2024-12-02 14:56:12 +00:00
|
|
|
initializeLibrary()
|
2024-10-24 13:07:08 +00:00
|
|
|
checkLibwakuParams(ctx, callback, userData)
|
|
|
|
|
2024-12-02 14:56:12 +00:00
|
|
|
handleRequest(
|
2024-10-24 13:07:08 +00:00
|
|
|
ctx,
|
|
|
|
RequestType.PING,
|
2024-11-08 07:36:16 +00:00
|
|
|
PingRequest.createShared(peerAddr, chronos.milliseconds(timeoutMs)),
|
2024-12-02 14:56:12 +00:00
|
|
|
callback,
|
|
|
|
userData,
|
2024-10-24 13:07:08 +00:00
|
|
|
)
|
|
|
|
|
2023-05-12 16:08:41 +00:00
|
|
|
### End of exported procs
|
2023-06-29 19:59:53 +00:00
|
|
|
################################################################################
|