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

refactor(gossipsub): revise symbol naming to follow conventions #3303

Merged
merged 23 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0303849
Rename types in gossipsub
StemCll Jan 1, 2023
11824b7
Examples fix
StemCll Jan 1, 2023
6b8ba63
Rename GossipsubEvent to Event
StemCll Jan 1, 2023
2a9982a
Rename Gossipsub to Behaviour; rename GossipsubConfig to Config
StemCll Jan 1, 2023
447ffe1
Rename Gossipsub handlers
StemCll Jan 2, 2023
27b4967
Rename Gossipsub handler error
StemCll Jan 2, 2023
d9a5fcd
Fix behaviour tests
StemCll Jan 2, 2023
bea120f
Fix examples and gossipsub/tests/smoke
StemCll Jan 4, 2023
be1503b
Rename GossipsubVersion to Version
StemCll Jan 4, 2023
d42a073
Add deprecations in lib.rs; make config module public
StemCll Jan 5, 2023
d328eaa
Fix doc's code
StemCll Jan 5, 2023
a061f87
Rename ProstMessage to ProtobufMessage in gossipsub/types
StemCll Jan 5, 2023
b6976d7
Revert Event::ProtobufMessage to Event:Message
StemCll Jan 10, 2023
25fe3ce
Remove config prefix from Config, Builder and Version
StemCll Jan 10, 2023
1a4d6c6
Revert renaming from Gossipsub to Behaviour in comments
StemCll Jan 13, 2023
5f5d2c6
Rename config::builder to ConfigBuilder; fix & add missing exports in…
StemCll Jan 15, 2023
2717c14
Add documentation renamings
StemCll Jan 15, 2023
d9efbc3
Fix rebase naming issues; remove whitespaces in lib.rs
StemCll Jan 26, 2023
07437bb
Add CHANGELOG entry
StemCll Jan 26, 2023
eff093a
Remove redundant deprecation
StemCll Jan 26, 2023
8d661ea
Update protocols/gossipsub/CHANGELOG.md
thomaseizinger Jan 26, 2023
4680e87
Update protocols/gossipsub/CHANGELOG.md
thomaseizinger Jan 27, 2023
2d983c1
Merge branch 'master' into chore/rename_gossipsub_symbols
mergify[bot] Jan 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions examples/gossipsub-chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@

use async_std::io;
use futures::{prelude::*, select};
use libp2p::gossipsub::MessageId;
use libp2p::gossipsub::{
Gossipsub, GossipsubEvent, GossipsubMessage, IdentTopic as Topic, MessageAuthenticity,
ValidationMode,
};
use libp2p::{
gossipsub, identity, mdns, swarm::NetworkBehaviour, swarm::SwarmEvent, PeerId, Swarm,
};
Expand All @@ -73,31 +68,34 @@ async fn main() -> Result<(), Box<dyn Error>> {
// We create a custom network behaviour that combines Gossipsub and Mdns.
#[derive(NetworkBehaviour)]
struct MyBehaviour {
gossipsub: Gossipsub,
gossipsub: gossipsub::Behaviour,
mdns: mdns::async_io::Behaviour,
}

// To content-address message, we can take the hash of message and use it as an ID.
let message_id_fn = |message: &GossipsubMessage| {
let message_id_fn = |message: &gossipsub::Message| {
let mut s = DefaultHasher::new();
message.data.hash(&mut s);
MessageId::from(s.finish().to_string())
gossipsub::MessageId::from(s.finish().to_string())
};

// Set a custom gossipsub configuration
let gossipsub_config = gossipsub::GossipsubConfigBuilder::default()
let gossipsub_config = gossipsub::ConfigBuilder::default()
.heartbeat_interval(Duration::from_secs(10)) // This is set to aid debugging by not cluttering the log space
.validation_mode(ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
.validation_mode(gossipsub::ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
.message_id_fn(message_id_fn) // content-address messages. No two messages of the same content will be propagated.
.build()
.expect("Valid config");

// build a gossipsub network behaviour
let mut gossipsub = Gossipsub::new(MessageAuthenticity::Signed(local_key), gossipsub_config)
.expect("Correct configuration");
let mut gossipsub = gossipsub::Behaviour::new(
gossipsub::MessageAuthenticity::Signed(local_key),
gossipsub_config,
)
.expect("Correct configuration");

// Create a Gossipsub topic
let topic = Topic::new("test-net");
let topic = gossipsub::IdentTopic::new("test-net");

// subscribes to our topic
gossipsub.subscribe(&topic)?;
Expand Down Expand Up @@ -140,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
swarm.behaviour_mut().gossipsub.remove_explicit_peer(&peer_id);
}
},
SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(GossipsubEvent::Message {
SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(gossipsub::Event::Message {
propagation_source: peer_id,
message_id: id,
message,
Expand Down
19 changes: 9 additions & 10 deletions examples/ipfs-private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use either::Either;
use futures::{prelude::*, select};
use libp2p::{
core::{muxing::StreamMuxerBox, transport, transport::upgrade::Version},
gossipsub::{self, Gossipsub, GossipsubConfigBuilder, GossipsubEvent, MessageAuthenticity},
identify, identity,
gossipsub, identify, identity,
multiaddr::Protocol,
noise, ping,
pnet::{PnetConfig, PreSharedKey},
Expand Down Expand Up @@ -150,19 +149,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
#[derive(NetworkBehaviour)]
#[behaviour(out_event = "MyBehaviourEvent")]
struct MyBehaviour {
gossipsub: Gossipsub,
gossipsub: gossipsub::Behaviour,
identify: identify::Behaviour,
ping: ping::Behaviour,
}

enum MyBehaviourEvent {
Gossipsub(GossipsubEvent),
Gossipsub(gossipsub::Event),
Identify(identify::Event),
Ping(ping::Event),
}

impl From<GossipsubEvent> for MyBehaviourEvent {
fn from(event: GossipsubEvent) -> Self {
impl From<gossipsub::Event> for MyBehaviourEvent {
fn from(event: gossipsub::Event) -> Self {
MyBehaviourEvent::Gossipsub(event)
}
}
Expand All @@ -181,13 +180,13 @@ async fn main() -> Result<(), Box<dyn Error>> {

// Create a Swarm to manage peers and events
let mut swarm = {
let gossipsub_config = GossipsubConfigBuilder::default()
let gossipsub_config = gossipsub::ConfigBuilder::default()
.max_transmit_size(262144)
.build()
.expect("valid config");
let mut behaviour = MyBehaviour {
gossipsub: Gossipsub::new(
MessageAuthenticity::Signed(local_key.clone()),
gossipsub: gossipsub::Behaviour::new(
gossipsub::MessageAuthenticity::Signed(local_key.clone()),
gossipsub_config,
)
.expect("Valid configuration"),
Expand Down Expand Up @@ -236,7 +235,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
SwarmEvent::Behaviour(MyBehaviourEvent::Identify(event)) => {
println!("identify: {event:?}");
}
SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(GossipsubEvent::Message {
SwarmEvent::Behaviour(MyBehaviourEvent::Gossipsub(gossipsub::Event::Message {
propagation_source: peer_id,
message_id: id,
message,
Expand Down
6 changes: 3 additions & 3 deletions misc/metrics/src/gossipsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ impl Metrics {
}
}

impl super::Recorder<libp2p_gossipsub::GossipsubEvent> for Metrics {
fn record(&self, event: &libp2p_gossipsub::GossipsubEvent) {
if let libp2p_gossipsub::GossipsubEvent::Message { .. } = event {
impl super::Recorder<libp2p_gossipsub::Event> for Metrics {
fn record(&self, event: &libp2p_gossipsub::Event) {
if let libp2p_gossipsub::Event::Message { .. } = event {
self.messages.inc();
}
}
Expand Down
4 changes: 2 additions & 2 deletions misc/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ impl Recorder<libp2p_dcutr::Event> for Metrics {

#[cfg(feature = "gossipsub")]
#[cfg(not(target_os = "unknown"))]
impl Recorder<libp2p_gossipsub::GossipsubEvent> for Metrics {
fn record(&self, event: &libp2p_gossipsub::GossipsubEvent) {
impl Recorder<libp2p_gossipsub::Event> for Metrics {
fn record(&self, event: &libp2p_gossipsub::Event) {
self.gossipsub.record(event)
}
}
Expand Down
8 changes: 8 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@

- Initialize `ProtocolConfig` via `GossipsubConfig`. See [PR 3381].

- Rename types as per [discussion 2174].
`Gossipsub` has been renamed to `Behaviour`.
The `Gossipsub` prefix has been removed from various types like `GossipsubConfig` or `GossipsubMessage`.
It is preferred to import the gossipsub protocol as a module (`use libp2p::gossipsub;`),
and refer to its types via `gossipsub::`. For example: `gossipsub::Behaviour` or `gossipsub::RawMessage`. See [PR 3303].
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved

[PR 3207]: https://github.com/libp2p/rust-libp2p/pull/3207/
[PR 3303]: https://github.com/libp2p/rust-libp2p/pull/3303/
[PR 3381]: https://github.com/libp2p/rust-libp2p/pull/3381/
[discussion 2174]: https://github.com/libp2p/rust-libp2p/discussions/2174

# 0.43.0

Expand Down
Loading