Skip to main content

Partial

Trait Partial 

pub trait Partial: Send + Sync {
    // Required methods
    fn group_id(&self) -> Vec<u8> ⓘ;
    fn metadata(&self) -> Box<dyn Metadata>;
    fn partial_action_from_metadata(
        &self,
        peer_id: PeerId,
        metadata: Option<&[u8]>,
    ) -> Result<PartialAction, PartialError>;
}
Available on crate features gossipsub and partial-messages only.
Expand description

PartialMessage is a message that can be broken up into parts. This trait allows applications to define custom strategies for splitting large messages into parts and reconstructing them from received partial data. It provides the core operations needed for the gossipsub partial messages extension.

The partial message protocol works as follows:

  1. Applications implement this trait to define how messages are split and reconstructed
  2. Peers advertise available and missing parts using the metadata() in PartialMessage
  3. When requests are received, partial_action_from_metadata() generates the response
  4. If a new part is received it is reported to the application layer to freely integrate it as it deems.
  5. The group_id() ties all parts of the same logical message together

Required Methods§

fn group_id(&self) -> Vec<u8> ⓘ

Returns the unique identifier for this message group.

All partial messages belonging to the same logical message should return the same group ID. This is used to associate partial messages together during reconstruction.

fn metadata(&self) -> Box<dyn Metadata>

Returns application defined metadata describing which parts of the message are available and which parts we want.

The returned bytes will be sent in partsMetadata field of the protobuf to advertise available and wanted parts to peers.

fn partial_action_from_metadata( &self, peer_id: PeerId, metadata: Option<&[u8]>, ) -> Result<PartialAction, PartialError>

Generates an action from the given metadata.

When a peer requests specific parts, this method generates the actual message data to send back. The metadata parameter describes both what parts are being requested by the peer, and what parts the peer has that we may not have yet.

Returns a PartialAction for the given metadata, or an error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§