Skip to content

Commit

Permalink
chore: change naming of symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Feb 5, 2025
1 parent 9db2ea0 commit 3bcd08a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 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 XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX).

## 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
44 changes: 23 additions & 21 deletions protocols/floodsub/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,18 @@ use libp2p_swarm::{
};
use smallvec::SmallVec;

use crate::{
protocol::{
FloodsubMessage, FloodsubProtocol, FloodsubRpc, FloodsubSubscription,
FloodsubSubscriptionAction,
},
topic::Topic,
FloodsubConfig,
};
use crate::{protocol::{
FloodsubMessage, FloodsubProtocol, FloodsubRpc, FloodsubSubscription,
FloodsubSubscriptionAction,
}, topic::Topic, Config, FloodsubConfig};

#[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,

Expand All @@ -73,15 +72,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,7 +240,7 @@ impl Floodsub {
}
if self.config.subscribe_local_messages {
self.events
.push_back(ToSwarm::GenerateEvent(FloodsubEvent::Message(
.push_back(ToSwarm::GenerateEvent(Event::Message(
message.clone(),
)));
}
Expand Down Expand Up @@ -337,9 +336,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 +392,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 +405,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 +438,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 +529,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
14 changes: 11 additions & 3 deletions protocols/floodsub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,23 @@ mod proto {
pub(crate) use self::floodsub::pb::{mod_RPC::SubOpts, Message, RPC};
}

#[allow(deprecated)]
pub use self::{
layer::{Floodsub, FloodsubEvent},
layer::{Floodsub, FloodsubEvent}
};

pub use self::{
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 +60,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 3bcd08a

Please sign in to comment.