diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index fc63a305923..8e292b87b05 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -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 diff --git a/protocols/gossipsub/src/protocol_priv.rs b/protocols/gossipsub/src/protocol_priv.rs index 34d931bbaf9..2145cd9dd4b 100644 --- a/protocols/gossipsub/src/protocol_priv.rs +++ b/protocols/gossipsub/src/protocol_priv.rs @@ -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(), @@ -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(), @@ -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::*; @@ -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" + ); + } }