@@ -13,7 +13,8 @@ use anyhow::{bail, Context, Result};
13
13
use futures_lite:: { Stream , StreamExt } ;
14
14
use iroh:: { key:: PublicKey , Endpoint , NodeAddr } ;
15
15
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 ,
17
18
} ;
18
19
use iroh_gossip:: net:: Gossip ;
19
20
use serde:: { Deserialize , Serialize } ;
@@ -125,6 +126,34 @@ impl<D: iroh_blobs::store::Store> Engine<D> {
125
126
} )
126
127
}
127
128
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
+
128
157
/// Get the blob store.
129
158
pub fn blob_store ( & self ) -> & D {
130
159
& self . blob_store
0 commit comments