pub struct P2pNetworkPubsubState {
pub clients: BTreeMap<PeerId, P2pNetworkPubsubClientState>,
pub seq: u64,
pub to_sign: VecDeque<Message>,
pub seen: VecDeque<Vec<u8>>,
pub mcache: P2pNetworkPubsubMessageCache,
pub incoming_transactions: Vec<(Transaction, u32)>,
pub incoming_snarks: Vec<(Snark, u32)>,
pub topics: BTreeMap<String, BTreeMap<PeerId, P2pNetworkPubsubClientTopicState>>,
pub iwant: VecDeque<P2pNetworkPubsubIwantRequestCount>,
}
Expand description
State of the P2P Network PubSub system.
This struct maintains information about connected peers, message sequencing, message caching, and topic subscriptions. It handles incoming and outgoing messages, manages the mesh network topology, and ensures efficient message broadcasting across the network.
Fields§
§clients: BTreeMap<PeerId, P2pNetworkPubsubClientState>
State of each connected peer.
seq: u64
Current message sequence number.
Increments with each new message to ensure proper ordering and uniqueness.
to_sign: VecDeque<Message>
Messages awaiting cryptographic signing.
seen: VecDeque<Vec<u8>>
Recently seen message identifiers to prevent duplication.
Keeps a limited history of message signatures to avoid processing the same message multiple times.
mcache: P2pNetworkPubsubMessageCache
Cache of published messages for efficient retrieval and broadcasting.
For quick access and reducing redundant data transmission across peers.
incoming_transactions: Vec<(Transaction, u32)>
Incoming transactions from peers along with their nonces.
incoming_snarks: Vec<(Snark, u32)>
Incoming snarks from peers along with their nonces.
topics: BTreeMap<String, BTreeMap<PeerId, P2pNetworkPubsubClientTopicState>>
Topics and their subscribed peers.
iwant: VecDeque<P2pNetworkPubsubIwantRequestCount>
iwant
requests, tracking the number of times peers have expressed interest in specific messages.
Implementations§
Source§impl P2pNetworkPubsubState
impl P2pNetworkPubsubState
pub fn prune_peer_state(&mut self, peer_id: &PeerId)
pub fn filter_iwant_message_ids( &mut self, message_id: &[u8], timestamp: Timestamp, ) -> bool
pub fn clear_incoming(&mut self)
Source§impl P2pNetworkPubsubState
impl P2pNetworkPubsubState
pub fn reducer<Action, State>(
state_context: Substate<'_, Action, State, Self>,
action: ActionWithMeta<P2pNetworkPubsubAction>,
) -> Result<(), String>where
State: P2pStateTrait,
Action: P2pActionTrait<State>,
fn prepare_to_sign<Action, State>(
state_context: Substate<'_, Action, State, Self>,
buffer: Vec<u8>,
) -> Result<(), String>where
State: P2pStateTrait,
Action: P2pActionTrait<State>,
Sourcefn reduce_incoming_validated_message(
&mut self,
message_id: P2pNetworkPubsubMessageCacheId,
peer_id: PeerId,
message: &Message,
)
fn reduce_incoming_validated_message( &mut self, message_id: P2pNetworkPubsubMessageCacheId, peer_id: PeerId, message: &Message, )
Queues a validated message for propagation to other peers in the pubsub network. For peers that are “on mesh” for the message’s topic, queues the full message. For other peers, queues an IHAVE control message to notify about message availability. The original sender is excluded from propagation.
Sourcefn reduce_incoming_message(
&mut self,
message: &Message,
seen_limit: usize,
) -> Result<Option<GossipNetMessageV2>, String>
fn reduce_incoming_message( &mut self, message: &Message, seen_limit: usize, ) -> Result<Option<GossipNetMessageV2>, String>
Processes an incoming message by checking for duplicates and deserializing its contents.
This function performs two main operations:
- Deduplication: Tracks recently seen messages using their signatures to avoid processing duplicates
- Deserialization: Converts valid message data into a
GossipNetMessageV2
structure
§Arguments
message
- The incoming message to processseen_limit
- Maximum number of message signatures to keep in the deduplication cache
§Returns
Ok(Some(GossipNetMessageV2))
- Successfully processed and deserialized messageOk(None)
- Message was a duplicate (already seen)Err(String)
- Error during processing (invalid message format or deserialization failure)
fn combined_with_pending_buffer<'a>( buffer: &'a mut Vec<u8>, data: &'a [u8], ) -> &'a [u8] ⓘ
Sourcefn reduce_incoming_data(
&mut self,
peer_id: &PeerId,
data: Data,
timestamp: Timestamp,
) -> Result<(), String>
fn reduce_incoming_data( &mut self, peer_id: &PeerId, data: Data, timestamp: Timestamp, ) -> Result<(), String>
Processes incoming data from a peer, handling subscriptions, control messages, and message broadcasting within the P2P pubsub system.
fn update_subscriptions( &mut self, peer_id: &PeerId, subscriptions: Vec<SubOpts>, )
Sourcefn apply_control_commands(&mut self, peer_id: &PeerId, control: &ControlMessage)
fn apply_control_commands(&mut self, peer_id: &PeerId, control: &ControlMessage)
Applies control commands (graft
and prune
) to manage the peer’s mesh states within topics.
fn respond_to_iwant_requests( &mut self, peer_id: &PeerId, iwant_requests: &[ControlIWant], )
fn process_ihave_messages( &mut self, peer_id: &PeerId, ihave_messages: Vec<ControlIHave>, timestamp: Timestamp, )
fn broadcast<Action, State>(
dispatcher: &mut Dispatcher<Action, State>,
state: &State,
) -> Result<(), String>where
State: P2pStateTrait,
Action: P2pActionTrait<State>,
Trait Implementations§
Source§impl Clone for P2pNetworkPubsubState
impl Clone for P2pNetworkPubsubState
Source§fn clone(&self) -> P2pNetworkPubsubState
fn clone(&self) -> P2pNetworkPubsubState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for P2pNetworkPubsubState
impl Debug for P2pNetworkPubsubState
Source§impl Default for P2pNetworkPubsubState
impl Default for P2pNetworkPubsubState
Source§fn default() -> P2pNetworkPubsubState
fn default() -> P2pNetworkPubsubState
Source§impl<'de> Deserialize<'de> for P2pNetworkPubsubState
impl<'de> Deserialize<'de> for P2pNetworkPubsubState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl MallocSizeOf for P2pNetworkPubsubState
impl MallocSizeOf for P2pNetworkPubsubState
Source§impl Serialize for P2pNetworkPubsubState
impl Serialize for P2pNetworkPubsubState
Source§impl SubstateAccess<P2pNetworkPubsubState> for P2pState
impl SubstateAccess<P2pNetworkPubsubState> for P2pState
Source§fn substate(&self) -> SubstateResult<&P2pNetworkPubsubState>
fn substate(&self) -> SubstateResult<&P2pNetworkPubsubState>
Source§fn substate_mut(&mut self) -> SubstateResult<&mut P2pNetworkPubsubState>
fn substate_mut(&mut self) -> SubstateResult<&mut P2pNetworkPubsubState>
Auto Trait Implementations§
impl Freeze for P2pNetworkPubsubState
impl RefUnwindSafe for P2pNetworkPubsubState
impl Send for P2pNetworkPubsubState
impl Sync for P2pNetworkPubsubState
impl Unpin for P2pNetworkPubsubState
impl UnwindSafe for P2pNetworkPubsubState
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.