diff --git a/libp2p/protocols/pubsub/floodsub.nim b/libp2p/protocols/pubsub/floodsub.nim index bd7069f69..56c08094f 100644 --- a/libp2p/protocols/pubsub/floodsub.nim +++ b/libp2p/protocols/pubsub/floodsub.nim @@ -139,7 +139,7 @@ method rpcHandler*(f: FloodSub, discard var toSendPeers = initHashSet[PubSubPeer]() - for t in msg.topicIDs: # for every topic in the message + for t in msg.topicIds: # for every topic in the message if t notin f.topics: continue f.floodsub.withValue(t, peers): toSendPeers.incl(peers[]) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index 1f20a7618..72beab51d 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -158,7 +158,7 @@ method onNewPeer(g: GossipSub, peer: PubSubPeer) = peer.iWantBudget = IWantPeerBudget peer.iHaveBudget = IHavePeerBudget -method onPubSubPeerEvent*(p: GossipSub, peer: PubSubPeer, event: PubsubPeerEvent) {.gcsafe.} = +method onPubSubPeerEvent*(p: GossipSub, peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe.} = case event.kind of PubSubPeerEventKind.Connected: discard @@ -261,7 +261,7 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) = var respControl: ControlMessage let iwant = g.handleIHave(peer, control.ihave) - if iwant.messageIDs.len > 0: + if iwant.messageIds.len > 0: respControl.iwant.add(iwant) respControl.prune.add(g.handleGraft(peer, control.graft)) let messages = g.handleIWant(peer, control.iwant) @@ -273,7 +273,7 @@ proc handleControl(g: GossipSub, peer: PubSubPeer, control: ControlMessage) = # iwant and prunes from here, also messages for smsg in messages: - for topic in smsg.topicIDs: + for topic in smsg.topicIds: if g.knownTopics.contains(topic): libp2p_pubsub_broadcast_messages.inc(labelValues = [topic]) else: @@ -307,7 +307,7 @@ proc validateAndRelay(g: GossipSub, of ValidationResult.Reject: debug "Dropping message after validation, reason: reject", msgId = shortLog(msgId), peer - g.punishInvalidMessage(peer, msg.topicIDs) + g.punishInvalidMessage(peer, msg.topicIds) return of ValidationResult.Ignore: debug "Dropping message after validation, reason: ignore", @@ -319,10 +319,10 @@ proc validateAndRelay(g: GossipSub, # store in cache only after validation g.mcache.put(msgId, msg) - g.rewardDelivered(peer, msg.topicIDs, true) + g.rewardDelivered(peer, msg.topicIds, true) var toSendPeers = HashSet[PubSubPeer]() - for t in msg.topicIDs: # for every topic in the message + for t in msg.topicIds: # for every topic in the message if t notin g.topics: continue @@ -338,7 +338,7 @@ proc validateAndRelay(g: GossipSub, # also have to be careful to only include validated messages g.broadcast(toSendPeers, RPCMsg(messages: @[msg])) trace "forwared message to peers", peers = toSendPeers.len, msgId, peer - for topic in msg.topicIDs: + for topic in msg.topicIds: if topic notin g.topics: continue if g.knownTopics.contains(topic): @@ -392,7 +392,7 @@ method rpcHandler*(g: GossipSub, if not alreadyReceived: let delay = Moment.now() - g.firstSeen(msgId) - g.rewardDelivered(peer, msg.topicIDs, false, delay) + g.rewardDelivered(peer, msg.topicIds, false, delay) libp2p_gossipsub_duplicate.inc() @@ -402,7 +402,7 @@ method rpcHandler*(g: GossipSub, libp2p_gossipsub_received.inc() # avoid processing messages we are not interested in - if msg.topicIDs.allIt(it notin g.topics): + if msg.topicIds.allIt(it notin g.topics): debug "Dropping message of topic without subscription", msgId = shortLog(msgId), peer continue @@ -410,14 +410,14 @@ method rpcHandler*(g: GossipSub, # always validate if signature is present or required debug "Dropping message due to failed signature verification", msgId = shortLog(msgId), peer - g.punishInvalidMessage(peer, msg.topicIDs) + g.punishInvalidMessage(peer, msg.topicIds) 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 = shortLog(msgId), peer - g.punishInvalidMessage(peer, msg.topicIDs) + g.punishInvalidMessage(peer, msg.topicIds) continue # g.anonymize needs no evaluation when receiving messages diff --git a/libp2p/protocols/pubsub/gossipsub/behavior.nim b/libp2p/protocols/pubsub/gossipsub/behavior.nim index 04a6062f5..5351e464e 100644 --- a/libp2p/protocols/pubsub/gossipsub/behavior.nim +++ b/libp2p/protocols/pubsub/gossipsub/behavior.nim @@ -246,21 +246,21 @@ proc handleIHave*(g: GossipSub, let deIhaves = ihaves.deduplicate() for ihave in deIhaves: trace "peer sent ihave", - peer, topic = ihave.topicId, msgs = ihave.messageIDs + peer, topic = ihave.topicId, msgs = ihave.messageIds if ihave.topicId in g.mesh: # also avoid duplicates here! - let deIhavesMsgs = ihave.messageIDs.deduplicate() + let deIhavesMsgs = ihave.messageIds.deduplicate() for msgId in deIhavesMsgs: if not g.hasSeen(msgId): if peer.iHaveBudget > 0: - res.messageIDs.add(msgId) + res.messageIds.add(msgId) dec peer.iHaveBudget trace "requested message via ihave", messageID=msgId else: break # shuffling res.messageIDs before sending it out to increase the likelihood # of getting an answer if the peer truncates the list due to internal size restrictions. - g.rng.shuffle(res.messageIDs) + g.rng.shuffle(res.messageIds) return res proc handleIWant*(g: GossipSub, @@ -274,7 +274,7 @@ proc handleIWant*(g: GossipSub, else: let deIwants = iwants.deduplicate() for iwant in deIwants: - let deIwantsMsgs = iwant.messageIDs.deduplicate() + let deIwantsMsgs = iwant.messageIds.deduplicate() for mid in deIwantsMsgs: trace "peer sent iwant", peer, messageID = mid let msg = g.mcache.get(mid) diff --git a/libp2p/protocols/pubsub/mcache.nim b/libp2p/protocols/pubsub/mcache.nim index d91cb6f61..ef7c8d03b 100644 --- a/libp2p/protocols/pubsub/mcache.nim +++ b/libp2p/protocols/pubsub/mcache.nim @@ -17,7 +17,7 @@ export sets, tables, messages, options type CacheEntry* = object mid*: MessageId - topicIDs*: seq[string] + topicIds*: seq[string] MCache* = object of RootObj msgs*: Table[MessageId, Message] @@ -37,7 +37,7 @@ func contains*(c: MCache, mid: MessageId): bool = func put*(c: var MCache, msgId: MessageId, msg: Message) = if not c.msgs.hasKeyOrPut(msgId, msg): # Only add cache entry if the message was not already in the cache - c.history[0].add(CacheEntry(mid: msgId, topicIDs: msg.topicIDs)) + c.history[0].add(CacheEntry(mid: msgId, topicIds: msg.topicIds)) func window*(c: MCache, topic: string): HashSet[MessageId] = let @@ -45,7 +45,7 @@ func window*(c: MCache, topic: string): HashSet[MessageId] = for i in 0.. 0: ipb.finish() @@ -109,7 +109,7 @@ proc encodeMessage*(msg: Message, anonymize: bool): seq[byte] = pb.write(2, msg.data) if len(msg.seqno) > 0 and not anonymize: pb.write(3, msg.seqno) - for topic in msg.topicIDs: + for topic in msg.topicIds: pb.write(4, topic) if len(msg.signature) > 0 and not anonymize: pb.write(5, msg.signature) @@ -182,8 +182,8 @@ proc decodeIHave*(pb: ProtoBuffer): ProtoResult[ControlIHave] {. trace "decodeIHave: read topicId", topic_id = control.topicId else: trace "decodeIHave: topicId is missing" - if ? pb.getRepeatedField(2, control.messageIDs): - trace "decodeIHave: read messageIDs", message_ids = control.messageIDs + if ? pb.getRepeatedField(2, control.messageIds): + trace "decodeIHave: read messageIDs", message_ids = control.messageIds else: trace "decodeIHave: no messageIDs" ok(control) @@ -194,8 +194,8 @@ proc decodeIWant*(pb: ProtoBuffer): ProtoResult[ControlIWant] {.inline.} = trace "decodeIWant: decoding message" var control = ControlIWant() - if ? pb.getRepeatedField(1, control.messageIDs): - trace "decodeIWant: read messageIDs", message_ids = control.messageIDs + if ? pb.getRepeatedField(1, control.messageIds): + trace "decodeIWant: read messageIDs", message_ids = control.messageIds else: trace "decodeIWant: no messageIDs" ok(control) @@ -281,8 +281,8 @@ proc decodeMessage*(pb: ProtoBuffer): ProtoResult[Message] {.inline.} = trace "decodeMessage: read seqno", seqno = msg.seqno else: trace "decodeMessage: seqno is missing" - if ? pb.getRepeatedField(4, msg.topicIDs): - trace "decodeMessage: read topics", topic_ids = msg.topicIDs + if ? pb.getRepeatedField(4, msg.topicIds): + trace "decodeMessage: read topics", topic_ids = msg.topicIds else: trace "decodeMessage: topics are missing" if ? pb.getField(5, msg.signature): diff --git a/tests/pubsub/testgossipinternal.nim b/tests/pubsub/testgossipinternal.nim index 07667eb5e..84f75e49c 100644 --- a/tests/pubsub/testgossipinternal.nim +++ b/tests/pubsub/testgossipinternal.nim @@ -690,7 +690,7 @@ suite "GossipSub internal": ) peer.iHaveBudget = 0 let iwants = gossipSub.handleIHave(peer, @[msg]) - check: iwants.messageIDs.len == 0 + check: iwants.messageIds.len == 0 block: # given duplicate ihave should generate only one iwant @@ -705,7 +705,7 @@ suite "GossipSub internal": messageIDs: @[id, id, id] ) let iwants = gossipSub.handleIHave(peer, @[msg]) - check: iwants.messageIDs.len == 1 + check: iwants.messageIds.len == 1 block: # given duplicate iwant should generate only one message diff --git a/tests/pubsub/testmcache.nim b/tests/pubsub/testmcache.nim index 28ee94a19..6c1222778 100644 --- a/tests/pubsub/testmcache.nim +++ b/tests/pubsub/testmcache.nim @@ -42,7 +42,7 @@ suite "MCache": check mids.len == 3 var id = toSeq(mids)[0] - check mCache.get(id).get().topicIDs[0] == "foo" + check mCache.get(id).get().topicIds[0] == "foo" test "shift - shift 1 window at a time": var mCache = MCache.init(1, 5) diff --git a/tests/pubsub/utils.nim b/tests/pubsub/utils.nim index 0e0e747d4..59918a70e 100644 --- a/tests/pubsub/utils.nim +++ b/tests/pubsub/utils.nim @@ -26,7 +26,7 @@ func defaultMsgIdProvider*(m: Message): Result[MessageId, ValidationResult] = # This part is irrelevant because it's not standard, # We use it exclusively for testing basically and users should # implement their own logic in the case they use anonymization - $m.data.hash & $m.topicIDs.hash + $m.data.hash & $m.topicIds.hash ok mid.toBytes() proc generateNodes*(