refactor log macros, ngd master key taken from args or file

Niko 1 year ago
parent a39490a30c
commit 7dc47ffeb0
  1. 1
      .gitignore
  2. 236
      Cargo.lock
  3. 1
      ng-app/src-tauri/Cargo.toml
  4. 20
      ng-app/src-tauri/src/lib.rs
  5. 1
      ng-sdk-js/Cargo.toml
  6. 19
      ng-sdk-js/src/lib.rs
  7. 1
      ng-wallet/Cargo.toml
  8. 66
      ng-wallet/src/lib.rs
  9. 24
      ng-wallet/src/types.rs
  10. 1
      ngcli/Cargo.toml
  11. 110
      ngcli/src/main.rs
  12. 11
      ngd/Cargo.toml
  13. 34
      ngd/src/cli.rs
  14. 256
      ngd/src/main.rs
  15. 27
      ngd/src/types.rs
  16. 3
      ngone/Cargo.toml
  17. 16
      ngone/src/main.rs
  18. 10
      p2p-broker/Cargo.toml
  19. 4
      p2p-broker/src/lib.rs
  20. 30
      p2p-broker/src/server.rs
  21. 26
      p2p-broker/src/server_ws.rs
  22. 92
      p2p-broker/src/types.rs
  23. 31
      p2p-broker/src/utils.rs
  24. 1
      p2p-client-ws/Cargo.toml
  25. 6
      p2p-client-ws/src/lib.rs
  26. 37
      p2p-client-ws/src/remote_ws.rs
  27. 22
      p2p-client-ws/src/remote_ws_wasm.rs
  28. 4
      p2p-net/Cargo.toml
  29. 2
      p2p-net/src/actor.rs
  30. 26
      p2p-net/src/broker.rs
  31. 44
      p2p-net/src/broker_connection.rs
  32. 35
      p2p-net/src/connection.rs
  33. 50
      p2p-net/src/lib.rs
  34. 31
      p2p-net/src/types.rs
  35. 17
      p2p-net/src/utils.rs
  36. 15
      p2p-repo/Cargo.toml
  37. 94
      p2p-repo/src/branch.rs
  38. 22
      p2p-repo/src/commit.rs
  39. 159
      p2p-repo/src/lib.rs
  40. 125
      p2p-repo/src/object.rs
  41. 12
      p2p-repo/src/utils.rs
  42. 1
      stores-lmdb/Cargo.toml
  43. 4
      stores-lmdb/src/kcv_store.rs
  44. 148
      stores-lmdb/src/repo_store.rs

1
.gitignore vendored

@ -1,4 +1,5 @@
*~
.ng
.direnv
!.github
\#*

236
Cargo.lock generated

@ -92,12 +92,55 @@ dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is-terminal",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d"
[[package]]
name = "anstyle-parse"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "anstyle-wincon"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
]
[[package]]
name = "anyhow"
version = "1.0.71"
@ -676,6 +719,48 @@ dependencies = [
"zeroize",
]
[[package]]
name = "clap"
version = "4.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80672091db20273a15cf9fdd4e47ed43b5091ec9841bf4c6145c9dfbbcae09ed"
dependencies = [
"clap_builder",
"clap_derive",
"once_cell",
]
[[package]]
name = "clap_builder"
version = "4.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1458a1df40e1e2afebb7ab60ce55c1fa8f431146205aa5f4887e0b111c27636"
dependencies = [
"anstream",
"anstyle",
"bitflags",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8cd2b2a819ad6eec39e8f1d6b53001af1e5469f8c177579cdaeb313115b825f"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.16",
]
[[package]]
name = "clap_lex"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b"
[[package]]
name = "cocoa"
version = "0.24.1"
@ -713,6 +798,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "combine"
version = "4.6.6"
@ -1010,6 +1101,23 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f215f9b7224f49fb73256115331f677d868b34d18b65dbe4db392e6021eea90"
[[package]]
name = "default-net"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b06254cc7a9b82a9e3e78849eab1af3dbef006bf629b2928b882534d84ded6b9"
dependencies = [
"dlopen2",
"libc",
"memalloc",
"netlink-packet-core",
"netlink-packet-route",
"netlink-sys",
"once_cell",
"system-configuration",
"windows 0.48.0",
]
[[package]]
name = "derive_more"
version = "0.99.17"
@ -1076,6 +1184,29 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
[[package]]
name = "dlopen2"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b121caccfc363e4d9a4589528f3bef7c71b83c6ed01c8dc68cbeeb7fd29ec698"
dependencies = [
"dlopen2_derive",
"libc",
"once_cell",
"winapi",
]
[[package]]
name = "dlopen2_derive"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a09ac8bb8c16a282264c379dffba707b9c998afc7506009137f3c6136888078"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
@ -2359,6 +2490,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5"
[[package]]
name = "memalloc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df39d232f5c40b0891c10216992c2f250c054105cb1e56f0fc9032db6203ecc1"
[[package]]
name = "memchr"
version = "2.5.0"
@ -2476,6 +2613,55 @@ dependencies = [
"jni-sys",
]
[[package]]
name = "netlink-packet-core"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e5cf0b54effda4b91615c40ff0fd12d0d4c9a6e0f5116874f03941792ff535a"
dependencies = [
"anyhow",
"byteorder",
"libc",
"netlink-packet-utils",
]
[[package]]
name = "netlink-packet-route"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea993e32c77d87f01236c38f572ecb6c311d592e56a06262a007fd2a6e31253c"
dependencies = [
"anyhow",
"bitflags",
"byteorder",
"libc",
"netlink-packet-core",
"netlink-packet-utils",
]
[[package]]
name = "netlink-packet-utils"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34"
dependencies = [
"anyhow",
"byteorder",
"paste",
"thiserror",
]
[[package]]
name = "netlink-sys"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6471bf08e7ac0135876a9581bf3217ef0333c191c128d34878079f42ee150411"
dependencies = [
"bytes",
"libc",
"log",
]
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
@ -2487,7 +2673,6 @@ name = "ng-app"
version = "0.1.0"
dependencies = [
"async-std",
"debug_print",
"ng-wallet",
"p2p-net",
"p2p-repo",
@ -2502,7 +2687,6 @@ name = "ng-sdk-js"
version = "0.1.0"
dependencies = [
"async-std",
"debug_print",
"futures",
"getrandom 0.1.16",
"gloo-timers",
@ -2532,7 +2716,6 @@ dependencies = [
"async-std",
"base64-url",
"chacha20poly1305",
"debug_print",
"getrandom 0.1.16",
"image",
"lazy_static",
@ -2553,7 +2736,6 @@ version = "0.1.0"
dependencies = [
"assert_cmd",
"async-std",
"debug_print",
"ed25519-dalek",
"fastbloom-rs",
"futures",
@ -2571,9 +2753,18 @@ name = "ngd"
version = "0.1.0"
dependencies = [
"async-std",
"base64-url",
"clap",
"default-net",
"env_logger",
"log",
"p2p-broker",
"p2p-net",
"p2p-repo",
"serde",
"serde_bare",
"serde_bytes",
"slice_as_array",
]
[[package]]
@ -2582,7 +2773,6 @@ version = "0.1.0"
dependencies = [
"base64-url",
"bytes",
"debug_print",
"env_logger",
"log",
"ng-wallet",
@ -2765,8 +2955,8 @@ dependencies = [
"async-std",
"async-trait",
"async-tungstenite",
"blake3",
"chacha20",
"debug_print",
"futures",
"getrandom 0.2.9",
"hex",
@ -2791,7 +2981,6 @@ dependencies = [
"async-trait",
"async-tungstenite",
"chacha20",
"debug_print",
"futures",
"getrandom 0.2.9",
"p2p-net",
@ -2814,11 +3003,9 @@ dependencies = [
"async-std",
"async-trait",
"blake3",
"debug_print",
"ed25519-dalek",
"futures",
"getrandom 0.2.9",
"gloo-timers",
"noise-protocol",
"noise-rust-crypto",
"num_enum",
@ -2842,11 +3029,14 @@ dependencies = [
"ed25519-dalek",
"fastbloom-rs",
"futures",
"gloo-timers",
"hex",
"log",
"rand 0.7.3",
"serde",
"serde_bare",
"serde_bytes",
"wasm-bindgen",
"web-time",
]
@ -4021,7 +4211,6 @@ dependencies = [
name = "stores-lmdb"
version = "0.1.0"
dependencies = [
"debug_print",
"hex",
"p2p-repo",
"rkv",
@ -4101,6 +4290,27 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "system-configuration"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
dependencies = [
"bitflags",
"core-foundation",
"system-configuration-sys",
]
[[package]]
name = "system-configuration-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "system-deps"
version = "6.1.0"
@ -4797,6 +5007,12 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "0.8.2"

@ -17,7 +17,6 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2.0.0-alpha.5", features = [] }
[dependencies]
debug_print = "1.0.0"
tauri = { version = "2.0.0-alpha.9", features = [] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

@ -10,8 +10,8 @@ use async_std::stream::StreamExt;
use ng_wallet::types::*;
use ng_wallet::*;
use p2p_net::broker::*;
use p2p_net::log;
use p2p_net::utils::{spawn_and_log_error, Receiver, ResultSend};
use p2p_repo::log::*;
use p2p_repo::types::*;
use tauri::{App, Manager};
@ -30,13 +30,13 @@ pub type SetupHook = Box<dyn FnOnce(&mut App) -> Result<(), Box<dyn std::error::
#[tauri::command(rename_all = "snake_case")]
async fn test() -> Result<(), ()> {
log!("test is {}", BROKER.read().await.test());
log_info!("test is {}", BROKER.read().await.test());
Ok(())
}
#[tauri::command(rename_all = "snake_case")]
async fn wallet_gen_shuffle_for_pazzle_opening(pazzle_length: u8) -> Result<ShuffledPazzle, ()> {
log!(
log_info!(
"wallet_gen_shuffle_for_pazzle_opening from rust {}",
pazzle_length
);
@ -45,7 +45,7 @@ async fn wallet_gen_shuffle_for_pazzle_opening(pazzle_length: u8) -> Result<Shuf
#[tauri::command(rename_all = "snake_case")]
async fn wallet_gen_shuffle_for_pin() -> Result<Vec<u8>, ()> {
log!("wallet_gen_shuffle_for_pin from rust");
log_info!("wallet_gen_shuffle_for_pin from rust");
Ok(gen_shuffle_for_pin())
}
@ -55,13 +55,13 @@ async fn wallet_open_wallet_with_pazzle(
pazzle: Vec<u8>,
pin: [u8; 4],
) -> Result<EncryptedWallet, String> {
log!("wallet_open_wallet_with_pazzle from rust {:?}", pazzle);
log_info!("wallet_open_wallet_with_pazzle from rust {:?}", pazzle);
open_wallet_with_pazzle(wallet, pazzle, pin).map_err(|e| e.to_string())
}
#[tauri::command(rename_all = "snake_case")]
async fn wallet_create_wallet(mut params: CreateWalletV0) -> Result<CreateWalletResultV0, String> {
//log!("wallet_create_wallet from rust {:?}", params);
//log_info!("wallet_create_wallet from rust {:?}", params);
params.result_with_wallet_file = false;
let local_save = params.local_save;
let res = create_wallet_v0(params).await.map_err(|e| e.to_string());
@ -77,7 +77,7 @@ async fn wallet_create_wallet(mut params: CreateWalletV0) -> Result<CreateWallet
#[tauri::command(rename_all = "snake_case")]
async fn doc_sync_branch(nuri: &str, stream_id: &str, app: tauri::AppHandle) -> Result<(), ()> {
log!("doc_sync_branch {} {}", nuri, stream_id);
log_info!("doc_sync_branch {} {}", nuri, stream_id);
let mut reader;
{
@ -99,7 +99,7 @@ async fn doc_sync_branch(nuri: &str, stream_id: &str, app: tauri::AppHandle) ->
BROKER.write().await.tauri_stream_cancel(stream_id);
log!("END OF LOOP");
log_info!("END OF LOOP");
Ok(())
}
@ -110,7 +110,7 @@ async fn doc_sync_branch(nuri: &str, stream_id: &str, app: tauri::AppHandle) ->
#[tauri::command(rename_all = "snake_case")]
async fn cancel_doc_sync_branch(stream_id: &str) -> Result<(), ()> {
log!("cancel stream {}", stream_id);
log_info!("cancel stream {}", stream_id);
BROKER
.write()
.await
@ -123,7 +123,7 @@ async fn doc_get_file_from_store_with_object_ref(
nuri: &str,
obj_ref: ObjectRef,
) -> Result<ObjectContent, String> {
log!(
log_info!(
"doc_get_file_from_store_with_object_ref {} {:?}",
nuri,
obj_ref

@ -23,7 +23,6 @@ ng-wallet = { path = "../ng-wallet" }
async-std = { version = "1.12.0", features = ["attributes","unstable"] }
futures = "0.3.24"
pharos = "0.5"
debug_print = "1.0.0"
serde = { version = "1.0", features = ["derive"] }
serde_bare = "0.5.0"
serde_bytes = "0.11.7"

@ -23,7 +23,7 @@ use p2p_net::broker::*;
use p2p_net::connection::{ClientConfig, StartConfig};
use p2p_net::types::{DirectPeerId, IP};
use p2p_net::utils::{spawn_and_log_error, Receiver, ResultSend, Sender};
use p2p_net::{log, sleep};
use p2p_repo::log::*;
use p2p_repo::types::*;
use p2p_repo::utils::generate_keypair;
use serde_json::json;
@ -31,6 +31,7 @@ use std::net::IpAddr;
use std::str::FromStr;
use std::sync::Arc;
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_futures::{future_to_promise, JsFuture};
#[cfg(target_arch = "wasm32")]
@ -112,7 +113,7 @@ extern "C" {
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub async fn test() {
log!("test is {}", BROKER.read().await.test());
log_info!("test is {}", BROKER.read().await.test());
}
#[cfg(target_arch = "wasm32")]
@ -123,7 +124,7 @@ pub async fn doc_get_file_from_store_with_object_ref(
) -> Result<JsValue, JsValue> {
let obj_ref = serde_wasm_bindgen::from_value::<ObjectRef>(obj_ref_js).unwrap();
log!(
log_info!(
"doc_get_file {} {:?} {}",
nuri,
obj_ref.id,
@ -181,14 +182,14 @@ pub async fn doc_sync_branch(anuri: String, callback: &js_sys::Function) -> JsVa
Err(_) => {}
}
}
log!("END OF LOOP");
log_info!("END OF LOOP");
Ok(())
}
spawn_and_log_error(inner_task(reader, anuri, callback.clone()));
let cb = Closure::once(move || {
log!("close channel");
log_info!("close channel");
sender.close_channel()
});
//Closure::wrap(Box::new(move |sender| sender.close_channel()) as Box<FnMut(Sender<Commit>)>);
@ -200,7 +201,7 @@ pub async fn doc_sync_branch(anuri: String, callback: &js_sys::Function) -> JsVa
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen]
pub async fn start() {
log!("random {}", random(10));
log_info!("random {}", random(10));
// let mut random_buf = [0u8; 32];
// getrandom::getrandom(&mut random_buf).unwrap();
@ -217,7 +218,7 @@ pub async fn start() {
let (client_priv_key, client_pub_key) = generate_keypair();
let (user_priv_key, user_pub_key) = generate_keypair();
log!("start connecting");
log_info!("start connecting");
let res = BROKER
.write()
@ -236,7 +237,7 @@ pub async fn start() {
}),
)
.await;
log!("broker.connect : {:?}", res);
log_info!("broker.connect : {:?}", res);
if res.is_err() {
return Ok(());
//panic!("Cannot connect");
@ -248,7 +249,7 @@ pub async fn start() {
async fn timer_close(remote_peer_id: DirectPeerId) -> ResultSend<()> {
async move {
sleep!(std::time::Duration::from_secs(3));
log!("timeout");
log_info!("timeout");
BROKER
.write()
.await

@ -8,7 +8,6 @@ description = "keeps the secret keys of all identities of the user in a safe wal
repository = "https://git.nextgraph.org/NextGraph/nextgraph-rs"
[dependencies]
debug_print = "1.0.0"
serde = { version = "1.0.142", features = ["derive"] }
serde_bare = "0.5.0"
serde_bytes = "0.11.7"

@ -9,13 +9,10 @@
// #[macro_use]
// extern crate slice_as_array;
#[macro_use]
extern crate p2p_net;
#[macro_use]
extern crate lazy_static;
use p2p_net::log;
pub mod types;
pub mod bip39;
@ -36,6 +33,7 @@ use chacha20poly1305::XChaCha20Poly1305;
use image::{imageops::FilterType, io::Reader as ImageReader, ImageOutputFormat};
use safe_transmute::transmute_to_bytes;
use p2p_repo::log::*;
use p2p_repo::types::{PubKey, Site, SiteType, Timestamp};
use p2p_repo::utils::{generate_keypair, now_timestamp, sign, verify};
use rand::prelude::*;
@ -61,7 +59,7 @@ pub fn enc_master_key(
.map_err(|e| NgWalletError::EncryptionError)?;
// `buffer` now contains the encrypted master key
// println!("cipher {:?}", buffer);
// log_debug!("cipher {:?}", buffer);
Ok(buffer.into_array::<48>().unwrap())
}
@ -124,7 +122,7 @@ pub fn enc_encrypted_block(
.map_err(|e| NgWalletError::EncryptionError)?;
// `buffer` now contains the message ciphertext
// println!("encrypted_block ciphertext {:?}", buffer);
// log_debug!("encrypted_block ciphertext {:?}", buffer);
Ok(buffer)
}
@ -151,7 +149,7 @@ pub fn dec_encrypted_block(
.map_err(|e| NgWalletError::DecryptionError)?;
// `ciphertext` now contains the decrypted block
//println!("decrypted_block {:?}", ciphertext);
//log_debug!("decrypted_block {:?}", ciphertext);
let decrypted_block =
from_slice::<EncryptedWalletV0>(&ciphertext).map_err(|e| NgWalletError::DecryptionError)?;
@ -205,7 +203,7 @@ pub fn open_wallet_with_pazzle(
v0.id,
)?;
log!(
log_info!(
"opening of wallet with pazzle took: {} ms",
opening_pazzle.elapsed().as_millis()
);
@ -287,16 +285,16 @@ pub fn display_pazzle(pazzle: &Vec<u8>) -> Vec<String> {
pub fn gen_shuffle_for_pazzle_opening(pazzle_length: u8) -> ShuffledPazzle {
let mut rng = rand::thread_rng();
let mut category_indices: Vec<u8> = (0..pazzle_length).collect();
//log!("{:?}", category_indices);
//log_info!("{:?}", category_indices);
category_indices.shuffle(&mut rng);
//log!("{:?}", category_indices);
//log_info!("{:?}", category_indices);
let mut emoji_indices: Vec<Vec<u8>> = Vec::with_capacity(pazzle_length.into());
for _ in 0..pazzle_length {
let mut idx: Vec<u8> = (0..15).collect();
//log!("{:?}", idx);
//log_info!("{:?}", idx);
idx.shuffle(&mut rng);
//log!("{:?}", idx);
//log_info!("{:?}", idx);
emoji_indices.push(idx)
}
ShuffledPazzle {
@ -308,9 +306,9 @@ pub fn gen_shuffle_for_pazzle_opening(pazzle_length: u8) -> ShuffledPazzle {
pub fn gen_shuffle_for_pin() -> Vec<u8> {
let mut rng = rand::thread_rng();
let mut digits: Vec<u8> = (0..10).collect();
//log!("{:?}", digits);
//log_info!("{:?}", digits);
digits.shuffle(&mut rng);
//log!("{:?}", digits);
//log_info!("{:?}", digits);
digits
}
@ -324,7 +322,7 @@ pub fn gen_shuffle_for_pin() -> Vec<u8> {
// for i in &mut mnemonic {
// *i = choices.chars().nth(ran.gen_range(0, 72)).unwrap();
// }
// log!("{}", mnemonic.iter().collect::<String>());
// log_info!("{}", mnemonic.iter().collect::<String>());
// }
/// creates a Wallet from a pin, a security text and image (with option to send the bootstrap and wallet to nextgraph.one)
@ -438,14 +436,14 @@ pub async fn create_wallet_v0(
*i = ran.gen_range(0, 15) + (category_indices[ix] << 4);
}
//println!("pazzle {:?}", pazzle);
//log_debug!("pazzle {:?}", pazzle);
let mut mnemonic = [0u16; 12];
for i in &mut mnemonic {
*i = ran.gen_range(0, 2048);
}
//println!("mnemonic {:?}", display_mnemonic(&mnemonic));
//log_debug!("mnemonic {:?}", display_mnemonic(&mnemonic));
//slice_as_array!(&mnemonic, [String; 12])
//.ok_or(NgWalletError::InternalError)?
@ -478,8 +476,8 @@ pub async fn create_wallet_v0(
let mut salt_mnemonic = [0u8; 16];
getrandom::getrandom(&mut salt_mnemonic).map_err(|e| NgWalletError::InternalError)?;
//println!("salt_pazzle {:?}", salt_pazzle);
//println!("salt_mnemonic {:?}", salt_mnemonic);
//log_debug!("salt_pazzle {:?}", salt_pazzle);
//log_debug!("salt_mnemonic {:?}", salt_mnemonic);
let mnemonic_key = derive_key_from_pass(
[transmute_to_bytes(&mnemonic), &params.pin].concat(),
@ -541,7 +539,7 @@ pub async fn create_wallet_v0(
// TODO send bootstrap (if)
// TODO send wallet (if)
log!(
log_info!(
"creating of wallet took: {} ms",
creating_pazzle.elapsed().as_millis()
);
@ -577,11 +575,11 @@ mod tests {
#[test]
fn test_gen_shuffle() {
let shuffle = gen_shuffle_for_pazzle_opening(9);
log!("{:?}", shuffle);
log_info!("{:?}", shuffle);
let shuffle = gen_shuffle_for_pazzle_opening(12);
log!("{:?}", shuffle);
log_info!("{:?}", shuffle);
let shuffle = gen_shuffle_for_pazzle_opening(15);
log!("{:?}", shuffle);
log_info!("{:?}", shuffle);
let digits = gen_shuffle_for_pin();
let digits = gen_shuffle_for_pin();
}
@ -618,26 +616,26 @@ mod tests {
.await
.expect("create_wallet_v0");
log!(
log_info!(
"creation of wallet took: {} ms",
creation.elapsed().as_millis()
);
log!("-----------------------------");
log_info!("-----------------------------");
let mut file = File::create("tests/wallet.ngw").expect("open wallet write file");
let ser_wallet = to_vec(&NgFile::V0(NgFileV0::Wallet(res.wallet.clone()))).unwrap();
file.write_all(&ser_wallet);
log!(
log_info!(
"wallet id: {:?}",
base64_url::encode(&res.wallet.id().slice())
);
log!("pazzle {:?}", display_pazzle(&res.pazzle));
log!("mnemonic {:?}", display_mnemonic(&res.mnemonic));
log!("pin {:?}", pin);
log_info!("pazzle {:?}", display_pazzle(&res.pazzle));
log_info!("mnemonic {:?}", display_mnemonic(&res.mnemonic));
log_info!("pin {:?}", pin);
if let Wallet::V0(v0) = res.wallet {
log!("security text: {:?}", v0.content.security_txt);
log_info!("security text: {:?}", v0.content.security_txt);
let mut file =
File::create("tests/generated_security_image.jpg").expect("open write file");
@ -658,9 +656,9 @@ mod tests {
let w = open_wallet_with_mnemonic(Wallet::V0(v0.clone()), res.mnemonic, pin)
.expect("open with mnemonic");
//println!("encrypted part {:?}", w);
//log_debug!("encrypted part {:?}", w);
log!(
log_info!(
"opening of wallet with mnemonic took: {} ms",
opening_mnemonic.elapsed().as_millis()
);
@ -669,12 +667,12 @@ mod tests {
let opening_pazzle = Instant::now();
let w = open_wallet_with_pazzle(Wallet::V0(v0.clone()), res.pazzle, pin)
.expect("open with pazzle");
log!(
log_info!(
"opening of wallet with pazzle took: {} ms",
opening_pazzle.elapsed().as_millis()
);
}
//println!("encrypted part {:?}", w);
//log_debug!("encrypted part {:?}", w);
}
}
}

@ -12,7 +12,7 @@ use std::fmt;
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;
use p2p_net::types::NetAddr;
use p2p_net::types::{BrokerServerV0, NetAddr};
use p2p_repo::types::*;
/// WalletId is a PubKey
@ -21,31 +21,11 @@ pub type WalletId = PubKey;
/// BootstrapId is a WalletId
pub type BootstrapId = WalletId;
/// BootstrapServer type
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub enum BoostrapServerTypeV0 {
Localhost(u16), // optional port number
BoxPrivate(Vec<NetAddr>),
BoxPublic(Vec<NetAddr>),
BoxPublicDyn(Vec<NetAddr>), // can be empty
Domain(String), // accepts an option trailing ":port" number
}
/// BootstrapServer details Version 0
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BootstrapServerV0 {
/// Network addresses
pub server_type: BoostrapServerTypeV0,
/// peerId of the server
pub peer_id: PubKey,
}
/// Bootstrap content Version 0
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BootstrapContentV0 {
/// list of servers, in order of preference
pub servers: Vec<BootstrapServerV0>,
pub servers: Vec<BrokerServerV0>,
}
/// Bootstrap Version 0

@ -8,7 +8,6 @@ description = "CLI command-line interpreter of NextGraph"
repository = "https://git.nextgraph.org/NextGraph/nextgraph-rs"
[dependencies]
debug_print = "1.0.0"
p2p-repo = { path = "../p2p-repo" }
p2p-net = { path = "../p2p-net" }
p2p-client-ws = { path = "../p2p-client-ws" }

@ -9,21 +9,21 @@
// notice may not be copied, modified, or distributed except
// according to those terms.
use debug_print::*;
use ed25519_dalek::*;
use fastbloom_rs::{BloomFilter as Filter, FilterBuilder, Membership};
use futures::{future, pin_mut, stream, SinkExt, StreamExt};
use p2p_broker::broker_store::config::ConfigMode;
use p2p_repo::object::Object;
use p2p_repo::store::{store_max_value_size, store_valid_value_size, HashMapRepoStore, RepoStore};
use stores_lmdb::kcv_store::LmdbKCVStore;
use stores_lmdb::repo_store::LmdbRepoStore;
use rand::rngs::OsRng;
use std::collections::HashMap;
use stores_lmdb::kcv_store::LmdbKCVStore;
use stores_lmdb::repo_store::LmdbRepoStore;
use p2p_net::errors::*;
use p2p_net::types::*;
use p2p_repo::log::*;
use p2p_repo::types::*;
use p2p_repo::utils::{generate_keypair, now_timestamp};
@ -50,9 +50,9 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
repo_pubkey,
repo_secret,
);
//println!(">>> add_obj");
println!(" id: {}", obj.id());
//println!(" deps: {:?}", obj.deps());
//log_debug!(">>> add_obj");
log_debug!(" id: {}", obj.id());
//log_debug!(" deps: {:?}", obj.deps());
obj.save(store).unwrap();
obj.reference().unwrap()
}
@ -94,7 +94,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
expiry,
)
.unwrap();
//println!("commit: {}", commit.id().unwrap());
//log_debug!("commit: {}", commit.id().unwrap());
add_obj(
ObjectContent::Commit(commit),
obj_deps,
@ -114,7 +114,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
let deps = vec![];
let expiry = None;
let body = CommitBody::Branch(branch);
//println!("body: {:?}", body);
//log_debug!("body: {:?}", body);
add_obj(
ObjectContent::CommitBody(body),
deps,
@ -134,7 +134,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
let expiry = None;
let content = [7u8; 777].to_vec();
let body = CommitBody::Transaction(Transaction::V0(content));
//println!("body: {:?}", body);
//log_debug!("body: {:?}", body);
add_obj(
ObjectContent::CommitBody(body),
deps,
@ -153,7 +153,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
) -> ObjectRef {
let expiry = None;
let body = CommitBody::Ack(Ack::V0());
//println!("body: {:?}", body);
//log_debug!("body: {:?}", body);
add_obj(
ObjectContent::CommitBody(body),
deps,
@ -170,12 +170,12 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
// repo
let repo_keypair: Keypair = Keypair::generate(&mut rng);
// println!(
// log_debug!(
// "repo private key: ({}) {:?}",
// repo_keypair.secret.as_bytes().len(),
// repo_keypair.secret.as_bytes()
// );
// println!(
// log_debug!(
// "repo public key: ({}) {:?}",
// repo_keypair.public.as_bytes().len(),
// repo_keypair.public.as_bytes()
@ -193,11 +193,11 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
// branch
let branch_keypair: Keypair = Keypair::generate(&mut rng);
//println!("branch public key: {:?}", branch_keypair.public.as_bytes());
//log_debug!("branch public key: {:?}", branch_keypair.public.as_bytes());
let branch_pubkey = PubKey::Ed25519PubKey(branch_keypair.public.to_bytes());
let member_keypair: Keypair = Keypair::generate(&mut rng);
//println!("member public key: {:?}", member_keypair.public.as_bytes());
//log_debug!("member public key: {:?}", member_keypair.public.as_bytes());
let member_privkey = PrivKey::Ed25519PrivKey(member_keypair.secret.to_bytes());
let member_pubkey = PubKey::Ed25519PubKey(member_keypair.public.to_bytes());
@ -221,18 +221,18 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
tags,
metadata,
);
//println!("branch: {:?}", branch);
println!("branch deps/acks:");
println!("");
println!(" br");
println!(" / \\");
println!(" t1 t2");
println!(" / \\ / \\");
println!(" a3 t4<--t5-->(t1)");
println!(" / \\");
println!(" a6 a7");
println!("");
//log_debug!("branch: {:?}", branch);
log_debug!("branch deps/acks:");
log_debug!("");
log_debug!(" br");
log_debug!(" / \\");
log_debug!(" t1 t2");
log_debug!(" / \\ / \\");
log_debug!(" a3 t4<--t5-->(t1)");
log_debug!(" / \\");
log_debug!(" a6 a7");
log_debug!("");
// commit bodies
@ -247,7 +247,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
// create & add commits to store
println!(">> br");
log_debug!(">> br");
let br = add_commit(
branch_body,
member_privkey,
@ -261,7 +261,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> t1");
log_debug!(">> t1");
let t1 = add_commit(
branch_body,
member_privkey,
@ -275,7 +275,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> t2");
log_debug!(">> t2");
let t2 = add_commit(
branch_body,
member_privkey,
@ -289,7 +289,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> a3");
log_debug!(">> a3");
let a3 = add_commit(
branch_body,
member_privkey,
@ -303,7 +303,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> t4");
log_debug!(">> t4");
let t4 = add_commit(
branch_body,
member_privkey,
@ -317,7 +317,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> t5");
log_debug!(">> t5");
let t5 = add_commit(
branch_body,
member_privkey,
@ -331,7 +331,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> a6");
log_debug!(">> a6");
let a6 = add_commit(
branch_body,
member_privkey,
@ -345,7 +345,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
println!(">> a7");
log_debug!(">> a7");
let a7 = add_commit(
branch_body,
member_privkey,
@ -366,7 +366,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
// Sending everything to the broker
for (v) in store.get_all() {
//debug_println!("SENDING {}", k);
//log_debug!("SENDING {}", k);
let _ = public_overlay_cnx
.put_block(&v)
.await
@ -403,7 +403,7 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
&mut store,
);
debug_println!("LOCAL STORE HAS {} BLOCKS", store.get_len());
log_debug!("LOCAL STORE HAS {} BLOCKS", store.get_len());
// Let's pretend that we know that the head of the branch in the broker is at commits a6 and a7.
// normally it would be the pub/sub that notifies us of those heads.
@ -433,14 +433,14 @@ async fn test_sync(cnx: &mut impl BrokerConnection, user_pub_key: PubKey, userpr
let mut i = 0;
while let Some(b) = synced_blocks_stream.next().await {
debug_println!("GOT BLOCK {}", b.id());
log_debug!("GOT BLOCK {}", b.id());
store.put(&b);
i += 1;
}
debug_println!("SYNCED {} BLOCKS", i);
log_debug!("SYNCED {} BLOCKS", i);
debug_println!("LOCAL STORE HAS {} BLOCKS", store.get_len());
log_debug!("LOCAL STORE HAS {} BLOCKS", store.get_len());
// now the client can verify the DAG and each commit. Then update its list of heads.
}
@ -471,7 +471,7 @@ async fn test(
});
let mut public_overlay_cnx = cnx.overlay_connect(&repo, true).await?;
debug_println!("put_block");
log_debug!("put_block");
let my_block_id = public_overlay_cnx
.put_block(&Block::new(
@ -483,7 +483,7 @@ async fn test(
))
.await?;
debug_println!("added block_id to store {}", my_block_id);
log_debug!("added block_id to store {}", my_block_id);
let object_id = public_overlay_cnx
.put_object(
@ -500,7 +500,7 @@ async fn test(
)
.await?;
debug_println!("added object_id to store {}", object_id);
log_debug!("added object_id to store {}", object_id);
let mut my_block_stream = public_overlay_cnx
.get_block(my_block_id, true, None)
@ -508,27 +508,27 @@ async fn test(
//.expect("get_block failed");
while let Some(b) = my_block_stream.next().await {
debug_println!("GOT BLOCK {}", b.id());
log_debug!("GOT BLOCK {}", b.id());
}
let mut my_object_stream = public_overlay_cnx.get_block(object_id, true, None).await?;
//.expect("get_block for object failed");
while let Some(b) = my_object_stream.next().await {
debug_println!("GOT BLOCK {}", b.id());
log_debug!("GOT BLOCK {}", b.id());
}
let object = public_overlay_cnx.get_object(object_id, None).await?;
//.expect("get_object failed");
debug_println!("GOT OBJECT with ID {}", object.id());
log_debug!("GOT OBJECT with ID {}", object.id());
// let object_id = public_overlay_cnx
// .copy_object(object_id, Some(now_timestamp() + 60))
// .await
// .expect("copy_object failed");
// debug_println!("COPIED OBJECT to OBJECT ID {}", object_id);
// log_debug!("COPIED OBJECT to OBJECT ID {}", object_id);
public_overlay_cnx.delete_object(object_id).await?;
//.expect("delete_object failed");
@ -538,7 +538,7 @@ async fn test(
.await
.unwrap_err();
debug_println!("result from get object after delete: {}", res);
log_debug!("result from get object after delete: {}", res);
assert_eq!(res, ProtocolError::NotFound);
//TODO test pin/unpin
@ -551,12 +551,12 @@ async fn test(
}
async fn test_local_connection() {
debug_println!("===== TESTING LOCAL API =====");
log_debug!("===== TESTING LOCAL API =====");
let root = tempfile::Builder::new().prefix("ngcli").tempdir().unwrap();
let master_key: [u8; 32] = [0; 32];
std::fs::create_dir_all(root.path()).unwrap();
println!("{}", root.path().to_str().unwrap());
log_debug!("{}", root.path().to_str().unwrap());
let store = LmdbKCVStore::open(root.path(), master_key);
//let mut server = BrokerServer::new(store, ConfigMode::Local).expect("starting broker");
@ -569,7 +569,7 @@ async fn test_local_connection() {
}
async fn test_remote_connection(url: &str) {
debug_println!("===== TESTING REMOTE API =====");
log_debug!("===== TESTING REMOTE API =====");
let (priv_key, pub_key) = generate_keypair();
@ -580,7 +580,7 @@ async fn test_remote_connection(url: &str) {
#[async_std::main]
async fn main() -> std::io::Result<()> {
debug_println!("Starting nextgraph CLI...");
log_debug!("Starting nextgraph CLI...");
//test_local_connection().await;
@ -606,12 +606,12 @@ mod test {
#[async_std::test]
pub async fn test_remote_cnx() -> Result<(), Box<dyn std::error::Error>> {
let keys = gen_keys();
// println!("Public key of node: {:?}", keys.1);
// println!("Private key of node: {:?}", keys.0.as_slice());
// log_debug!("Public key of node: {:?}", keys.1);
// log_debug!("Private key of node: {:?}", keys.0.as_slice());
let pubkey = PubKey::Ed25519PubKey(keys.1);
println!("Public key of node: {:?}", pubkey);
println!("Private key of node: {:?}", keys.0.as_slice());
log_debug!("Public key of node: {:?}", pubkey);