diff --git a/bin/tau/taud/src/main.rs b/bin/tau/taud/src/main.rs index d3d101033..84587f6a7 100644 --- a/bin/tau/taud/src/main.rs +++ b/bin/tau/taud/src/main.rs @@ -48,7 +48,7 @@ async fn start(settings: Settings, executor: Arc>) -> TaudResult<() let raft_sender = raft.get_broadcast(); let commits = raft.get_commits(); - let initial_sync_commits = raft.get_commits().clone(); + let initial_sync_commits = commits.clone(); let initial_sync_raft_sender = raft_sender.clone(); // @@ -66,37 +66,42 @@ async fn start(settings: Settings, executor: Arc>) -> TaudResult<() let rpc_interface = Arc::new(JsonRpcInterface::new(rpc_snd, settings.dataset_path.clone())); + let dataset_path_cloned = settings.dataset_path.clone(); let recv_update_from_raft: smol::Task> = executor.spawn(async move { loop { let task_info = rpc_rcv.recv().await.map_err(Error::from)?; if let Some(tk) = task_info { - tk.save()?; + info!(target: "tau", "save the received task {:?}", tk); + tk.save(&dataset_path_cloned)?; raft_sender.send(tk).await.map_err(Error::from)?; } let recv_commits = commits.lock().await; for task_info in recv_commits.iter() { - task_info.save()?; + info!(target: "tau", "update from the commits"); + task_info.save(&dataset_path_cloned)?; } } }); + let dataset_path_cloned = settings.dataset_path.clone(); let initial_sync: smol::Task> = executor.spawn(async move { - info!("Start initial sync waiting the network for 5 seconds"); + info!(target: "tau", "Start initial sync waiting the network for 5 seconds"); sleep(5).await; - info!("Save received tasks"); let recv_commits = initial_sync_commits.lock().await; for task_info in recv_commits.iter() { - task_info.save()?; + info!(target: "tau", "Save received tasks {:?}", task_info); + task_info.save(&dataset_path_cloned)?; } - info!("Upload local tasks"); + info!(target: "tau", "Upload local tasks"); - let tasks = MonthTasks::load_current_open_tasks(&settings.dataset_path)?; + let tasks = MonthTasks::load_current_open_tasks(&dataset_path_cloned)?; for task in tasks { + info!(target: "tau", "send local task {:?}", task); initial_sync_raft_sender.send(task).await.map_err(Error::from)?; } diff --git a/bin/tau/taud/src/month_tasks.rs b/bin/tau/taud/src/month_tasks.rs index 6aeaa12ac..0b4b506e5 100644 --- a/bin/tau/taud/src/month_tasks.rs +++ b/bin/tau/taud/src/month_tasks.rs @@ -12,17 +12,12 @@ use crate::{ #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct MonthTasks { created_at: Timestamp, - dataset_path: PathBuf, task_tks: Vec, } impl MonthTasks { - pub fn new(task_tks: &[String], dataset_path: &Path) -> Self { - Self { - created_at: get_current_time(), - dataset_path: dataset_path.to_path_buf(), - task_tks: task_tks.to_owned(), - } + pub fn new(task_tks: &[String]) -> Self { + Self { created_at: get_current_time(), task_tks: task_tks.to_owned() } } pub fn add(&mut self, ref_id: &str) { @@ -31,11 +26,11 @@ impl MonthTasks { } } - pub fn objects(&self) -> TaudResult> { + pub fn objects(&self, dataset_path: &Path) -> TaudResult> { let mut tks: Vec = vec![]; for ref_id in self.task_tks.iter() { - tks.push(TaskInfo::load(ref_id, &self.dataset_path)?); + tks.push(TaskInfo::load(ref_id, dataset_path)?); } Ok(tks) @@ -47,10 +42,6 @@ impl MonthTasks { } } - pub fn set_dataset_path(&mut self, dataset_path: &Path) { - self.dataset_path = dataset_path.to_path_buf(); - } - pub fn set_date(&mut self, date: &Timestamp) { self.created_at = date.clone(); } @@ -59,21 +50,18 @@ impl MonthTasks { dataset_path.join("month").join(Utc.timestamp(date.0, 0).format("%m%y").to_string()) } - pub fn save(&self) -> TaudResult<()> { - crate::util::save::(&Self::get_path(&self.created_at, &self.dataset_path), self) + pub fn save(&self, dataset_path: &Path) -> TaudResult<()> { + crate::util::save::(&Self::get_path(&self.created_at, dataset_path), self) .map_err(TaudError::Darkfi) } pub fn load_or_create(date: &Timestamp, dataset_path: &Path) -> TaudResult { match crate::util::load::(&Self::get_path(date, dataset_path)) { - Ok(mut mt) => { - mt.set_dataset_path(dataset_path); - Ok(mt) - } + Ok(mt) => Ok(mt), Err(_) => { - let mut mt = Self::new(&[], dataset_path); + let mut mt = Self::new(&[]); mt.set_date(date); - mt.save()?; + mt.save(dataset_path)?; Ok(mt) } } @@ -81,7 +69,7 @@ impl MonthTasks { pub fn load_current_open_tasks(dataset_path: &Path) -> TaudResult> { let mt = Self::load_or_create(&get_current_time(), dataset_path)?; - Ok(mt.objects()?.into_iter().filter(|t| t.get_state() != "stop").collect()) + Ok(mt.objects(dataset_path)?.into_iter().filter(|t| t.get_state() != "stop").collect()) } } @@ -117,7 +105,7 @@ mod tests { let mut task = TaskInfo::new("test_title", "test_desc", None, 0.0, &dataset_path)?; - task.save()?; + task.save(&dataset_path)?; let t_load = TaskInfo::load(&task.ref_id, &dataset_path)?; @@ -125,7 +113,7 @@ mod tests { task.set_title("test_title_2"); - task.save()?; + task.save(&dataset_path)?; let t_load = TaskInfo::load(&task.ref_id, &dataset_path)?; @@ -136,9 +124,9 @@ mod tests { let task_tks = vec![]; - let mut mt = MonthTasks::new(&task_tks, &dataset_path); + let mut mt = MonthTasks::new(&task_tks); - mt.save()?; + mt.save(&dataset_path)?; let mt_load = MonthTasks::load_or_create(&get_current_time(), &dataset_path)?; @@ -146,7 +134,7 @@ mod tests { mt.add(&task.ref_id); - mt.save()?; + mt.save(&dataset_path)?; let mt_load = MonthTasks::load_or_create(&get_current_time(), &dataset_path)?; @@ -157,7 +145,7 @@ mod tests { let task = TaskInfo::new("test_title_3", "test_desc", None, 0.0, &dataset_path)?; - task.save()?; + task.save(&dataset_path)?; let mt_load = MonthTasks::load_or_create(&get_current_time(), &dataset_path)?; diff --git a/bin/tau/taud/src/task_info.rs b/bin/tau/taud/src/task_info.rs index d01984071..1d3526ca6 100644 --- a/bin/tau/taud/src/task_info.rs +++ b/bin/tau/taud/src/task_info.rs @@ -62,8 +62,6 @@ pub struct TaskInfo { created_at: Timestamp, events: TaskEvents, comments: TaskComments, - #[serde(skip_serializing, skip_deserializing)] - dataset_path: PathBuf, } impl TaskInfo { @@ -102,39 +100,37 @@ impl TaskInfo { created_at, comments: TaskComments(vec![]), events: TaskEvents(vec![]), - dataset_path: dataset_path.to_path_buf(), }) } pub fn load(ref_id: &str, dataset_path: &Path) -> TaudResult { - let mut task = crate::util::load::(&Self::get_path(ref_id, dataset_path))?; - task.set_dataset_path(dataset_path); + let task = crate::util::load::(&Self::get_path(ref_id, dataset_path))?; Ok(task) } - pub fn save(&self) -> TaudResult<()> { - crate::util::save::(&Self::get_path(&self.ref_id, &self.dataset_path), self) + pub fn save(&self, dataset_path: &Path) -> TaudResult<()> { + crate::util::save::(&Self::get_path(&self.ref_id, dataset_path), self) .map_err(TaudError::Darkfi)?; if self.get_state() != "open" { - self.deactivate()?; + self.deactivate(dataset_path)?; } else { - self.activate()?; + self.activate(dataset_path)?; } Ok(()) } - pub fn activate(&self) -> TaudResult<()> { - let mut mt = MonthTasks::load_or_create(&self.created_at, &self.dataset_path)?; + pub fn activate(&self, path: &Path) -> TaudResult<()> { + let mut mt = MonthTasks::load_or_create(&self.created_at, path)?; mt.add(&self.ref_id); - mt.save() + mt.save(path) } - pub fn deactivate(&self) -> TaudResult<()> { - let mut mt = MonthTasks::load_or_create(&self.created_at, &self.dataset_path)?; + pub fn deactivate(&self, path: &Path) -> TaudResult<()> { + let mut mt = MonthTasks::load_or_create(&self.created_at, path)?; mt.remove(&self.ref_id); - mt.save() + mt.save(path) } pub fn get_state(&self) -> String { @@ -181,10 +177,6 @@ impl TaskInfo { self.due = d; } - pub fn set_dataset_path(&mut self, dataset_path: &Path) { - self.dataset_path = dataset_path.to_path_buf(); - } - pub fn set_state(&mut self, action: &str) { if self.get_state() == action { return diff --git a/bin/tau/taud_config.toml b/bin/tau/taud_config.toml index d2352fdd9..8d620e99d 100644 --- a/bin/tau/taud_config.toml +++ b/bin/tau/taud_config.toml @@ -12,22 +12,19 @@ datastore_raft = "~/.config/tau/tau.db" # openssl pkcs12 -export -out identity.pfx -inkey key.pem -in cert.pem -certfile chain_certs.pem tls_identity_path = "" +### Number of outbound connections +#outbound_connections = 5 + # The address where taud should bind its RPC socket [rpc_listener_url] url="127.0.0.1:8875" password = "FOOBAR" -## -## P2P network -## ### The accept address #[accept_address] #url="127.0.0.1:8822" #password = "FOOBAR" -### Number of outbound connections -#outbound_connections = 5 - ### Seed node addresses #[[seeds]] #url="127.0.0.1:8811"