Skip to content

Commit

Permalink
protocols/gossipsub: Allow publishing to anything that implements `In…
Browse files Browse the repository at this point in the history
…to<TopicHash>` (#2862)
  • Loading branch information
GamePad64 authored Sep 5, 2022
1 parent f04df29 commit b8c3b28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit b8c3b28

Please sign in to comment.