Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gossipsub): always honor support_floodsub setting #3837

Merged
merged 10 commits into from
Apr 27, 2023
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 XXXX].

[PR 3777]: https://github.com/libp2p/rust-libp2p/pull/3777
[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

## 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"
);
}
}