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

Changes regarding the  #2217
This commit is contained in:
StemCll
2023-01-27 05:44:04 +01:00
committed by GitHub
parent e2b3c1190a
commit ab59af4d46
18 changed files with 639 additions and 633 deletions

View File

@ -25,25 +25,22 @@
//! algorithms that can be topic-specific. Once the raw data is transformed the message-id is then
//! calculated, allowing for applications to employ message-id functions post compression.
use crate::{GossipsubMessage, RawGossipsubMessage, TopicHash};
use crate::{Message, RawMessage, TopicHash};
/// A general trait of transforming a [`RawGossipsubMessage`] into a [`GossipsubMessage`]. The
/// [`RawGossipsubMessage`] is obtained from the wire and the [`GossipsubMessage`] is used to
/// A general trait of transforming a [`RawMessage`] into a [`Message`]. The
/// [`RawMessage`] is obtained from the wire and the [`Message`] is used to
/// calculate the [`crate::MessageId`] of the message and is what is sent to the application.
///
/// The inbound/outbound transforms must be inverses. Applying the inbound transform and then the
/// outbound transform MUST leave the underlying data un-modified.
///
/// By default, this is the identity transform for all fields in [`GossipsubMessage`].
/// By default, this is the identity transform for all fields in [`Message`].
pub trait DataTransform {
/// Takes a [`RawGossipsubMessage`] received and converts it to a [`GossipsubMessage`].
fn inbound_transform(
&self,
raw_message: RawGossipsubMessage,
) -> Result<GossipsubMessage, std::io::Error>;
/// Takes a [`RawMessage`] received and converts it to a [`Message`].
fn inbound_transform(&self, raw_message: RawMessage) -> Result<Message, std::io::Error>;
/// Takes the data to be published (a topic and associated data) transforms the data. The
/// transformed data will then be used to create a [`crate::RawGossipsubMessage`] to be sent to peers.
/// transformed data will then be used to create a [`crate::RawMessage`] to be sent to peers.
fn outbound_transform(
&self,
topic: &TopicHash,
@ -56,11 +53,8 @@ pub trait DataTransform {
pub struct IdentityTransform;
impl DataTransform for IdentityTransform {
fn inbound_transform(
&self,
raw_message: RawGossipsubMessage,
) -> Result<GossipsubMessage, std::io::Error> {
Ok(GossipsubMessage {
fn inbound_transform(&self, raw_message: RawMessage) -> Result<Message, std::io::Error> {
Ok(Message {
source: raw_message.source,
data: raw_message.data,
sequence_number: raw_message.sequence_number,