mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 15:46:33 +00:00
deploy: e7ebd190a372a2ee843a8db9b4b79a795e744313
This commit is contained in:
parent
2e16cdddf6
commit
949e95237b
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# libtool - Provide generalized library-building support services.
|
# libtool - Provide generalized library-building support services.
|
||||||
# Generated automatically by config.status (libbacktrace) version-unused
|
# Generated automatically by config.status (libbacktrace) version-unused
|
||||||
# Libtool was configured on host fv-az259-289:
|
# Libtool was configured on host fv-az190-570:
|
||||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||||
#
|
#
|
||||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
nimcrypto
|
nimcrypto/sha2
|
||||||
import
|
import
|
||||||
../protocol/waku_message,
|
../protocol/waku_message,
|
||||||
./time
|
./time
|
||||||
@ -11,33 +11,33 @@ import
|
|||||||
|
|
||||||
type Index* = object
|
type Index* = object
|
||||||
## This type contains the description of an Index used in the pagination of WakuMessages
|
## This type contains the description of an Index used in the pagination of WakuMessages
|
||||||
digest*: MDigest[256] # calculated over payload and content topic
|
|
||||||
receiverTime*: Timestamp
|
|
||||||
senderTime*: Timestamp # the time at which the message is generated
|
|
||||||
pubsubTopic*: string
|
pubsubTopic*: string
|
||||||
|
senderTime*: Timestamp # the time at which the message is generated
|
||||||
|
receiverTime*: Timestamp
|
||||||
|
digest*: MDigest[256] # calculated over payload and content topic
|
||||||
|
|
||||||
|
proc computeDigest*(msg: WakuMessage): MDigest[256] =
|
||||||
|
var ctx: sha256
|
||||||
|
ctx.init()
|
||||||
|
defer: ctx.clear()
|
||||||
|
|
||||||
|
ctx.update(msg.contentTopic.toBytes())
|
||||||
|
ctx.update(msg.payload)
|
||||||
|
|
||||||
|
# Computes the hash
|
||||||
|
return ctx.finish()
|
||||||
|
|
||||||
proc compute*(T: type Index, msg: WakuMessage, receivedTime: Timestamp, pubsubTopic: string): T =
|
proc compute*(T: type Index, msg: WakuMessage, receivedTime: Timestamp, pubsubTopic: string): T =
|
||||||
## Takes a WakuMessage with received timestamp and returns its Index.
|
## Takes a WakuMessage with received timestamp and returns its Index.
|
||||||
## Received timestamp will default to system time if not provided.
|
|
||||||
|
|
||||||
let
|
let
|
||||||
contentTopic = toBytes(msg.contentTopic)
|
digest = computeDigest(msg)
|
||||||
payload = msg.payload
|
|
||||||
senderTime = msg.timestamp
|
senderTime = msg.timestamp
|
||||||
|
|
||||||
var ctx: sha256
|
|
||||||
ctx.init()
|
|
||||||
ctx.update(contentTopic)
|
|
||||||
ctx.update(payload)
|
|
||||||
let digest = ctx.finish() # computes the hash
|
|
||||||
ctx.clear()
|
|
||||||
|
|
||||||
Index(
|
Index(
|
||||||
digest:digest,
|
pubsubTopic: pubsubTopic,
|
||||||
receiverTime: receivedTime,
|
|
||||||
senderTime: senderTime,
|
senderTime: senderTime,
|
||||||
pubsubTopic: pubsubTopic
|
receiverTime: receivedTime,
|
||||||
|
digest: digest
|
||||||
)
|
)
|
||||||
|
|
||||||
proc `==`*(x, y: Index): bool =
|
proc `==`*(x, y: Index): bool =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user