Skip to content

Commit

Permalink
fix(gossipsub): always honor support_floodsub setting
Browse files Browse the repository at this point in the history
Previously, we only honored the `support_floodsub` setting when the user did not specify a custom protocol for gossipsub. This patch fixes this and allows users to advertise floodsub even when they use a custom protocol.

Pull-Request: #3837.
  • Loading branch information
thomaseizinger authored Apr 27, 2023
1 parent 71805ca commit 9d1058d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 0.44.4 - unreleased

- Deprecate `metrics`, `protocol`, `subscription_filter`, `time_cache` modules to make them private. See [PR 3777].
- Honor the `gossipsub::Config::support_floodsub` in all cases.
Previously, it was ignored when a custom protocol id was set via `gossipsub::Config::protocol_id`.
See [PR 3837].

[PR 3777]: https://github.com/libp2p/rust-libp2p/pull/3777
[PR 3837]: https://github.com/libp2p/rust-libp2p/pull/3837

## 0.44.3

Expand Down
40 changes: 29 additions & 11 deletions protocols/gossipsub/src/protocol_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl ProtocolConfig {
///
/// Sets the maximum gossip transmission size.
pub fn new(gossipsub_config: &Config) -> ProtocolConfig {
let protocol_ids = match gossipsub_config.custom_id_version() {
let mut protocol_ids = match gossipsub_config.custom_id_version() {
Some(v) => match v {
Version::V1_0 => vec![ProtocolId::new(
gossipsub_config.protocol_id(),
Expand All @@ -71,24 +71,22 @@ impl ProtocolConfig {
)],
},
None => {
let mut protocol_ids = vec![
vec![
ProtocolId::new(
gossipsub_config.protocol_id(),
PeerKind::Gossipsubv1_1,
true,
),
ProtocolId::new(gossipsub_config.protocol_id(), PeerKind::Gossipsub, true),
];

// add floodsub support if enabled.
if gossipsub_config.support_floodsub() {
protocol_ids.push(ProtocolId::new("", PeerKind::Floodsub, false));
}

protocol_ids
]
}
};

// add floodsub support if enabled.
if gossipsub_config.support_floodsub() {
protocol_ids.push(ProtocolId::new("", PeerKind::Floodsub, false));
}

ProtocolConfig {
protocol_ids,
max_transmit_size: gossipsub_config.max_transmit_size(),
Expand Down Expand Up @@ -556,8 +554,8 @@ impl Decoder for GossipsubCodec {
mod tests {
use super::*;
use crate::config::Config;
use crate::Behaviour;
use crate::IdentTopic as Topic;
use crate::{Behaviour, ConfigBuilder};
use libp2p_core::identity::Keypair;
use quickcheck_ext::*;

Expand Down Expand Up @@ -653,4 +651,24 @@ mod tests {

QuickCheck::new().quickcheck(prop as fn(_) -> _)
}

#[test]
fn support_floodsub_with_custom_protocol() {
let gossipsub_config = ConfigBuilder::default()
.protocol_id("/foosub", Version::V1_1)
.support_floodsub()
.build()
.unwrap();

let protocol_config = ProtocolConfig::new(&gossipsub_config);

assert_eq!(
String::from_utf8_lossy(&protocol_config.protocol_ids[0].protocol_id),
"/foosub"
);
assert_eq!(
String::from_utf8_lossy(&protocol_config.protocol_ids[1].protocol_id),
"/floodsub/1.0.0"
);
}
}

0 comments on commit 9d1058d

Please sign in to comment.