From 6b41712a18310bd7a1179b9e29170ce90144a05a Mon Sep 17 00:00:00 2001 From: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com> Date: Fri, 26 Apr 2024 09:54:41 +0200 Subject: [PATCH] Changes upon review comments --- waku/node/waku_node.nim | 6 +++--- waku/waku_api/rest/builder.nim | 2 +- waku/waku_lightpush/self_req_handler.nim | 27 ++++++++++++------------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index 0d7b362b11..40ad0015ca 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -843,6 +843,9 @@ proc lightpushPublish*( ## Returns whether relaying was successful or not. ## `WakuMessage` should contain a `contentTopic` field for light node ## functionality. + if node.wakuLightpushClient.isNil() and node.wakuLightPush.isNil(): + return err("Waku lightpush not available") + let internalPublish = proc( node: WakuNode, pubsubTopic: PubsubTopic, @@ -861,9 +864,6 @@ proc lightpushPublish*( pubsubTopic = pubsubTopic, contentTopic = message.contentTopic return await node.wakuLightPush.handleSelfLightPushRequest(pubsubTopic, message) - if node.wakuLightpushClient.isNil() and node.wakuLightPush.isNil(): - return err("waku lightpush not available") - if pubsubTopic.isSome(): debug "publishing message with lightpush", pubsubTopic = pubsubTopic.get(), diff --git a/waku/waku_api/rest/builder.nim b/waku/waku_api/rest/builder.nim index 06e20bbf7a..a00140753a 100644 --- a/waku/waku_api/rest/builder.nim +++ b/waku/waku_api/rest/builder.nim @@ -178,7 +178,7 @@ proc startRestServerProtocolSupport*( ## Install it either if lightpushnode (lightpush service node) is configured and client is mounted) ## or install it to be used with self-hosted lightpush service if (conf.lightpushnode != "" and node.wakuLightpushClient != nil) or - (conf.lightpush and node.wakuLightPush != nil): + (conf.lightpush and node.wakuLightPush != nil and node.wakuRelay != nil): let lightDiscoHandler = if wakuDiscv5.isSome(): some(defaultDiscoveryHandler(wakuDiscv5.get(), Lightpush)) diff --git a/waku/waku_lightpush/self_req_handler.nim b/waku/waku_lightpush/self_req_handler.nim index 792b86b63e..b08a87035d 100644 --- a/waku/waku_lightpush/self_req_handler.nim +++ b/waku/waku_lightpush/self_req_handler.nim @@ -1,17 +1,16 @@ -## -## This file is aimed to attend the requests that come directly -## from the 'self' node. It is expected to attend the store requests that -## come from REST-store endpoint when those requests don't indicate -## any store-peer address. -## -## Notice that the REST-store requests normally assume that the REST -## server is acting as a store-client. In this module, we allow that -## such REST-store node can act as store-server as well by retrieving -## its own stored messages. The typical use case for that is when -## using `nwaku-compose`, which spawn a Waku node connected to a local -## database, and the user is interested in retrieving the messages -## stored by that local store node. -## +when (NimMajor, NimMinor) < (1, 4): + {.push raises: [Defect].} +else: + {.push raises: [].} + +## Notice that the REST /lightpush requests normally assume that the node +## is acting as a lightpush-client that will trigger the service provider node +## to relay the message. +## In this module, we allow that a lightpush service node (full node) can be +## triggered directly through the REST /lightpush endpoint. +## The typical use case for that is when using `nwaku-compose`, +## which spawn a full service Waku node +## that could be used also as a lightpush client, helping testing and development. import stew/results, chronos, chronicles, std/options, metrics import