2024-05-18 15:04:04 +02:00
|
|
|
import std/json
|
2025-06-12 12:49:05 +02:00
|
|
|
import
|
|
|
|
|
chronicles,
|
|
|
|
|
chronos,
|
|
|
|
|
results,
|
|
|
|
|
eth/p2p/discoveryv5/enr,
|
|
|
|
|
strutils,
|
|
|
|
|
libp2p/peerid,
|
|
|
|
|
metrics
|
2025-06-16 18:44:21 +02:00
|
|
|
import
|
2025-06-26 11:27:39 +02:00
|
|
|
../../../waku/factory/waku,
|
|
|
|
|
../../../waku/node/waku_node,
|
|
|
|
|
../../../waku/node/health_monitor
|
2024-02-21 12:06:05 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
type DebugNodeMsgType* = enum
|
|
|
|
|
RETRIEVE_LISTENING_ADDRESSES
|
2024-08-22 12:01:14 +02:00
|
|
|
RETRIEVE_MY_ENR
|
2024-10-17 19:13:00 +03:00
|
|
|
RETRIEVE_MY_PEER_ID
|
2025-06-12 12:49:05 +02:00
|
|
|
RETRIEVE_METRICS
|
2025-06-16 18:44:21 +02:00
|
|
|
RETRIEVE_ONLINE_STATE
|
2025-06-24 23:20:08 +02:00
|
|
|
CHECK_WAKU_NOT_BLOCKED
|
2024-02-21 12:06:05 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
type DebugNodeRequest* = object
|
|
|
|
|
operation: DebugNodeMsgType
|
2024-02-21 12:06:05 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
proc createShared*(T: type DebugNodeRequest, op: DebugNodeMsgType): ptr type T =
|
2024-02-21 12:06:05 +01:00
|
|
|
var ret = createShared(T)
|
|
|
|
|
ret[].operation = op
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
proc destroyShared(self: ptr DebugNodeRequest) =
|
|
|
|
|
deallocShared(self)
|
|
|
|
|
|
|
|
|
|
proc getMultiaddresses(node: WakuNode): seq[string] =
|
|
|
|
|
return node.info().listenAddresses
|
|
|
|
|
|
2025-06-12 12:49:05 +02:00
|
|
|
proc getMetrics(): string =
|
|
|
|
|
{.gcsafe.}:
|
|
|
|
|
return defaultRegistry.toText() ## defaultRegistry is {.global.} in metrics module
|
|
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
proc process*(
|
2024-05-03 14:07:15 +02:00
|
|
|
self: ptr DebugNodeRequest, waku: Waku
|
2024-03-16 00:08:47 +01:00
|
|
|
): Future[Result[string, string]] {.async.} =
|
|
|
|
|
defer:
|
|
|
|
|
destroyShared(self)
|
2024-02-21 12:06:05 +01:00
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
case self.operation
|
|
|
|
|
of RETRIEVE_LISTENING_ADDRESSES:
|
2024-10-16 14:07:23 +03:00
|
|
|
## returns a comma-separated string of the listen addresses
|
|
|
|
|
return ok(waku.node.getMultiaddresses().join(","))
|
2024-08-22 12:01:14 +02:00
|
|
|
of RETRIEVE_MY_ENR:
|
2024-10-08 17:22:49 +03:00
|
|
|
return ok(waku.node.enr.toURI())
|
2024-10-17 19:13:00 +03:00
|
|
|
of RETRIEVE_MY_PEER_ID:
|
|
|
|
|
return ok($waku.node.peerId())
|
2025-06-12 12:49:05 +02:00
|
|
|
of RETRIEVE_METRICS:
|
|
|
|
|
return ok(getMetrics())
|
2025-06-16 18:44:21 +02:00
|
|
|
of RETRIEVE_ONLINE_STATE:
|
|
|
|
|
return ok($waku.healthMonitor.onlineMonitor.amIOnline())
|
2025-06-24 23:20:08 +02:00
|
|
|
of CHECK_WAKU_NOT_BLOCKED:
|
|
|
|
|
return ok("waku thread is not blocked")
|
2024-02-21 12:06:05 +01:00
|
|
|
|
2024-10-01 12:23:04 +03:00
|
|
|
error "unsupported operation in DebugNodeRequest"
|
2024-02-21 12:06:05 +01:00
|
|
|
return err("unsupported operation in DebugNodeRequest")
|