summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-12-18 17:32:41 +0100
committerMatthias Beyer <mail@beyermatthias.de>2021-12-18 17:32:41 +0100
commit1c90ee16661006c8cbfd628a93608566a9bc6b76 (patch)
treea6ac58c5013df6b7e663f533c8ae8f0cbf4b112e /lib
parentaa5c1f79dcdfae35f10835ea43bac6f451d7149d (diff)
parent19ea5662c661d5a7ab3eeeafa1f7a7846ea4f762 (diff)
Merge branch 'gui-timeline'
Diffstat (limited to 'lib')
-rw-r--r--lib/src/client.rs28
-rw-r--r--lib/src/config.rs10
-rw-r--r--lib/src/lib.rs1
-rw-r--r--lib/src/profile/mod.rs26
-rw-r--r--lib/src/stream.rs2
-rw-r--r--lib/src/types/payload.rs2
6 files changed, 23 insertions, 46 deletions
diff --git a/lib/src/client.rs b/lib/src/client.rs
index da8ad94..a6a51d4 100644
--- a/lib/src/client.rs
+++ b/lib/src/client.rs
@@ -3,29 +3,25 @@ use std::convert::TryFrom;
use anyhow::Result;
use ipfs::Cid;
-use crate::config::Config;
use crate::ipfs_client::IpfsClient;
use crate::types::Node;
use crate::types::Payload;
use crate::types::DateTime;
+#[derive(Clone)]
pub struct Client {
pub(crate) ipfs: IpfsClient,
- config: Config,
}
impl std::fmt::Debug for Client {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- write!(f, "Client {{ config: {:?} }}", self.config)
+ write!(f, "Client {{ }}")
}
}
impl Client {
- pub fn new(ipfs: IpfsClient, config: Config) -> Self {
- Client {
- ipfs,
- config
- }
+ pub fn new(ipfs: IpfsClient) -> Self {
+ Client { ipfs }
}
pub async fn exit(self) -> Result<()> {
@@ -131,7 +127,6 @@ mod tests {
use cid::Cid;
use crate::client::Client;
- use crate::config::Config;
use crate::ipfs_client::IpfsClient;
use crate::types::DateTime;
@@ -153,8 +148,7 @@ mod tests {
async fn test_post_text_blob() {
let _ = env_logger::try_init();
let ipfs = mk_ipfs().await;
- let config = Config::default();
- let client = Client::new(ipfs, config);
+ let client = Client::new(ipfs);
let cid = client.post_text_blob(String::from("text")).await;
assert!(cid.is_ok());
@@ -167,8 +161,7 @@ mod tests {
async fn test_post_text_node() {
let _ = env_logger::try_init();
let ipfs = mk_ipfs().await;
- let config = Config::default();
- let client = Client::new(ipfs, config);
+ let client = Client::new(ipfs);
let datetime = mkdate(2021, 11, 27, 12, 30, 0);
@@ -183,8 +176,7 @@ mod tests {
async fn test_post_text_node_roundtrip() {
let _ = env_logger::try_init();
let ipfs = mk_ipfs().await;
- let config = Config::default();
- let client = Client::new(ipfs, config);
+ let client = Client::new(ipfs);
let datetime = mkdate(2021, 11, 27, 12, 30, 0);
@@ -221,8 +213,7 @@ mod tests {
async fn test_post_text_chain() {
let _ = env_logger::try_init();
let ipfs = mk_ipfs().await;
- let config = Config::default();
- let client = Client::new(ipfs, config);
+ let client = Client::new(ipfs);
let chain_elements = vec![
(mkdate(2021, 11, 27, 12, 30, 0), "text1", "bafyreidaxkxog3bssyxxjxlsubgg6wauxbobp7gwyucs6gwzyrtsavb7yu"),
@@ -251,8 +242,7 @@ mod tests {
async fn test_post_text_dag() {
let _ = env_logger::try_init();
let ipfs = mk_ipfs().await;
- let config = Config::default();
- let client = Client::new(ipfs, config);
+ let client = Client::new(ipfs);
async fn post_chain(client: &Client, chain_elements: &Vec<(DateTime, &str, &str)>) {
let mut prev: Option<ipfs::Cid> = None;
diff --git a/lib/src/config.rs b/lib/src/config.rs
deleted file mode 100644
index 0d25e78..0000000
--- a/lib/src/config.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#[derive(Debug)]
-pub struct Config {
-}
-
-impl Default for Config {
- fn default() -> Self {
- Config { }
- }
-}
-
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index 0cccef9..04fc959 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -1,5 +1,4 @@
pub mod client;
-pub mod config;
pub mod consts;
pub mod ipfs_client;
pub mod profile;
diff --git a/lib/src/profile/mod.rs b/lib/src/profile/mod.rs
index 050d53d..39c4829 100644
--- a/lib/src/profile/mod.rs
+++ b/lib/src/profile/mod.rs
@@ -5,22 +5,21 @@ use anyhow::Context;
use anyhow::Result;
use crate::client::Client;
-use crate::config::Config;
use crate::ipfs_client::IpfsClient;
mod state;
use state::*;
-#[derive(Debug, getset::Getters)]
+#[derive(Debug, getset::Getters, getset::MutGetters)]
pub struct Profile {
state: ProfileState,
- #[getset(get = "pub")]
+ #[getset(get = "pub", get_mut = "pub")]
client: Client,
}
impl Profile {
- pub async fn create(state_dir: &StateDir, name: &str, config: Config) -> Result<Self> {
+ pub async fn create(state_dir: &StateDir, name: &str) -> Result<Self> {
let bootstrap = vec![]; // TODO
let mdns = true; // TODO
let keypair = ipfs::Keypair::generate_ed25519();
@@ -40,20 +39,20 @@ impl Profile {
.start()
.await?;
tokio::task::spawn(fut);
- Self::new(ipfs, config, name.to_string(), keypair).await
+ Self::new(ipfs, name.to_string(), keypair).await
}
- pub async fn new_inmemory(config: Config, name: &str) -> Result<Self> {
+ pub async fn new_inmemory(name: &str) -> Result<Self> {
let mut opts = ipfs::IpfsOptions::inmemory_with_generated_keys();
opts.mdns = true;
let keypair = opts.keypair.clone();
let (ipfs, fut): (ipfs::Ipfs<_>, _) = ipfs::UninitializedIpfs::<_>::new(opts).start().await.unwrap();
tokio::task::spawn(fut);
- Self::new(ipfs, config, format!("inmemory-{}", name), keypair).await
+ Self::new(ipfs, format!("inmemory-{}", name), keypair).await
}
- async fn new(ipfs: IpfsClient, config: Config, profile_name: String, keypair: libp2p::identity::Keypair) -> Result<Self> {
- let client = Client::new(ipfs, config);
+ async fn new(ipfs: IpfsClient, profile_name: String, keypair: libp2p::identity::Keypair) -> Result<Self> {
+ let client = Client::new(ipfs);
let state = ProfileState::new(profile_name, keypair);
Ok(Profile { state, client })
}
@@ -123,7 +122,7 @@ impl Profile {
.map_err(anyhow::Error::from)
}
- pub async fn load(config: Config, name: &str) -> Result<Self> {
+ pub async fn load(name: &str) -> Result<Self> {
let state_dir_path = Self::state_dir_path(name)?;
log::trace!("state_dir_path = {:?}", state_dir_path.display());
let state: ProfileState = ProfileStateSaveable::load_from_disk(&state_dir_path)
@@ -156,7 +155,7 @@ impl Profile {
log::debug!("Profile loading finished");
Ok(Profile {
state,
- client: Client::new(ipfs, config),
+ client: Client::new(ipfs),
})
}
@@ -171,12 +170,11 @@ impl Profile {
mod tests {
use super::*;
use std::convert::TryFrom;
- use crate::config::Config;
#[tokio::test]
async fn test_create_profile() {
let _ = env_logger::try_init();
- let profile = Profile::new_inmemory(Config::default(), "test-create-profile").await;
+ let profile = Profile::new_inmemory("test-create-profile").await;
assert!(profile.is_ok());
let exit = profile.unwrap().exit().await;
assert!(exit.is_ok(), "Not cleanly exited: {:?}", exit);
@@ -185,7 +183,7 @@ mod tests {
#[tokio::test]
async fn test_create_profile_and_helloworld() {
let _ = env_logger::try_init();
- let profile = Profile::new_inmemory(Config::default(), "test-create-profile-and-helloworld").await;
+ let profile = Profile::new_inmemory("test-create-profile-and-helloworld").await;
assert!(profile.is_ok());
let profile = profile.unwrap();
assert!(profile.head().is_none());
diff --git a/lib/src/stream.rs b/lib/src/stream.rs
index 01548e6..2dd2781 100644
--- a/lib/src/stream.rs
+++ b/lib/src/stream.rs
@@ -15,7 +15,7 @@ impl NodeStreamBuilder {
}
}
- pub fn into_stream<'a>(self, client: &'a Client) -> impl futures::stream::Stream<Item = Result<Node>> + 'a {
+ pub fn into_stream(self, client: Client) -> impl futures::stream::Stream<Item = Result<Node>> {
futures::stream::unfold((client, self.state), move |(client, mut state)| {
async move {
if let Some(node_cid) = state.pop() {
diff --git a/lib/src/types/payload.rs b/lib/src/types/payload.rs
index a11b215..33b2342 100644
--- a/lib/src/types/payload.rs
+++ b/lib/src/types/payload.rs
@@ -4,7 +4,7 @@ use anyhow::Result;
use crate::types::DateTime;
-#[derive(Debug, Eq, PartialEq, getset::Getters)]
+#[derive(Clone, Debug, Eq, PartialEq, getset::Getters)]
pub struct Payload {
// TODO: Make this a mime::Mime, but as this type does not impl Serialize/Deserialize, we
// cannot do this trivially yet