@@ -14,17 +14,49 @@ use serde::{Deserialize, Serialize};
1414
1515pub const IWANT_TIMEOUT_DURATION : Duration = Duration :: from_secs ( 5 ) ;
1616
17+ /// State of the P2P Network PubSub system.
18+ ///
19+ /// This struct maintains information about connected peers, message sequencing,
20+ /// message caching, and topic subscriptions. It handles incoming and outgoing
21+ /// messages, manages the mesh network topology, and ensures efficient message
22+ /// broadcasting across the network.
1723#[ derive( Default , Serialize , Deserialize , Debug , Clone ) ]
1824pub struct P2pNetworkPubsubState {
25+ /// State of each connected peer.
1926 pub clients : BTreeMap < PeerId , P2pNetworkPubsubClientState > ,
27+
28+ /// Current message sequence number.
29+ ///
30+ /// Increments with each new message to ensure proper ordering and uniqueness.
2031 pub seq : u64 ,
32+
33+ /// Messages awaiting cryptographic signing.
2134 pub to_sign : VecDeque < pb:: Message > ,
35+
36+ /// Recently seen message identifiers to prevent duplication.
37+ ///
38+ /// Keeps a limited history of message signatures to avoid processing
39+ /// the same message multiple times.
2240 pub seen : VecDeque < Vec < u8 > > ,
41+
42+ /// Cache of published messages for efficient retrieval and broadcasting.
43+ ///
44+ /// For quick access and reducing redundant data transmission across peers.
2345 pub mcache : P2pNetworkPubsubMessageCache ,
46+
47+ /// Incoming block from a peer, if any.
2448 pub incoming_block : Option < ( PeerId , Arc < v2:: MinaBlockBlockStableV2 > ) > ,
49+
50+ /// Incoming transactions from peers along with their nonces.
2551 pub incoming_transactions : Vec < ( Transaction , u32 ) > ,
52+
53+ /// Incoming snarks from peers along with their nonces.
2654 pub incoming_snarks : Vec < ( Snark , u32 ) > ,
55+
56+ /// Topics and their subscribed peers.
2757 pub topics : BTreeMap < String , BTreeMap < PeerId , P2pNetworkPubsubClientTopicState > > ,
58+
59+ /// `iwant` requests, tracking the number of times peers have expressed interest in specific messages.
2860 pub iwant : VecDeque < P2pNetworkPubsubIwantRequestCount > ,
2961}
3062
@@ -86,14 +118,45 @@ impl P2pNetworkPubsubState {
86118 }
87119}
88120
121+ /// State of a pubsub client connected to a peer.
122+ ///
123+ /// This struct maintains essential information about the client's protocol,
124+ /// connection details, message buffers, and caching mechanisms. It facilitates
125+ /// efficient message handling and broadcasting within the pubsub system.
89126#[ derive( Serialize , Deserialize , Debug , Clone ) ]
90127pub struct P2pNetworkPubsubClientState {
128+ /// Broadcast algorithm used for this client.
91129 pub protocol : BroadcastAlgorithm ,
130+
131+ /// Connection address of the peer.
92132 pub addr : ConnectionAddr ,
133+
134+ /// Outgoing stream identifier, if any.
135+ ///
136+ /// - `Some(StreamId)`: Indicates an active outgoing stream.
137+ /// - `None`: No outgoing stream is currently established.
93138 pub outgoing_stream_id : Option < StreamId > ,
139+
140+ /// Current RPC message being constructed or processed.
141+ ///
142+ /// - `subscriptions`: List of subscription options for various topics.
143+ /// - `publish`: Messages queued for publishing.
144+ /// - `control`: Control commands for managing the mesh network.
94145 pub message : pb:: Rpc ,
146+
147+ /// Cache of recently published messages.
95148 pub cache : P2pNetworkPubsubRecentlyPublishCache ,
149+
150+ /// Buffer for incoming data fragments.
151+ ///
152+ /// Stores partial data received from peers, facilitating the assembly of complete
153+ /// messages when all fragments are received.
96154 pub buffer : Vec < u8 > ,
155+
156+ /// Collection of incoming messages from the peer.
157+ ///
158+ /// Holds fully decoded `pb::Message` instances received from the peer,
159+ /// ready for further handling such as validation, caching, and broadcasting.
97160 pub incoming_messages : Vec < pb:: Message > ,
98161}
99162
0 commit comments