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>;
}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:
- Applications implement this trait to define how messages are split and reconstructed
- Peers advertise available and missing parts using the
metadata()in PartialMessage - When requests are received,
partial_action_from_metadata()generates the response - If a new part is received it is reported to the application layer to freely integrate it as it deems.
- The
group_id()ties all parts of the same logical message together
Required Methods§
fn group_id(&self) -> Vec<u8> ⓘ
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>
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>
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".