Fix gossip messages seqno according to spec

This commit is contained in:
Giovanni Petrantoni 2020-07-08 16:08:19 +09:00
parent a52763cc6d
commit 74dd254158
2 changed files with 5 additions and 4 deletions

View File

@ -39,6 +39,7 @@ type
privateKey*: PrivateKey
of HasPublic:
key: Option[PublicKey]
seqno*: uint64
proc id*(p: PeerInfo): string =
if not(isNil(p)):

View File

@ -19,6 +19,7 @@ import messages, protobuf,
../../../peerinfo,
../../../crypto/crypto,
../../../protobuf/minprotobuf
import stew/endians2
logScope:
topics = "pubsubmessage"
@ -63,13 +64,12 @@ proc init*(
topic: string,
sign: bool = true): Message {.gcsafe, raises: [CatchableError, Defect].} =
var seqno: seq[byte] = newSeq[byte](8)
if randomBytes(addr seqno[0], 8) <= 0:
raise (ref CatchableError)(msg: "Cannot get randomness for message")
# peer is a ref obj
inc p.seqno
result = Message(
fromPeer: p.peerId,
data: data,
seqno: seqno,
seqno: @(p.seqno.toBytesBE), # unefficient, fine for now
topicIDs: @[topic])
if sign and p.publicKey.isSome: