From 8baa236d81523c822decb0331bdad3f3cdf5e0ed Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 21 Apr 2020 10:05:38 +0100 Subject: [PATCH] Feature/wasm js demo (#191) * Moved `nym-sphinx-wasm` into `wasm` folder and renamed its examples * A proposal for some structural cleanup * desktop client: beginning of a Rust example for chunking. * Simplifying desktop client readme * Tarting up webassembly README * A more visual webassembly client example * clients/webassembly: grouping a few things into named functions for clarity * clients/webassembly: put URLs at top of file, prepping for drop-down action * mixnode + provider run: changed startup error messages a bit * clients/webassembly: scrolling from the bottom in the demo --- Cargo.toml | 14 ++-- {nym-client => clients/desktop}/Cargo.lock | 0 {nym-client => clients/desktop}/Cargo.toml | 22 ++--- clients/desktop/README.md | 3 + {nym-client => clients/desktop}/build.rs | 0 clients/desktop/examples/chunking.rs | 69 ++++++++++++++++ .../desktop}/js-examples/websocket/.gitignore | 0 .../desktop}/js-examples/websocket/README.md | 0 .../js-examples/websocket/package-lock.json | 0 .../js-examples/websocket/package.json | 0 .../js-examples/websocket/src/index.html | 0 .../js-examples/websocket/src/index.js | 0 .../js-examples/websocket/webpack.config.js | 0 .../desktop}/src/built_info.rs | 0 .../src/client/cover_traffic_stream.rs | 0 .../desktop}/src/client/mix_traffic.rs | 0 .../desktop}/src/client/mod.rs | 0 .../desktop}/src/client/provider_poller.rs | 0 .../src/client/real_traffic_stream.rs | 0 .../desktop}/src/client/received_buffer.rs | 0 .../desktop}/src/client/topology_control.rs | 0 .../desktop}/src/commands/init.rs | 0 .../desktop}/src/commands/mod.rs | 0 .../desktop}/src/commands/run.rs | 0 .../desktop}/src/config/mod.rs | 0 .../desktop}/src/config/persistence/mod.rs | 0 .../src/config/persistence/pathfinder.rs | 0 .../desktop}/src/config/template.rs | 0 {nym-client => clients/desktop}/src/lib.rs | 0 {nym-client => clients/desktop}/src/main.rs | 0 .../desktop}/src/sockets/mod.rs | 0 .../desktop}/src/sockets/tcp.rs | 0 .../src/sockets/websocket/connection.rs | 0 .../src/sockets/websocket/listener.rs | 0 .../desktop}/src/sockets/websocket/mod.rs | 0 .../desktop}/src/sockets/websocket/types.rs | 0 .../webassembly}/.appveyor.yml | 0 .../webassembly}/.cargo-ok | 0 .../webassembly}/.gitignore | 0 .../webassembly}/.travis.yml | 0 .../webassembly}/Cargo.toml | 4 +- .../webassembly}/LICENSE_APACHE | 0 .../webassembly}/README.md | 2 +- .../js-examples}/.bin/create-wasm-app.js | 0 .../webassembly/js-examples}/.gitignore | 0 .../webassembly/js-examples}/.travis.yml | 0 .../webassembly/js-examples}/LICENSE-APACHE | 0 .../webassembly/js-examples}/README.md | 0 .../webassembly/js-examples}/bootstrap.js | 0 clients/webassembly/js-examples/index.html | 30 +++++++ .../webassembly/js-examples}/index.js | 80 +++++++++++-------- .../js-examples}/package-lock.json | 0 .../webassembly/js-examples}/package.json | 0 .../js-examples}/webpack.config.js | 0 .../webassembly}/src/lib.rs | 0 .../webassembly}/src/utils.rs | 0 .../webassembly}/tests/web.rs | 0 .../directory-client/Cargo.toml | 0 .../directory-client/src/lib.rs | 0 .../directory-client/src/metrics.rs | 0 .../src/presence/coconodes.rs | 0 .../directory-client/src/presence/mixnodes.rs | 0 .../directory-client/src/presence/mod.rs | 0 .../src/presence/providers.rs | 0 .../src/requests/health_check_get.rs | 0 .../src/requests/metrics_mixes_get.rs | 0 .../src/requests/metrics_mixes_post.rs | 0 .../directory-client/src/requests/mod.rs | 0 .../src/requests/presence_coconodes_post.rs | 0 .../src/requests/presence_mixnodes_post.rs | 0 .../src/requests/presence_providers_post.rs | 0 .../src/requests/presence_topology_get.rs | 0 .../mix-client/Cargo.toml | 0 .../mix-client/src/lib.rs | 0 .../mix-client/src/packet.rs | 0 .../mix-client/src/poisson.rs | 0 .../multi-tcp-client/Cargo.toml | 0 .../src/connection_manager/mod.rs | 0 .../src/connection_manager/reconnector.rs | 0 .../src/connection_manager/writer.rs | 0 .../multi-tcp-client/src/lib.rs | 0 .../provider-client/Cargo.toml | 0 .../provider-client/src/lib.rs | 0 .../validator-client/Cargo.toml | 0 .../validator-client/src/lib.rs | 0 common/healthcheck/Cargo.toml | 6 +- gateway/Cargo.toml | 2 +- mixnode/Cargo.toml | 4 +- mixnode/src/node/mod.rs | 2 +- nym-client/README.md | 10 --- nym-sphinx-wasm/www/index.html | 11 --- sfw-provider/Cargo.toml | 4 +- sfw-provider/src/provider/mod.rs | 2 +- validator/Cargo.toml | 2 +- 94 files changed, 181 insertions(+), 86 deletions(-) rename {nym-client => clients/desktop}/Cargo.lock (100%) rename {nym-client => clients/desktop}/Cargo.toml (56%) create mode 100644 clients/desktop/README.md rename {nym-client => clients/desktop}/build.rs (100%) create mode 100644 clients/desktop/examples/chunking.rs rename {nym-client => clients/desktop}/js-examples/websocket/.gitignore (100%) rename {nym-client => clients/desktop}/js-examples/websocket/README.md (100%) rename {nym-client => clients/desktop}/js-examples/websocket/package-lock.json (100%) rename {nym-client => clients/desktop}/js-examples/websocket/package.json (100%) rename {nym-client => clients/desktop}/js-examples/websocket/src/index.html (100%) rename {nym-client => clients/desktop}/js-examples/websocket/src/index.js (100%) rename {nym-client => clients/desktop}/js-examples/websocket/webpack.config.js (100%) rename {nym-client => clients/desktop}/src/built_info.rs (100%) rename {nym-client => clients/desktop}/src/client/cover_traffic_stream.rs (100%) rename {nym-client => clients/desktop}/src/client/mix_traffic.rs (100%) rename {nym-client => clients/desktop}/src/client/mod.rs (100%) rename {nym-client => clients/desktop}/src/client/provider_poller.rs (100%) rename {nym-client => clients/desktop}/src/client/real_traffic_stream.rs (100%) rename {nym-client => clients/desktop}/src/client/received_buffer.rs (100%) rename {nym-client => clients/desktop}/src/client/topology_control.rs (100%) rename {nym-client => clients/desktop}/src/commands/init.rs (100%) rename {nym-client => clients/desktop}/src/commands/mod.rs (100%) rename {nym-client => clients/desktop}/src/commands/run.rs (100%) rename {nym-client => clients/desktop}/src/config/mod.rs (100%) rename {nym-client => clients/desktop}/src/config/persistence/mod.rs (100%) rename {nym-client => clients/desktop}/src/config/persistence/pathfinder.rs (100%) rename {nym-client => clients/desktop}/src/config/template.rs (100%) rename {nym-client => clients/desktop}/src/lib.rs (100%) rename {nym-client => clients/desktop}/src/main.rs (100%) rename {nym-client => clients/desktop}/src/sockets/mod.rs (100%) rename {nym-client => clients/desktop}/src/sockets/tcp.rs (100%) rename {nym-client => clients/desktop}/src/sockets/websocket/connection.rs (100%) rename {nym-client => clients/desktop}/src/sockets/websocket/listener.rs (100%) rename {nym-client => clients/desktop}/src/sockets/websocket/mod.rs (100%) rename {nym-client => clients/desktop}/src/sockets/websocket/types.rs (100%) rename {nym-sphinx-wasm => clients/webassembly}/.appveyor.yml (100%) rename {nym-sphinx-wasm => clients/webassembly}/.cargo-ok (100%) rename {nym-sphinx-wasm => clients/webassembly}/.gitignore (100%) rename {nym-sphinx-wasm => clients/webassembly}/.travis.yml (100%) rename {nym-sphinx-wasm => clients/webassembly}/Cargo.toml (92%) rename {nym-sphinx-wasm => clients/webassembly}/LICENSE_APACHE (100%) rename {nym-sphinx-wasm => clients/webassembly}/README.md (90%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/.bin/create-wasm-app.js (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/.gitignore (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/.travis.yml (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/LICENSE-APACHE (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/README.md (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/bootstrap.js (100%) create mode 100644 clients/webassembly/js-examples/index.html rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/index.js (62%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/package-lock.json (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/package.json (100%) rename {nym-sphinx-wasm/www => clients/webassembly/js-examples}/webpack.config.js (100%) rename {nym-sphinx-wasm => clients/webassembly}/src/lib.rs (100%) rename {nym-sphinx-wasm => clients/webassembly}/src/utils.rs (100%) rename {nym-sphinx-wasm => clients/webassembly}/tests/web.rs (100%) rename common/{clients => client-libs}/directory-client/Cargo.toml (100%) rename common/{clients => client-libs}/directory-client/src/lib.rs (100%) rename common/{clients => client-libs}/directory-client/src/metrics.rs (100%) rename common/{clients => client-libs}/directory-client/src/presence/coconodes.rs (100%) rename common/{clients => client-libs}/directory-client/src/presence/mixnodes.rs (100%) rename common/{clients => client-libs}/directory-client/src/presence/mod.rs (100%) rename common/{clients => client-libs}/directory-client/src/presence/providers.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/health_check_get.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/metrics_mixes_get.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/metrics_mixes_post.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/mod.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/presence_coconodes_post.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/presence_mixnodes_post.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/presence_providers_post.rs (100%) rename common/{clients => client-libs}/directory-client/src/requests/presence_topology_get.rs (100%) rename common/{clients => client-libs}/mix-client/Cargo.toml (100%) rename common/{clients => client-libs}/mix-client/src/lib.rs (100%) rename common/{clients => client-libs}/mix-client/src/packet.rs (100%) rename common/{clients => client-libs}/mix-client/src/poisson.rs (100%) rename common/{clients => client-libs}/multi-tcp-client/Cargo.toml (100%) rename common/{clients => client-libs}/multi-tcp-client/src/connection_manager/mod.rs (100%) rename common/{clients => client-libs}/multi-tcp-client/src/connection_manager/reconnector.rs (100%) rename common/{clients => client-libs}/multi-tcp-client/src/connection_manager/writer.rs (100%) rename common/{clients => client-libs}/multi-tcp-client/src/lib.rs (100%) rename common/{clients => client-libs}/provider-client/Cargo.toml (100%) rename common/{clients => client-libs}/provider-client/src/lib.rs (100%) rename common/{clients => client-libs}/validator-client/Cargo.toml (100%) rename common/{clients => client-libs}/validator-client/src/lib.rs (100%) delete mode 100644 nym-client/README.md delete mode 100644 nym-sphinx-wasm/www/index.html diff --git a/Cargo.toml b/Cargo.toml index f9cc5f358e..3c73502e56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,11 +5,13 @@ opt-level = "s" [workspace] members = [ - "common/clients/directory-client", - "common/clients/mix-client", - "common/clients/multi-tcp-client", - "common/clients/provider-client", - "common/clients/validator-client", + "clients/desktop", + "clients/webassembly", + "common/client-libs/directory-client", + "common/client-libs/mix-client", + "common/client-libs/multi-tcp-client", + "common/client-libs/provider-client", + "common/client-libs/validator-client", "common/config", "common/crypto", "common/healthcheck", @@ -18,8 +20,6 @@ members = [ "common/topology", "gateway", "mixnode", - "nym-client", - "nym-sphinx-wasm", "sfw-provider", "sfw-provider/sfw-provider-requests", "validator", diff --git a/nym-client/Cargo.lock b/clients/desktop/Cargo.lock similarity index 100% rename from nym-client/Cargo.lock rename to clients/desktop/Cargo.lock diff --git a/nym-client/Cargo.toml b/clients/desktop/Cargo.toml similarity index 56% rename from nym-client/Cargo.toml rename to clients/desktop/Cargo.toml index bed5976670..e9009eefab 100644 --- a/nym-client/Cargo.toml +++ b/clients/desktop/Cargo.toml @@ -28,17 +28,17 @@ tokio = { version = "0.2", features = ["full"] } tokio-tungstenite = "0.10.1" ## internal -config = {path = "../common/config"} -crypto = {path = "../common/crypto"} -directory-client = { path = "../common/clients/directory-client" } -healthcheck = { path = "../common/healthcheck" } -mix-client = { path = "../common/clients/mix-client" } -multi-tcp-client = { path = "../common/clients/multi-tcp-client" } -nymsphinx = { path = "../common/nymsphinx" } -pemstore = {path = "../common/pemstore"} -provider-client = { path = "../common/clients/provider-client" } -sfw-provider-requests = { path = "../sfw-provider/sfw-provider-requests" } -topology = {path = "../common/topology" } +config = {path = "../../common/config"} +crypto = {path = "../../common/crypto"} +directory-client = { path = "../../common/client-libs/directory-client" } +healthcheck = { path = "../../common/healthcheck" } +mix-client = { path = "../../common/client-libs/mix-client" } +multi-tcp-client = { path = "../../common/client-libs/multi-tcp-client" } +nymsphinx = { path = "../../common/nymsphinx" } +pemstore = {path = "../../common/pemstore"} +provider-client = { path = "../../common/client-libs/provider-client" } +sfw-provider-requests = { path = "../../sfw-provider/sfw-provider-requests" } +topology = {path = "../../common/topology" } [build-dependencies] built = "0.3.2" diff --git a/clients/desktop/README.md b/clients/desktop/README.md new file mode 100644 index 0000000000..2edd44934e --- /dev/null +++ b/clients/desktop/README.md @@ -0,0 +1,3 @@ +# Nym Desktop Client + +The Nym Desktop Client communicates with the remote, decentralised nodes which make up the Nym system as a whole. diff --git a/nym-client/build.rs b/clients/desktop/build.rs similarity index 100% rename from nym-client/build.rs rename to clients/desktop/build.rs diff --git a/clients/desktop/examples/chunking.rs b/clients/desktop/examples/chunking.rs new file mode 100644 index 0000000000..0e0d87f839 --- /dev/null +++ b/clients/desktop/examples/chunking.rs @@ -0,0 +1,69 @@ +// Copyright 2020 Nym Technologies SA +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use config::NymConfig; +use std::time; +use tokio::runtime::Runtime; + +fn setup_logging() { + let mut log_builder = pretty_env_logger::formatted_timed_builder(); + if let Ok(s) = ::std::env::var("RUST_LOG") { + log_builder.parse_filters(&s); + } else { + // default to 'Info' + log_builder.filter(None, log::LevelFilter::Info); + } + + log_builder + .filter_module("hyper", log::LevelFilter::Warn) + .filter_module("tokio_reactor", log::LevelFilter::Warn) + .filter_module("reqwest", log::LevelFilter::Warn) + .filter_module("mio", log::LevelFilter::Warn) + .filter_module("want", log::LevelFilter::Warn) + .init(); +} + +fn main() { + // totally optional + setup_logging(); + + let mut rt = Runtime::new().unwrap(); + + // note: I have manually initialised the client with this config (because the keys weren't + // saved, etc - a really dodgy setup but good enough for a quick test) + // so to run it, you need to do the usual `nym-client init --id native-local` + // then optionally modify config.toml to increase rates, etc. if you want + let config = nym_client::config::Config::load_from_file(None, Some("native-local")).unwrap(); + let mut client = nym_client::client::NymClient::new(config); + + let input_data = std::fs::read("trailer.mp4").unwrap(); + + client.start(); + let address = client.as_mix_destination(); + client.send_message(address, input_data); + + loop { + let mut messages = rt.block_on(async { + tokio::time::delay_for(time::Duration::from_secs(2)).await; + client.check_for_messages_async().await + }); + + if !messages.is_empty() { + assert_eq!(messages.len(), 1); + std::fs::write("downloaded.mp4", messages.pop().unwrap()).unwrap(); + println!("done!"); + std::process::exit(0); + } + } +} diff --git a/nym-client/js-examples/websocket/.gitignore b/clients/desktop/js-examples/websocket/.gitignore similarity index 100% rename from nym-client/js-examples/websocket/.gitignore rename to clients/desktop/js-examples/websocket/.gitignore diff --git a/nym-client/js-examples/websocket/README.md b/clients/desktop/js-examples/websocket/README.md similarity index 100% rename from nym-client/js-examples/websocket/README.md rename to clients/desktop/js-examples/websocket/README.md diff --git a/nym-client/js-examples/websocket/package-lock.json b/clients/desktop/js-examples/websocket/package-lock.json similarity index 100% rename from nym-client/js-examples/websocket/package-lock.json rename to clients/desktop/js-examples/websocket/package-lock.json diff --git a/nym-client/js-examples/websocket/package.json b/clients/desktop/js-examples/websocket/package.json similarity index 100% rename from nym-client/js-examples/websocket/package.json rename to clients/desktop/js-examples/websocket/package.json diff --git a/nym-client/js-examples/websocket/src/index.html b/clients/desktop/js-examples/websocket/src/index.html similarity index 100% rename from nym-client/js-examples/websocket/src/index.html rename to clients/desktop/js-examples/websocket/src/index.html diff --git a/nym-client/js-examples/websocket/src/index.js b/clients/desktop/js-examples/websocket/src/index.js similarity index 100% rename from nym-client/js-examples/websocket/src/index.js rename to clients/desktop/js-examples/websocket/src/index.js diff --git a/nym-client/js-examples/websocket/webpack.config.js b/clients/desktop/js-examples/websocket/webpack.config.js similarity index 100% rename from nym-client/js-examples/websocket/webpack.config.js rename to clients/desktop/js-examples/websocket/webpack.config.js diff --git a/nym-client/src/built_info.rs b/clients/desktop/src/built_info.rs similarity index 100% rename from nym-client/src/built_info.rs rename to clients/desktop/src/built_info.rs diff --git a/nym-client/src/client/cover_traffic_stream.rs b/clients/desktop/src/client/cover_traffic_stream.rs similarity index 100% rename from nym-client/src/client/cover_traffic_stream.rs rename to clients/desktop/src/client/cover_traffic_stream.rs diff --git a/nym-client/src/client/mix_traffic.rs b/clients/desktop/src/client/mix_traffic.rs similarity index 100% rename from nym-client/src/client/mix_traffic.rs rename to clients/desktop/src/client/mix_traffic.rs diff --git a/nym-client/src/client/mod.rs b/clients/desktop/src/client/mod.rs similarity index 100% rename from nym-client/src/client/mod.rs rename to clients/desktop/src/client/mod.rs diff --git a/nym-client/src/client/provider_poller.rs b/clients/desktop/src/client/provider_poller.rs similarity index 100% rename from nym-client/src/client/provider_poller.rs rename to clients/desktop/src/client/provider_poller.rs diff --git a/nym-client/src/client/real_traffic_stream.rs b/clients/desktop/src/client/real_traffic_stream.rs similarity index 100% rename from nym-client/src/client/real_traffic_stream.rs rename to clients/desktop/src/client/real_traffic_stream.rs diff --git a/nym-client/src/client/received_buffer.rs b/clients/desktop/src/client/received_buffer.rs similarity index 100% rename from nym-client/src/client/received_buffer.rs rename to clients/desktop/src/client/received_buffer.rs diff --git a/nym-client/src/client/topology_control.rs b/clients/desktop/src/client/topology_control.rs similarity index 100% rename from nym-client/src/client/topology_control.rs rename to clients/desktop/src/client/topology_control.rs diff --git a/nym-client/src/commands/init.rs b/clients/desktop/src/commands/init.rs similarity index 100% rename from nym-client/src/commands/init.rs rename to clients/desktop/src/commands/init.rs diff --git a/nym-client/src/commands/mod.rs b/clients/desktop/src/commands/mod.rs similarity index 100% rename from nym-client/src/commands/mod.rs rename to clients/desktop/src/commands/mod.rs diff --git a/nym-client/src/commands/run.rs b/clients/desktop/src/commands/run.rs similarity index 100% rename from nym-client/src/commands/run.rs rename to clients/desktop/src/commands/run.rs diff --git a/nym-client/src/config/mod.rs b/clients/desktop/src/config/mod.rs similarity index 100% rename from nym-client/src/config/mod.rs rename to clients/desktop/src/config/mod.rs diff --git a/nym-client/src/config/persistence/mod.rs b/clients/desktop/src/config/persistence/mod.rs similarity index 100% rename from nym-client/src/config/persistence/mod.rs rename to clients/desktop/src/config/persistence/mod.rs diff --git a/nym-client/src/config/persistence/pathfinder.rs b/clients/desktop/src/config/persistence/pathfinder.rs similarity index 100% rename from nym-client/src/config/persistence/pathfinder.rs rename to clients/desktop/src/config/persistence/pathfinder.rs diff --git a/nym-client/src/config/template.rs b/clients/desktop/src/config/template.rs similarity index 100% rename from nym-client/src/config/template.rs rename to clients/desktop/src/config/template.rs diff --git a/nym-client/src/lib.rs b/clients/desktop/src/lib.rs similarity index 100% rename from nym-client/src/lib.rs rename to clients/desktop/src/lib.rs diff --git a/nym-client/src/main.rs b/clients/desktop/src/main.rs similarity index 100% rename from nym-client/src/main.rs rename to clients/desktop/src/main.rs diff --git a/nym-client/src/sockets/mod.rs b/clients/desktop/src/sockets/mod.rs similarity index 100% rename from nym-client/src/sockets/mod.rs rename to clients/desktop/src/sockets/mod.rs diff --git a/nym-client/src/sockets/tcp.rs b/clients/desktop/src/sockets/tcp.rs similarity index 100% rename from nym-client/src/sockets/tcp.rs rename to clients/desktop/src/sockets/tcp.rs diff --git a/nym-client/src/sockets/websocket/connection.rs b/clients/desktop/src/sockets/websocket/connection.rs similarity index 100% rename from nym-client/src/sockets/websocket/connection.rs rename to clients/desktop/src/sockets/websocket/connection.rs diff --git a/nym-client/src/sockets/websocket/listener.rs b/clients/desktop/src/sockets/websocket/listener.rs similarity index 100% rename from nym-client/src/sockets/websocket/listener.rs rename to clients/desktop/src/sockets/websocket/listener.rs diff --git a/nym-client/src/sockets/websocket/mod.rs b/clients/desktop/src/sockets/websocket/mod.rs similarity index 100% rename from nym-client/src/sockets/websocket/mod.rs rename to clients/desktop/src/sockets/websocket/mod.rs diff --git a/nym-client/src/sockets/websocket/types.rs b/clients/desktop/src/sockets/websocket/types.rs similarity index 100% rename from nym-client/src/sockets/websocket/types.rs rename to clients/desktop/src/sockets/websocket/types.rs diff --git a/nym-sphinx-wasm/.appveyor.yml b/clients/webassembly/.appveyor.yml similarity index 100% rename from nym-sphinx-wasm/.appveyor.yml rename to clients/webassembly/.appveyor.yml diff --git a/nym-sphinx-wasm/.cargo-ok b/clients/webassembly/.cargo-ok similarity index 100% rename from nym-sphinx-wasm/.cargo-ok rename to clients/webassembly/.cargo-ok diff --git a/nym-sphinx-wasm/.gitignore b/clients/webassembly/.gitignore similarity index 100% rename from nym-sphinx-wasm/.gitignore rename to clients/webassembly/.gitignore diff --git a/nym-sphinx-wasm/.travis.yml b/clients/webassembly/.travis.yml similarity index 100% rename from nym-sphinx-wasm/.travis.yml rename to clients/webassembly/.travis.yml diff --git a/nym-sphinx-wasm/Cargo.toml b/clients/webassembly/Cargo.toml similarity index 92% rename from nym-sphinx-wasm/Cargo.toml rename to clients/webassembly/Cargo.toml index 750de0ba0e..fe106a7a96 100644 --- a/nym-sphinx-wasm/Cargo.toml +++ b/clients/webassembly/Cargo.toml @@ -17,8 +17,8 @@ slice_as_array = "1.1.0" wasm-bindgen = "0.2" # internal -crypto = { path = "../common/crypto" } -nymsphinx = { path = "../common/nymsphinx" } +crypto = { path = "../../common/crypto" } +nymsphinx = { path = "../../common/nymsphinx" } # The `console_error_panic_hook` crate provides better debugging of panics by diff --git a/nym-sphinx-wasm/LICENSE_APACHE b/clients/webassembly/LICENSE_APACHE similarity index 100% rename from nym-sphinx-wasm/LICENSE_APACHE rename to clients/webassembly/LICENSE_APACHE diff --git a/nym-sphinx-wasm/README.md b/clients/webassembly/README.md similarity index 90% rename from nym-sphinx-wasm/README.md rename to clients/webassembly/README.md index 3554a6abf8..0611489e8e 100644 --- a/nym-sphinx-wasm/README.md +++ b/clients/webassembly/README.md @@ -2,7 +2,7 @@ This is a Rust crate which is set up to automatically cross-compile the contents of `lib.rs` to WebAssembly (aka wasm). -Wasm is pretty close to bare metal. Browser-based or server-side JavaScript (or other wasm-using environments) can use the wasm output from this crate to create Sphinx packets at much higher speeds than would be possible using (interpreted) JavaScript. This helps browser-based and mobile applications get stronger privacy, in a way that wasn't previously possible. +Wasm is pretty close to bare metal. Browser-based or server-side JavaScript (or other wasm-using environments) can use the wasm output from this crate to create Sphinx packets at much higher speeds than would be possible using (interpreted) JavaScript. This enables browser-based and mobile applications get stronger privacy, in a way that wasn't previously possible. ### Compiling diff --git a/nym-sphinx-wasm/www/.bin/create-wasm-app.js b/clients/webassembly/js-examples/.bin/create-wasm-app.js similarity index 100% rename from nym-sphinx-wasm/www/.bin/create-wasm-app.js rename to clients/webassembly/js-examples/.bin/create-wasm-app.js diff --git a/nym-sphinx-wasm/www/.gitignore b/clients/webassembly/js-examples/.gitignore similarity index 100% rename from nym-sphinx-wasm/www/.gitignore rename to clients/webassembly/js-examples/.gitignore diff --git a/nym-sphinx-wasm/www/.travis.yml b/clients/webassembly/js-examples/.travis.yml similarity index 100% rename from nym-sphinx-wasm/www/.travis.yml rename to clients/webassembly/js-examples/.travis.yml diff --git a/nym-sphinx-wasm/www/LICENSE-APACHE b/clients/webassembly/js-examples/LICENSE-APACHE similarity index 100% rename from nym-sphinx-wasm/www/LICENSE-APACHE rename to clients/webassembly/js-examples/LICENSE-APACHE diff --git a/nym-sphinx-wasm/www/README.md b/clients/webassembly/js-examples/README.md similarity index 100% rename from nym-sphinx-wasm/www/README.md rename to clients/webassembly/js-examples/README.md diff --git a/nym-sphinx-wasm/www/bootstrap.js b/clients/webassembly/js-examples/bootstrap.js similarity index 100% rename from nym-sphinx-wasm/www/bootstrap.js rename to clients/webassembly/js-examples/bootstrap.js diff --git a/clients/webassembly/js-examples/index.html b/clients/webassembly/js-examples/index.html new file mode 100644 index 0000000000..1d6a419228 --- /dev/null +++ b/clients/webassembly/js-examples/index.html @@ -0,0 +1,30 @@ + + + + + + + Nym WebAssembly Demo + + + +

+ +

+ + + +

Send messages to the mixnet using the "send" button.

+

Sent messages show in blue, received + messages show in green.

+ +
+

+ +

+ + + + + \ No newline at end of file diff --git a/nym-sphinx-wasm/www/index.js b/clients/webassembly/js-examples/index.js similarity index 62% rename from nym-sphinx-wasm/www/index.js rename to clients/webassembly/js-examples/index.js index daeaa29767..a44791edcd 100644 --- a/nym-sphinx-wasm/www/index.js +++ b/clients/webassembly/js-examples/index.js @@ -14,8 +14,6 @@ import * as wasm from "nym-sphinx-wasm"; -console.log("Retrieving topology..."); - class Route { constructor(nodes) { this.nodes = nodes; @@ -29,20 +27,48 @@ class NodeData { } } -async function getTopology() { - let topologyURL = 'http://127.0.0.1:8080/api/presence/topology'; // TODO change this DAVE!!!! - let response = await makeRequest('get', topologyURL); +async function main() { + var gatewayUrl = "ws://127.0.0.1:1793"; + var directoryUrl = "http://127.0.0.1:8080/api/presence/topology"; + + // Get the topology, then the mixnode and provider data + const topology = await getTopology(directoryUrl); + + // Set up a websocket connection to the gateway node + var connection = await connectWebsocket(gatewayUrl).then(function (c) { + return c + }).catch(function (err) { + console.log("Websocket ERROR: " + err); + }) + + // Set up the send button + const sendButton = document.querySelector('#send-button'); + sendButton.onclick = function () { + sendMessageToMixnet(connection, topology); + } +} + +// Create a Sphinx packet and send it to the mixnet through the Gateway node. +function sendMessageToMixnet(connection, topology) { + let route = constructRoute(topology); + var recipient = document.getElementById("recipient").value; + var sendText = document.getElementById("sendtext").value; + let packet = wasm.create_sphinx_packet(JSON.stringify(route), sendText, recipient); + connection.send(packet); + displaySend(packet); + display("Sent a Sphinx packet containing message: " + sendText); +} + +async function getTopology(directoryUrl) { + let response = await http('get', directoryUrl); let topology = JSON.parse(response); return topology; } -async function main() { - // Get the topology, then the mixnode and provider data - const topology = await getTopology(); +// Construct a route from the current network topology so we can get wasm to build us a Sphinx packet +function constructRoute(topology) { const mixnodes = topology.mixNodes; const provider = topology.mixProviderNodes[0]; - - // Construct a route so we can get wasm to build us a Sphinx packet let nodes = []; mixnodes.forEach(node => { let n = new NodeData(node.host, node.pubKey); @@ -50,29 +76,23 @@ async function main() { }); let p = new NodeData(provider.mixnetListener, provider.pubKey) nodes.push(p); - let route = new Route(nodes); - - // Create the packet - let packet = wasm.create_sphinx_packet(JSON.stringify(route), "THIS IS THE MESSAGE", "C2fdNoUybRuGrVYUM6QRejiELPQCohGbxjhKpU4UZ4ci"); - - // Set up a websocket connection to the gateway node - var port = "1793" // gateway websocket listens on 1793 by default, change if yours is different - var url = "ws://127.0.0.1:" + port; - - connectWebsocket(url).then(function (server) { - server.send("hello gateway"); - console.log(packet); - server.send(packet); - }).catch(function (err) { - console.log("Websocket ERROR: " + err); - }) + return new Route(nodes); } + // Let's get started! main(); // utility functions below here, nothing too interesting... -function makeRequest(method, url) { +function display(message) { + document.getElementById("output").innerHTML = "

" + message + "

" + document.getElementById("output").innerHTML; +} + +function displaySend(message) { + document.getElementById("output").innerHTML = "

sent >>> " + message + "

" + document.getElementById("output").innerHTML; +} + +function http(method, url) { return new Promise(function (resolve, reject) { let xhr = new XMLHttpRequest(); xhr.open(method, url); @@ -96,12 +116,6 @@ function makeRequest(method, url) { }); } - -function print(name, obj) { - console.log(name + ": " + JSON.stringify(obj)); -} - - function connectWebsocket(url) { return new Promise(function (resolve, reject) { var server = new WebSocket(url); diff --git a/nym-sphinx-wasm/www/package-lock.json b/clients/webassembly/js-examples/package-lock.json similarity index 100% rename from nym-sphinx-wasm/www/package-lock.json rename to clients/webassembly/js-examples/package-lock.json diff --git a/nym-sphinx-wasm/www/package.json b/clients/webassembly/js-examples/package.json similarity index 100% rename from nym-sphinx-wasm/www/package.json rename to clients/webassembly/js-examples/package.json diff --git a/nym-sphinx-wasm/www/webpack.config.js b/clients/webassembly/js-examples/webpack.config.js similarity index 100% rename from nym-sphinx-wasm/www/webpack.config.js rename to clients/webassembly/js-examples/webpack.config.js diff --git a/nym-sphinx-wasm/src/lib.rs b/clients/webassembly/src/lib.rs similarity index 100% rename from nym-sphinx-wasm/src/lib.rs rename to clients/webassembly/src/lib.rs diff --git a/nym-sphinx-wasm/src/utils.rs b/clients/webassembly/src/utils.rs similarity index 100% rename from nym-sphinx-wasm/src/utils.rs rename to clients/webassembly/src/utils.rs diff --git a/nym-sphinx-wasm/tests/web.rs b/clients/webassembly/tests/web.rs similarity index 100% rename from nym-sphinx-wasm/tests/web.rs rename to clients/webassembly/tests/web.rs diff --git a/common/clients/directory-client/Cargo.toml b/common/client-libs/directory-client/Cargo.toml similarity index 100% rename from common/clients/directory-client/Cargo.toml rename to common/client-libs/directory-client/Cargo.toml diff --git a/common/clients/directory-client/src/lib.rs b/common/client-libs/directory-client/src/lib.rs similarity index 100% rename from common/clients/directory-client/src/lib.rs rename to common/client-libs/directory-client/src/lib.rs diff --git a/common/clients/directory-client/src/metrics.rs b/common/client-libs/directory-client/src/metrics.rs similarity index 100% rename from common/clients/directory-client/src/metrics.rs rename to common/client-libs/directory-client/src/metrics.rs diff --git a/common/clients/directory-client/src/presence/coconodes.rs b/common/client-libs/directory-client/src/presence/coconodes.rs similarity index 100% rename from common/clients/directory-client/src/presence/coconodes.rs rename to common/client-libs/directory-client/src/presence/coconodes.rs diff --git a/common/clients/directory-client/src/presence/mixnodes.rs b/common/client-libs/directory-client/src/presence/mixnodes.rs similarity index 100% rename from common/clients/directory-client/src/presence/mixnodes.rs rename to common/client-libs/directory-client/src/presence/mixnodes.rs diff --git a/common/clients/directory-client/src/presence/mod.rs b/common/client-libs/directory-client/src/presence/mod.rs similarity index 100% rename from common/clients/directory-client/src/presence/mod.rs rename to common/client-libs/directory-client/src/presence/mod.rs diff --git a/common/clients/directory-client/src/presence/providers.rs b/common/client-libs/directory-client/src/presence/providers.rs similarity index 100% rename from common/clients/directory-client/src/presence/providers.rs rename to common/client-libs/directory-client/src/presence/providers.rs diff --git a/common/clients/directory-client/src/requests/health_check_get.rs b/common/client-libs/directory-client/src/requests/health_check_get.rs similarity index 100% rename from common/clients/directory-client/src/requests/health_check_get.rs rename to common/client-libs/directory-client/src/requests/health_check_get.rs diff --git a/common/clients/directory-client/src/requests/metrics_mixes_get.rs b/common/client-libs/directory-client/src/requests/metrics_mixes_get.rs similarity index 100% rename from common/clients/directory-client/src/requests/metrics_mixes_get.rs rename to common/client-libs/directory-client/src/requests/metrics_mixes_get.rs diff --git a/common/clients/directory-client/src/requests/metrics_mixes_post.rs b/common/client-libs/directory-client/src/requests/metrics_mixes_post.rs similarity index 100% rename from common/clients/directory-client/src/requests/metrics_mixes_post.rs rename to common/client-libs/directory-client/src/requests/metrics_mixes_post.rs diff --git a/common/clients/directory-client/src/requests/mod.rs b/common/client-libs/directory-client/src/requests/mod.rs similarity index 100% rename from common/clients/directory-client/src/requests/mod.rs rename to common/client-libs/directory-client/src/requests/mod.rs diff --git a/common/clients/directory-client/src/requests/presence_coconodes_post.rs b/common/client-libs/directory-client/src/requests/presence_coconodes_post.rs similarity index 100% rename from common/clients/directory-client/src/requests/presence_coconodes_post.rs rename to common/client-libs/directory-client/src/requests/presence_coconodes_post.rs diff --git a/common/clients/directory-client/src/requests/presence_mixnodes_post.rs b/common/client-libs/directory-client/src/requests/presence_mixnodes_post.rs similarity index 100% rename from common/clients/directory-client/src/requests/presence_mixnodes_post.rs rename to common/client-libs/directory-client/src/requests/presence_mixnodes_post.rs diff --git a/common/clients/directory-client/src/requests/presence_providers_post.rs b/common/client-libs/directory-client/src/requests/presence_providers_post.rs similarity index 100% rename from common/clients/directory-client/src/requests/presence_providers_post.rs rename to common/client-libs/directory-client/src/requests/presence_providers_post.rs diff --git a/common/clients/directory-client/src/requests/presence_topology_get.rs b/common/client-libs/directory-client/src/requests/presence_topology_get.rs similarity index 100% rename from common/clients/directory-client/src/requests/presence_topology_get.rs rename to common/client-libs/directory-client/src/requests/presence_topology_get.rs diff --git a/common/clients/mix-client/Cargo.toml b/common/client-libs/mix-client/Cargo.toml similarity index 100% rename from common/clients/mix-client/Cargo.toml rename to common/client-libs/mix-client/Cargo.toml diff --git a/common/clients/mix-client/src/lib.rs b/common/client-libs/mix-client/src/lib.rs similarity index 100% rename from common/clients/mix-client/src/lib.rs rename to common/client-libs/mix-client/src/lib.rs diff --git a/common/clients/mix-client/src/packet.rs b/common/client-libs/mix-client/src/packet.rs similarity index 100% rename from common/clients/mix-client/src/packet.rs rename to common/client-libs/mix-client/src/packet.rs diff --git a/common/clients/mix-client/src/poisson.rs b/common/client-libs/mix-client/src/poisson.rs similarity index 100% rename from common/clients/mix-client/src/poisson.rs rename to common/client-libs/mix-client/src/poisson.rs diff --git a/common/clients/multi-tcp-client/Cargo.toml b/common/client-libs/multi-tcp-client/Cargo.toml similarity index 100% rename from common/clients/multi-tcp-client/Cargo.toml rename to common/client-libs/multi-tcp-client/Cargo.toml diff --git a/common/clients/multi-tcp-client/src/connection_manager/mod.rs b/common/client-libs/multi-tcp-client/src/connection_manager/mod.rs similarity index 100% rename from common/clients/multi-tcp-client/src/connection_manager/mod.rs rename to common/client-libs/multi-tcp-client/src/connection_manager/mod.rs diff --git a/common/clients/multi-tcp-client/src/connection_manager/reconnector.rs b/common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs similarity index 100% rename from common/clients/multi-tcp-client/src/connection_manager/reconnector.rs rename to common/client-libs/multi-tcp-client/src/connection_manager/reconnector.rs diff --git a/common/clients/multi-tcp-client/src/connection_manager/writer.rs b/common/client-libs/multi-tcp-client/src/connection_manager/writer.rs similarity index 100% rename from common/clients/multi-tcp-client/src/connection_manager/writer.rs rename to common/client-libs/multi-tcp-client/src/connection_manager/writer.rs diff --git a/common/clients/multi-tcp-client/src/lib.rs b/common/client-libs/multi-tcp-client/src/lib.rs similarity index 100% rename from common/clients/multi-tcp-client/src/lib.rs rename to common/client-libs/multi-tcp-client/src/lib.rs diff --git a/common/clients/provider-client/Cargo.toml b/common/client-libs/provider-client/Cargo.toml similarity index 100% rename from common/clients/provider-client/Cargo.toml rename to common/client-libs/provider-client/Cargo.toml diff --git a/common/clients/provider-client/src/lib.rs b/common/client-libs/provider-client/src/lib.rs similarity index 100% rename from common/clients/provider-client/src/lib.rs rename to common/client-libs/provider-client/src/lib.rs diff --git a/common/clients/validator-client/Cargo.toml b/common/client-libs/validator-client/Cargo.toml similarity index 100% rename from common/clients/validator-client/Cargo.toml rename to common/client-libs/validator-client/Cargo.toml diff --git a/common/clients/validator-client/src/lib.rs b/common/client-libs/validator-client/src/lib.rs similarity index 100% rename from common/clients/validator-client/src/lib.rs rename to common/client-libs/validator-client/src/lib.rs diff --git a/common/healthcheck/Cargo.toml b/common/healthcheck/Cargo.toml index 3914b4f70b..d680e4f1bb 100644 --- a/common/healthcheck/Cargo.toml +++ b/common/healthcheck/Cargo.toml @@ -19,10 +19,10 @@ tokio = { version = "0.2", features = ["full"] } ## internal crypto = { path = "../crypto" } -directory-client = { path = "../clients/directory-client" } -multi-tcp-client = { path = "../clients/multi-tcp-client" } +directory-client = { path = "../client-libs/directory-client" } +multi-tcp-client = { path = "../client-libs/multi-tcp-client" } nymsphinx = {path = "../nymsphinx" } -provider-client = { path = "../clients/provider-client" } +provider-client = { path = "../client-libs/provider-client" } sfw-provider-requests = { path = "../../sfw-provider/sfw-provider-requests" } topology = {path = "../topology" } diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index 018d097792..dcbed977b9 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -12,7 +12,7 @@ futures = "0.3" futures-channel = "0.3" futures-util = { version = "0.3", default-features = false, features = ["async-await", "sink", "std"] } log = "0.4" -multi-tcp-client = { path = "../common/clients/multi-tcp-client" } +multi-tcp-client = { path = "../common/client-libs/multi-tcp-client" } pretty_env_logger = "0.3" tokio = { version = "0.2", features = ["full"] } tokio-tungstenite = "0.10.1" diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 1753a2e312..3ea359b7b8 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -22,8 +22,8 @@ tokio = { version = "0.2", features = ["full"] } ## internal config = {path = "../common/config"} crypto = {path = "../common/crypto"} -directory-client = { path = "../common/clients/directory-client" } -multi-tcp-client = { path = "../common/clients/multi-tcp-client" } +directory-client = { path = "../common/client-libs/directory-client" } +multi-tcp-client = { path = "../common/client-libs/multi-tcp-client" } nymsphinx = {path = "../common/nymsphinx" } pemstore = {path = "../common/pemstore"} topology = {path = "../common/topology"} diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 97d42f97b4..e0e007da30 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -130,7 +130,7 @@ impl MixNode { if let Some(duplicate_node_key) = self.check_if_same_ip_node_exists() { error!( - "Our announce-host is identical to one of existing nodes! (its key is {:?}", + "Our announce-host is identical to an existing node's announce-host! (its key is {:?}", duplicate_node_key ); return; diff --git a/nym-client/README.md b/nym-client/README.md deleted file mode 100644 index 5ae5823824..0000000000 --- a/nym-client/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Nym Client - -The Nym Client communicates with the remote, decentralised nodes which make up the Nym system as a whole. - -It needs to handle communication with 3 types of remote nodes. Here's the development status of each: - -- [ ] Directory nodes -- [ ] Mix nodes -- [ ] Validator nodes - diff --git a/nym-sphinx-wasm/www/index.html b/nym-sphinx-wasm/www/index.html deleted file mode 100644 index ca5615c129..0000000000 --- a/nym-sphinx-wasm/www/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - Hello wasm-pack! - - - - - - diff --git a/sfw-provider/Cargo.toml b/sfw-provider/Cargo.toml index c54e9327b7..9318a980c7 100644 --- a/sfw-provider/Cargo.toml +++ b/sfw-provider/Cargo.toml @@ -27,7 +27,7 @@ hmac = "0.7.1" ## internal crypto = { path = "../common/crypto" } config = { path = "../common/config" } -directory-client = { path = "../common/clients/directory-client" } +directory-client = { path = "../common/client-libs/directory-client" } nymsphinx = { path = "../common/nymsphinx" } pemstore = { path = "../common/pemstore" } sfw-provider-requests = { path = "./sfw-provider-requests" } @@ -36,7 +36,7 @@ topology = { path = "../common/topology"} # this dependency is due to requiring to know content of loop message. however, mix-client module itself # is going to be removed or renamed at some point as it no longer servers its purpose of sending traffic to mix network # and only provides utility functions -mix-client = { path = "../common/clients/mix-client" } +mix-client = { path = "../common/client-libs/mix-client" } [build-dependencies] diff --git a/sfw-provider/src/provider/mod.rs b/sfw-provider/src/provider/mod.rs index a5dcdc43ec..9d88f1a8e9 100644 --- a/sfw-provider/src/provider/mod.rs +++ b/sfw-provider/src/provider/mod.rs @@ -127,7 +127,7 @@ impl ServiceProvider { if let Some(duplicate_provider_key) = self.check_if_same_ip_provider_exists() { error!( - "Our announce-host is identical to one of existing nodes! (its key is {:?}", + "Our announce-host is identical to an existing node's announce-host! (its key is {:?}", duplicate_provider_key ); return; diff --git a/validator/Cargo.toml b/validator/Cargo.toml index a7a43d1d3a..c56568e51d 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -28,7 +28,7 @@ tokio = { version = "0.2", features = ["full"] } ## internal crypto = {path = "../common/crypto"} config = {path = "../common/config"} -directory-client = { path = "../common/clients/directory-client" } +directory-client = { path = "../common/client-libs/directory-client" } healthcheck = {path = "../common/healthcheck" } topology = {path = "../common/topology"}