mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-11 23:35:08 +00:00
make lightpush return msg hash after successful publish
This commit is contained in:
parent
d932dd10cc
commit
1b7a7c9841
@ -97,12 +97,12 @@ proc process*(
|
||||
error "PUBLISH failed", error = errorMsg
|
||||
return err(errorMsg)
|
||||
|
||||
(
|
||||
let msgHashHex = (
|
||||
await waku.node.wakuLightpushClient.publish(
|
||||
pubsubTopic, msg, peer = peerOpt.get()
|
||||
)
|
||||
).isOkOr:
|
||||
).valueOr:
|
||||
error "PUBLISH failed", error = error
|
||||
return err("LightpushRequest error publishing: " & $error)
|
||||
|
||||
return ok("")
|
||||
return ok(msgHashHex)
|
||||
|
@ -972,7 +972,7 @@ proc lightpushPublish*(
|
||||
pubsubTopic: Option[PubsubTopic],
|
||||
message: WakuMessage,
|
||||
peer: RemotePeerInfo,
|
||||
): Future[WakuLightPushResult[void]] {.async, gcsafe.} =
|
||||
): Future[WakuLightPushResult[string]] {.async, gcsafe.} =
|
||||
## Pushes a `WakuMessage` to a node which relays it further on PubSub topic.
|
||||
## Returns whether relaying was successful or not.
|
||||
## `WakuMessage` should contain a `contentTopic` field for light node
|
||||
@ -986,7 +986,7 @@ proc lightpushPublish*(
|
||||
pubsubTopic: PubsubTopic,
|
||||
message: WakuMessage,
|
||||
peer: RemotePeerInfo,
|
||||
): Future[WakuLightPushResult[void]] {.async, gcsafe.} =
|
||||
): Future[WakuLightPushResult[string]] {.async, gcsafe.} =
|
||||
let msgHash = pubsubTopic.computeMessageHash(message).to0xHex()
|
||||
if not node.wakuLightpushClient.isNil():
|
||||
notice "publishing message with lightpush",
|
||||
@ -1023,7 +1023,7 @@ proc lightpushPublish*(
|
||||
# TODO: Move to application module (e.g., wakunode2.nim)
|
||||
proc lightpushPublish*(
|
||||
node: WakuNode, pubsubTopic: Option[PubsubTopic], message: WakuMessage
|
||||
): Future[WakuLightPushResult[void]] {.
|
||||
): Future[WakuLightPushResult[string]] {.
|
||||
async, gcsafe, deprecated: "Use 'node.lightpushPublish()' instead"
|
||||
.} =
|
||||
if node.wakuLightpushClient.isNil() and node.wakuLightPush.isNil():
|
||||
@ -1040,13 +1040,7 @@ proc lightpushPublish*(
|
||||
elif not node.wakuLightPush.isNil():
|
||||
peerOpt = some(RemotePeerInfo.init($node.switch.peerInfo.peerId))
|
||||
|
||||
let publishRes =
|
||||
await node.lightpushPublish(pubsubTopic, message, peer = peerOpt.get())
|
||||
|
||||
if publishRes.isErr():
|
||||
error "failed to publish message", error = publishRes.error
|
||||
|
||||
return publishRes
|
||||
return await node.lightpushPublish(pubsubTopic, message, peer = peerOpt.get())
|
||||
|
||||
## Waku RLN Relay
|
||||
proc mountRlnRelay*(
|
||||
|
@ -71,24 +71,23 @@ proc publish*(
|
||||
wl: WakuLightPushClient,
|
||||
pubSubTopic: PubsubTopic,
|
||||
message: WakuMessage,
|
||||
peer: PeerId | RemotePeerInfo,
|
||||
): Future[WakuLightPushResult[void]] {.async, gcsafe.} =
|
||||
when peer is PeerId:
|
||||
info "publish",
|
||||
peerId = shortLog(peer),
|
||||
msg_hash = computeMessageHash(pubsubTopic, message).to0xHex
|
||||
else:
|
||||
info "publish",
|
||||
peerId = shortLog(peer.peerId),
|
||||
msg_hash = computeMessageHash(pubsubTopic, message).to0xHex
|
||||
|
||||
peer: RemotePeerInfo,
|
||||
): Future[WakuLightPushResult[string]] {.async, gcsafe.} =
|
||||
## On success, returns the msg_hash of the published message
|
||||
let msg_hash_hex_str = computeMessageHash(pubsubTopic, message).to0xHex()
|
||||
let pushRequest = PushRequest(pubSubTopic: pubSubTopic, message: message)
|
||||
?await wl.sendPushRequest(pushRequest, peer)
|
||||
|
||||
for obs in wl.publishObservers:
|
||||
obs.onMessagePublished(pubSubTopic, message)
|
||||
|
||||
return ok()
|
||||
notice "publishing message with lightpush",
|
||||
pubsubTopic = pubsubTopic,
|
||||
contentTopic = message.contentTopic,
|
||||
target_peer_id = peer.peerId,
|
||||
msg_hash = msg_hash_hex_str
|
||||
|
||||
return ok(msg_hash_hex_str)
|
||||
|
||||
proc publishToAny*(
|
||||
wl: WakuLightPushClient, pubSubTopic: PubsubTopic, message: WakuMessage
|
||||
|
@ -9,7 +9,7 @@
|
||||
## which spawn a full service Waku node
|
||||
## that could be used also as a lightpush client, helping testing and development.
|
||||
|
||||
import results, chronos, std/options, metrics
|
||||
import results, chronos, chronicles, std/options, metrics, stew/byteutils
|
||||
import
|
||||
../waku_core,
|
||||
./protocol,
|
||||
@ -21,9 +21,10 @@ import
|
||||
|
||||
proc handleSelfLightPushRequest*(
|
||||
self: WakuLightPush, pubSubTopic: PubsubTopic, message: WakuMessage
|
||||
): Future[WakuLightPushResult[void]] {.async.} =
|
||||
): Future[WakuLightPushResult[string]] {.async.} =
|
||||
## Handles the lightpush requests made by the node to itself.
|
||||
## Normally used in REST-lightpush requests
|
||||
## On success, returns the msg_hash of the published message.
|
||||
|
||||
try:
|
||||
# provide self peerId as now this node is used directly, thus there is no light client sender peer.
|
||||
@ -45,6 +46,14 @@ proc handleSelfLightPushRequest*(
|
||||
else:
|
||||
return err("unknown failure")
|
||||
|
||||
return ok()
|
||||
let msg_hash_hex_str = computeMessageHash(pubSubTopic, message).to0xHex()
|
||||
|
||||
notice "publishing message with self hosted lightpush",
|
||||
pubsubTopic = pubsubTopic,
|
||||
contentTopic = message.contentTopic,
|
||||
self_peer_id = selfPeerId,
|
||||
msg_hash = msg_hash_hex_str
|
||||
|
||||
return ok(msg_hash_hex_str)
|
||||
except Exception:
|
||||
return err("exception in handleSelfLightPushRequest: " & getCurrentExceptionMsg())
|
||||
|
Loading…
x
Reference in New Issue
Block a user