From 4198a50cd13c62e2e41b394b56e291387e1f973e Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Thu, 5 Feb 2026 17:06:12 +0530 Subject: [PATCH] add apis to know peercounts --- library/kernel_api/debug_node_api.nim | 16 ++++++++++++++++ library/kernel_api/protocols/store_api.nim | 8 +++++++- simulations/mixnet/config.toml | 6 +++--- simulations/mixnet/config1.toml | 8 ++++---- simulations/mixnet/config2.toml | 8 ++++---- simulations/mixnet/config3.toml | 8 ++++---- simulations/mixnet/config4.toml | 8 ++++---- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/library/kernel_api/debug_node_api.nim b/library/kernel_api/debug_node_api.nim index 98f5332b4..702632d3a 100644 --- a/library/kernel_api/debug_node_api.nim +++ b/library/kernel_api/debug_node_api.nim @@ -9,6 +9,7 @@ import metrics, ffi import waku/factory/waku, waku/node/waku_node, waku/node/health_monitor, library/declare_lib +import waku/waku_core/codecs proc getMultiaddresses(node: WakuNode): seq[string] = return node.info().listenAddresses @@ -47,3 +48,18 @@ proc waku_is_online( ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer ) {.ffi.} = return ok($ctx.myLib[].healthMonitor.onlineMonitor.amIOnline()) + +proc waku_get_mixnode_pool_size( + ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer +) {.ffi.} = + ## Returns the number of mix nodes in the pool + if ctx.myLib[].node.wakuMix.isNil(): + return ok("0") + return ok($ctx.myLib[].node.getMixNodePoolSize()) + +proc waku_get_lightpush_peers_count( + ctx: ptr FFIContext[Waku], callback: FFICallBack, userData: pointer +) {.ffi.} = + ## Returns the count of all peers in peerstore supporting lightpush protocol + let peers = ctx.myLib[].node.peerManager.switch.peerStore.getPeersByProtocol(WakuLightPushCodec) + return ok($peers.len) diff --git a/library/kernel_api/protocols/store_api.nim b/library/kernel_api/protocols/store_api.nim index 0df4d9b1f..7de276689 100644 --- a/library/kernel_api/protocols/store_api.nim +++ b/library/kernel_api/protocols/store_api.nim @@ -8,8 +8,13 @@ import waku/waku_store/common, waku/waku_store/client, waku/common/paging, + waku/common/base64, library/declare_lib +# Custom JSON serialization for seq[byte] to avoid ambiguity +proc `%`*(data: seq[byte]): JsonNode = + %base64.encode(data) + func fromJsonNode(jsonContent: JsonNode): Result[StoreQueryRequest, string] = var contentTopics: seq[string] if jsonContent.contains("contentTopics"): @@ -90,5 +95,6 @@ proc waku_store_query( ).valueOr: return err("StoreRequest failed store query: " & $error) - let res = $(%*(queryResponse.toHex())) + let hexResponse = queryResponse.toHex() + let res = $(%*hexResponse) return ok(res) ## returning the response in json format diff --git a/simulations/mixnet/config.toml b/simulations/mixnet/config.toml index bd051cff1..2d9528c88 100644 --- a/simulations/mixnet/config.toml +++ b/simulations/mixnet/config.toml @@ -5,10 +5,10 @@ filter = true store = false lightpush = true max-connections = 150 -peer-exchange = false +peer-exchange = true metrics-logging = false cluster-id = 2 -discv5-discovery = false +discv5-discovery = true discv5-udp-port = 9000 discv5-enr-auto-update = true enable-kad-discovery = true @@ -20,7 +20,7 @@ shard = [0] agent-string = "nwaku-mix" nodekey = "f98e3fba96c32e8d1967d460f1b79457380e1a895f7971cecc8528abe733781a" mixkey = "a87db88246ec0eedda347b9b643864bee3d6933eb15ba41e6d58cb678d813258" -rendezvous = false +rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" ext-multiaddr = ["/ip4/127.0.0.1/tcp/60001"] diff --git a/simulations/mixnet/config1.toml b/simulations/mixnet/config1.toml index 1a28a5104..19a2960e8 100644 --- a/simulations/mixnet/config1.toml +++ b/simulations/mixnet/config1.toml @@ -5,12 +5,12 @@ filter = true store = false lightpush = true max-connections = 150 -peer-exchange = false +peer-exchange = true metrics-logging = false cluster-id = 2 -discv5-discovery = false +discv5-discovery = true discv5-udp-port = 9001 -discv5-enr-auto-update = false +discv5-enr-auto-update = true discv5-bootstrap-node = ["enr:-LG4QBaAbcA921hmu3IrreLqGZ4y3VWCjBCgNN9mpX9vqkkbSrM3HJHZTXnb5iVXgc5pPtDhWLxkB6F3yY25hSwMezkEgmlkgnY0gmlwhH8AAAGKbXVsdGlhZGRyc4oACATAqEQ-BuphgnJzhQACAQAAiXNlY3AyNTZrMaEDpEW1UlUGHRJg6g_zGuCddKWmIUBGZCQX13xGfh9J6KiDdGNwguphg3VkcIIjKYV3YWt1Mg0"] kad-bootstrap-node = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"] rest = true @@ -21,7 +21,7 @@ shard = [0] agent-string = "nwaku-mix" nodekey = "09e9d134331953357bd38bbfce8edb377f4b6308b4f3bfbe85c610497053d684" mixkey = "c86029e02c05a7e25182974b519d0d52fcbafeca6fe191fbb64857fb05be1a53" -rendezvous = false +rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" ext-multiaddr = ["/ip4/127.0.0.1/tcp/60002"] diff --git a/simulations/mixnet/config2.toml b/simulations/mixnet/config2.toml index 3a8da0a13..a10f8cb11 100644 --- a/simulations/mixnet/config2.toml +++ b/simulations/mixnet/config2.toml @@ -5,12 +5,12 @@ filter = true store = false lightpush = true max-connections = 150 -peer-exchange = false +peer-exchange = true metrics-logging = false cluster-id = 2 -discv5-discovery = false +discv5-discovery = true discv5-udp-port = 9002 -discv5-enr-auto-update = false +discv5-enr-auto-update = true discv5-bootstrap-node = ["enr:-LG4QBaAbcA921hmu3IrreLqGZ4y3VWCjBCgNN9mpX9vqkkbSrM3HJHZTXnb5iVXgc5pPtDhWLxkB6F3yY25hSwMezkEgmlkgnY0gmlwhH8AAAGKbXVsdGlhZGRyc4oACATAqEQ-BuphgnJzhQACAQAAiXNlY3AyNTZrMaEDpEW1UlUGHRJg6g_zGuCddKWmIUBGZCQX13xGfh9J6KiDdGNwguphg3VkcIIjKYV3YWt1Mg0"] kad-bootstrap-node = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"] rest = false @@ -21,7 +21,7 @@ shard = [0] agent-string = "nwaku-mix" nodekey = "ed54db994682e857d77cd6fb81be697382dc43aa5cd78e16b0ec8098549f860e" mixkey = "b858ac16bbb551c4b2973313b1c8c8f7ea469fca03f1608d200bbf58d388ec7f" -rendezvous = false +rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" ext-multiaddr = ["/ip4/127.0.0.1/tcp/60003"] diff --git a/simulations/mixnet/config3.toml b/simulations/mixnet/config3.toml index 7265f2323..41baafacc 100644 --- a/simulations/mixnet/config3.toml +++ b/simulations/mixnet/config3.toml @@ -5,12 +5,12 @@ filter = true store = false lightpush = true max-connections = 150 -peer-exchange = false +peer-exchange = true metrics-logging = false cluster-id = 2 -discv5-discovery = false +discv5-discovery = true discv5-udp-port = 9003 -discv5-enr-auto-update = false +discv5-enr-auto-update = true discv5-bootstrap-node = ["enr:-LG4QBaAbcA921hmu3IrreLqGZ4y3VWCjBCgNN9mpX9vqkkbSrM3HJHZTXnb5iVXgc5pPtDhWLxkB6F3yY25hSwMezkEgmlkgnY0gmlwhH8AAAGKbXVsdGlhZGRyc4oACATAqEQ-BuphgnJzhQACAQAAiXNlY3AyNTZrMaEDpEW1UlUGHRJg6g_zGuCddKWmIUBGZCQX13xGfh9J6KiDdGNwguphg3VkcIIjKYV3YWt1Mg0"] kad-bootstrap-node = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"] rest = false @@ -21,7 +21,7 @@ shard = [0] agent-string = "nwaku-mix" nodekey = "42f96f29f2d6670938b0864aced65a332dcf5774103b4c44ec4d0ea4ef3c47d6" mixkey = "d8bd379bb394b0f22dd236d63af9f1a9bc45266beffc3fbbe19e8b6575f2535b" -rendezvous = false +rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" ext-multiaddr = ["/ip4/127.0.0.1/tcp/60004"] diff --git a/simulations/mixnet/config4.toml b/simulations/mixnet/config4.toml index f127f9b72..549939917 100644 --- a/simulations/mixnet/config4.toml +++ b/simulations/mixnet/config4.toml @@ -5,12 +5,12 @@ filter = true store = false lightpush = true max-connections = 150 -peer-exchange = false +peer-exchange = true metrics-logging = false cluster-id = 2 -discv5-discovery = false +discv5-discovery = true discv5-udp-port = 9004 -discv5-enr-auto-update = false +discv5-enr-auto-update = true discv5-bootstrap-node = ["enr:-LG4QBaAbcA921hmu3IrreLqGZ4y3VWCjBCgNN9mpX9vqkkbSrM3HJHZTXnb5iVXgc5pPtDhWLxkB6F3yY25hSwMezkEgmlkgnY0gmlwhH8AAAGKbXVsdGlhZGRyc4oACATAqEQ-BuphgnJzhQACAQAAiXNlY3AyNTZrMaEDpEW1UlUGHRJg6g_zGuCddKWmIUBGZCQX13xGfh9J6KiDdGNwguphg3VkcIIjKYV3YWt1Mg0"] kad-bootstrap-node = ["/ip4/127.0.0.1/tcp/60001/p2p/16Uiu2HAmPiEs2ozjjJF2iN2Pe2FYeMC9w4caRHKYdLdAfjgbWM6o"] rest = false @@ -21,7 +21,7 @@ shard = [0] agent-string = "nwaku-mix" nodekey = "3ce887b3c34b7a92dd2868af33941ed1dbec4893b054572cd5078da09dd923d4" mixkey = "780fff09e51e98df574e266bf3266ec6a3a1ddfcf7da826a349a29c137009d49" -rendezvous = false +rendezvous = true listen-address = "127.0.0.1" nat = "extip:127.0.0.1" ext-multiaddr = ["/ip4/127.0.0.1/tcp/60005"]