bless
This commit is contained in:
parent
1dcab4cabe
commit
0992c28d9a
@ -6,7 +6,6 @@ edition = "2024"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = "0.29.0"
|
crossterm = "0.29.0"
|
||||||
ratatui = "0.29.0"
|
ratatui = "0.29.0"
|
||||||
ws = "0.9.2"
|
vlogger = { path = "../vlogger" }
|
||||||
vlogger = { path = "../lib/logger-rs" }
|
|
||||||
clap = { version = "4.5.47", features = ["derive"] }
|
clap = { version = "4.5.47", features = ["derive"] }
|
||||||
textwrap = "0.16.2"
|
textwrap = "0.16.2"
|
||||||
|
|||||||
179
native_client/Cargo.lock
generated
179
native_client/Cargo.lock
generated
@ -64,7 +64,7 @@ dependencies = [
|
|||||||
"nom",
|
"nom",
|
||||||
"pin-project",
|
"pin-project",
|
||||||
"pinentry",
|
"pinentry",
|
||||||
"rand",
|
"rand 0.8.5",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"scrypt",
|
"scrypt",
|
||||||
@ -86,7 +86,7 @@ dependencies = [
|
|||||||
"hkdf",
|
"hkdf",
|
||||||
"io_tee",
|
"io_tee",
|
||||||
"nom",
|
"nom",
|
||||||
"rand",
|
"rand 0.8.5",
|
||||||
"secrecy",
|
"secrecy",
|
||||||
"sha2",
|
"sha2",
|
||||||
]
|
]
|
||||||
@ -691,7 +691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
|
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"subtle",
|
"subtle",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
@ -738,6 +738,12 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "data-encoding"
|
||||||
|
version = "2.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "der"
|
name = "der"
|
||||||
version = "0.7.10"
|
version = "0.7.10"
|
||||||
@ -978,7 +984,7 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
"group",
|
"group",
|
||||||
"pkcs8",
|
"pkcs8",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"sec1",
|
"sec1",
|
||||||
"subtle",
|
"subtle",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
@ -1093,7 +1099,7 @@ version = "0.13.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
|
checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1172,6 +1178,12 @@ dependencies = [
|
|||||||
"thiserror 1.0.69",
|
"thiserror 1.0.69",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fnv"
|
||||||
|
version = "1.0.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foldhash"
|
name = "foldhash"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -1445,7 +1457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
|
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ff",
|
"ff",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1520,6 +1532,23 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "http"
|
||||||
|
version = "1.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"fnv",
|
||||||
|
"itoa",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "httparse"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "i18n-config"
|
name = "i18n-config"
|
||||||
version = "0.4.8"
|
version = "0.4.8"
|
||||||
@ -2002,10 +2031,13 @@ dependencies = [
|
|||||||
name = "native_client"
|
name = "native_client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bincode",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
"hex",
|
"hex",
|
||||||
"serde",
|
"serde",
|
||||||
|
"shared",
|
||||||
|
"tungstenite",
|
||||||
"vlogger",
|
"vlogger",
|
||||||
"watchlet",
|
"watchlet",
|
||||||
]
|
]
|
||||||
@ -2650,8 +2682,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha",
|
"rand_chacha 0.3.1",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.9.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
|
||||||
|
dependencies = [
|
||||||
|
"rand_chacha 0.9.0",
|
||||||
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2661,7 +2703,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ppv-lite86",
|
"ppv-lite86",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_chacha"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
|
||||||
|
dependencies = [
|
||||||
|
"ppv-lite86",
|
||||||
|
"rand_core 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2673,6 +2725,15 @@ dependencies = [
|
|||||||
"getrandom 0.2.16",
|
"getrandom 0.2.16",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand_core"
|
||||||
|
version = "0.9.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom 0.3.3",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "raw-window-handle"
|
name = "raw-window-handle"
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
@ -2713,6 +2774,20 @@ dependencies = [
|
|||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ring"
|
||||||
|
version = "0.17.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"cfg-if",
|
||||||
|
"getrandom 0.2.16",
|
||||||
|
"libc",
|
||||||
|
"untrusted",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ron"
|
name = "ron"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
@ -2828,6 +2903,36 @@ dependencies = [
|
|||||||
"windows-sys 0.61.0",
|
"windows-sys 0.61.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls"
|
||||||
|
version = "0.23.26"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "df51b5869f3a441595eac5e8ff14d486ff285f7b8c0df8770e49c3b56351f0f0"
|
||||||
|
dependencies = [
|
||||||
|
"once_cell",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"rustls-webpki",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-pki-types"
|
||||||
|
version = "1.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustls-webpki"
|
||||||
|
version = "0.103.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03"
|
||||||
|
dependencies = [
|
||||||
|
"ring",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"untrusted",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.22"
|
version = "1.0.22"
|
||||||
@ -2957,6 +3062,17 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sha1"
|
||||||
|
version = "0.10.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"cpufeatures",
|
||||||
|
"digest",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@ -3006,7 +3122,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"digest",
|
"digest",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3280,6 +3396,26 @@ version = "0.25.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tungstenite"
|
||||||
|
version = "0.27.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "eadc29d668c91fcc564941132e17b28a7ceb2f3ebf0b9dae3e03fd7a6748eb0d"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"data-encoding",
|
||||||
|
"http",
|
||||||
|
"httparse",
|
||||||
|
"log",
|
||||||
|
"rand 0.9.2",
|
||||||
|
"rustls",
|
||||||
|
"rustls-pki-types",
|
||||||
|
"sha1",
|
||||||
|
"thiserror 2.0.16",
|
||||||
|
"utf-8",
|
||||||
|
"webpki-roots",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "type-map"
|
name = "type-map"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@ -3342,6 +3478,12 @@ dependencies = [
|
|||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "untrusted"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unty"
|
name = "unty"
|
||||||
version = "0.0.4"
|
version = "0.0.4"
|
||||||
@ -3360,6 +3502,12 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf-8"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8_iter"
|
name = "utf8_iter"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
@ -3662,6 +3810,15 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "webpki-roots"
|
||||||
|
version = "0.26.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5d642ff16b7e79272ae451b7322067cdc17cadf68c23264be9d94a32319efe7e"
|
||||||
|
dependencies = [
|
||||||
|
"rustls-pki-types",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "weezl"
|
name = "weezl"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@ -4162,7 +4319,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277"
|
checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"curve25519-dalek",
|
"curve25519-dalek",
|
||||||
"rand_core",
|
"rand_core 0.6.4",
|
||||||
"serde",
|
"serde",
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -17,3 +17,6 @@ serde = { version = "1.0.219", features = ["derive"] }
|
|||||||
watchlet = { path = "../watchlet" }
|
watchlet = { path = "../watchlet" }
|
||||||
hex = "0.4.3"
|
hex = "0.4.3"
|
||||||
vlogger = { path = "../vlogger" }
|
vlogger = { path = "../vlogger" }
|
||||||
|
tungstenite = { version = "0.27.0", features = ["rustls-tls-webpki-roots"] }
|
||||||
|
bincode = { version = "2.0.1", features = ["serde"] }
|
||||||
|
shared = { path = "../shared" }
|
||||||
|
|||||||
@ -9,6 +9,8 @@ use crate::messages::frontend::FrontendMessage;
|
|||||||
use crate::messages::backend::BackendMessage;
|
use crate::messages::backend::BackendMessage;
|
||||||
use crate::constants::DATA_DIR_PATH;
|
use crate::constants::DATA_DIR_PATH;
|
||||||
|
|
||||||
|
use std::path;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct WalletState {
|
pub struct WalletState {
|
||||||
pub address: String,
|
pub address: String,
|
||||||
@ -27,7 +29,7 @@ impl WalletService {
|
|||||||
receiver: Receiver<BackendMessage>,
|
receiver: Receiver<BackendMessage>,
|
||||||
sender: Sender<FrontendMessage>,
|
sender: Sender<FrontendMessage>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let wallet_path = format!("{}/wallet/wallet.age", DATA_DIR_PATH);
|
let wallet_path = path::PathBuf::from(format!("{}/wallet/wallet.age", DATA_DIR_PATH));
|
||||||
let storage = FileStorage::new(wallet_path.into());
|
let storage = FileStorage::new(wallet_path.into());
|
||||||
let mut wallet_manager = WalletManager::new(storage);
|
let mut wallet_manager = WalletManager::new(storage);
|
||||||
wallet_manager.load_wallet("password".into()).unwrap();
|
wallet_manager.load_wallet("password".into()).unwrap();
|
||||||
|
|||||||
12
native_client/src/backend/ws_client.rs
Normal file
12
native_client/src/backend/ws_client.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use shared::WsClientRequest;
|
||||||
|
|
||||||
|
pub fn run_client() {
|
||||||
|
let (mut stream, _response) = tungstenite::connect("ws://localhost:9001").unwrap();
|
||||||
|
|
||||||
|
let msg = bincode::encode_to_vec(WsClientRequest::Ping, bincode::config::standard()).unwrap();
|
||||||
|
stream.send(msg.into()).unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
println!("{:#?}", stream.read())
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -28,4 +28,5 @@ pub mod messages {
|
|||||||
|
|
||||||
pub mod backend {
|
pub mod backend {
|
||||||
pub mod wallet;
|
pub mod wallet;
|
||||||
|
pub mod ws_client;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![warn(clippy::all, rust_2018_idioms)]
|
#![warn(clippy::all, rust_2018_idioms)]
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use native_client::{backend::wallet::WalletService, frontend, messages::{backend::BackendMessage, frontend::FrontendMessage}};
|
use native_client::{backend::{wallet::WalletService, ws_client::run_client}, frontend, messages::{backend::BackendMessage, frontend::FrontendMessage}};
|
||||||
use std::sync::mpsc::{self, Receiver, Sender};
|
use std::sync::mpsc::{self, Receiver, Sender};
|
||||||
|
|
||||||
fn dispatch_frontend(
|
fn dispatch_frontend(
|
||||||
@ -25,6 +25,9 @@ fn main() -> Result<(), std::io::Error> {
|
|||||||
let (front_tx, front_rx) = mpsc::channel::<FrontendMessage>();
|
let (front_tx, front_rx) = mpsc::channel::<FrontendMessage>();
|
||||||
let (back_tx, back_rx) = mpsc::channel::<BackendMessage>();
|
let (back_tx, back_rx) = mpsc::channel::<BackendMessage>();
|
||||||
|
|
||||||
|
run_client();
|
||||||
|
return Ok(());
|
||||||
|
|
||||||
let backend_handle = std::thread::spawn( || {
|
let backend_handle = std::thread::spawn( || {
|
||||||
let mut wallet_service = WalletService::new(back_rx, front_tx);
|
let mut wallet_service = WalletService::new(back_rx, front_tx);
|
||||||
wallet_service.run();
|
wallet_service.run();
|
||||||
|
|||||||
697
node/Cargo.lock
generated
697
node/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@ serde_json = "1.0.143"
|
|||||||
sha2 = "0.10.9"
|
sha2 = "0.10.9"
|
||||||
thiserror = "2.0.16"
|
thiserror = "2.0.16"
|
||||||
tokio = { version = "1.47.1", features = ["rt-multi-thread", "net", "sync", "time", "macros"] }
|
tokio = { version = "1.47.1", features = ["rt-multi-thread", "net", "sync", "time", "macros"] }
|
||||||
tokio-tungstenite = "0.27.0"
|
tokio-tungstenite = { version = "0.27.0", features = ["handshake", "rustls-tls-webpki-roots"] }
|
||||||
uuid = { version = "1.18.0", features = ["v4", "serde"] }
|
uuid = { version = "1.18.0", features = ["v4", "serde"] }
|
||||||
vlogger = { path = "../vlogger" }
|
vlogger = { path = "../vlogger" }
|
||||||
ratatui = "0.29.0"
|
ratatui = "0.29.0"
|
||||||
@ -30,6 +30,6 @@ futures = "0.3.31"
|
|||||||
secp256k1 = { version = "0.31.1", features = ["hashes", "rand", "recovery", "serde"] }
|
secp256k1 = { version = "0.31.1", features = ["hashes", "rand", "recovery", "serde"] }
|
||||||
ring = "0.17.14"
|
ring = "0.17.14"
|
||||||
shared = { path = "../shared", features = ["node"] }
|
shared = { path = "../shared", features = ["node"] }
|
||||||
wallet = { path = "../wallet" }
|
watchlet = { path = "../watchlet" }
|
||||||
cli-renderer = { path = "../cli-renderer" }
|
cli-renderer = { path = "../cli-renderer" }
|
||||||
tiny_http = "0.12.0"
|
tiny_http = "0.12.0"
|
||||||
|
|||||||
@ -12,7 +12,7 @@ use crate::{
|
|||||||
use shared::print_error_chain;
|
use shared::print_error_chain;
|
||||||
|
|
||||||
use crate::PROJECT_PATH;
|
use crate::PROJECT_PATH;
|
||||||
static BINCODE_CONFIG: Configuration = bincode::config::standard();
|
pub static BINCODE_CONFIG: Configuration = bincode::config::standard();
|
||||||
|
|
||||||
const DB_TREE: &str = "blocks";
|
const DB_TREE: &str = "blocks";
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,8 @@ pub mod node {
|
|||||||
|
|
||||||
pub mod blockchain;
|
pub mod blockchain;
|
||||||
pub use blockchain::*;
|
pub use blockchain::*;
|
||||||
|
|
||||||
|
pub mod ws_server;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod constants;
|
pub mod constants;
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use crate::protocol::ProtocolMessage;
|
|||||||
use crate::protocol::{Connector, ConnectorCommand};
|
use crate::protocol::{Connector, ConnectorCommand};
|
||||||
use crate::seeds_constants::SEED_NODES;
|
use crate::seeds_constants::SEED_NODES;
|
||||||
use crate::watcher::{WatcherCommand, WatcherMode};
|
use crate::watcher::{WatcherCommand, WatcherMode};
|
||||||
|
use super::ws_server::{WsCommand, WsServer};
|
||||||
use super::{ Blockchain, BlockchainError, ValidationError };
|
use super::{ Blockchain, BlockchainError, ValidationError };
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -477,10 +478,18 @@ impl Node {
|
|||||||
.await;
|
.await;
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle = tokio::spawn(async move {
|
let http_handle = tokio::spawn(async move {
|
||||||
let _ = crate::api::server::start_server().await;
|
let _ = crate::api::server::start_server().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let (tx, rx) = mpsc::channel::<WsCommand>(100);
|
||||||
|
|
||||||
|
let mut ws_server = WsServer::new(rx, self.exec_tx());
|
||||||
|
|
||||||
|
let ws_handle = tokio::spawn(async move {
|
||||||
|
ws_server.run().await;
|
||||||
|
});
|
||||||
|
|
||||||
let mut system_rx = subscribe_system_event();
|
let mut system_rx = subscribe_system_event();
|
||||||
publish_system_event(SystemEvent::NodeStarted);
|
publish_system_event(SystemEvent::NodeStarted);
|
||||||
|
|
||||||
@ -506,7 +515,7 @@ impl Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handle.abort_handle().abort();
|
http_handle.abort_handle().abort();
|
||||||
self.shutdown().await;
|
self.shutdown().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
141
node/src/node/ws_server.rs
Normal file
141
node/src/node/ws_server.rs
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
use tokio::net::TcpStream;
|
||||||
|
use futures::{SinkExt, StreamExt};
|
||||||
|
use tokio::sync::mpsc::{self, Receiver, Sender};
|
||||||
|
use thiserror::Error;
|
||||||
|
use vlogger::*;
|
||||||
|
use shared::ws_protocol::{ WsClientRequest, WsClientResponse };
|
||||||
|
|
||||||
|
use crate::db::BINCODE_CONFIG;
|
||||||
|
use crate::executor::ExecutorCommand;
|
||||||
|
use crate::log;
|
||||||
|
use crate::seeds_constants::WS_LISTEN_ADDRESS;
|
||||||
|
|
||||||
|
#[derive(Debug, bincode::Encode, bincode::Decode)]
|
||||||
|
pub enum WsCommand {
|
||||||
|
Respond{
|
||||||
|
msg: WsClientResponse,
|
||||||
|
addr: SocketAddr,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum WsError {
|
||||||
|
#[error("Socker Error: {0}")]
|
||||||
|
Socket(#[from] std::io::Error),
|
||||||
|
|
||||||
|
#[error("Tungstenite Error: {0}")]
|
||||||
|
Connection(#[from] tokio_tungstenite::tungstenite::Error),
|
||||||
|
|
||||||
|
#[error("Encoding Error: {0}")]
|
||||||
|
Encode(#[from] bincode::error::EncodeError),
|
||||||
|
|
||||||
|
#[error("Decoding Error: {0}")]
|
||||||
|
Decode(#[from] bincode::error::DecodeError),
|
||||||
|
|
||||||
|
#[error("MPSC Send Error: {0}")]
|
||||||
|
MpscSend(#[from] mpsc::error::SendError<WsClientResponse>)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WsServer {
|
||||||
|
rx: Receiver<WsCommand>,
|
||||||
|
tx: Sender<ExecutorCommand>,
|
||||||
|
clients: HashMap<SocketAddr, Sender<WsClientResponse>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn ws_connection(
|
||||||
|
stream: TcpStream,
|
||||||
|
mut rx: Receiver<WsClientResponse>,
|
||||||
|
_tx: Sender<ExecutorCommand>,
|
||||||
|
) -> Result<(), WsError> {
|
||||||
|
let ws_server = tokio_tungstenite::accept_async(stream).await.unwrap();
|
||||||
|
let (mut write, mut read) = ws_server.split();
|
||||||
|
|
||||||
|
tokio::select! {
|
||||||
|
ws_res = read.next() => {
|
||||||
|
match ws_res {
|
||||||
|
Some(Ok(msg)) => {
|
||||||
|
log(msg!(DEBUG, "msg: {:#?}", msg));
|
||||||
|
if msg.is_text() || msg.is_binary() {
|
||||||
|
let (message, _size): (WsClientRequest, usize) = bincode::decode_from_slice(msg.to_string().as_bytes(), BINCODE_CONFIG)?;
|
||||||
|
match message {
|
||||||
|
WsClientRequest::Ping => {
|
||||||
|
log(msg!(DEBUG, "Received Ping from client"));
|
||||||
|
let response = bincode::encode_to_vec(WsClientResponse::Pong, BINCODE_CONFIG)?;
|
||||||
|
write.send(response.into()).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws_cmd = rx.recv() => {
|
||||||
|
match ws_cmd {
|
||||||
|
Some(cmd) => {
|
||||||
|
let bin_cmd = bincode::encode_to_vec(&cmd, BINCODE_CONFIG)?;
|
||||||
|
write.send(bin_cmd.into()).await?;
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WsServer {
|
||||||
|
pub fn new(rx: Receiver<WsCommand>, tx: Sender<ExecutorCommand>) -> Self {
|
||||||
|
Self {
|
||||||
|
rx,
|
||||||
|
tx,
|
||||||
|
clients: HashMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn run(&mut self) -> Result<(), WsError> {
|
||||||
|
let listener = tokio::net::TcpListener::bind(*WS_LISTEN_ADDRESS).await?;
|
||||||
|
let mut tasks = Vec::new();
|
||||||
|
|
||||||
|
log(msg!(DEBUG, "Starting WsServer at {}", *WS_LISTEN_ADDRESS));
|
||||||
|
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
ws_cmd = self.rx.recv() => {
|
||||||
|
match ws_cmd {
|
||||||
|
Some(cmd) => {
|
||||||
|
match cmd {
|
||||||
|
WsCommand::Respond { msg, addr } => {
|
||||||
|
if let Some(sender) = self.clients.get(&addr) {
|
||||||
|
sender.send(msg).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
con_res = listener.accept() => {
|
||||||
|
match con_res {
|
||||||
|
Ok((stream, addr)) => {
|
||||||
|
log(msg!(DEBUG, "Received Connection Attempt from {}", addr));
|
||||||
|
let (tx, rx) = mpsc::channel::<WsClientResponse>(100);
|
||||||
|
self.clients.insert(addr, tx);
|
||||||
|
let tx = self.tx.clone();
|
||||||
|
let task_handle = tokio::spawn(async move {
|
||||||
|
if let Err(e) = ws_connection(stream, rx, tx).await {
|
||||||
|
log(msg!(ERROR, "{e}"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tasks.push(task_handle);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log(msg!(ERROR, "{e}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,10 @@
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
|
pub static WS_LISTEN_ADDRESS: Lazy<SocketAddr> = Lazy::new(|| {
|
||||||
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9001)
|
||||||
|
});
|
||||||
|
|
||||||
pub static SEED_NODES: Lazy<[SocketAddr; 3]> = Lazy::new(|| {
|
pub static SEED_NODES: Lazy<[SocketAddr; 3]> = Lazy::new(|| {
|
||||||
[
|
[
|
||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8333),
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8333),
|
||||||
|
|||||||
@ -227,9 +227,9 @@ impl Watcher {
|
|||||||
pub async fn log_memory() {
|
pub async fn log_memory() {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut id = format!("{}_{}", current_timestamp(), std::process::id());
|
let mut id = format!("{}_{}", current_timestamp(), std::process::id());
|
||||||
id.replace(":", "_");
|
let id = id.replace(":", "_");
|
||||||
let mut path = std::path::PathBuf::new();
|
let mut path = std::path::PathBuf::new();
|
||||||
path.push("./proc/");
|
path.push("proc");
|
||||||
path.push(id);
|
path.push(id);
|
||||||
let mut mem_map = std::fs::OpenOptions::new()
|
let mut mem_map = std::fs::OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
|
|||||||
@ -13,8 +13,12 @@ pub mod core {
|
|||||||
|
|
||||||
pub mod address;
|
pub mod address;
|
||||||
pub use address::*;
|
pub use address::*;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod ws_protocol;
|
||||||
|
pub use ws_protocol::*;
|
||||||
|
|
||||||
pub fn print_error_chain(err: &anyhow::Error) {
|
pub fn print_error_chain(err: &anyhow::Error) {
|
||||||
let mut err_string = String::from(format!("Error: {}\n", err));
|
let mut err_string = String::from(format!("Error: {}\n", err));
|
||||||
|
|
||||||
|
|||||||
9
shared/src/ws_protocol.rs
Normal file
9
shared/src/ws_protocol.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#[derive(Debug, bincode::Encode, bincode::Decode)]
|
||||||
|
pub enum WsClientRequest {
|
||||||
|
Ping
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, bincode::Encode, bincode::Decode)]
|
||||||
|
pub enum WsClientResponse {
|
||||||
|
Pong
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user