2022-10-21 13:01:39 +00:00
|
|
|
import
|
2022-11-23 23:58:17 +00:00
|
|
|
std/[times, random],
|
2022-10-25 12:55:31 +00:00
|
|
|
stew/byteutils
|
2022-10-21 13:01:39 +00:00
|
|
|
import
|
|
|
|
../../../waku/v2/protocol/waku_message,
|
|
|
|
../../../waku/v2/utils/time
|
|
|
|
|
2022-11-09 08:55:47 +00:00
|
|
|
export
|
|
|
|
waku_message.DefaultPubsubTopic,
|
|
|
|
waku_message.DefaultContentTopic
|
2022-10-21 13:01:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc now*(): Timestamp =
|
|
|
|
getNanosecondTime(getTime().toUnixFloat())
|
|
|
|
|
|
|
|
proc ts*(offset=0, origin=now()): Timestamp =
|
|
|
|
origin + getNanosecondTime(offset)
|
|
|
|
|
|
|
|
|
|
|
|
proc fakeWakuMessage*(
|
|
|
|
payload: string|seq[byte] = "TEST-PAYLOAD",
|
2022-11-23 23:58:17 +00:00
|
|
|
contentTopic = DefaultContentTopic,
|
2022-10-21 13:01:39 +00:00
|
|
|
ts = now(),
|
|
|
|
ephemeral = false
|
2022-11-23 23:58:17 +00:00
|
|
|
): WakuMessage =
|
2022-10-21 13:01:39 +00:00
|
|
|
var payloadBytes: seq[byte]
|
|
|
|
when payload is string:
|
|
|
|
payloadBytes = toBytes(payload)
|
|
|
|
else:
|
|
|
|
payloadBytes = payload
|
|
|
|
|
|
|
|
WakuMessage(
|
|
|
|
payload: payloadBytes,
|
|
|
|
contentTopic: contentTopic,
|
|
|
|
version: 2,
|
|
|
|
timestamp: ts,
|
|
|
|
ephemeral: ephemeral
|
|
|
|
)
|
2022-11-23 23:58:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Randomization
|
|
|
|
|
|
|
|
proc randomize*() =
|
|
|
|
## Initializes the default random number generator with the given seed.
|
|
|
|
## From: https://nim-lang.org/docs/random.html#randomize,int64
|
|
|
|
let now = getTime()
|
|
|
|
randomize(now.toUnix() * 1_000_000_000 + now.nanosecond)
|