From a966f626af5f3243a67207856c6a79df846d316a Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Wed, 12 Feb 2025 11:50:50 -0500 Subject: [PATCH] chore(floodsub): change naming conventions related to https://github.com/libp2p/rust-libp2p/issues/2217. Pull-Request: #5855. --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/floodsub/CHANGELOG.md | 4 ++++ protocols/floodsub/Cargo.toml | 2 +- protocols/floodsub/src/layer.rs | 38 ++++++++++++++++++--------------- protocols/floodsub/src/lib.rs | 11 +++++++--- 6 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1fedcba41b..b917d0a96e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2833,7 +2833,7 @@ dependencies = [ [[package]] name = "libp2p-floodsub" -version = "0.46.0" +version = "0.46.1" dependencies = [ "asynchronous-codec", "bytes", diff --git a/Cargo.toml b/Cargo.toml index c97b610d80f..0d1880eb2b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,7 +79,7 @@ libp2p-connection-limits = { version = "0.5.1", path = "misc/connection-limits" libp2p-core = { version = "0.43.0", path = "core" } libp2p-dcutr = { version = "0.13.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.43.0", path = "transports/dns" } -libp2p-floodsub = { version = "0.46.0", path = "protocols/floodsub" } +libp2p-floodsub = { version = "0.46.1", path = "protocols/floodsub" } libp2p-gossipsub = { version = "0.48.1", path = "protocols/gossipsub" } libp2p-identify = { version = "0.46.0", path = "protocols/identify" } libp2p-identity = { version = "0.2.10" } diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 959bf539108..e2bd50141d7 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.46.1 +- Rename types to match naming convention in [discussion 2174](https://github.com/libp2p/rust-libp2p/discussions/2174). + See [PR 5855](https://github.com/libp2p/rust-libp2p/pull/5855). + ## 0.46.0 diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 15652bd46c0..e005d7eb7f2 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-floodsub" edition = "2021" rust-version = { workspace = true } description = "Floodsub protocol for libp2p" -version = "0.46.0" +version = "0.46.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index 477172b42c0..dfadbe4e0e4 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -46,15 +46,18 @@ use crate::{ FloodsubSubscriptionAction, }, topic::Topic, - FloodsubConfig, + Config, }; +#[deprecated = "Use `Behaviour` instead."] +pub type Floodsub = Behaviour; + /// Network behaviour that handles the floodsub protocol. -pub struct Floodsub { +pub struct Behaviour { /// Events that need to be yielded to the outside when polling. - events: VecDeque>, + events: VecDeque>, - config: FloodsubConfig, + config: Config, /// List of peers to send messages to. target_peers: FnvHashSet, @@ -73,15 +76,15 @@ pub struct Floodsub { received: CuckooFilter, } -impl Floodsub { +impl Behaviour { /// Creates a `Floodsub` with default configuration. pub fn new(local_peer_id: PeerId) -> Self { - Self::from_config(FloodsubConfig::new(local_peer_id)) + Self::from_config(Config::new(local_peer_id)) } /// Creates a `Floodsub` with the given configuration. - pub fn from_config(config: FloodsubConfig) -> Self { - Floodsub { + pub fn from_config(config: Config) -> Self { + Behaviour { events: VecDeque::new(), config, target_peers: FnvHashSet::default(), @@ -241,9 +244,7 @@ impl Floodsub { } if self.config.subscribe_local_messages { self.events - .push_back(ToSwarm::GenerateEvent(FloodsubEvent::Message( - message.clone(), - ))); + .push_back(ToSwarm::GenerateEvent(Event::Message(message.clone()))); } } // Don't publish the message if we have to check subscriptions @@ -337,9 +338,9 @@ impl Floodsub { } } -impl NetworkBehaviour for Floodsub { +impl NetworkBehaviour for Behaviour { type ConnectionHandler = OneShotHandler; - type ToSwarm = FloodsubEvent; + type ToSwarm = Event; fn handle_established_inbound_connection( &mut self, @@ -393,7 +394,7 @@ impl NetworkBehaviour for Floodsub { remote_peer_topics.push(subscription.topic.clone()); } self.events - .push_back(ToSwarm::GenerateEvent(FloodsubEvent::Subscribed { + .push_back(ToSwarm::GenerateEvent(Event::Subscribed { peer_id: propagation_source, topic: subscription.topic, })); @@ -406,7 +407,7 @@ impl NetworkBehaviour for Floodsub { remote_peer_topics.remove(pos); } self.events - .push_back(ToSwarm::GenerateEvent(FloodsubEvent::Unsubscribed { + .push_back(ToSwarm::GenerateEvent(Event::Unsubscribed { peer_id: propagation_source, topic: subscription.topic, })); @@ -439,7 +440,7 @@ impl NetworkBehaviour for Floodsub { .iter() .any(|t| message.topics.iter().any(|u| t == u)) { - let event = FloodsubEvent::Message(message.clone()); + let event = Event::Message(message.clone()); self.events.push_back(ToSwarm::GenerateEvent(event)); } @@ -530,9 +531,12 @@ impl From<()> for InnerMessage { } } +#[deprecated = "Use `Event` instead."] +pub type FloodsubEvent = Event; + /// Event that can happen on the floodsub behaviour. #[derive(Debug)] -pub enum FloodsubEvent { +pub enum Event { /// A message has been received. Message(FloodsubMessage), diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index d43b0c88788..ec4e2cf1b30 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -35,15 +35,20 @@ mod proto { pub(crate) use self::floodsub::pb::{mod_RPC::SubOpts, Message, RPC}; } +#[allow(deprecated)] +pub use self::layer::{Floodsub, FloodsubEvent}; pub use self::{ - layer::{Floodsub, FloodsubEvent}, + layer::{Behaviour, Event}, protocol::{FloodsubMessage, FloodsubRpc}, topic::Topic, }; +#[deprecated = "Use `Config` instead."] +pub type FloodsubConfig = Config; + /// Configuration options for the Floodsub protocol. #[derive(Debug, Clone)] -pub struct FloodsubConfig { +pub struct Config { /// Peer id of the local node. Used for the source of the messages that we publish. pub local_peer_id: PeerId, @@ -52,7 +57,7 @@ pub struct FloodsubConfig { pub subscribe_local_messages: bool, } -impl FloodsubConfig { +impl Config { pub fn new(local_peer_id: PeerId) -> Self { Self { local_peer_id,