Skip to content

Commit

Permalink
Merge dec57e9 into 55ff667
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos authored Feb 29, 2024
2 parents 55ff667 + dec57e9 commit bb57b8c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions library/alloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ proc alloc*(str: string): cstring =
return ret

proc allocSharedSeq*[T](s: seq[T]): SharedSeq[T] =
let data = cast[ptr T](allocShared(s.len))
copyMem(data, unsafeAddr s, s.len)
let data = allocShared(sizeof(T) * s.len)
if s.len != 0:
copyMem(data, unsafeAddr s[0], s.len)
return (cast[ptr UncheckedArray[T]](data), s.len)

proc deallocSharedSeq*[T](s: var SharedSeq[T]) =
Expand Down
5 changes: 2 additions & 3 deletions library/events/json_message_event.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ proc `%`*(value: WakuMessageHash): JsonNode =

type JsonMessageEvent* = ref object of JsonEvent
pubsubTopic*: string
messageId*: string
messageHash*: WakuMessageHash
wakuMessage*: JsonMessage

proc new*(T: type JsonMessageEvent,
Expand All @@ -83,12 +83,11 @@ proc new*(T: type JsonMessageEvent,
copyMem(addr proof[0], unsafeAddr msg.proof[0], len(msg.proof))

let msgHash = computeMessageHash(pubSubTopic, msg)
let msgHashHex = to0xHex(msgHash)

return JsonMessageEvent(
eventType: "message",
pubSubTopic: pubSubTopic,
messageId: msgHashHex,
messageHash: msgHash,
wakuMessage: JsonMessage(
payload: base64.encode(payload),
contentTopic: msg.contentTopic,
Expand Down
2 changes: 2 additions & 0 deletions library/libwaku.nim
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ proc waku_relay_publish(ctx: ptr Context,
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
return RET_ERR

let msgHash = $sendReqRes.value
callback(RET_OK, unsafeAddr msgHash[0], cast[csize_t](len(msgHash)), userData)
return RET_OK

proc waku_start(ctx: ptr Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import
import
chronicles,
chronos,
stew/byteutils,
stew/results,
stew/shims/net
import
../../../../../waku/waku_core/message/message,
../../../../../waku/node/waku_node,
../../../../../waku/waku_core/message,
../../../../../waku/waku_core/time, # Timestamp
../../../../../waku/waku_core/topics/pubsub_topic,
../../../../../waku/waku_relay/protocol,
Expand Down Expand Up @@ -104,13 +106,16 @@ proc process*(self: ptr RelayRequest,
node.wakuRelay.unsubscribeAll($self.pubsubTopic)

of PUBLISH:
let numPeers = await node.wakuRelay.publish($self.pubsubTopic,
self.message.toWakuMessage())
let msg = self.message.toWakuMessage()
let pubsubTopic = $self.pubsubTopic

let numPeers = await node.wakuRelay.publish(pubsubTopic,
msg)
if numPeers == 0:
return err("Message not sent because no peers found.")

elif numPeers > 0:
# TODO: pending to return a valid message Id
return ok("hard-coded-message-id")
let msgHash = computeMessageHash(pubSubTopic, msg).to0xHex
return ok(msgHash)

return ok("")

0 comments on commit bb57b8c

Please sign in to comment.