mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-02-14 10:53:13 +00:00
* Fix protocol strength metric to consider connected peers only * Remove polling loop; event-driven node connection health updates * Remove 10s WakuRelay topic health polling loop; now event-driven * Change NodeHealthStatus to ConnectionStatus * Change new nodeState (rest API /health) field to connectionStatus * Add getSyncProtocolHealthInfo and getSyncNodeHealthReport * Add ConnectionStatusChangeEvent * Add RequestHealthReport * Refactor sync/async protocol health queries in the health monitor * Add EventRelayTopicHealthChange * Add EventWakuPeer emitted by PeerManager * Add Edge support for topics health requests and events * Rename "RelayTopic" -> "Topic" * Add RequestContentTopicsHealth sync request * Add EventContentTopicHealthChange * Rename RequestTopicsHealth -> RequestShardTopicsHealth * Remove health check gating from checkApiAvailability * Add basic health smoke tests * Other misc improvements, refactors, fixes Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Co-authored-by: Ivan FB <128452529+Ivansete-status@users.noreply.github.com>
65 lines
2.1 KiB
Nim
65 lines
2.1 KiB
Nim
import chronicles, chronos, results, std/strutils
|
|
|
|
import waku/factory/waku
|
|
import waku/[requests/health_requests, waku_core, waku_node]
|
|
import waku/node/delivery_service/send_service
|
|
import waku/node/delivery_service/subscription_service
|
|
import ./[api_conf, types]
|
|
|
|
logScope:
|
|
topics = "api"
|
|
|
|
# TODO: Specs says it should return a `WakuNode`. As `send` and other APIs are defined, we can align.
|
|
proc createNode*(config: NodeConfig): Future[Result[Waku, string]] {.async.} =
|
|
let wakuConf = toWakuConf(config).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.deliveryService.subscriptionService.subscribe(contentTopic)
|
|
|
|
proc unsubscribe*(w: Waku, contentTopic: ContentTopic): Result[void, string] =
|
|
?checkApiAvailability(w)
|
|
|
|
return w.deliveryService.subscriptionService.unsubscribe(contentTopic)
|
|
|
|
proc send*(
|
|
w: Waku, envelope: MessageEnvelope
|
|
): Future[Result[RequestId, string]] {.async.} =
|
|
?checkApiAvailability(w)
|
|
|
|
let requestId = RequestId.new(w.rng)
|
|
|
|
let deliveryTask = DeliveryTask.new(requestId, envelope, w.brokerCtx).valueOr:
|
|
return err("API send: Failed to create delivery task: " & error)
|
|
|
|
info "API send: scheduling delivery task",
|
|
requestId = $requestId,
|
|
pubsubTopic = deliveryTask.pubsubTopic,
|
|
contentTopic = deliveryTask.msg.contentTopic,
|
|
msgHash = deliveryTask.msgHash.to0xHex(),
|
|
myPeerId = w.node.peerId()
|
|
|
|
asyncSpawn w.deliveryService.sendService.send(deliveryTask)
|
|
|
|
return ok(requestId)
|