mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-02-12 09:53:08 +00:00
* refactors waku_filter
* refactors waku_lightpush
* refactors waku_swap
* refactor namespacing.nim
* refactor peers
* refactors requests
* adds top level {.push raises: [Defect].}
* log scope for rln relay
* cleans up comments
* removes comments
* comments out raise Defect
* defines temp var then pass to constructor
* Update waku/v2/protocol/waku_rln_relay/rln.nim
Co-authored-by: oskarth <ot@oskarthoren.com>
* Update waku/v2/protocol/waku_swap/waku_swap.nim
Co-authored-by: oskarth <ot@oskarthoren.com>
* explains the potential exception in waku_swap
* creates temp var before return
* adjusts spaces
* adds line breaks, temp vars and fixes format
* removes type declaration
* fixes and indentation issue
* adjusts spacing
* adjusts line <80ch
* formating improvement
Co-authored-by: oskarth <ot@oskarthoren.com>
51 lines
1.5 KiB
Nim
51 lines
1.5 KiB
Nim
## Waku Message module.
|
|
##
|
|
## See https://github.com/vacp2p/specs/blob/master/specs/waku/v2/waku-message.md
|
|
## for spec.
|
|
##
|
|
## For payload content and encryption, see waku/v2/node/waku_payload.nim
|
|
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
import
|
|
libp2p/protobuf/minprotobuf
|
|
|
|
type
|
|
ContentTopic* = string
|
|
|
|
WakuMessage* = object
|
|
payload*: seq[byte]
|
|
contentTopic*: ContentTopic
|
|
version*: uint32
|
|
# sender generated timestamp
|
|
timestamp*: float64
|
|
# the proof field indicates that the message is not a spam
|
|
# this field will be used in the rln-relay protocol
|
|
# XXX Experimental, this is part of https://rfc.vac.dev/spec/17/ spec and not yet part of WakuMessage spec
|
|
proof*: seq[byte]
|
|
|
|
|
|
# Encoding and decoding -------------------------------------------------------
|
|
proc init*(T: type WakuMessage, buffer: seq[byte]): ProtoResult[T] =
|
|
var msg = WakuMessage()
|
|
let pb = initProtoBuffer(buffer)
|
|
|
|
discard ? pb.getField(1, msg.payload)
|
|
discard ? pb.getField(2, msg.contentTopic)
|
|
discard ? pb.getField(3, msg.version)
|
|
discard ? pb.getField(4, msg.timestamp)
|
|
# XXX Experimental, this is part of https://rfc.vac.dev/spec/17/ spec and not yet part of WakuMessage spec
|
|
discard ? pb.getField(21, msg.proof)
|
|
|
|
ok(msg)
|
|
|
|
proc encode*(message: WakuMessage): ProtoBuffer =
|
|
result = initProtoBuffer()
|
|
|
|
result.write(1, message.payload)
|
|
result.write(2, message.contentTopic)
|
|
result.write(3, message.version)
|
|
result.write(4, message.timestamp)
|
|
result.write(21, message.proof)
|