From c0f8f50440a71349cda32d9013f2902563c7fea1 Mon Sep 17 00:00:00 2001 From: Emil Sayahi <97276123+emmyoh@users.noreply.github.com> Date: Wed, 4 Dec 2024 14:38:46 -0500 Subject: [PATCH] feat: Notify when OkuNet fetches performed --- src/fs/core.rs | 2 ++ src/fs/mod.rs | 2 ++ src/fs/net.rs | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/src/fs/core.rs b/src/fs/core.rs index 28dbd05..1d33ef1 100644 --- a/src/fs/core.rs +++ b/src/fs/core.rs @@ -122,11 +122,13 @@ impl OkuFs { info!("Default author ID is {} … ", default_author_id.fmt_short()); let (replica_sender, _replica_receiver) = watch::channel(()); + let (okunet_fetch_sender, _okunet_fetch_receiver) = watch::channel(false); let oku_fs = Self { running_node, node, replica_sender, + okunet_fetch_sender, #[cfg(feature = "fuse")] fs_handles: Arc::new(RwLock::new(HashMap::new())), #[cfg(feature = "fuse")] diff --git a/src/fs/mod.rs b/src/fs/mod.rs index f04003f..ce5a82b 100644 --- a/src/fs/mod.rs +++ b/src/fs/mod.rs @@ -52,6 +52,8 @@ pub struct OkuFs { pub(crate) node: Iroh, /// A watcher for when replicas are created, deleted, or imported. pub replica_sender: Sender<()>, + /// A watcher for whether or not content is being fetched from the OkuNet. + pub okunet_fetch_sender: Sender, #[cfg(feature = "fuse")] /// The handles pointing to paths within the file system; used by FUSE. pub(crate) fs_handles: Arc>>, diff --git a/src/fs/net.rs b/src/fs/net.rs index c8004c0..3a9b8ef 100644 --- a/src/fs/net.rs +++ b/src/fs/net.rs @@ -599,6 +599,7 @@ impl OkuFs { /// /// A ticket for the home replica of the user with the given content authorship ID. pub async fn resolve_author_id(&self, author_id: AuthorId) -> anyhow::Result { + self.okunet_fetch_sender.send_replace(true); let get_stream = self.dht.get_mutable(author_id.as_bytes(), None, None)?; tokio::pin!(get_stream); let mut tickets = Vec::new(); @@ -609,6 +610,7 @@ impl OkuFs { }); tickets.push(DocTicket::from_bytes(mutable_item.value())?) } + self.okunet_fetch_sender.send_replace(false); merge_tickets(tickets).ok_or(anyhow!( "Could not find tickets for {} … ", author_id.to_string() @@ -755,6 +757,7 @@ impl OkuFs { /// /// The latest version of an OkuNet user's content. pub async fn fetch_user(&self, author_id: AuthorId) -> miette::Result { + self.okunet_fetch_sender.send_replace(true); let ticket = self .resolve_author_id(author_id) .await @@ -772,6 +775,7 @@ impl OkuFs { .unwrap_or_default(), identity: profile, })?; + self.okunet_fetch_sender.send_replace(false); DATABASE .get_user(author_id)? .ok_or(miette::miette!("User {} not found … ", author_id))