mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2026-01-09 03:47:55 -05:00
allow to omit peerId and seqno (#372)
* allow to omit peerId and seqno * small refactor * wip * fix message encoding * improve rpc signature logic * remove peerid from verify * trace fixes * fix message test * fix gossip 1.0 tests
This commit is contained in:
committed by
GitHub
parent
abd234601b
commit
ec322124ac
@@ -72,10 +72,19 @@ method rpcHandler*(f: FloodSub,
|
||||
trace "Dropping already-seen message", msgId, peer
|
||||
continue
|
||||
|
||||
if f.verifySignature and not msg.verify(peer.peerId):
|
||||
if (msg.signature.len > 0 or f.verifySignature) and not msg.verify():
|
||||
# always validate if signature is present or required
|
||||
debug "Dropping message due to failed signature verification", msgId, peer
|
||||
continue
|
||||
|
||||
if msg.seqno.len > 0 and msg.seqno.len != 8:
|
||||
# if we have seqno should be 8 bytes long
|
||||
debug "Dropping message due to invalid seqno length", msgId, peer
|
||||
continue
|
||||
|
||||
# g.anonymize needs no evaluation when receiving messages
|
||||
# as we have a "lax" policy and allow signed messages
|
||||
|
||||
if not (await f.validate(msg)):
|
||||
trace "Dropping message due to failed validation", msgId, peer
|
||||
continue
|
||||
@@ -129,7 +138,11 @@ method publish*(f: FloodSub,
|
||||
|
||||
inc f.msgSeqno
|
||||
let
|
||||
msg = Message.init(f.peerInfo, data, topic, f.msgSeqno, f.sign)
|
||||
msg =
|
||||
if f.anonymize:
|
||||
Message.init(none(PeerInfo), data, topic, none(uint64), false)
|
||||
else:
|
||||
Message.init(some(f.peerInfo), data, topic, some(f.msgSeqno), f.sign)
|
||||
msgId = f.msgIdProvider(msg)
|
||||
|
||||
trace "Created new message",
|
||||
|
||||
Reference in New Issue
Block a user