Skip to content

Commit eeb8833

Browse files
authored
Merge pull request #11 from n0-computer/try-out-gc
feat!: use the new way to register gc exemptions in iroh-blobs
2 parents c146f7a + 4caa21f commit eeb8833

File tree

10 files changed

+76
-113
lines changed

10 files changed

+76
-113
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ jobs:
170170
run: |
171171
echo "HEAD_COMMIT_SHA=$(git rev-parse origin/main)" >> ${GITHUB_ENV}
172172
- name: Check semver
173+
continue-on-error: true
173174
# uses: obi1kenobi/cargo-semver-checks-action@v2
174175
uses: n0-computer/cargo-semver-checks-action@feat-baseline
175176
with:
@@ -255,6 +256,7 @@ jobs:
255256
uses: mozilla-actions/[email protected]
256257

257258
- name: Check MSRV all features
259+
continue-on-error: true
258260
run: |
259261
cargo +$MSRV check --workspace --all-targets
260262

Cargo.lock

Lines changed: 17 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/engine.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use anyhow::{bail, Context, Result};
1313
use futures_lite::{Stream, StreamExt};
1414
use iroh::{key::PublicKey, Endpoint, NodeAddr};
1515
use iroh_blobs::{
16-
downloader::Downloader, store::EntryStatus, util::local_pool::LocalPoolHandle, Hash,
16+
downloader::Downloader, net_protocol::ProtectCb, store::EntryStatus,
17+
util::local_pool::LocalPoolHandle, Hash,
1718
};
1819
use iroh_gossip::net::Gossip;
1920
use serde::{Deserialize, Serialize};
@@ -125,6 +126,34 @@ impl<D: iroh_blobs::store::Store> Engine<D> {
125126
})
126127
}
127128

129+
/// Return a callback that can be added to blobs to protect the content of
130+
/// all docs from garbage collection.
131+
pub fn protect_cb(&self) -> ProtectCb {
132+
let this = self.clone();
133+
Box::new(move |live| {
134+
let this = this.clone();
135+
Box::pin(async move {
136+
let doc_hashes = match this.sync.content_hashes().await {
137+
Ok(hashes) => hashes,
138+
Err(err) => {
139+
tracing::warn!("Error getting doc hashes: {}", err);
140+
return;
141+
}
142+
};
143+
for hash in doc_hashes {
144+
match hash {
145+
Ok(hash) => {
146+
live.insert(hash);
147+
}
148+
Err(err) => {
149+
tracing::error!("Error getting doc hash: {}", err);
150+
}
151+
}
152+
}
153+
})
154+
})
155+
}
156+
128157
/// Get the blob store.
129158
pub fn blob_store(&self) -> &D {
130159
&self.blob_store

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ mod heads;
6464
mod keys;
6565
mod ranger;
6666

67+
#[cfg(feature = "net")]
68+
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
69+
#[doc(inline)]
70+
pub use net::ALPN;
71+
6772
#[cfg(feature = "net")]
6873
#[cfg_attr(iroh_docsrs, doc(cfg(feature = "net")))]
6974
pub use self::ticket::DocTicket;

src/net.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
};
2121

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

2525
mod codec;
2626

@@ -35,7 +35,7 @@ pub async fn connect_and_sync(
3535
let peer_id = peer.node_id;
3636
trace!("connect");
3737
let connection = endpoint
38-
.connect(peer, DOCS_ALPN)
38+
.connect(peer, crate::ALPN)
3939
.await
4040
.map_err(ConnectError::connect)?;
4141

src/ranger.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ mod tests {
877877
Prefix(K),
878878
}
879879

880-
impl<'a, K, V> Iterator for SimpleRangeIterator<'a, K, V>
880+
impl<K, V> Iterator for SimpleRangeIterator<'_, K, V>
881881
where
882882
K: RangeKey + Default,
883883
V: Clone,

src/store/fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,13 @@ impl<'a> StoreInstance<'a> {
630630
}
631631
}
632632

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

639-
impl<'a> super::DownloadPolicyStore for StoreInstance<'a> {
639+
impl super::DownloadPolicyStore for StoreInstance<'_> {
640640
fn get_download_policy(&mut self, namespace: &NamespaceId) -> Result<DownloadPolicy> {
641641
self.store.get_download_policy(namespace)
642642
}
@@ -936,7 +936,7 @@ impl<'a> LatestIterator<'a> {
936936
}
937937
}
938938

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

942942
fn next(&mut self) -> Option<Self::Item> {

src/store/fs/ranges.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub trait RangeExt<K: Key, V: Value> {
3737
}
3838
}
3939

40-
impl<'a, K: Key + 'static, V: Value + 'static> RangeExt<K, V> for Range<'a, K, V> {
40+
impl<K: Key + 'static, V: Value + 'static> RangeExt<K, V> for Range<'_, K, V> {
4141
fn next_map<T>(
4242
&mut self,
4343
map: impl for<'x> Fn(K::SelfType<'x>, V::SelfType<'x>) -> T,
@@ -114,7 +114,7 @@ impl RecordsRange<'static> {
114114
}
115115
}
116116

117-
impl<'a> Iterator for RecordsRange<'a> {
117+
impl Iterator for RecordsRange<'_> {
118118
type Item = anyhow::Result<SignedEntry>;
119119
fn next(&mut self) -> Option<Self::Item> {
120120
self.0.next_map(into_entry)

src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ mod tests {
22922292
store: &'a mut Store,
22932293
namespace: NamespaceId,
22942294
}
2295-
impl<'a> QueryTester<'a> {
2295+
impl QueryTester<'_> {
22962296
fn assert(&mut self, query: impl Into<Query>, expected: Vec<(&'static str, &Author)>) {
22972297
let query = query.into();
22982298
let actual = self

0 commit comments

Comments
 (0)