commonware_p2p/authenticated/discovery/actors/peer/
ingress.rs

1use crate::authenticated::{discovery::types, Mailbox};
2use commonware_cryptography::PublicKey;
3use commonware_utils::channels::fallible::AsyncFallibleExt;
4
5/// Messages that can be sent to the peer [super::Actor].
6#[derive(Clone, Debug)]
7pub enum Message<C: PublicKey> {
8    /// Send a bit vector to the peer.
9    BitVec(types::BitVec),
10
11    /// Send a list of [types::Info] to the peer.
12    Peers(Vec<types::Info<C>>),
13
14    /// Kill the peer actor.
15    Kill,
16}
17
18impl<C: PublicKey> Mailbox<Message<C>> {
19    pub async fn bit_vec(&mut self, bit_vec: types::BitVec) {
20        self.0.send_lossy(Message::BitVec(bit_vec)).await;
21    }
22
23    pub async fn peers(&mut self, peers: Vec<types::Info<C>>) {
24        self.0.send_lossy(Message::Peers(peers)).await;
25    }
26
27    pub async fn kill(&mut self) {
28        self.0.send_lossy(Message::Kill).await;
29    }
30}