diff --git a/libp2p/protocols/pubsub/pubsub.nim b/libp2p/protocols/pubsub/pubsub.nim index b84816ce66..02436a9b4b 100644 --- a/libp2p/protocols/pubsub/pubsub.nim +++ b/libp2p/protocols/pubsub/pubsub.nim @@ -142,7 +142,7 @@ proc send*(p: PubSub, peer: PubSubPeer, msg: RPCMsg) {.raises: [].} = ## trace "sending pubsub message to peer", peer, msg = shortLog(msg) - discard peer.send(msg, p.anonymize) + peer.send(msg, p.anonymize) proc broadcast*( p: PubSub, diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index b3a6a02b42..f52337696e 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -272,7 +272,7 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte]) {.raises: [], async.} = await conn.close() # This will clean up the send connection -proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool): seq[RPCMsg] {.raises: [].} = +proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool) {.raises: [].} = # When sending messages, we take care to re-encode them with the right # anonymization flag to ensure that we're not penalized for sending invalid # or malicious data on the wire - in particular, re-encoding protects against @@ -290,8 +290,6 @@ proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool): seq[RPCMsg] {.raises: [ sendMetrics(msg) encodeRpcMsg(msg, anonymize) - var sentMessages: seq[RPCMsg] - # Check if the encoded message size exceeds the maxMessageSize if encoded.len > p.maxMessageSize: var controlSent = false # Split the RPCMsg into individual messages and send them separately @@ -305,13 +303,10 @@ proc send*(p: PubSubPeer, msg: RPCMsg, anonymize: bool): seq[RPCMsg] {.raises: [ let newMsgEncoded = encodeRpcMsg(newMsg, anonymize) trace "sending msg to peer", peer = p, rpcMsg = shortLog(newMsg) asyncSpawn p.sendEncoded(newMsgEncoded) - sentMessages.add(newMsg) else: # If the message size is within limits, send it as is trace "sending msg to peer", peer = p, rpcMsg = shortLog(msg) asyncSpawn p.sendEncoded(encoded) - sentMessages.add(msg) - return sentMessages proc canAskIWant*(p: PubSubPeer, msgId: MessageId): bool = for sentIHave in p.sentIHaves.mitems(): diff --git a/tests/pubsub/testpubsubpeer.nim b/tests/pubsub/testpubsubpeer.nim deleted file mode 100644 index a9930fbe2c..0000000000 --- a/tests/pubsub/testpubsubpeer.nim +++ /dev/null @@ -1,68 +0,0 @@ -# Nim-Libp2p -# Copyright (c) 2023 Status Research & Development GmbH -# Licensed under either of -# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE)) -# * MIT license ([LICENSE-MIT](LICENSE-MIT)) -# at your option. -# This file may not be copied, modified, or distributed except according to -# those terms. - -{.used.} - -import utils, ../../libp2p/[protocols/pubsub/pubsub, - protocols/pubsub/pubsubpeer, - protocols/pubsub/rpc/messages, - protocols/pubsub/rpc/protobuf] -import ../helpers - -suite "GossipSub": - teardown: - checkTrackers() - - test "Test oversized RPCMsg splitting": - let - gossipSub = TestGossipSub.init(newStandardSwitch()) - topic = "test_topic" - peer = gossipSub.getPubSubPeer(randomPeerId()) - largeMessageSize = peer.maxMessageSize div 2 + 100 # Just over half the max size - - # Create a dummy ControlMessage - let - graft = @[ControlGraft(topicID: "topic1")] - prune = @[ControlPrune(topicID: "topic2")] - ihave = @[ControlIHave(topicID: "topic3", messageIDs: @[@[1'u8, 2, 3], @[4'u8, 5, 6]])] - iwant = @[ControlIWant(messageIDs: @[@[7'u8, 8, 9]])] - - let control = some(ControlMessage( - graft: graft, - prune: prune, - ihave: ihave, - iwant: iwant - )) - - # Create a message that's just over half the max size - let largeMessage = Message(data: newSeq[byte](largeMessageSize)) - - # Create an RPCMsg with two such messages, making it oversized - var oversizedMsg = RPCMsg(messages: @[largeMessage, largeMessage], control: control) - - # Mock the sendEncoded function to capture the messages being sent - var sentMessages = peer.send(oversizedMsg, false) - - # The first split message should have the control data, others shouldn't - check: sentMessages[0].control == control - for i in 1..