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

protocols/gossipsub: Allow publishing to anything that implements Into<TopicHash> #2862

Merged
merged 6 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
4 changes: 4 additions & 0 deletions protocols/gossipsub/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Update to `libp2p-swarm` `v0.39.0`.

- Allow publishing with any `impl Into<TopicHash>` as a topic. See [PR 2862].

[PR 2862]: https://github.com/libp2p/rust-libp2p/pull/2862

# 0.40.0

- Update prost requirement from 0.10 to 0.11 which no longer installs the protoc Protobuf compiler.
Expand Down
9 changes: 5 additions & 4 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,19 +587,20 @@ where
}

/// Publishes a message with multiple topics to the network.
pub fn publish<H: Hasher>(
pub fn publish(
&mut self,
topic: Topic<H>,
topic: impl Into<TopicHash>,
data: impl Into<Vec<u8>>,
) -> Result<MessageId, PublishError> {
let data = data.into();
let topic = topic.into();

// Transform the data before building a raw_message.
let transformed_data = self
.data_transform
.outbound_transform(&topic.hash(), data.clone())?;
.outbound_transform(&topic, data.clone())?;

let raw_message = self.build_raw_message(topic.into(), transformed_data)?;
let raw_message = self.build_raw_message(topic, transformed_data)?;

// calculate the message id from the un-transformed data
let msg_id = self.config.message_id(&GossipsubMessage {
Expand Down