diff --git a/libp2p/peerinfo.nim b/libp2p/peerinfo.nim index b885714d9..c37802c1a 100644 --- a/libp2p/peerinfo.nim +++ b/libp2p/peerinfo.nim @@ -39,6 +39,7 @@ type privateKey*: PrivateKey of HasPublic: key: Option[PublicKey] + seqno*: uint64 proc id*(p: PeerInfo): string = if not(isNil(p)): diff --git a/libp2p/protocols/pubsub/rpc/message.nim b/libp2p/protocols/pubsub/rpc/message.nim index d203035d4..3cb16bf96 100644 --- a/libp2p/protocols/pubsub/rpc/message.nim +++ b/libp2p/protocols/pubsub/rpc/message.nim @@ -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: