pub struct State<PI, R> { /* private fields */ }
Expand description
The state of the iroh-gossip
protocol.
The implementation works as an IO-less state machine. The implementer injects events through
Self::handle
, which returns an iterator of OutEvent
s to be processed.
This struct contains a map of topic::State
for each topic that was joined. It mostly acts as
a forwarder of InEvent
s to matching topic state. Each topic’s state is completely
independent; thus the actual protocol logic lives with topic::State
.
Implementations§
Source§impl<PI: PeerIdentity, R: Rng + Clone> State<PI, R>
impl<PI: PeerIdentity, R: Rng + Clone> State<PI, R>
Sourcepub fn new(me: PI, me_data: Option<PeerData>, config: Config, rng: R) -> Self
pub fn new(me: PI, me_data: Option<PeerData>, config: Config, rng: R) -> Self
Create a new protocol state instance.
me
is the PeerIdentity
of the local node, peer_data
is the initial PeerData
(which can be updated over time).
For the protocol to perform as recommended in the papers, the Config
should be
identical for all nodes in the network.
Sourcepub fn me(&self) -> &PI
pub fn me(&self) -> &PI
Get a reference to the node’s PeerIdentity
Sourcepub fn state(&self, topic: &TopicId) -> Option<&State<PI, R>>
pub fn state(&self, topic: &TopicId) -> Option<&State<PI, R>>
Get a reference to the protocol state for a topic.
Sourcepub fn states(&self) -> impl Iterator<Item = (&TopicId, &State<PI, R>)>
pub fn states(&self) -> impl Iterator<Item = (&TopicId, &State<PI, R>)>
Get an iterator for the states of all joined topics.
Sourcepub fn has_active_peers(&self, topic: &TopicId) -> bool
pub fn has_active_peers(&self, topic: &TopicId) -> bool
Check if a topic has any active (connected) peers.
Sourcepub fn max_message_size(&self) -> usize
pub fn max_message_size(&self) -> usize
Returns the maximum message size configured in the gossip protocol.