mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-24 05:23:16 +00:00
* rename NetworkConf -> NetworkPresetConf and related procs/vars * Rewrite applyNetworkPresetConf to apply user-set fields over preset fields * New dedicated parser for configJson * Fix tests to use actual extract JSON nodeconf parser * Change all confbuilder defaults from literal values to DefaultXXX consts * Change int/bool WakuNodeConf fields to Option to get user intent w/o sentinels * Make Option CLI default-value help mention defaults now owned by confbuilder * Document CLI defaults that differ from confbuilder defaults * Fix agent-string builder default deviating from CLI default * Add WakuConfBuilder.enforceSecurityConstraints() * Fail on RLN user preset overrides instead of drop-and-continue * Add regression tests for initial set of conf constraints * fix kademliaDiscoveryConfBuilder.build() enable/disable kad logic * Misc refactors, fixes * Add tests Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
56 lines
1.7 KiB
Nim
56 lines
1.7 KiB
Nim
import std/[net, options]
|
|
|
|
import chronicles, chronos, libp2p/peerid, results
|
|
|
|
import logos_delivery/waku/factory/waku
|
|
import logos_delivery/messaging/messaging_client
|
|
import logos_delivery/waku/[requests/health_requests, waku_core, waku_node]
|
|
import logos_delivery/messaging/delivery_service/send_service
|
|
import logos_delivery/waku/node/subscription_manager
|
|
import libp2p/peerid
|
|
import tools/confutils/cli_args
|
|
import ./[api_conf, types]
|
|
|
|
export cli_args
|
|
|
|
logScope:
|
|
topics = "api"
|
|
|
|
proc createNode*(conf: WakuNodeConf): Future[Result[Waku, string]] {.async.} =
|
|
let wakuConf = conf.toWakuConf().valueOr:
|
|
return err("Failed to handle the configuration: " & error)
|
|
|
|
## We are not defining app callbacks at node creation
|
|
let wakuRes = (await Waku.new(wakuConf)).valueOr:
|
|
error "waku initialization failed", error = error
|
|
return err("Failed setting up Waku: " & $error)
|
|
|
|
return ok(wakuRes)
|
|
|
|
proc checkApiAvailability(w: Waku): Result[void, string] =
|
|
if w.isNil():
|
|
return err("Waku node is not initialized")
|
|
|
|
# TODO: Conciliate request-bouncing health checks here with unit testing.
|
|
# (For now, better to just allow all sends and rely on retries.)
|
|
|
|
return ok()
|
|
|
|
proc subscribe*(
|
|
w: Waku, contentTopic: ContentTopic
|
|
): Future[Result[void, string]] {.async.} =
|
|
?checkApiAvailability(w)
|
|
|
|
return w.node.subscriptionManager.subscribe(contentTopic)
|
|
|
|
proc unsubscribe*(w: Waku, contentTopic: ContentTopic): Result[void, string] =
|
|
?checkApiAvailability(w)
|
|
|
|
return w.node.subscriptionManager.unsubscribe(contentTopic)
|
|
|
|
proc send*(
|
|
w: Waku, envelope: MessageEnvelope
|
|
): Future[Result[RequestId, string]] {.async.} =
|
|
?checkApiAvailability(w)
|
|
return await w.messagingClient.send(envelope)
|