Skip to content

Commit

Permalink
feat: Notify when OkuNet fetches performed
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoh committed Dec 4, 2024
1 parent ccea806 commit c0f8f50
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/fs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
#[cfg(feature = "fuse")]
/// The handles pointing to paths within the file system; used by FUSE.
pub(crate) fs_handles: Arc<RwLock<HashMap<u64, PathBuf>>>,
Expand Down
4 changes: 4 additions & 0 deletions src/fs/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DocTicket> {
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();
Expand All @@ -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()
Expand Down Expand Up @@ -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<OkuUser> {
self.okunet_fetch_sender.send_replace(true);
let ticket = self
.resolve_author_id(author_id)
.await
Expand All @@ -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))
Expand Down

0 comments on commit c0f8f50

Please sign in to comment.