Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion library/kernel_api/debug_node_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import
metrics,
ffi
import
waku/factory/waku, waku/node/waku_node, waku/node/health_monitor, library/declare_lib
waku/factory/waku,
waku/node/waku_node,
waku/node/health_monitor,
library/declare_lib,
waku/waku_core/codecs

proc getMultiaddresses(node: WakuNode): seq[string] =
return node.info().listenAddresses
Expand Down Expand Up @@ -48,3 +52,19 @@ 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)
9 changes: 6 additions & 3 deletions library/kernel_api/protocols/filter_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ proc waku_filter_subscribe(
error "fail filter subscribe", error = errorMsg
return err(errorMsg)

let pubsubTopicOpt =
if ($pubsubTopic).len > 0:
some(PubsubTopic($pubsubTopic))
Comment thread
chaitanyaprem marked this conversation as resolved.
else:
none(PubsubTopic)
let subFut = ctx.myLib[].node.filterSubscribe(
some(PubsubTopic($pubsubTopic)),
($contentTopics).split(",").mapIt(ContentTopic(it)),
peer,
pubsubTopicOpt, ($contentTopics).split(",").mapIt(ContentTopic(it)), peer
)
if not await subFut.withTimeout(FilterOpTimeout):
let errorMsg = "filter subscription timed out"
Expand Down
18 changes: 10 additions & 8 deletions library/kernel_api/protocols/lightpush_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ proc waku_lightpush_publish(
let errorMsg = "failed to lightpublish message, no suitable remote peers"
error "PUBLISH failed", error = errorMsg
return err(errorMsg)
let topic =
if ($pubsubTopic).len == 0:
none(PubsubTopic)
else:
some(PubsubTopic($pubsubTopic))

let msgHashHex = (
await ctx.myLib[].node.wakuLegacyLightpushClient.publish(
$pubsubTopic, msg, peer = peerOpt.get()
)
).valueOr:
error "PUBLISH failed", error = error
return err($error)
let messageHash = (await ctx.myLib[].node.lightpushPublish(topic, msg, peerOpt)).valueOr:
let errorMsg = error.desc.get($error.code.int)
error "PUBLISH failed", error = errorMsg
return err(errorMsg)

return ok(msgHashHex)
return ok($messageHash)
29 changes: 23 additions & 6 deletions library/kernel_api/protocols/relay_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,47 @@ proc waku_relay_subscribe(
callback: FFICallBack,
userData: pointer,
pubSubTopic: cstring,
contentTopic: cstring,
Comment thread
chaitanyaprem marked this conversation as resolved.
) {.ffi.} =
echo "Subscribing to topic: " & $pubSubTopic & " ..."
proc onReceivedMessage(ctx: ptr FFIContext[Waku]): WakuRelayHandler =
return proc(pubsubTopic: PubsubTopic, msg: WakuMessage) {.async.} =
callEventCallback(ctx, "onReceivedMessage"):
$JsonMessageEvent.new(pubsubTopic, msg)

var cb = onReceivedMessage(ctx)

ctx.myLib[].node.subscribe(
(kind: SubscriptionKind.PubsubSub, topic: $pubsubTopic),
handler = WakuRelayHandler(cb),
).isOkOr:
# If contentTopic is provided and non-empty, use ContentSub, otherwise use PubsubSub
let subscription =
if contentTopic != nil and len($contentTopic) > 0:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick :) Applies elsewhere

Suggested change
if contentTopic != nil and len($contentTopic) > 0:
if not isNil(contentTopic) and len($contentTopic) > 0:

echo "Subscribing to content topic: " & $contentTopic & " ..."
(kind: SubscriptionKind.ContentSub, topic: $contentTopic)
else:
echo "Subscribing to pubsub topic: " & $pubSubTopic & " ..."
(kind: SubscriptionKind.PubsubSub, topic: $pubsubTopic)

ctx.myLib[].node.subscribe(subscription, handler = WakuRelayHandler(cb)).isOkOr:
error "SUBSCRIBE failed", error = error
return err($error)
return ok("")

# NOTE: When unsubscribing via contentTopic, this will unsubscribe from the entire
# underlying pubsub topic/shard that the content topic maps to. This affects ALL
# content topics on the same shard, not just the specified content topic.
proc waku_relay_unsubscribe(
ctx: ptr FFIContext[Waku],
callback: FFICallBack,
userData: pointer,
pubSubTopic: cstring,
contentTopic: cstring,
) {.ffi.} =
ctx.myLib[].node.unsubscribe((kind: SubscriptionKind.PubsubSub, topic: $pubsubTopic)).isOkOr:
# If contentTopic is provided and non-empty, use ContentUnsub, otherwise use PubsubUnsub
let subscription =
if contentTopic != nil and len($contentTopic) > 0:
(kind: SubscriptionKind.ContentUnsub, topic: $contentTopic)
else:
(kind: SubscriptionKind.PubsubUnsub, topic: $pubsubTopic)

ctx.myLib[].node.unsubscribe(subscription).isOkOr:
error "UNSUBSCRIBE failed", error = error
return err($error)

Expand Down
8 changes: 7 additions & 1 deletion library/kernel_api/protocols/store_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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
14 changes: 12 additions & 2 deletions library/libwaku.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ extern "C"
int waku_relay_subscribe(void *ctx,
FFICallBack callback,
void *userData,
const char *pubSubTopic);
const char *pubSubTopic,
const char *contentTopic);
Comment thread
chaitanyaprem marked this conversation as resolved.

int waku_relay_add_protected_shard(void *ctx,
FFICallBack callback,
Expand All @@ -97,7 +98,8 @@ extern "C"
int waku_relay_unsubscribe(void *ctx,
FFICallBack callback,
void *userData,
const char *pubSubTopic);
const char *pubSubTopic,
const char *contentTopic);

int waku_filter_subscribe(void *ctx,
FFICallBack callback,
Expand Down Expand Up @@ -247,6 +249,14 @@ extern "C"
FFICallBack callback,
void *userData);

int waku_get_mixnode_pool_size(void *ctx,
FFICallBack callback,
void *userData);

int waku_get_lightpush_peers_count(void *ctx,
FFICallBack callback,
void *userData);
Comment thread
chaitanyaprem marked this conversation as resolved.

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions simulations/mixnet/config2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ discv5-udp-port = 9002
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
rest-admin = false
rest = true
rest-admin = true
ports-shift = 3
num-shards-in-network = 1
shard = [0]
Expand Down
4 changes: 2 additions & 2 deletions simulations/mixnet/config3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ discv5-udp-port = 9003
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
rest-admin = false
rest = true
rest-admin = true
ports-shift = 4
num-shards-in-network = 1
shard = [0]
Expand Down
4 changes: 2 additions & 2 deletions simulations/mixnet/config4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ discv5-udp-port = 9004
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
rest-admin = false
rest = true
rest-admin = true
ports-shift = 5
num-shards-in-network = 1
shard = [0]
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-libp2p
Submodule nim-libp2p updated 40 files
+90 −0 .github/pull_request_template.md
+1 −1 .pinned
+2 −2 README.md
+17 −31 examples/mix_ping.nim
+1 −1 libp2p.nimble
+9 −3 libp2p/builders.nim
+68 −4 libp2p/connmanager.nim
+1 −1 libp2p/dialer.nim
+2 −7 libp2p/protocols/mix.nim
+15 −4 libp2p/protocols/mix/delay_strategy.nim
+29 −265 libp2p/protocols/mix/mix_node.nim
+1 −30 libp2p/protocols/mix/mix_protocol.nim
+5 −0 libp2p/protocols/mix/pool.nim
+44 −54 libp2p/protocols/pubsub/gossipsub.nim
+4 −4 libp2p/protocols/pubsub/gossipsub/behavior.nim
+112 −52 libp2p/protocols/pubsub/gossipsub/extension_partial_message.nim
+4 −2 libp2p/protocols/pubsub/gossipsub/extensions.nim
+36 −62 libp2p/protocols/pubsub/pubsub.nim
+16 −8 libp2p/protocols/pubsub/pubsubpeer.nim
+1 −1 libp2p/switch.nim
+37 −12 libp2p/transports/quictransport.nim
+20 −1 libp2p/upgrademngrs/muxedupgrade.nim
+6 −0 libp2p/utility.nim
+23 −0 libp2p/utils/tablekey.nim
+111 −0 tests/interop/partial_message.nim
+126 −0 tests/interop/test_partial_message.nim
+2 −2 tests/libp2p/mix/mock_mix.nim
+191 −52 tests/libp2p/mix/test_conn.nim
+22 −1 tests/libp2p/mix/test_delay_strategy.nim
+39 −1 tests/libp2p/mix/test_mix_message.nim
+0 −88 tests/libp2p/mix/test_mix_node.nim
+31 −21 tests/libp2p/mix/test_pool.nim
+55 −24 tests/libp2p/mix/test_spam_protection_mixnode.nim
+70 −45 tests/libp2p/mix/utils.nim
+151 −31 tests/libp2p/pubsub/extensions/test_extension_partial_message.nim
+7 −2 tests/libp2p/pubsub/extensions/test_extensions.nim
+2 −2 tests/libp2p/pubsub/test_gossipsub.nim
+1 −1 tests/libp2p/pubsub/test_scoring.nim
+0 −2 tests/libp2p/pubsub/utils.nim
+54 −17 tests/libp2p/test_conn_manager.nim
11 changes: 7 additions & 4 deletions waku/node/kernel_api/lightpush.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ proc lightpushPublish*(
return lighpushErrorResult(
LightPushErrorCode.SERVICE_NOT_AVAILABLE, "Waku lightpush not available"
)
if mixify and node.wakuMix.isNil():
error "failed to publish message using mix as mix protocol is not mounted"
var lmixify = mixify
if not node.wakuMix.isNil():
lmixify = true
Comment thread
chaitanyaprem marked this conversation as resolved.

#[ error "failed to publish message using mix as mix protocol is not mounted"
return lighpushErrorResult(
LightPushErrorCode.SERVICE_NOT_AVAILABLE, "Waku lightpush with mix not available"
)
) ]#
let toPeer: RemotePeerInfo = peerOpt.valueOr:
if not node.wakuLightPush.isNil():
RemotePeerInfo.init(node.peerId())
Expand Down Expand Up @@ -281,4 +284,4 @@ proc lightpushPublish*(
error "lightpush publish error", error = msg
return lighpushErrorResult(LightPushErrorCode.INTERNAL_SERVER_ERROR, msg)

return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer, mixify)
return await lightpushPublishHandler(node, pubsubForPublish, message, toPeer, lmixify)
Loading