Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit d65c981

Browse files
author
Joonas Koivunen
committed
refactor: remove IpfsOptions::{new,default}
rationale for `new`: IpfsOptions is already a struct with only pub fields, explaining them again in a doc comment would be useless. rationale for `default`: config file loading is quite out of place being *inside* the library. configuration is an applciation level concern. this also removes UninitializedIpfs::default and replaces their uses with IpfsOptions::inmemory_with_generated_keys or direct struct creation.
1 parent a7418ae commit d65c981

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

src/lib.rs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -208,79 +208,6 @@ impl<I: Borrow<Keypair>> DebuggableKeypair<I> {
208208
}
209209
}
210210

211-
impl IpfsOptions {
212-
pub fn new(
213-
ipfs_path: PathBuf,
214-
keypair: Keypair,
215-
bootstrap: Vec<(Multiaddr, PeerId)>,
216-
mdns: bool,
217-
kad_protocol: Option<String>,
218-
listening_addrs: Vec<Multiaddr>,
219-
span: Option<Span>,
220-
) -> Self {
221-
Self {
222-
ipfs_path,
223-
keypair,
224-
bootstrap,
225-
mdns,
226-
kad_protocol,
227-
listening_addrs,
228-
span,
229-
}
230-
}
231-
}
232-
233-
impl Default for IpfsOptions {
234-
/// Create `IpfsOptions` from environment.
235-
///
236-
/// # Panics
237-
///
238-
/// Can panic if two threads call this method at the same time due to race condition on
239-
/// creating a configuration file under `IPFS_PATH` and other thread failing to read the just
240-
/// created empty file. Because of this, the implementation has been disabled in tests.
241-
fn default() -> Self {
242-
use self::config::ConfigFile;
243-
244-
if cfg!(test) {
245-
// making this implementation conditional on `not(test)` results in multiple dead_code
246-
// lints on config.rs but for rustc 1.42.0 at least having this `cfg!(test)` branch
247-
// does not result in the same.
248-
panic!(
249-
"This implementation must not be invoked when testing as it cannot be safely
250-
used from multiple threads"
251-
);
252-
}
253-
254-
let ipfs_path = if let Ok(path) = env::var("IPFS_PATH") {
255-
PathBuf::from(path)
256-
} else {
257-
let root = if let Some(home) = dirs::home_dir() {
258-
home
259-
} else {
260-
env::current_dir().unwrap()
261-
};
262-
root.join(".rust-ipfs")
263-
};
264-
let config_path = dirs::config_dir()
265-
.unwrap()
266-
.join("rust-ipfs")
267-
.join("config.json");
268-
let config = ConfigFile::new(config_path).unwrap();
269-
let keypair = config.identity_key_pair();
270-
let bootstrap = config.bootstrap();
271-
272-
IpfsOptions {
273-
ipfs_path,
274-
keypair,
275-
bootstrap,
276-
mdns: true,
277-
kad_protocol: None,
278-
listening_addrs: Vec::new(),
279-
span: None,
280-
}
281-
}
282-
}
283-
284211
/// The facade for the Ipfs node.
285212
///
286213
/// The facade has most of the functionality either directly as a method or the functionality can
@@ -395,10 +322,6 @@ impl<Types: IpfsTypes> UninitializedIpfs<Types> {
395322
}
396323
}
397324

398-
pub fn default() -> Self {
399-
Self::new(IpfsOptions::default())
400-
}
401-
402325
/// Initialize the ipfs node. The returned `Ipfs` value is cloneable, send and sync, and the
403326
/// future should be spawned on a executor as soon as possible.
404327
pub async fn start(self) -> Result<(Ipfs<Types>, impl Future<Output = ()>), Error> {
@@ -1822,10 +1745,4 @@ mod tests {
18221745
ipfs.remove_pin(&cid, false).await.unwrap();
18231746
assert!(!ipfs.is_pinned(&cid).await.unwrap());
18241747
}
1825-
1826-
#[test]
1827-
#[should_panic]
1828-
fn default_ipfs_options_disabled_when_testing() {
1829-
IpfsOptions::default();
1830-
}
18311748
}

0 commit comments

Comments
 (0)