@@ -6,7 +6,7 @@ use std::{
66} ;
77
88use iroh:: { discovery:: IntoDiscovery , dns:: DnsResolver , EndpointId , RelayMode , SecretKey } ;
9- use iroh_blobs:: store:: fs :: options :: { GcConfig , Options } ;
9+ use iroh_blobs:: store:: GcConfig ;
1010use iroh_docs:: { engine:: ProtectCallbackHandler , protocol:: Docs } ;
1111use iroh_gossip:: net:: Gossip ;
1212
@@ -64,7 +64,7 @@ impl Client {
6464pub struct Builder {
6565 endpoint : iroh:: endpoint:: Builder ,
6666 use_n0_discovery : bool ,
67- path : Option < PathBuf > ,
67+ storage : Storage ,
6868 // node_discovery: Option<Box<dyn Discovery>>,
6969 gc_interval : Option < std:: time:: Duration > ,
7070 #[ debug( skip) ]
@@ -97,9 +97,10 @@ impl Builder {
9797 let endpoint = builder. bind ( ) . await ?;
9898 let mut router = iroh:: protocol:: Router :: builder ( endpoint. clone ( ) ) ;
9999 let gossip = Gossip :: builder ( ) . spawn ( endpoint. clone ( ) ) ;
100- let mut docs_builder = match self . path {
101- Some ( ref path) => Docs :: persistent ( path. to_path_buf ( ) ) ,
102- None => Docs :: memory ( ) ,
100+ let mut docs_builder = match self . storage {
101+ Storage :: Memory => Docs :: memory ( ) ,
102+ #[ cfg( feature = "fs-store" ) ]
103+ Storage :: Persistent ( ref path) => Docs :: persistent ( path. to_path_buf ( ) ) ,
103104 } ;
104105 if let Some ( protect_cb) = protect_cb {
105106 docs_builder = docs_builder. protect_handler ( protect_cb) ;
@@ -183,11 +184,11 @@ impl Builder {
183184 self
184185 }
185186
186- fn new ( path : Option < PathBuf > ) -> Self {
187+ fn new ( storage : Storage ) -> Self {
187188 Self {
188189 endpoint : iroh:: Endpoint :: empty_builder ( RelayMode :: Disabled ) ,
189190 use_n0_discovery : true ,
190- path ,
191+ storage ,
191192 gc_interval : None ,
192193 bind_random_port : false ,
193194 // node_discovery: None,
@@ -197,30 +198,38 @@ impl Builder {
197198 }
198199}
199200
201+ #[ derive( Debug ) ]
202+ enum Storage {
203+ Memory ,
204+ #[ cfg( feature = "fs-store" ) ]
205+ Persistent ( PathBuf ) ,
206+ }
207+
200208impl Node {
201209 /// Creates a new node with memory storage
202210 pub fn memory ( ) -> Builder {
203- Builder :: new ( None )
211+ Builder :: new ( Storage :: Memory )
204212 }
205213
206214 /// Creates a new node with persistent storage
215+ #[ cfg( feature = "fs-store" ) ]
207216 pub fn persistent ( path : impl AsRef < Path > ) -> Builder {
208- let path = Some ( path. as_ref ( ) . to_owned ( ) ) ;
209- Builder :: new ( path)
217+ Builder :: new ( Storage :: Persistent ( path. as_ref ( ) . to_owned ( ) ) )
210218 }
211219}
212220
213221impl Builder {
214222 /// Spawns the node
215223 pub async fn spawn ( self ) -> anyhow:: Result < Node > {
216- let ( store, protect_handler) = match self . path {
217- None => {
224+ let ( store, protect_handler) = match self . storage {
225+ Storage :: Memory => {
218226 let store = iroh_blobs:: store:: mem:: MemStore :: new ( ) ;
219227 ( ( * store) . clone ( ) , None )
220228 }
221- Some ( ref path) => {
229+ #[ cfg( feature = "fs-store" ) ]
230+ Storage :: Persistent ( ref path) => {
222231 let db_path = path. join ( "blobs.db" ) ;
223- let mut opts = Options :: new ( path) ;
232+ let mut opts = iroh_blobs :: store :: fs :: options :: Options :: new ( path) ;
224233 let protect_handler = if let Some ( interval) = self . gc_interval {
225234 let ( handler, cb) = ProtectCallbackHandler :: new ( ) ;
226235 opts. gc = Some ( GcConfig {
0 commit comments