From d87479f28c0fae0b9db7fb82959037f2a429720e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 18 May 2022 16:06:48 +0200 Subject: [PATCH] Uncomment code and try build --- clients/native/src/commands/init.rs | 6 +- hrycyszynvpn/Cargo.lock | 159 ++++++++++++- hrycyszynvpn/src-tauri/Cargo.toml | 29 +-- hrycyszynvpn/src-tauri/src/main.rs | 2 +- hrycyszynvpn/src-tauri/src/state.rs | 342 ++++++++++++++-------------- 5 files changed, 346 insertions(+), 192 deletions(-) diff --git a/clients/native/src/commands/init.rs b/clients/native/src/commands/init.rs index b2cfd95a4d..ab764a1e89 100644 --- a/clients/native/src/commands/init.rs +++ b/clients/native/src/commands/init.rs @@ -88,7 +88,7 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { app } -async fn register_with_gateway( +pub async fn register_with_gateway( gateway: &gateway::Node, our_identity: Arc, ) -> Arc { @@ -110,7 +110,7 @@ async fn register_with_gateway( .expect("failed to register with the gateway!") } -async fn gateway_details( +pub async fn gateway_details( validator_servers: Vec, chosen_gateway_id: Option<&str>, ) -> gateway::Node { @@ -144,7 +144,7 @@ async fn gateway_details( } } -fn show_address(config: &Config) { +pub fn show_address(config: &Config) { fn load_identity_keys(pathfinder: &ClientKeyPathfinder) -> identity::KeyPair { let identity_keypair: identity::KeyPair = pemstore::load_keypair(&pemstore::KeyPairPath::new( diff --git a/hrycyszynvpn/Cargo.lock b/hrycyszynvpn/Cargo.lock index 0a4022e548..430a044223 100644 --- a/hrycyszynvpn/Cargo.lock +++ b/hrycyszynvpn/Cargo.lock @@ -1366,6 +1366,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dotenv" version = "0.15.0" @@ -1542,6 +1548,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "error-chain" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d2f06b9cac1506ece98fe3231e3cc9c4410ec3d5b1f24ae1c8946f0742cdefc" +dependencies = [ + "version_check", +] + [[package]] name = "ethabi" version = "14.1.0" @@ -2522,13 +2537,23 @@ dependencies = [ "argon2", "base64", "bip39", + "client-core", + "coconut-interface", + "config", "cosmrs", "cosmwasm-std", + "credentials", "dirs 4.0.0", "eyre", "fix-path-env", + "log", + "mixnet-contract-common", + "network-defaults", "nym-client", - "rand 0.6.5", + "nym-network-requester", + "nym-socks5-client", + "nymsphinx", + "rand 0.7.3", "serde", "serde_json", "strum 0.23.0", @@ -2542,6 +2567,8 @@ dependencies = [ "tokio", "ts-rs", "url", + "validator-client", + "version-checker", "zeroize", ] @@ -2850,6 +2877,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +[[package]] +name = "ipnetwork" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c3eaab3ac0ede60ffa41add21970a7df7d91772c03383aac6c2c3d53cc716b" +dependencies = [ + "serde", +] + [[package]] name = "itertools" version = "0.10.3" @@ -3103,9 +3139,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -3497,6 +3533,60 @@ dependencies = [ "websocket-requests", ] +[[package]] +name = "nym-network-requester" +version = "1.0.0-rc.2" +dependencies = [ + "clap", + "dirs 3.0.2", + "futures", + "ipnetwork", + "log", + "nymsphinx", + "ordered-buffer", + "pretty_env_logger", + "proxy-helpers", + "publicsuffix", + "socks5-requests", + "tokio", + "tokio-tungstenite", + "websocket-requests", +] + +[[package]] +name = "nym-socks5-client" +version = "1.0.0-rc.2" +dependencies = [ + "clap", + "client-core", + "config", + "credential-storage", + "crypto", + "dirs 3.0.2", + "dotenv", + "futures", + "gateway-client", + "gateway-requests", + "log", + "network-defaults", + "nymsphinx", + "ordered-buffer", + "pemstore", + "pin-project", + "pretty_env_logger", + "proxy-helpers", + "rand 0.7.3", + "serde", + "snafu", + "socks5-requests", + "tokio", + "topology", + "url", + "validator-client", + "vergen", + "version-checker", +] + [[package]] name = "nymcoconut" version = "0.5.0" @@ -3720,6 +3810,13 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-buffer" +version = "0.1.0" +dependencies = [ + "log", +] + [[package]] name = "pairing" version = "0.20.0" @@ -4285,6 +4382,33 @@ dependencies = [ "prost", ] +[[package]] +name = "proxy-helpers" +version = "0.1.0" +dependencies = [ + "bytes", + "futures", + "log", + "ordered-buffer", + "socks5-requests", + "tokio", + "tokio-util 0.6.9", +] + +[[package]] +name = "publicsuffix" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" +dependencies = [ + "error-chain", + "idna", + "lazy_static", + "native-tls", + "regex", + "url", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5168,6 +5292,27 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +[[package]] +name = "snafu" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eab12d3c261b2308b0d80c26fffb58d17eba81a4be97890101f416b478c79ca7" +dependencies = [ + "doc-comment", + "snafu-derive", +] + +[[package]] +name = "snafu-derive" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1508efa03c362e23817f96cde18abed596a25219a8b2c66e8db33c03543d315b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "socket2" version = "0.4.4" @@ -5178,6 +5323,14 @@ dependencies = [ "winapi", ] +[[package]] +name = "socks5-requests" +version = "0.1.0" +dependencies = [ + "nymsphinx-addressing", + "ordered-buffer", +] + [[package]] name = "soketto" version = "0.5.0" diff --git a/hrycyszynvpn/src-tauri/Cargo.toml b/hrycyszynvpn/src-tauri/Cargo.toml index 6948bbf401..15d38c8665 100644 --- a/hrycyszynvpn/src-tauri/Cargo.toml +++ b/hrycyszynvpn/src-tauri/Cargo.toml @@ -31,7 +31,7 @@ bip39 = "1.0" thiserror = "1.0" tendermint-rpc = "0.23.0" url = "2.2" -rand = "0.6.5" +rand = "0.7" eyre = "0.6.5" aes-gcm = "0.9.4" @@ -43,21 +43,22 @@ cosmrs = { git = "https://github.com/nymtech/cosmos-rust", branch = "bugfix/acco cosmwasm-std = "1.0.0-beta3" nym-client = { path = "../../clients/native" } -#client-core = { path = "../../clients/client-core" } -#nym-socks5-client = { path = "../../clients/socks5" } -#nym-network-requester = { path = "../../service-providers/network-requester"} -#nymsphinx = { path = "../../common/nymsphinx" } -#validator-client = { path = "../../common/client-libs/validator-client", features = [ -# "nymd-client", -#] } -#mixnet-contract-common = { path = "../../common/cosmwasm-smart-contracts/mixnet-contract" } -#config = { path = "../../common/config" } -#coconut-interface = { path = "../../common/coconut-interface" } -#credentials = { path = "../../common/credentials" } -#version-checker = { path = "../../common/version-checker" } -#network-defaults = { path = "../../common/network-defaults" } +client-core = { path = "../../clients/client-core" } +nym-socks5-client = { path = "../../clients/socks5" } +nym-network-requester = { path = "../../service-providers/network-requester"} +nymsphinx = { path = "../../common/nymsphinx" } +validator-client = { path = "../../common/client-libs/validator-client", features = [ + "nymd-client", +] } +mixnet-contract-common = { path = "../../common/cosmwasm-smart-contracts/mixnet-contract" } +config = { path = "../../common/config" } +coconut-interface = { path = "../../common/coconut-interface" } +credentials = { path = "../../common/credentials" } +version-checker = { path = "../../common/version-checker" } +network-defaults = { path = "../../common/network-defaults" } fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs", branch = "release"} +log = "0.4" [dev-dependencies] ts-rs = "6.1.2" diff --git a/hrycyszynvpn/src-tauri/src/main.rs b/hrycyszynvpn/src-tauri/src/main.rs index 135496c6e5..52389a7bcc 100644 --- a/hrycyszynvpn/src-tauri/src/main.rs +++ b/hrycyszynvpn/src-tauri/src/main.rs @@ -16,7 +16,7 @@ use crate::menu::{create_tray_menu, tray_menu_event_handler}; use crate::state::State; use crate::window::window_toggle; -// mod config; +mod config; mod error; mod menu; mod models; diff --git a/hrycyszynvpn/src-tauri/src/state.rs b/hrycyszynvpn/src-tauri/src/state.rs index d8da53518a..55a0b875b7 100644 --- a/hrycyszynvpn/src-tauri/src/state.rs +++ b/hrycyszynvpn/src-tauri/src/state.rs @@ -1,19 +1,78 @@ -use crate::models::{ - AppEventConnectionStatusChangedPayload, ConnectionStatusKind, APP_EVENT_CONNECTION_STATUS_CHANGED, -}; -use tauri::Manager; -use tokio::time::{sleep, Duration}; +//use crate::models::{ +// AppEventConnectionStatusChangedPayload, ConnectionStatusKind, APP_EVENT_CONNECTION_STATUS_CHANGED, +//}; +//use tauri::Manager; +//use tokio::time::{sleep, Duration}; +// +//type StatusChangedHandler = fn(status: &ConnectionStatusKind) -> (); +// +//pub struct State { +// status: ConnectionStatusKind, +//} +// +//impl State { +// pub fn new() -> Self { +// State { +// status: ConnectionStatusKind::Disconnected, +// } +// } +// +// pub fn get_status(&self) -> ConnectionStatusKind { +// self.status.clone() +// } +// +// fn set_state(&mut self, status: ConnectionStatusKind, window: &tauri::Window) { +// self.status = status.clone(); +// window.emit_all( +// APP_EVENT_CONNECTION_STATUS_CHANGED, +// AppEventConnectionStatusChangedPayload { status }, +// ); +// } +// +// pub async fn init_config() { +// // crate::config::Config::init().await; +// } +// +// pub async fn start_connecting(&mut self, window: &tauri::Window) { +// self.set_state(ConnectionStatusKind::Connecting, window); +// sleep(Duration::from_secs(2)).await; +// self.set_state(ConnectionStatusKind::Connected, window); +// } +// +// pub async fn start_disconnecting(&mut self, window: &tauri::Window) { +// self.set_state(ConnectionStatusKind::Disconnecting, window); +// sleep(Duration::from_secs(2)).await; +// self.set_state(ConnectionStatusKind::Disconnected, window); +// } +//} -type StatusChangedHandler = fn(status: &ConnectionStatusKind) -> (); +use log::{error, info}; + +use config::NymConfig; +use nym_client::client::NymClient as NativeNymClient; +#[cfg(not(feature = "coconut"))] +use nym_socks5::client::NymClient as Socks5NymClient; +use nymsphinx::addressing::clients::Recipient; +use std::sync::Arc; +use tokio::sync::RwLock; + +use crate::config::{NATIVE_CLIENT_CONFIG_ID, SOCKS5_CONFIG_ID}; +use crate::models::ConnectionStatusKind; pub struct State { status: ConnectionStatusKind, + nym_client: Arc>>, + socks5_client: Arc>>, + nym_network_requester: Arc>>, } impl State { pub fn new() -> Self { State { status: ConnectionStatusKind::Disconnected, + nym_client: Arc::new(RwLock::new(None)), + socks5_client: Arc::new(RwLock::new(None)), + nym_network_requester: Arc::new(RwLock::new(None)), } } @@ -21,176 +80,117 @@ impl State { self.status.clone() } - fn set_state(&mut self, status: ConnectionStatusKind, window: &tauri::Window) { - self.status = status.clone(); - window.emit_all( - APP_EVENT_CONNECTION_STATUS_CHANGED, - AppEventConnectionStatusChangedPayload { status }, - ); - } - pub async fn init_config() { - // crate::config::Config::init().await; + crate::config::Config::init().await; } - pub async fn start_connecting(&mut self, window: &tauri::Window) { - self.set_state(ConnectionStatusKind::Connecting, window); - sleep(Duration::from_secs(2)).await; - self.set_state(ConnectionStatusKind::Connected, window); + pub async fn start_connecting(&mut self) { + self.status = ConnectionStatusKind::Connecting; + + let mut nym_client_guard = self.nym_client.write().await; + let mut socks5_client_guard = self.socks5_client.write().await; + let mut nym_network_requester_guard = self.nym_network_requester.write().await; + + *nym_client_guard = start_nym_native_client().await; + if nym_client_guard.is_none() { + self.status = ConnectionStatusKind::Disconnected; + return; + } + + let address = nym_client_guard.unwrap().as_mix_recipient(); + info!("Nym client address is {}", address); + + *socks5_client_guard = self.start_nym_socks5_client(&address).await; + if socks5_client_guard.is_none() { + self.status = ConnectionStatusKind::Disconnected; + return; + } + + *nym_network_requester_guard = self.start_network_requester().await; + self.status = ConnectionStatusKind::Connected; } - pub async fn start_disconnecting(&mut self, window: &tauri::Window) { - self.set_state(ConnectionStatusKind::Disconnecting, window); - sleep(Duration::from_secs(2)).await; - self.set_state(ConnectionStatusKind::Disconnected, window); + pub async fn start_disconnecting(&mut self) { + self.status = ConnectionStatusKind::Disconnecting; + + let nym_client_guard = self.nym_client.write().await; + let socks5_client_guard = self.socks5_client.write().await; + let nym_network_requester_guard = self.nym_network_requester.write().await; + + if nym_network_requester_guard.is_some() { + // TODO: implement + // nym_network_requester_guard.unwrap().stop().await; + *nym_network_requester_guard = None; + } + + if socks5_client_guard.is_some() { + // TODO: implement + // socks5_client_guard.unwrap().stop().await; + *socks5_client_guard = None; + } + + if nym_client_guard.is_some() { + // TODO: implement + // nym_client_guard.unwrap().stop().await; + *nym_client_guard = None; + } + + self.status = ConnectionStatusKind::Disconnected; } } -// use log::{error, info}; -// -// use config::NymConfig; -// use nym_client::client::NymClient as NativeNymClient; -// #[cfg(not(feature = "coconut"))] -// use nym_socks5::client::NymClient as Socks5NymClient; -// use nymsphinx::addressing::clients::Recipient; -// use std::sync::Arc; -// use tokio::sync::RwLock; -// -// use crate::config::{NATIVE_CLIENT_CONFIG_ID, SOCKS5_CONFIG_ID}; -// use crate::models::ConnectionStatusKind; -// -// pub struct State { -// status: ConnectionStatusKind, -// nym_client: Arc>>, -// socks5_client: Arc>>, -// nym_network_requester: Arc>>, -// } -// -// impl State { -// pub fn new() -> Self { -// State { -// status: ConnectionStatusKind::Disconnected, -// nym_client: Arc::new(RwLock::new(None)), -// socks5_client: Arc::new(RwLock::new(None)), -// nym_network_requester: Arc::new(RwLock::new(None)), -// } -// } -// -// pub fn get_status(&self) -> ConnectionStatusKind { -// self.status.clone() -// } -// -// pub async fn init_config() { -// crate::config::Config::init().await; -// } -// -// pub async fn start_connecting(&mut self) { -// self.status = ConnectionStatusKind::Connecting; -// -// let mut nym_client_guard = self.nym_client.write().await; -// let mut socks5_client_guard = self.socks5_client.write().await; -// let mut nym_network_requester_guard = self.nym_network_requester.write().await; -// -// *nym_client_guard = start_nym_native_client().await; -// if nym_client_guard.is_none() { -// self.status = ConnectionStatusKind::Disconnected; -// return; -// } -// -// let address = nym_client_guard.unwrap().as_mix_recipient(); -// info!("Nym client address is {}", address); -// -// *socks5_client_guard = self.start_nym_socks5_client(&address).await; -// if socks5_client_guard.is_none() { -// self.status = ConnectionStatusKind::Disconnected; -// return; -// } -// -// *nym_network_requester_guard = self.start_network_requester().await; -// self.status = ConnectionStatusKind::Connected; -// } -// -// pub async fn start_disconnecting(&mut self) { -// self.status = ConnectionStatusKind::Disconnecting; -// -// let nym_client_guard = self.nym_client.write().await; -// let socks5_client_guard = self.socks5_client.write().await; -// let nym_network_requester_guard = self.nym_network_requester.write().await; -// -// if nym_network_requester_guard.is_some() { -// // TODO: implement -// // nym_network_requester_guard.unwrap().stop().await; -// *nym_network_requester_guard = None; -// } -// -// if socks5_client_guard.is_some() { -// // TODO: implement -// // socks5_client_guard.unwrap().stop().await; -// *socks5_client_guard = None; -// } -// -// if nym_client_guard.is_some() { -// // TODO: implement -// // nym_client_guard.unwrap().stop().await; -// *nym_client_guard = None; -// } -// -// self.status = ConnectionStatusKind::Disconnected; -// } -// } -// -// async fn start_nym_native_client() -> Option { -// let id = NATIVE_CLIENT_CONFIG_ID; -// -// let config = match nym_client::client::config::Config::load_from_file(Some(id)) { -// Ok(cfg) => cfg, -// Err(err) => { -// error!( -// "Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", -// id, err -// ); -// return None; -// } -// }; -// -// // let base_config = config.get_base_mut(); -// // base_config.with_gateway_id("83x9YyNkQ5QEY84ZU6Wmq8XHqfwf9SUtR7g5PAYB1FRY"); -// -// let mut nym_client = NativeNymClient::new(config); -// nym_client.start().await; -// Some(nym_client) -// } -// -// async fn start_nym_socks5_client(recipient: &Recipient) -> Option { -// let id = SOCKS5_CONFIG_ID; -// -// let mut config = match nym_socks5::client::config::Config::load_from_file(Some(id)) { -// Ok(cfg) => cfg, -// Err(err) => { -// error!( -// "Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", -// id, err -// ); -// return None; -// } -// }; -// -// // let base_config = config.get_base_mut(); -// // base_config.with_gateway_id("83x9YyNkQ5QEY84ZU6Wmq8XHqfwf9SUtR7g5PAYB1FRY"); -// -// config = config.with_provider_mix_address(recipient.to_string()); -// -// let mut socks5_client = Socks5NymClient::new(config); -// socks5_client.start().await; -// Some(socks5_client) -// } -// -// // TODO: use remote network requester -// async fn start_network_requester() -> nym_network_requester::core::ServiceProvider { -// let open_proxy = true; -// let uri = "ws://localhost:1977"; -// info!("Starting socks5 service provider:"); -// let mut server = nym_network_requester::core::ServiceProvider::new(uri.into(), open_proxy); -// server.run().await; -// server -// } +async fn start_nym_native_client() -> Option { + let id = NATIVE_CLIENT_CONFIG_ID; + + let config = match nym_client::client::config::Config::load_from_file(Some(id)) { + Ok(cfg) => cfg, + Err(err) => { + error!( + "Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", + id, err + ); + return None; + } + }; + + // let base_config = config.get_base_mut(); + // base_config.with_gateway_id("83x9YyNkQ5QEY84ZU6Wmq8XHqfwf9SUtR7g5PAYB1FRY"); + + let mut nym_client = NativeNymClient::new(config); + nym_client.start().await; + Some(nym_client) +} + +async fn start_nym_socks5_client(recipient: &Recipient) -> Option { + let id = SOCKS5_CONFIG_ID; + + let mut config = match nym_socks5::client::config::Config::load_from_file(Some(id)) { + Ok(cfg) => cfg, + Err(err) => { + error!( + "Failed to load config for {}. Are you sure you have run `init` before? (Error was: {})", + id, err + ); + return None; + } + }; + + // let base_config = config.get_base_mut(); + // base_config.with_gateway_id("83x9YyNkQ5QEY84ZU6Wmq8XHqfwf9SUtR7g5PAYB1FRY"); + + config = config.with_provider_mix_address(recipient.to_string()); + + let mut socks5_client = Socks5NymClient::new(config); + socks5_client.start().await; + Some(socks5_client) +} + +// TODO: use remote network requester +async fn start_network_requester() -> nym_network_requester::core::ServiceProvider { + let open_proxy = true; + let uri = "ws://localhost:1977"; + info!("Starting socks5 service provider:"); + let mut server = nym_network_requester::core::ServiceProvider::new(uri.into(), open_proxy); + server.run().await; + server +}