Skip to content

Commit 5ac2e20

Browse files
authored
fix(gossipsub): Improve max_messages_per_rpc consistency
Currently, when a gossipsub [Rpc](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.0.md#protobuf) is received, only the publish messages are being checked for `max_messages_per_rpc`. This PR improves the config flag consistency by applying the check to the Control Messages as well. Pull-Request: #5826.
1 parent 3ce976d commit 5ac2e20

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ libp2p-core = { version = "0.43.0", path = "core" }
8080
libp2p-dcutr = { version = "0.13.0", path = "protocols/dcutr" }
8181
libp2p-dns = { version = "0.43.0", path = "transports/dns" }
8282
libp2p-floodsub = { version = "0.46.0", path = "protocols/floodsub" }
83-
libp2p-gossipsub = { version = "0.48.0", path = "protocols/gossipsub" }
83+
libp2p-gossipsub = { version = "0.48.1", path = "protocols/gossipsub" }
8484
libp2p-identify = { version = "0.46.0", path = "protocols/identify" }
8585
libp2p-identity = { version = "0.2.10" }
8686
libp2p-kad = { version = "0.47.0", path = "protocols/kad" }

protocols/gossipsub/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.48.1
2+
- Improve `max_messages_per_rpc` consistency by ensuring RPC control messages also adhere to the existing limits.
3+
See [PR 5826](https://github.com/libp2p/rust-libp2p/pull/5826)
4+
15
## 0.48.0
26

37
- Allow broadcasting `IDONTWANT` messages when publishing to avoid downloading data that is already available.

protocols/gossipsub/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
33
edition = "2021"
44
rust-version = { workspace = true }
55
description = "Gossipsub protocol for libp2p"
6-
version = "0.48.0"
6+
version = "0.48.1"
77
authors = ["Age Manning <Age@AgeManning.com>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

protocols/gossipsub/src/behaviour.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,8 +3245,10 @@ where
32453245
// Handle messages
32463246
for (count, raw_message) in rpc.messages.into_iter().enumerate() {
32473247
// Only process the amount of messages the configuration allows.
3248-
if self.config.max_messages_per_rpc().is_some()
3249-
&& Some(count) >= self.config.max_messages_per_rpc()
3248+
if self
3249+
.config
3250+
.max_messages_per_rpc()
3251+
.is_some_and(|max_msg| count >= max_msg)
32503252
{
32513253
tracing::warn!("Received more messages than permitted. Ignoring further messages. Processed: {}", count);
32523254
break;
@@ -3260,7 +3262,17 @@ where
32603262
let mut ihave_msgs = vec![];
32613263
let mut graft_msgs = vec![];
32623264
let mut prune_msgs = vec![];
3263-
for control_msg in rpc.control_msgs {
3265+
for (count, control_msg) in rpc.control_msgs.into_iter().enumerate() {
3266+
// Only process the amount of messages the configuration allows.
3267+
if self
3268+
.config
3269+
.max_messages_per_rpc()
3270+
.is_some_and(|max_msg| count >= max_msg)
3271+
{
3272+
tracing::warn!("Received more control messages than permitted. Ignoring further messages. Processed: {}", count);
3273+
break;
3274+
}
3275+
32643276
match control_msg {
32653277
ControlAction::IHave(IHave {
32663278
topic_hash,

0 commit comments

Comments
 (0)