p2p_chat/network/layer/
providers.rs1use anyhow::Result;
3use tokio::sync::mpsc;
4
5use crate::cli::commands::UiNotification;
6use crate::mailbox::{make_mailbox_provider_key, make_recipient_mailbox_key};
7use crate::sync::SyncEvent;
8
9use super::NetworkLayer;
10
11impl NetworkLayer {
12 pub fn set_sync_event_sender(&mut self, sender: mpsc::UnboundedSender<SyncEvent>) {
14 self.sync_event_tx = Some(sender);
15 }
16
17 pub fn set_ui_notify_sender(&mut self, sender: mpsc::UnboundedSender<UiNotification>) {
19 self.ui_notify_tx = Some(sender);
20 }
21
22 pub fn bootstrap_dht(&mut self) -> Result<()> {
28 self.swarm.behaviour_mut().discovery.bootstrap()
29 }
30
31 pub fn start_providing_mailbox(&mut self) -> Result<()> {
37 let key = make_mailbox_provider_key();
38 self.swarm.behaviour_mut().discovery.start_providing(key)
39 }
40
41 pub fn start_providing_for_recipient(&mut self, recipient_hash: [u8; 32]) -> Result<()> {
51 let key = make_recipient_mailbox_key(recipient_hash);
52 self.swarm.behaviour_mut().discovery.start_providing(key)
53 }
54}