atm0s_small_p2p/
requester.rs1use tokio::sync::{mpsc::UnboundedSender, oneshot};
2
3use crate::{ControlCmd, PeerAddress};
4
5pub struct P2pNetworkRequester {
6 pub(crate) control_tx: UnboundedSender<ControlCmd>,
7}
8
9impl P2pNetworkRequester {
10 pub async fn connect(&self, addr: PeerAddress) -> anyhow::Result<()> {
11 let (tx, rx) = oneshot::channel();
12 self.control_tx.send(ControlCmd::Connect(addr, Some(tx))).expect("should send to main loop");
13 rx.await?
14 }
15
16 pub fn try_connect(&self, addr: PeerAddress) {
17 self.control_tx.send(ControlCmd::Connect(addr, None)).expect("should send to main loop");
18 }
19}