mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-06-16 14:39:34 +00:00
* bump nim-libp2p pin to v2.0.0 tag * bump json_rpc to v0.6.1, lsquic to v0.5.1, boringssl to v0.0.8 (latest tags) * add libp2p_mix dep; repoint libp2p/protocols/mix -> libp2p_mix * pin nimble.lock: websock / protobuf_serialization / npeg / jwt * Makefile: add -d:libp2p_quic_support * regenerate nix/deps.nix (adds libp2p_mix, refreshes pins) * migrate rng ref HmacDrbgContext -> libp2p Rng across prod/channels/tests (interface-only; same DRBG) * waku_switch: TransportConfig factory; unified 2.0.0 connection limits (withMaxInOut, withMaxConnections); local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery rename) * call Service.setup() on post-build switch services (2.0.0 split setup/start) * drop libp2p/utils/semaphore -> chronos AsyncSemaphore * add logos_delivery/waku/compat/option_valueor shim (Option[T] valueOr/withValue, dropped upstream) * add std/options where a transitive re-export was removed * add newStandardSwitch shim (libp2p removed it in 2.0.0); mounts yamux+mplex to match prod muxer * PeerId.random(rng); common.rng()/crypto.newRng(); hoist shared rng (instantiation cleanup) * update expectations for 2.0.0 defaults: DEFAULT_PROTOCOLS += /ipfs/id/push/1.0.0; agent "nim-libp2p" * drop relay reboot/reconnect test (asserted a Switch restart capability that is simply not supported) * fix up a few tests that were flaking on MacOS (libp2p upgrade may have exposed these)
87 lines
3.0 KiB
Nim
87 lines
3.0 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
import std/[options, json, strutils, net]
|
|
import chronos, chronicles, results, confutils, confutils/std/net, ffi
|
|
|
|
import
|
|
logos_delivery/waku/node/peer_manager/peer_manager,
|
|
tools/confutils/cli_args,
|
|
logos_delivery/waku/factory/waku,
|
|
logos_delivery/waku/factory/node_factory,
|
|
logos_delivery/waku/factory/app_callbacks,
|
|
logos_delivery/waku/rest_api/endpoint/builder,
|
|
library/declare_lib
|
|
|
|
proc createWaku(
|
|
configJson: cstring, appCallbacks: AppCallbacks = nil
|
|
): Future[Result[Waku, string]] {.async.} =
|
|
var conf = defaultWakuNodeConf().valueOr:
|
|
return err("Failed creating node: " & error)
|
|
|
|
var errorResp: string
|
|
|
|
var jsonNode: JsonNode
|
|
try:
|
|
jsonNode = parseJson($configJson)
|
|
except Exception:
|
|
return err(
|
|
"exception in createWaku when calling parseJson: " & getCurrentExceptionMsg() &
|
|
" configJson string: " & $configJson
|
|
)
|
|
|
|
for confField, confValue in fieldPairs(conf):
|
|
if jsonNode.contains(confField):
|
|
# Make sure string doesn't contain the leading or trailing " character
|
|
let formattedString = ($jsonNode[confField]).strip(chars = {'\"'})
|
|
# Override conf field with the value set in the json-string
|
|
try:
|
|
confValue = parseCmdArg(typeof(confValue), formattedString)
|
|
except Exception:
|
|
return err(
|
|
"exception in createWaku when parsing configuration. exc: " &
|
|
getCurrentExceptionMsg() & ". string that could not be parsed: " &
|
|
formattedString & ". expected type: " & $typeof(confValue)
|
|
)
|
|
|
|
# Don't send relay app callbacks if relay is disabled
|
|
if not conf.relay and not appCallbacks.isNil():
|
|
appCallbacks.relayHandler = nil
|
|
appCallbacks.topicHealthChangeHandler = nil
|
|
|
|
# TODO: Convert `confJson` directly to `WakuConf`
|
|
var wakuConf = conf.toWakuConf().valueOr:
|
|
return err("Configuration error: " & $error)
|
|
|
|
wakuConf.restServerConf = none(RestServerConf) ## don't want REST in libwaku
|
|
|
|
let wakuRes = (await Waku.new(wakuConf, appCallbacks)).valueOr:
|
|
error "waku initialization failed", error = error
|
|
return err("Failed setting up Waku: " & $error)
|
|
|
|
return ok(wakuRes)
|
|
|
|
registerReqFFI(CreateNodeWithCallbacksRequest, ctx: ptr FFIContext[Waku]):
|
|
proc(
|
|
configJson: cstring, appCallbacks: AppCallbacks
|
|
): Future[Result[string, string]] {.async.} =
|
|
ctx.myLib[] = (await createWaku(configJson, cast[AppCallbacks](appCallbacks))).valueOr:
|
|
error "CreateNodeWithCallbacksRequest failed", error = error
|
|
return err($error)
|
|
|
|
return ok("")
|
|
|
|
proc waku_start(
|
|
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
|
) {.ffi.} =
|
|
(await ctx.myLib[].start()).isOkOr:
|
|
error "START_NODE failed", error = error
|
|
return err("failed to start: " & $error)
|
|
return ok("")
|
|
|
|
proc waku_stop(
|
|
ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer
|
|
) {.ffi.} =
|
|
(await ctx.myLib[].stop()).isOkOr:
|
|
error "STOP_NODE failed", error = error
|
|
return err("failed to stop: " & $error)
|
|
return ok("")
|