commonware_p2p/authenticated/discovery/actors/spawner/
ingress.rs1use crate::authenticated::{discovery::actors::tracker::Reservation, Mailbox};
2use commonware_cryptography::PublicKey;
3use commonware_runtime::{Sink, Stream};
4use commonware_stream::{Receiver, Sender};
5use commonware_utils::channels::fallible::AsyncFallibleExt;
6
7pub enum Message<O: Sink, I: Stream, P: PublicKey> {
9 Spawn {
11 peer: P,
13 connection: (Sender<O>, Receiver<I>),
15 reservation: Reservation<P>,
17 },
18}
19
20impl<P: PublicKey, O: Sink, I: Stream> Mailbox<Message<O, I, P>> {
21 pub async fn spawn(
26 &mut self,
27 connection: (Sender<O>, Receiver<I>),
28 reservation: Reservation<P>,
29 ) {
30 self.0
31 .send_lossy(Message::Spawn {
32 peer: reservation.metadata().public_key().clone(),
33 connection,
34 reservation,
35 })
36 .await;
37 }
38}