Skip to content

Commit

Permalink
Merge pull request #11 from n0-computer/try-out-gc
Browse files Browse the repository at this point in the history
feat!: use the new way to register gc exemptions in iroh-blobs
  • Loading branch information
rklaehn authored Nov 29, 2024
2 parents c146f7a + 4caa21f commit eeb8833
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 113 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ jobs:
run: |
echo "HEAD_COMMIT_SHA=$(git rev-parse origin/main)" >> ${GITHUB_ENV}
- name: Check semver
continue-on-error: true
# uses: obi1kenobi/cargo-semver-checks-action@v2
uses: n0-computer/cargo-semver-checks-action@feat-baseline
with:
Expand Down Expand Up @@ -255,6 +256,7 @@ jobs:
uses: mozilla-actions/sccache-action@v0.0.6

- name: Check MSRV all features
continue-on-error: true
run: |
cargo +$MSRV check --workspace --all-targets
Expand Down
67 changes: 17 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use anyhow::{bail, Context, Result};
use futures_lite::{Stream, StreamExt};
use iroh::{key::PublicKey, Endpoint, NodeAddr};
use iroh_blobs::{
downloader::Downloader, store::EntryStatus, util::local_pool::LocalPoolHandle, Hash,
downloader::Downloader, net_protocol::ProtectCb, store::EntryStatus,
util::local_pool::LocalPoolHandle, Hash,
};
use iroh_gossip::net::Gossip;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -125,6 +126,34 @@ impl<D: iroh_blobs::store::Store> Engine<D> {
})
}

/// Return a callback that can be added to blobs to protect the content of
/// all docs from garbage collection.
pub fn protect_cb(&self) -> ProtectCb {
let this = self.clone();
Box::new(move |live| {
let this = this.clone();
Box::pin(async move {
let doc_hashes = match this.sync.content_hashes().await {
Ok(hashes) => hashes,
Err(err) => {
tracing::warn!("Error getting doc hashes: {}", err);
return;
}
};
for hash in doc_hashes {
match hash {
Ok(hash) => {
live.insert(hash);
}
Err(err) => {
tracing::error!("Error getting doc hash: {}", err);
}
}
}
})
})
}

/// Get the blob store.
pub fn blob_store(&self) -> &D {
&self.blob_store
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ mod heads;
mod keys;
mod ranger;

#[cfg(feature = "net")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
#[doc(inline)]
pub use net::ALPN;

#[cfg(feature = "net")]
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
pub use self::ticket::DocTicket;
Expand Down
4 changes: 2 additions & 2 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
};

/// The ALPN identifier for the iroh-docs protocol
pub const DOCS_ALPN: &[u8] = b"/iroh-sync/1";
pub const ALPN: &[u8] = b"/iroh-sync/1";

mod codec;

Expand All @@ -35,7 +35,7 @@ pub async fn connect_and_sync(
let peer_id = peer.node_id;
trace!("connect");
let connection = endpoint
.connect(peer, DOCS_ALPN)
.connect(peer, crate::ALPN)
.await
.map_err(ConnectError::connect)?;

Expand Down
2 changes: 1 addition & 1 deletion src/ranger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ mod tests {
Prefix(K),
}

impl<'a, K, V> Iterator for SimpleRangeIterator<'a, K, V>
impl<K, V> Iterator for SimpleRangeIterator<'_, K, V>
where
K: RangeKey + Default,
V: Clone,
Expand Down
6 changes: 3 additions & 3 deletions src/store/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ impl<'a> StoreInstance<'a> {
}
}

impl<'a> PublicKeyStore for StoreInstance<'a> {
impl PublicKeyStore for StoreInstance<'_> {
fn public_key(&self, id: &[u8; 32]) -> std::result::Result<VerifyingKey, SignatureError> {
self.store.public_key(id)
}
}

impl<'a> super::DownloadPolicyStore for StoreInstance<'a> {
impl super::DownloadPolicyStore for StoreInstance<'_> {
fn get_download_policy(&mut self, namespace: &NamespaceId) -> Result<DownloadPolicy> {
self.store.get_download_policy(namespace)
}
Expand Down Expand Up @@ -936,7 +936,7 @@ impl<'a> LatestIterator<'a> {
}
}

impl<'a> Iterator for LatestIterator<'a> {
impl Iterator for LatestIterator<'_> {
type Item = Result<(AuthorId, u64, Vec<u8>)>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
4 changes: 2 additions & 2 deletions src/store/fs/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub trait RangeExt<K: Key, V: Value> {
}
}

impl<'a, K: Key + 'static, V: Value + 'static> RangeExt<K, V> for Range<'a, K, V> {
impl<K: Key + 'static, V: Value + 'static> RangeExt<K, V> for Range<'_, K, V> {
fn next_map<T>(
&mut self,
map: impl for<'x> Fn(K::SelfType<'x>, V::SelfType<'x>) -> T,
Expand Down Expand Up @@ -114,7 +114,7 @@ impl RecordsRange<'static> {
}
}

impl<'a> Iterator for RecordsRange<'a> {
impl Iterator for RecordsRange<'_> {
type Item = anyhow::Result<SignedEntry>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next_map(into_entry)
Expand Down
2 changes: 1 addition & 1 deletion src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,7 @@ mod tests {
store: &'a mut Store,
namespace: NamespaceId,
}
impl<'a> QueryTester<'a> {
impl QueryTester<'_> {
fn assert(&mut self, query: impl Into<Query>, expected: Vec<(&'static str, &Author)>) {
let query = query.into();
let actual = self
Expand Down
Loading

0 comments on commit eeb8833

Please # to comment.