|
@@ -4,27 +4,27 @@ use darkfi::{
|
|
|
raft::DataStore,
|
|
raft::DataStore,
|
|
|
util::{
|
|
util::{
|
|
|
expand_path,
|
|
expand_path,
|
|
|
- serial::{SerialDecodable, SerialEncodable},
|
|
|
|
|
|
|
+ serial::{deserialize, SerialDecodable, SerialEncodable},
|
|
|
},
|
|
},
|
|
|
Result,
|
|
Result,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
|
-struct Log {
|
|
|
|
|
- _term: u64,
|
|
|
|
|
- _msg: Vec<u8>,
|
|
|
|
|
|
|
+pub struct Info<T> {
|
|
|
|
|
+ pub logs: Vec<Log<T>>,
|
|
|
|
|
+ pub commits: Vec<T>,
|
|
|
|
|
+ pub voted_for: Vec<Option<NodeId>>,
|
|
|
|
|
+ pub terms: Vec<u64>,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
|
-struct NodeId(Vec<u8>);
|
|
|
|
|
|
|
+pub struct Log<T> {
|
|
|
|
|
+ pub term: u64,
|
|
|
|
|
+ pub msg: T,
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
#[derive(Debug)]
|
|
|
-struct Info<T> {
|
|
|
|
|
- _logs: Vec<Log>,
|
|
|
|
|
- _commits: Vec<T>,
|
|
|
|
|
- _voted_for: Vec<Option<NodeId>>,
|
|
|
|
|
- _terms: Vec<u64>,
|
|
|
|
|
-}
|
|
|
|
|
|
|
+pub struct NodeId(Vec<u8>);
|
|
|
|
|
|
|
|
#[derive(Debug, SerialEncodable, SerialDecodable)]
|
|
#[derive(Debug, SerialEncodable, SerialDecodable)]
|
|
|
struct EncryptedTask {
|
|
struct EncryptedTask {
|
|
@@ -42,15 +42,10 @@ struct Privmsg {
|
|
|
message: String,
|
|
message: String,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[async_std::main]
|
|
|
|
|
-async fn main() -> Result<()> {
|
|
|
|
|
- // Load datastore, uncomment desired bin structures
|
|
|
|
|
- // Taud
|
|
|
|
|
- //let db_path = expand_path(&"~/.config/darkfi/tau/tau.db").unwrap();
|
|
|
|
|
- //let datastore = DataStore::<EncryptedTask>::new(&db_path.to_str().unwrap())?;
|
|
|
|
|
- // Ircd
|
|
|
|
|
- let db_path = expand_path(&"~/.config/darkfi/ircd/ircd.db").unwrap();
|
|
|
|
|
- let datastore = DataStore::<Privmsg>::new(&db_path.to_str().unwrap())?;
|
|
|
|
|
|
|
+fn extract_taud() -> Result<String> {
|
|
|
|
|
+ let db_path = expand_path(&"~/.config/darkfi/tau/tau.db").unwrap();
|
|
|
|
|
+ let datastore = DataStore::<EncryptedTask>::new(&db_path.to_str().unwrap())?;
|
|
|
|
|
+
|
|
|
println!("Extracting db from: {:?}", db_path);
|
|
println!("Extracting db from: {:?}", db_path);
|
|
|
|
|
|
|
|
// Retrieve all data trees
|
|
// Retrieve all data trees
|
|
@@ -65,16 +60,59 @@ async fn main() -> Result<()> {
|
|
|
// Logs
|
|
// Logs
|
|
|
let mut logs = vec![];
|
|
let mut logs = vec![];
|
|
|
for log in sled_logs {
|
|
for log in sled_logs {
|
|
|
- logs.push(Log { _term: log.term, _msg: log.msg });
|
|
|
|
|
|
|
+ logs.push(Log { term: log.term, msg: deserialize(&log.msg)? });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Commits
|
|
// Commits
|
|
|
let mut commits = vec![];
|
|
let mut commits = vec![];
|
|
|
for commit in &sled_commits {
|
|
for commit in &sled_commits {
|
|
|
- /*
|
|
|
|
|
commits
|
|
commits
|
|
|
.push(EncryptedTask { nonce: commit.nonce.clone(), payload: commit.payload.clone() });
|
|
.push(EncryptedTask { nonce: commit.nonce.clone(), payload: commit.payload.clone() });
|
|
|
- */
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Voted for
|
|
|
|
|
+ let mut voted_for = vec![];
|
|
|
|
|
+ for vote in sled_voted_for {
|
|
|
|
|
+ match vote {
|
|
|
|
|
+ Some(v) => voted_for.push(Some(NodeId(v.0.clone()))),
|
|
|
|
|
+ None => voted_for.push(None),
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Terms
|
|
|
|
|
+ let mut terms = vec![];
|
|
|
|
|
+ for term in sled_terms {
|
|
|
|
|
+ terms.push(term);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ let info = Info::<EncryptedTask> { logs, commits, voted_for, terms };
|
|
|
|
|
+ let info_string = format!("{:#?}", info);
|
|
|
|
|
+ Ok(info_string)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+fn extract_ircd() -> Result<String> {
|
|
|
|
|
+ let db_path = expand_path(&"~/.config/darkfi/ircd/ircd.db").unwrap();
|
|
|
|
|
+ let datastore = DataStore::<Privmsg>::new(&db_path.to_str().unwrap())?;
|
|
|
|
|
+ println!("Extracting db from: {:?}", db_path);
|
|
|
|
|
+
|
|
|
|
|
+ // Retrieve all data trees
|
|
|
|
|
+ let sled_logs = datastore.logs.get_all()?;
|
|
|
|
|
+ let sled_commits = datastore.commits.get_all()?;
|
|
|
|
|
+ let sled_voted_for = datastore.voted_for.get_all()?;
|
|
|
|
|
+ let sled_terms = datastore.current_term.get_all()?;
|
|
|
|
|
+
|
|
|
|
|
+ // Parse retrieved data trees
|
|
|
|
|
+ println!("Data extracted, parsing to viewable form...");
|
|
|
|
|
+
|
|
|
|
|
+ // Logs
|
|
|
|
|
+ let mut logs = vec![];
|
|
|
|
|
+ for log in sled_logs {
|
|
|
|
|
+ logs.push(Log { term: log.term, msg: deserialize(&log.msg)? });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Commits
|
|
|
|
|
+ let mut commits = vec![];
|
|
|
|
|
+ for commit in &sled_commits {
|
|
|
commits.push(Privmsg {
|
|
commits.push(Privmsg {
|
|
|
id: commit.id,
|
|
id: commit.id,
|
|
|
nickname: commit.nickname.clone(),
|
|
nickname: commit.nickname.clone(),
|
|
@@ -98,18 +136,16 @@ async fn main() -> Result<()> {
|
|
|
terms.push(term);
|
|
terms.push(term);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- let info = Info::<EncryptedTask> {
|
|
|
|
|
- _logs: logs,
|
|
|
|
|
- _commits: commits,
|
|
|
|
|
- _voted_for: voted_for,
|
|
|
|
|
- _terms: terms,
|
|
|
|
|
- };
|
|
|
|
|
- */
|
|
|
|
|
- let info =
|
|
|
|
|
- Info::<Privmsg> { _logs: logs, _commits: commits, _voted_for: voted_for, _terms: terms };
|
|
|
|
|
|
|
+ let info = Info::<Privmsg> { logs, commits, voted_for, terms };
|
|
|
let info_string = format!("{:#?}", info);
|
|
let info_string = format!("{:#?}", info);
|
|
|
|
|
|
|
|
|
|
+ Ok(info_string)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#[async_std::main]
|
|
|
|
|
+async fn main() -> Result<()> {
|
|
|
|
|
+ let info_string = extract_taud()?;
|
|
|
|
|
+
|
|
|
// Generating file
|
|
// Generating file
|
|
|
let file_path = "raft_db";
|
|
let file_path = "raft_db";
|
|
|
println!("Data parsed, writing to file {:?}", file_path);
|
|
println!("Data parsed, writing to file {:?}", file_path);
|