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

This commit is contained in:
Alexander Shishenko
2022-09-05 07:31:13 +03:00
committed by GitHub
parent f04df2901b
commit b8c3b282ee
2 changed files with 9 additions and 4 deletions

View File

@ -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.

View File

@ -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 {