mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-05 23:43:07 +00:00
fix: return message id on waku_relay_publish (#2485)
* fix: return message id on `waku_relay_publish` * fix: remove unneeded cast and handle 0 len seqs * chore: rename messageId to messageHash
This commit is contained in:
parent
a8769955f0
commit
b7f3db0b0a
@ -19,8 +19,9 @@ proc alloc*(str: string): cstring =
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
proc allocSharedSeq*[T](s: seq[T]): SharedSeq[T] =
|
proc allocSharedSeq*[T](s: seq[T]): SharedSeq[T] =
|
||||||
let data = cast[ptr T](allocShared(s.len))
|
let data = allocShared(sizeof(T) * s.len)
|
||||||
copyMem(data, unsafeAddr s, s.len)
|
if s.len != 0:
|
||||||
|
copyMem(data, unsafeAddr s[0], s.len)
|
||||||
return (cast[ptr UncheckedArray[T]](data), s.len)
|
return (cast[ptr UncheckedArray[T]](data), s.len)
|
||||||
|
|
||||||
proc deallocSharedSeq*[T](s: var SharedSeq[T]) =
|
proc deallocSharedSeq*[T](s: var SharedSeq[T]) =
|
||||||
|
|||||||
@ -61,7 +61,7 @@ proc `%`*(value: WakuMessageHash): JsonNode =
|
|||||||
|
|
||||||
type JsonMessageEvent* = ref object of JsonEvent
|
type JsonMessageEvent* = ref object of JsonEvent
|
||||||
pubsubTopic*: string
|
pubsubTopic*: string
|
||||||
messageId*: string
|
messageHash*: WakuMessageHash
|
||||||
wakuMessage*: JsonMessage
|
wakuMessage*: JsonMessage
|
||||||
|
|
||||||
proc new*(T: type JsonMessageEvent,
|
proc new*(T: type JsonMessageEvent,
|
||||||
@ -83,12 +83,11 @@ proc new*(T: type JsonMessageEvent,
|
|||||||
copyMem(addr proof[0], unsafeAddr msg.proof[0], len(msg.proof))
|
copyMem(addr proof[0], unsafeAddr msg.proof[0], len(msg.proof))
|
||||||
|
|
||||||
let msgHash = computeMessageHash(pubSubTopic, msg)
|
let msgHash = computeMessageHash(pubSubTopic, msg)
|
||||||
let msgHashHex = to0xHex(msgHash)
|
|
||||||
|
|
||||||
return JsonMessageEvent(
|
return JsonMessageEvent(
|
||||||
eventType: "message",
|
eventType: "message",
|
||||||
pubSubTopic: pubSubTopic,
|
pubSubTopic: pubSubTopic,
|
||||||
messageId: msgHashHex,
|
messageHash: msgHash,
|
||||||
wakuMessage: JsonMessage(
|
wakuMessage: JsonMessage(
|
||||||
payload: base64.encode(payload),
|
payload: base64.encode(payload),
|
||||||
contentTopic: msg.contentTopic,
|
contentTopic: msg.contentTopic,
|
||||||
|
|||||||
@ -235,6 +235,8 @@ proc waku_relay_publish(ctx: ptr Context,
|
|||||||
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
|
||||||
return RET_ERR
|
return RET_ERR
|
||||||
|
|
||||||
|
let msgHash = $sendReqRes.value
|
||||||
|
callback(RET_OK, unsafeAddr msgHash[0], cast[csize_t](len(msgHash)), userData)
|
||||||
return RET_OK
|
return RET_OK
|
||||||
|
|
||||||
proc waku_start(ctx: ptr Context,
|
proc waku_start(ctx: ptr Context,
|
||||||
|
|||||||
@ -4,11 +4,13 @@ import
|
|||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
|
stew/byteutils,
|
||||||
stew/results,
|
stew/results,
|
||||||
stew/shims/net
|
stew/shims/net
|
||||||
import
|
import
|
||||||
../../../../../waku/waku_core/message/message,
|
../../../../../waku/waku_core/message/message,
|
||||||
../../../../../waku/node/waku_node,
|
../../../../../waku/node/waku_node,
|
||||||
|
../../../../../waku/waku_core/message,
|
||||||
../../../../../waku/waku_core/time, # Timestamp
|
../../../../../waku/waku_core/time, # Timestamp
|
||||||
../../../../../waku/waku_core/topics/pubsub_topic,
|
../../../../../waku/waku_core/topics/pubsub_topic,
|
||||||
../../../../../waku/waku_relay/protocol,
|
../../../../../waku/waku_relay/protocol,
|
||||||
@ -104,13 +106,16 @@ proc process*(self: ptr RelayRequest,
|
|||||||
node.wakuRelay.unsubscribeAll($self.pubsubTopic)
|
node.wakuRelay.unsubscribeAll($self.pubsubTopic)
|
||||||
|
|
||||||
of PUBLISH:
|
of PUBLISH:
|
||||||
let numPeers = await node.wakuRelay.publish($self.pubsubTopic,
|
let msg = self.message.toWakuMessage()
|
||||||
self.message.toWakuMessage())
|
let pubsubTopic = $self.pubsubTopic
|
||||||
|
|
||||||
|
let numPeers = await node.wakuRelay.publish(pubsubTopic,
|
||||||
|
msg)
|
||||||
if numPeers == 0:
|
if numPeers == 0:
|
||||||
return err("Message not sent because no peers found.")
|
return err("Message not sent because no peers found.")
|
||||||
|
|
||||||
elif numPeers > 0:
|
elif numPeers > 0:
|
||||||
# TODO: pending to return a valid message Id
|
let msgHash = computeMessageHash(pubSubTopic, msg).to0xHex
|
||||||
return ok("hard-coded-message-id")
|
return ok(msgHash)
|
||||||
|
|
||||||
return ok("")
|
return ok("")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user