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

1use crate::authenticated::{discovery::actors::tracker::Reservation, Mailbox};
2use commonware_cryptography::PublicKey;
3use commonware_runtime::{Clock, Metrics, Network, Sink, Spawner, Stream};
4use commonware_stream::public_key::Connection;
5
6/// Messages that can be processed by the spawner actor.
7pub enum Message<E: Spawner + Clock + Metrics, 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: Connection<Si, St>,
14        /// The reservation for the peer.
15        reservation: Reservation<E, P>,
16    },
17}
18
19impl<E: Spawner + Clock + Metrics + Network, P: PublicKey, Si: Sink, St: Stream>
20    Mailbox<Message<E, Si, St, P>>
21{
22    /// Send a message to the actor to spawn a new task for the given peer.
23    pub async fn spawn(&mut self, connection: Connection<Si, St>, reservation: Reservation<E, P>) {
24        self.send(Message::Spawn {
25            peer: reservation.metadata().public_key().clone(),
26            connection,
27            reservation,
28        })
29        .await
30        .unwrap();
31    }
32}