Skip to content

Commit

Permalink
chore(floodsub): change naming conventions
Browse files Browse the repository at this point in the history
related to #2217.

Pull-Request: #5855.
  • Loading branch information
dariusc93 authored Feb 12, 2025
1 parent 5f0d3f2 commit a966f62
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions protocols/floodsub/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

<!-- Update to libp2p-core v0.43.0 -->
Expand Down
2 changes: 1 addition & 1 deletion protocols/floodsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
38 changes: 21 additions & 17 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToSwarm<FloodsubEvent, FloodsubRpc>>,
events: VecDeque<ToSwarm<Event, FloodsubRpc>>,

config: FloodsubConfig,
config: Config,

/// List of peers to send messages to.
target_peers: FnvHashSet<PeerId>,
Expand All @@ -73,15 +76,15 @@ pub struct Floodsub {
received: CuckooFilter<DefaultHasher>,
}

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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -337,9 +338,9 @@ impl Floodsub {
}
}

impl NetworkBehaviour for Floodsub {
impl NetworkBehaviour for Behaviour {
type ConnectionHandler = OneShotHandler<FloodsubProtocol, FloodsubRpc, InnerMessage>;
type ToSwarm = FloodsubEvent;
type ToSwarm = Event;

fn handle_established_inbound_connection(
&mut self,
Expand Down Expand Up @@ -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,
}));
Expand All @@ -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,
}));
Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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),

Expand Down
11 changes: 8 additions & 3 deletions protocols/floodsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -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,
Expand Down

0 comments on commit a966f62

Please sign in to comment.