commonware_p2p/authenticated/lookup/actors/spawner/
ingress.rs

1use crate::authenticated::{lookup::actors::tracker::Reservation, Mailbox};
2use commonware_cryptography::PublicKey;
3use commonware_runtime::{Sink, Stream};
4use commonware_stream::{Receiver, Sender};
5
6/// Messages that can be processed by the spawner actor.
7pub enum Message<Si: Sink, St: Stream, P: PublicKey> {
8    /// Notify the spawner to create a new task for the given peer.
9    Spawn {
10        /// The peer's public key.
11        peer: P,
12        /// The connection to the peer.
13        connection: (Sender<Si>, Receiver<St>),
14        /// The reservation for the peer.
15        reservation: Reservation<P>,
16    },
17}
18
19impl<Si: Sink, St: Stream, P: PublicKey> Mailbox<Message<Si, St, P>> {
20    /// Send a message to the actor to spawn a new task for the given peer.
21    pub async fn spawn(
22        &mut self,
23        connection: (Sender<Si>, Receiver<St>),
24        reservation: Reservation<P>,
25    ) {
26        self.send(Message::Spawn {
27            peer: reservation.metadata().public_key().clone(),
28            connection,
29            reservation,
30        })
31        .await
32        .unwrap();
33    }
34}