From 9d85699ed7ab6d4449a3798bbaea7227b7c79358 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 28 Nov 2019 19:32:09 +0000 Subject: [PATCH 001/167] Moved subclients into their own directory --- src/{ => clients}/directory.rs | 23 +++++++++++------------ src/{ => clients}/mix.rs | 16 +++++++++++----- src/clients/mod.rs | 3 +++ src/{ => clients}/validator.rs | 0 4 files changed, 25 insertions(+), 17 deletions(-) rename src/{ => clients}/directory.rs (95%) rename src/{ => clients}/mix.rs (65%) create mode 100644 src/clients/mod.rs rename src/{ => clients}/validator.rs (100%) diff --git a/src/directory.rs b/src/clients/directory.rs similarity index 95% rename from src/directory.rs rename to src/clients/directory.rs index 18ef0356e3..adea26a9db 100644 --- a/src/directory.rs +++ b/src/clients/directory.rs @@ -22,7 +22,17 @@ impl DirectoryClient { } } - +fn fake_directory_mixes() -> Vec { + let node1 = sphinx::route::Node{ + address: [0u8; 32], //"127.0.0.1:8080".as_bytes(), // start here tomorrow :) + pub_key: Default::default() + }; + let node2 = sphinx::route::Node{ + address: [1u8;32], + pub_key: Default::default() + }; + vec![node1, node2] +} #[cfg(test)] mod retrieving_mixnode_list { @@ -57,14 +67,3 @@ mod retrieving_destinations { } } -fn fake_directory_mixes() -> Vec { - let node1 = sphinx::route::Node{ - address: [0u8;32], - pub_key: Default::default() - }; - let node2 = sphinx::route::Node{ - address: [1u8;32], - pub_key: Default::default() - }; - vec![node1, node2] -} \ No newline at end of file diff --git a/src/mix.rs b/src/clients/mix.rs similarity index 65% rename from src/mix.rs rename to src/clients/mix.rs index 4e903d644c..0766b8eb93 100644 --- a/src/mix.rs +++ b/src/clients/mix.rs @@ -1,17 +1,23 @@ -use crate::directory::DirectoryClient; +use crate::clients::directory::DirectoryClient; use sphinx::SphinxPacket; -use sphinx::route::Node; +use sphinx::route::Node as MixNode; +use tokio::net::TcpStream; +use tokio::prelude::*; -struct MixClient {} +pub struct MixClient {} impl MixClient { - fn new() -> MixClient { + pub fn new() -> MixClient { MixClient {} } - fn send(&self, packet: SphinxPacket, mix: &Node) { + pub async fn send(&self, packet: SphinxPacket, mix: &MixNode) -> Result<(), Box>{ let bytes = packet.to_bytes(); + // now we shoot it into space! + let mut stream = TcpStream::connect("127.0.0.1:8080").await?; + stream.write_all(&bytes[..]).await?; + Ok(()) } } diff --git a/src/clients/mod.rs b/src/clients/mod.rs new file mode 100644 index 0000000000..d862db038d --- /dev/null +++ b/src/clients/mod.rs @@ -0,0 +1,3 @@ +pub mod directory; +pub mod mix; +mod validator; diff --git a/src/validator.rs b/src/clients/validator.rs similarity index 100% rename from src/validator.rs rename to src/clients/validator.rs From fb7db57c5e85f146c37b48382b1ab53617567f2f Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 28 Nov 2019 19:32:18 +0000 Subject: [PATCH 002/167] Added tokio --- Cargo.lock | 305 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 3 +- 2 files changed, 307 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 65f9a99d86..c7f0092d8f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,11 @@ dependencies = [ "stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arc-swap" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arrayref" version = "0.3.5" @@ -89,6 +94,11 @@ name = "byteorder" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bytes" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "c2-chacha" version = "0.2.3" @@ -175,11 +185,35 @@ name = "fake-simd" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fnv" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures-core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "generic-array" version = "0.12.3" @@ -198,6 +232,14 @@ dependencies = [ "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hermit-abi" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hkdf" version = "0.8.0" @@ -216,11 +258,33 @@ dependencies = [ "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "keystream" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.65" @@ -237,11 +301,103 @@ dependencies = [ "keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memchr" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mio" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mio-named-pipes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mio-uds" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miow" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miow" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "net2" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num_cpus" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "nym-client" version = "0.1.0" dependencies = [ "sphinx 0.1.0", + "tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -249,11 +405,32 @@ name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "pin-project-lite" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ppv-lite86" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro2" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.7.2" @@ -333,6 +510,11 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "sha2" version = "0.8.0" @@ -344,6 +526,31 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "signal-hook-registry" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "socket2" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sphinx" version = "0.1.0" @@ -380,16 +587,67 @@ name = "subtle" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "syn" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "typenum" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wasi" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.3.8" @@ -399,6 +657,11 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -409,10 +672,20 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" +"checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" @@ -421,6 +694,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum bytes 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c85319f157e4e26c703678e68e26ab71a46c0199286fa670b21cc9fec13d895" "checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" "checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" @@ -432,16 +706,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +"checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" +"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum lioness 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ae926706ba42c425c9457121178330d75e273df2e82e28b758faf3de3a9acb9" +"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +"checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" +"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +"checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" +"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +"checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +"checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" @@ -451,12 +745,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" +"checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" +"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799" +"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "beeef686ef92a222de07e089f455d9f8478bbba9651718f9e4b276babe829082" +"checksum tokio-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5795a71419535c6dcecc9b6ca95bdd3c2d6142f7e8343d7beb9923f129aa87e" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index fa5e930d61..d9825f5f10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -sphinx = { path = "../sphinx" } \ No newline at end of file +sphinx = { path = "../sphinx" } +tokio = { version = "0.2", features = ["full"] } \ No newline at end of file From 98ab15397879d7e31b6057679bd5d112abf95891 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 28 Nov 2019 19:32:32 +0000 Subject: [PATCH 003/167] Sending packet :) --- src/main.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0dfebd32d1..bb572b1f78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,25 @@ -mod directory; -mod mix; +mod clients; -fn main() { - let _ = "Hello, Sphinx!".as_bytes().to_vec(); +use tokio::prelude::*; + +use crate::clients::mix::MixClient; +use crate::clients::directory::DirectoryClient; + +#[tokio::main] +async fn main() { + let message = "Hello, Sphinx!".as_bytes().to_vec(); + + // set up the route + let directory = DirectoryClient::new(); + let route = directory.get_mixes(); + let destination = directory.get_destination(); + + // build the packet + let packet = sphinx::SphinxPacket::new(message, &route[..], &destination); + + // send to mixnet + let mix_client = MixClient::new(); + let result = mix_client.send(packet, route.first().unwrap()).await; } From 8ee4bd0fb90f353d4f6fef7ee70180e716281828 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Fri, 29 Nov 2019 12:30:03 +0000 Subject: [PATCH 004/167] Banging things around to get a duct-taped version working end-to-end --- src/clients/directory.rs | 1 + src/clients/mix.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clients/directory.rs b/src/clients/directory.rs index adea26a9db..bf8e90520f 100644 --- a/src/clients/directory.rs +++ b/src/clients/directory.rs @@ -27,6 +27,7 @@ fn fake_directory_mixes() -> Vec { address: [0u8; 32], //"127.0.0.1:8080".as_bytes(), // start here tomorrow :) pub_key: Default::default() }; +// vec![node1] let node2 = sphinx::route::Node{ address: [1u8;32], pub_key: Default::default() diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 0766b8eb93..77081fd4d8 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -11,10 +11,10 @@ impl MixClient { MixClient {} } + // Sends a Sphinx packet to a mixnode. pub async fn send(&self, packet: SphinxPacket, mix: &MixNode) -> Result<(), Box>{ let bytes = packet.to_bytes(); - // now we shoot it into space! let mut stream = TcpStream::connect("127.0.0.1:8080").await?; stream.write_all(&bytes[..]).await?; Ok(()) From 92eb260313194397d64d3264234f68bd8fb9a6e3 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Fri, 29 Nov 2019 15:55:06 +0000 Subject: [PATCH 005/167] Updating to work with constant sized packets --- Cargo.lock | 1 + src/clients/mix.rs | 3 ++- src/main.rs | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7f0092d8f..81c39a2055 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,6 +558,7 @@ dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "chacha 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 77081fd4d8..22802482c6 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -34,7 +34,8 @@ mod sending_a_sphinx_packet { let message = "Hello, Sphinx!".as_bytes().to_vec(); let mixes = directory.get_mixes(); let destination = directory.get_destination(); - let packet = SphinxPacket::new(message, &mixes, &destination); + let delays = sphinx::header::delays::generate(2); + let packet = SphinxPacket::new(message, &mixes, &destination, &delays).unwrap(); let mix_client = MixClient::new(); let first_hop = mixes.first().unwrap(); diff --git a/src/main.rs b/src/main.rs index bb572b1f78..b44d8dd838 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,13 +13,15 @@ async fn main() { let directory = DirectoryClient::new(); let route = directory.get_mixes(); let destination = directory.get_destination(); + let delays = sphinx::header::delays::generate(2); // build the packet - let packet = sphinx::SphinxPacket::new(message, &route[..], &destination); + let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); // send to mixnet let mix_client = MixClient::new(); let result = mix_client.send(packet, route.first().unwrap()).await; + println!("packet sent"); } From bea04cf7382731b17a4874bfa71fbe669bbe0316 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 2 Dec 2019 13:50:57 +0000 Subject: [PATCH 006/167] Sending continuous stream of packets in a loop. --- src/main.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index b44d8dd838..4cf3bae6b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,24 +4,33 @@ use tokio::prelude::*; use crate::clients::mix::MixClient; use crate::clients::directory::DirectoryClient; +use std::time::{ Duration}; +use tokio::time::{interval_at, Instant}; #[tokio::main] async fn main() { - let message = "Hello, Sphinx!".as_bytes().to_vec(); + let start = Instant::now() + Duration::from_nanos(1000); + let mut interval = interval_at(start, Duration::from_nanos(1000)); + let mut i = 0; + loop { + interval.tick().await; + let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - // set up the route - let directory = DirectoryClient::new(); - let route = directory.get_mixes(); - let destination = directory.get_destination(); - let delays = sphinx::header::delays::generate(2); + // set up the route + let directory = DirectoryClient::new(); + let route = directory.get_mixes(); + let destination = directory.get_destination(); + let delays = sphinx::header::delays::generate(2); - // build the packet - let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + // build the packet + let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - // send to mixnet - let mix_client = MixClient::new(); - let result = mix_client.send(packet, route.first().unwrap()).await; - println!("packet sent"); + // send to mixnet + let mix_client = MixClient::new(); + let result = mix_client.send(packet, route.first().unwrap()).await; + println!("packet sent: {:?}", i); + i += 1; + } } From 5baa822eeb381f28d05d2eb865d85757b621b4ed Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 2 Dec 2019 21:23:19 +0000 Subject: [PATCH 007/167] Removing dead comment --- src/clients/directory.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clients/directory.rs b/src/clients/directory.rs index bf8e90520f..adea26a9db 100644 --- a/src/clients/directory.rs +++ b/src/clients/directory.rs @@ -27,7 +27,6 @@ fn fake_directory_mixes() -> Vec { address: [0u8; 32], //"127.0.0.1:8080".as_bytes(), // start here tomorrow :) pub_key: Default::default() }; -// vec![node1] let node2 = sphinx::route::Node{ address: [1u8;32], pub_key: Default::default() From 94231356d1be4c86e1f952a5f850ab46b9170018 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 9 Dec 2019 10:47:04 +0000 Subject: [PATCH 008/167] slightly increased default interval --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4cf3bae6b9..bdc2ace554 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,8 +10,8 @@ use tokio::time::{interval_at, Instant}; #[tokio::main] async fn main() { let start = Instant::now() + Duration::from_nanos(1000); - let mut interval = interval_at(start, Duration::from_nanos(1000)); - let mut i = 0; + let mut interval = interval_at(start, Duration::from_millis(5000)); + let mut i: usize = 0; loop { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); @@ -22,6 +22,7 @@ async fn main() { let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); + println!("delays: {:?}",delays); // build the packet let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); From f92e2119603d6554a1acd81a7b0771e6af4d282c Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 9 Dec 2019 12:33:06 +0000 Subject: [PATCH 009/167] Argument parsing --- Cargo.lock | 62 ++++++++++++++++ Cargo.toml | 3 +- src/clients/mix.rs | 3 +- src/main.rs | 177 ++++++++++++++++++++++++++++++++++++++------- 4 files changed, 214 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 81c39a2055..154aa1844c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,14 @@ dependencies = [ "stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "arc-swap" version = "0.4.4" @@ -41,6 +49,15 @@ name = "arrayref" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "atty" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -126,6 +143,20 @@ dependencies = [ "keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clap" +version = "2.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clear_on_drop" version = "0.2.3" @@ -396,6 +427,7 @@ dependencies = [ name = "nym-client" version = "0.1.0" dependencies = [ + "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "sphinx 0.1.0", "tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -578,6 +610,11 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "subtle" version = "1.0.0" @@ -598,6 +635,14 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio" version = "0.2.1" @@ -634,11 +679,21 @@ name = "typenum" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "wasi" version = "0.7.0" @@ -686,8 +741,10 @@ dependencies = [ "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" +"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" @@ -700,6 +757,7 @@ dependencies = [ "checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chacha 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf3c081b5fba1e5615640aae998e0fbd10c24cbd897ee39ed754a77601a4862" +"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" @@ -752,13 +810,17 @@ dependencies = [ "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799" "checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "beeef686ef92a222de07e089f455d9f8478bbba9651718f9e4b276babe829082" "checksum tokio-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5795a71419535c6dcecc9b6ca95bdd3c2d6142f7e8343d7beb9923f129aa87e" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" diff --git a/Cargo.toml b/Cargo.toml index d9825f5f10..6d643fe588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,5 @@ edition = "2018" [dependencies] sphinx = { path = "../sphinx" } -tokio = { version = "0.2", features = ["full"] } \ No newline at end of file +tokio = { version = "0.2", features = ["full"] } +clap = "2.33.0" \ No newline at end of file diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 22802482c6..af7844dc02 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,7 +1,6 @@ use crate::clients::directory::DirectoryClient; use sphinx::SphinxPacket; use sphinx::route::Node as MixNode; -use tokio::net::TcpStream; use tokio::prelude::*; pub struct MixClient {} @@ -15,7 +14,7 @@ impl MixClient { pub async fn send(&self, packet: SphinxPacket, mix: &MixNode) -> Result<(), Box>{ let bytes = packet.to_bytes(); - let mut stream = TcpStream::connect("127.0.0.1:8080").await?; + let mut stream = tokio::net::TcpStream::connect("127.0.0.1:8080").await?; stream.write_all(&bytes[..]).await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index bdc2ace554..1fbe250580 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,37 +1,158 @@ +use std::process; +use std::time::Duration; + +use clap::{App, Arg, ArgMatches, SubCommand}; +use tokio::runtime::Runtime; +use tokio::time::{Instant, interval_at}; + +use crate::clients::directory::DirectoryClient; +use crate::clients::mix::MixClient; + mod clients; -use tokio::prelude::*; +const TCP_SOCKET_TYPE: &str = "tcp"; +const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; -use crate::clients::mix::MixClient; -use crate::clients::directory::DirectoryClient; -use std::time::{ Duration}; -use tokio::time::{interval_at, Instant}; -#[tokio::main] -async fn main() { - let start = Instant::now() + Duration::from_nanos(1000); - let mut interval = interval_at(start, Duration::from_millis(5000)); - let mut i: usize = 0; - loop { - interval.tick().await; - let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); +fn execute(matches: ArgMatches) -> Result<(), String> { + match matches.subcommand() { + ("init", Some(m)) => Ok(init(m)), + ("run", Some(m)) => Ok(run(m)), + ("socket", Some(m)) => Ok(socket(m)), - // set up the route - let directory = DirectoryClient::new(); - let route = directory.get_mixes(); - let destination = directory.get_destination(); - let delays = sphinx::header::delays::generate(2); - - println!("delays: {:?}",delays); - // build the packet - let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - - // send to mixnet - let mix_client = MixClient::new(); - let result = mix_client.send(packet, route.first().unwrap()).await; - println!("packet sent: {:?}", i); - i += 1; + _ => Err(String::from("Unknown command")), } } +fn init(matches: &ArgMatches) { + println!("Running client init!"); + // don't unwrap it, pass it as it is, if it's None, choose a random + let provider_id = matches.value_of("providerID"); + let init_local = matches.is_present("local"); + + println!( + "client init goes here with providerID: {:?} and running locally: {:?}", + provider_id, init_local + ); +} + +fn run(matches: &ArgMatches) { + let custom_cfg = matches.value_of("customCfg"); + println!("Going to start client with custom config of: {:?}", custom_cfg); + + // Create the runtime, probably later move it to Client struct itself? + let mut rt = Runtime::new().unwrap(); + + // Spawn the root task + rt.block_on(async { + let start = Instant::now() + Duration::from_nanos(1000); + let mut interval = interval_at(start, Duration::from_millis(5000)); + let mut i: usize = 0; + loop { + interval.tick().await; + let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); + + // set up the route + let directory = DirectoryClient::new(); + let route = directory.get_mixes(); + let destination = directory.get_destination(); + let delays = sphinx::header::delays::generate(2); + + println!("delays: {:?}", delays); + // build the packet + let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + + // send to mixnet + let mix_client = MixClient::new(); + let result = mix_client.send(packet, route.first().unwrap()).await; + println!("packet sent: {:?}", i); + i += 1; + } + }) +} + +fn socket(matches: &ArgMatches) { + let custom_cfg = matches.value_of("customCfg"); + let socket_type = match matches.value_of("socketType").unwrap() { + TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, + WEBSOCKET_SOCKET_TYPE => WEBSOCKET_SOCKET_TYPE, + other => panic!("Invalid socket type provided - {}", other) + }; + let port = match matches.value_of("port").unwrap().parse::() { + Ok(n) => n, + Err(err) => panic!("Invalid port value provided - {:?}", err), + }; + + println!("Going to start socket client with custom config of: {:?}", custom_cfg); + println!("Using the following socket type: {:?}", socket_type); + println!("On the following port: {:?}", port); + +} + +// TODO: perhaps more subcommands and/or args to distinguish between coco client and mix client +fn main() { + let arg_matches = App::new("Nym Client") + .version("0.1.0") + .author("Nymtech") + .about("Implementation of the Nym Client") + .subcommand( + SubCommand::with_name("init") + .about("Initialise a Nym client") + .arg(Arg::with_name("providerID") + .short("pid") + .long("providerID") + .help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen") + .takes_value(true) + ) + .arg(Arg::with_name("local") + .short("loc") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment") + ) + ) + .subcommand( + SubCommand::with_name("run") + .about("Run a persistent Nym client process") + .arg( + Arg::with_name("customCfg") + .short("cfg") + .long("customCfg") + .help("Path to custom configuration file of the client") + .takes_value(true) + ) + ) + .subcommand( + SubCommand::with_name("socket") + .about("Run a background Nym client listening on a specified socket") + .arg( + Arg::with_name("customCfg") + .short("cfg") + .long("customCfg") + .help("Path to custom configuration file of the client") + .takes_value(true) + ) + .arg( + Arg::with_name("socketType") + .short("s") + .long("socketType") + .help("Type of the socket we want to run on (tcp / websocket)") + .takes_value(true) + .required(true) + ) + .arg( + Arg::with_name("port") + .short("p") + .long("port") + .help("Port to listen on") + .takes_value(true) + .required(true), + ) + ) + .get_matches(); + + if let Err(e) = execute(arg_matches) { + println!("Application error: {}", e); + process::exit(1); + } +} From b1d650c76d03e35b85129a004b1c6d7165d7cc82 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 9 Dec 2019 17:59:54 +0000 Subject: [PATCH 010/167] WIP --- Cargo.lock | 1104 +++++++++++++++++ Cargo.toml | 4 +- .../{directory.rs => directory/mod.rs} | 28 +- src/clients/directory/models.rs | 51 + src/clients/mix.rs | 4 +- src/main.rs | 8 +- 6 files changed, 1184 insertions(+), 15 deletions(-) rename src/clients/{directory.rs => directory/mod.rs} (72%) create mode 100644 src/clients/directory/models.rs diff --git a/Cargo.lock b/Cargo.lock index 81c39a2055..2323935b3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "aes-ctr" version = "0.3.0" @@ -41,6 +46,39 @@ name = "arrayref" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "backtrace" +version = "0.3.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bitflags" version = "1.2.1" @@ -94,6 +132,16 @@ name = "byteorder" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bytes" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bytes" version = "0.5.2" @@ -142,6 +190,103 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cookie" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cookie_store" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "core-foundation-sys" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-queue" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crypto-mac" version = "0.7.0" @@ -180,16 +325,86 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dtoa" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "encoding_rs" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "error-chain" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fake-simd" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "flate2" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fnv" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -209,11 +424,25 @@ name = "fuchsia-zircon-sys" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-cpupool" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "generic-array" version = "0.12.3" @@ -232,6 +461,23 @@ dependencies = [ "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "h2" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hermit-abi" version = "0.1.3" @@ -258,6 +504,101 @@ dependencies = [ "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "http" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "http-body" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "httparse" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "hyper" +version = "0.12.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hyper-tls" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "indexmap" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "iovec" version = "0.1.4" @@ -266,6 +607,11 @@ dependencies = [ "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itoa" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -301,6 +647,14 @@ dependencies = [ "keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.8" @@ -309,11 +663,51 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "memchr" version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "memoffset" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mime" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mime_guess" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio" version = "0.6.21" @@ -373,6 +767,23 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "native-tls" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", + "schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "net2" version = "0.2.33" @@ -396,6 +807,8 @@ dependencies = [ name = "nym-client" version = "0.1.0" dependencies = [ + "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sphinx 0.1.0", "tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -405,11 +818,80 @@ name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "openssl" +version = "0.10.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "openssl-sys" +version = "0.9.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pin-project-lite" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ppv-lite86" version = "0.2.6" @@ -423,6 +905,18 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "publicsuffix" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "1.0.2" @@ -431,6 +925,24 @@ dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.7.2" @@ -443,6 +955,15 @@ dependencies = [ "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_chacha" version = "0.2.1" @@ -481,6 +1002,14 @@ dependencies = [ "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_hc" version = "0.2.0" @@ -489,6 +1018,24 @@ dependencies = [ "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_os" version = "0.1.3" @@ -502,6 +1049,23 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rdrand" version = "0.4.0" @@ -515,6 +1079,163 @@ name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "regex" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "remove_dir_all" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "reqwest" +version = "0.9.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ryu" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "schannel" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "scopeguard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "security-framework" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "security-framework-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_derive" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_json" +version = "1.0.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "serde_urlencoded" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.0" @@ -540,6 +1261,19 @@ name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "smallvec" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "smallvec" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "socket2" version = "0.3.11" @@ -578,6 +1312,14 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "string" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "subtle" version = "1.0.0" @@ -598,6 +1340,58 @@ dependencies = [ "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "synstructure" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tempfile" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "time" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio" version = "0.2.1" @@ -620,6 +1414,44 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-buf" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-current-thread" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-executor" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-io" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-macros" version = "0.2.0" @@ -629,16 +1461,173 @@ dependencies = [ "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-reactor" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-sync" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-tcp" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-threadpool" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-timer" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "try-lock" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "try_from" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "typenum" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicode-xid" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "url" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "uuid" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "vcpkg" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "version_check" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "want" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "wasi" version = "0.7.0" @@ -673,6 +1662,14 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "winreg" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -683,11 +1680,16 @@ dependencies = [ ] [metadata] +"checksum adler32 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" +"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" +"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" @@ -695,6 +1697,7 @@ dependencies = [ "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum bytes 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c85319f157e4e26c703678e68e26ab71a46c0199286fa670b21cc9fec13d895" "checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" "checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" @@ -702,67 +1705,168 @@ dependencies = [ "checksum chacha 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf3c081b5fba1e5615640aae998e0fbd10c24cbd897ee39ed754a77601a4862" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" +"checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" +"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +"checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +"checksum crossbeam-deque 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3aa945d63861bfe624b55d153a39684da1e8c0bc8fba932f7ee3a3c16cea3ca" +"checksum crossbeam-epoch 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5064ebdbf05ce3cb95e45c8b086f72263f4166b29b97f6baff7ef7fe047b55ac" +"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" +"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +"checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9" +"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum failure_derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0bc225b78e0391e4b8683440bf2e63c2deeeb2ce5189eab46e2b68c6d3725d08" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" "checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" +"checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +"checksum http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" +"checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" +"checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +"checksum hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)" = "9dbe6ed1438e1f8ad955a4701e9a944938e9519f6888d12d8558b645e247d5f6" +"checksum hyper-tls 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3a800d6aa50af4b5850b2b0f659625ce9504df908e9733b635720483be26174f" +"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +"checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum lioness 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ae926706ba42c425c9457121178330d75e273df2e82e28b758faf3de3a9acb9" +"checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +"checksum maybe-uninit 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" +"checksum memoffset 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "75189eb85871ea5c2e2c15abbdd541185f63b408415e5051f5cac122d8c774b9" +"checksum mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "dd1d63acd1b78403cc0c325605908475dd9b9a3acbf65ed8bcab97e27014afcf" +"checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" +"checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" "checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" +"checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +"checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" +"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +"checksum openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)" = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" +"checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" +"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" +"checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" +"checksum publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae1b169243eaf61759b8475a998f0a385e42042370f3a7dbaf35246eacc8412" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" "checksum rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853" "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" "checksum rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" "checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" "checksum rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "96977acbdd3a6576fb1d27391900035bf3863d4a16422973a409b488cf29ffb2" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" +"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" +"checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" +"checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" +"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" +"checksum schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +"checksum security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df" +"checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702" +"checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0" +"checksum serde_json 1.0.42 (registry+https://github.com/rust-lang/crates.io-index)" = "1a3351dcbc1f067e2c92ab7c3c1f288ad1a4cffc470b5aaddb4c2e0a3ae80043" +"checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" +"checksum smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecf3b85f68e8abaa7555aa5abdb1153079387e60b718283d732f03897fcfc86" "checksum socket2 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" "checksum stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8131256a5896cabcf5eb04f4d6dacbe1aefda854b0d9896e09cb58829ec5638c" +"checksum string 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d24114bfcceb867ca7f71a0d3fe45d45619ec47a6fbfa98cb14e14250bfa5d6d" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab3af2eb31c42e8f0ccf43548232556c42737e01a96db6e1777b0be108e79799" "checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" +"checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +"checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" "checksum tokio 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "beeef686ef92a222de07e089f455d9f8478bbba9651718f9e4b276babe829082" +"checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" +"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" +"checksum tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "ca6df436c42b0c3330a82d855d2ef017cd793090ad550a6bc2184f4b933532ab" +"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-macros 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5795a71419535c6dcecc9b6ca95bdd3c2d6142f7e8343d7beb9923f129aa87e" +"checksum tokio-reactor 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "6732fe6b53c8d11178dcb77ac6d9682af27fc6d4cb87789449152e5377377146" +"checksum tokio-sync 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d06554cce1ae4a50f42fba8023918afa931413aded705b560e29600ccf7c6d76" +"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" +"checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" +"checksum tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1739638e364e558128461fc1ad84d997702c8e31c2e6b18fb99842268199e827" +"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +"checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" +"checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +"checksum unicode-normalization 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b561e267b2326bb4cebfc0ef9e68355c7abe6c6f522aeac2f5bf95d56c59bdcf" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" +"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" +"checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" +"checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" +"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +"checksum want 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6395efa4784b027708f7451087e647ec73cc74f5d9bc2e418404248d679a230" "checksum wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +"checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index d9825f5f10..56f160a4da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +reqwest = "0.9.22" +serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } -tokio = { version = "0.2", features = ["full"] } \ No newline at end of file +tokio = { version = "0.2", features = ["full"] } diff --git a/src/clients/directory.rs b/src/clients/directory/mod.rs similarity index 72% rename from src/clients/directory.rs rename to src/clients/directory/mod.rs index adea26a9db..15de2405f6 100644 --- a/src/clients/directory.rs +++ b/src/clients/directory/mod.rs @@ -1,13 +1,21 @@ use sphinx::route::{Node as SphinxNode, Destination}; +use crate::clients::directory::models::Topology; -pub struct DirectoryClient {} +use serde::Deserialize; -impl DirectoryClient { - pub fn new() -> DirectoryClient { - DirectoryClient {} +mod models; + +pub struct Client { +// topology: Topology, +} + +impl Client { + pub fn new() -> Client { + let topology = retrieve_topology().unwrap(); + Client {} } - // Hardcoded for now. Later, this should make a network request to the directory server (if one + // Hardcoded for now. Later, this should make a network request to the clients.directory server (if one // has not yet been made), parse the returned JSON, memoize the full tree of active nodes, // and return the list of currently active mix nodes. pub fn get_mixes(&self) -> Vec { @@ -22,6 +30,12 @@ impl DirectoryClient { } } +fn retrieve_topology() -> Result { + let topology: Topology = reqwest::get("https://directory.nymtech.net/api/presence/topology")? + .json()?; + Ok(topology) +} + fn fake_directory_mixes() -> Vec { let node1 = sphinx::route::Node{ address: [0u8; 32], //"127.0.0.1:8080".as_bytes(), // start here tomorrow :) @@ -40,7 +54,7 @@ mod retrieving_mixnode_list { #[test] fn always_works_because_it_is_hardcoded() { - let directory = DirectoryClient::new(); + let directory = Client::new(); let expected = fake_directory_mixes().as_slice().to_owned(); let mixes = directory.get_mixes(); @@ -55,7 +69,7 @@ mod retrieving_destinations { #[test] fn always_works_because_it_is_hardcoded() { - let directory = DirectoryClient::new(); + let directory = Client::new(); let expected = Destination { address: [0u8;32], identifier: [0u8; 16], diff --git a/src/clients/directory/models.rs b/src/clients/directory/models.rs new file mode 100644 index 0000000000..769b8fd6fb --- /dev/null +++ b/src/clients/directory/models.rs @@ -0,0 +1,51 @@ +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct CocoHostInfo{ + host_info: HostInfo, +} + +#[derive(Deserialize)] +pub struct CocoPresence { + coco_host_info: CocoHostInfo, + last_seen: i64, +} + +#[derive(Deserialize)] +pub struct HostInfo { + host: String, + pub_key: String, +} + +#[derive(Deserialize)] +pub struct MixHostInfo { + host_info: HostInfo, + layer: u64, +} + +#[derive(Deserialize)] +pub struct MixNodePresence{ + mix_host_info: MixHostInfo, + last_seen: i64, +} + +#[derive(Deserialize)] +pub struct MixProviderPresence{ + mix_provider_host_info: MixProviderHostInfo, + +} + +#[derive(Deserialize)] +pub struct MixProviderHostInfo{ + host_info: HostInfo, + last_seen: i64, +} + +// Topology shows us the current state of the overall Nym network +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Topology { + coco_nodes: Vec, + mix_nodes: Vec, + mix_provider_nodes: Vec +} diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 22802482c6..303670fd9f 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,4 +1,4 @@ -use crate::clients::directory::DirectoryClient; +use crate::clients::directory::Client; use sphinx::SphinxPacket; use sphinx::route::Node as MixNode; use tokio::net::TcpStream; @@ -30,7 +30,7 @@ mod sending_a_sphinx_packet { #[test] fn works() { // arrange - let directory = DirectoryClient::new(); + let directory = Client::new(); let message = "Hello, Sphinx!".as_bytes().to_vec(); let mixes = directory.get_mixes(); let destination = directory.get_destination(); diff --git a/src/main.rs b/src/main.rs index 4cf3bae6b9..9f838da7b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod clients; use tokio::prelude::*; use crate::clients::mix::MixClient; -use crate::clients::directory::DirectoryClient; +use crate::clients::directory; use std::time::{ Duration}; use tokio::time::{interval_at, Instant}; @@ -17,7 +17,7 @@ async fn main() { let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); // set up the route - let directory = DirectoryClient::new(); + let directory = directory::Client::new(); let route = directory.get_mixes(); let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); @@ -31,6 +31,4 @@ async fn main() { println!("packet sent: {:?}", i); i += 1; } -} - - +} \ No newline at end of file From 3fe8ef72a5fc71842606f66438b0c0c1642ec85d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 15:30:40 +0000 Subject: [PATCH 011/167] WIP: the healthcheck requests work, main construction doesn't yet --- Cargo.lock | 67 +++++ Cargo.toml | 4 + src/clients/directory/healthcheck/mod.rs | 1 + src/clients/directory/healthcheck/requests.rs | 80 ++++++ src/clients/directory/metrics/mod.rs | 1 + src/clients/directory/mod.rs | 79 ++---- src/clients/directory/presence/mod.rs | 2 + .../directory/{ => presence}/models.rs | 35 +-- src/clients/directory/presence/requests.rs | 244 ++++++++++++++++++ src/main.rs | 2 +- 10 files changed, 425 insertions(+), 90 deletions(-) rename src/clients/directory/{ => presence}/models.rs (57%) diff --git a/Cargo.lock b/Cargo.lock index 37eb748835..824624b6e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,6 +36,14 @@ dependencies = [ "stream-cipher 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "aho-corasick" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -54,6 +62,15 @@ name = "arrayref" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "assert-json-diff" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.13" @@ -221,6 +238,16 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "colored" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cookie" version = "0.12.0" @@ -348,6 +375,11 @@ dependencies = [ "subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "difference" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "digest" version = "0.8.1" @@ -798,6 +830,23 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mockito" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "assert-json-diff 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "native-tls" version = "0.2.3" @@ -839,6 +888,7 @@ name = "nym-client" version = "0.1.0" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "sphinx 0.1.0", @@ -1116,7 +1166,10 @@ name = "regex" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1409,6 +1462,14 @@ dependencies = [ "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "time" version = "0.1.42" @@ -1739,9 +1800,11 @@ dependencies = [ "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" +"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" +"checksum assert-json-diff 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9881d306dee755eccf052d652b774a6b2861e86b4772f555262130e58e4f81d2" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" @@ -1763,6 +1826,7 @@ dependencies = [ "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "433e7ac7d511768127ed85b0c4947f47a254131e37864b2dc13f52aa32cd37e5" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" "checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" @@ -1776,6 +1840,7 @@ dependencies = [ "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" +"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" @@ -1829,6 +1894,7 @@ dependencies = [ "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226" +"checksum mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e524e85ea7c80559354217a6470c14abc2411802a9996aed1821559b9e28e3c" "checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" @@ -1895,6 +1961,7 @@ dependencies = [ "checksum synstructure 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)" = "5a09c0b5bb588872ab2f09afa13ee6e9dac11e10a0ec9e8e3ba39a5a5d530af6" "checksum tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bcced6bb623d4bff3739c176c415f13c418f426395c169c9c3cd9a492c715b16" diff --git a/Cargo.toml b/Cargo.toml index f39565e6c2..9679ba337c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,7 @@ reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } tokio = { version = "0.2", features = ["full"] } + + +[dev-dependencies] +mockito = "0.22.0" \ No newline at end of file diff --git a/src/clients/directory/healthcheck/mod.rs b/src/clients/directory/healthcheck/mod.rs index e69de29bb2..4e83d422e0 100644 --- a/src/clients/directory/healthcheck/mod.rs +++ b/src/clients/directory/healthcheck/mod.rs @@ -0,0 +1 @@ +pub mod requests; \ No newline at end of file diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index e69de29bb2..dd08caa2f1 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -0,0 +1,80 @@ +#[cfg(not(test))] +use mockito; + +struct Requester { + base_url: String +} + +trait HealthCheckRequester { + fn new(base_url: String) -> Self; + fn get(&self) -> bool; +} + +impl HealthCheckRequester for Requester { + fn new(base_url: String) -> Requester { + Requester { + base_url, + } + } + + fn get(&self) -> bool { + let url = format!("{}/healthcheck", self.base_url); + match reqwest::get(&url) { + Ok(response) => { + if response.status() == 200 { + true + } else { + false + } + }, + Err(e) => false, + } + } +} + +struct HealthCheckResponse { + ok: bool, +} + +mod healthcheck_requests { + use super::*; + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + fn it_returns_false() { + let _m = mock("GET", "/healthcheck") + .with_status(400) + .create(); + let req = Requester::new(mockito::server_url()); + + let expected = false; + assert_eq!(expected, req.get()); + } + } + + #[cfg(test)] + mod on_a_200_with_ok_json { + use super::*; + + #[test] + fn it_returns_true() { + let _m = mock("GET", "/healthcheck") + .with_status(200) + .create(); + let req = Requester::new(mockito::server_url()); + + let expected = true; + assert_eq!(expected, req.get()); + } + } +} + + +#[cfg(test)] +mod fixtures { + +} \ No newline at end of file diff --git a/src/clients/directory/metrics/mod.rs b/src/clients/directory/metrics/mod.rs index e69de29bb2..4e83d422e0 100644 --- a/src/clients/directory/metrics/mod.rs +++ b/src/clients/directory/metrics/mod.rs @@ -0,0 +1 @@ +pub mod requests; \ No newline at end of file diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 15de2405f6..962fadd1e4 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,32 +1,29 @@ use sphinx::route::{Node as SphinxNode, Destination}; -use crate::clients::directory::models::Topology; +use crate::clients::directory::presence::models::Topology; +use reqwest::Error; -use serde::Deserialize; +//use serde::Deserialize; -mod models; +mod healthcheck; +mod metrics; +mod presence; -pub struct Client { -// topology: Topology, +trait DirectoryClient { + fn new(base_url: String) -> Self; + fn get_topology(&self) -> Result; +// fn send_provider_presence(&self) -> Result; } -impl Client { - pub fn new() -> Client { +pub struct Client {} + +impl DirectoryClient for Client { + fn new(base_url: String) -> Client { let topology = retrieve_topology().unwrap(); Client {} } - // Hardcoded for now. Later, this should make a network request to the clients.directory server (if one - // has not yet been made), parse the returned JSON, memoize the full tree of active nodes, - // and return the list of currently active mix nodes. - pub fn get_mixes(&self) -> Vec { - fake_directory_mixes() - } - - pub fn get_destination(&self) -> Destination { - Destination { - address: [0u8;32], - identifier: [0u8; 16], - } + fn get_topology(&self) -> Result { + unimplemented!() } } @@ -36,48 +33,4 @@ fn retrieve_topology() -> Result { Ok(topology) } -fn fake_directory_mixes() -> Vec { - let node1 = sphinx::route::Node{ - address: [0u8; 32], //"127.0.0.1:8080".as_bytes(), // start here tomorrow :) - pub_key: Default::default() - }; - let node2 = sphinx::route::Node{ - address: [1u8;32], - pub_key: Default::default() - }; - vec![node1, node2] -} - -#[cfg(test)] -mod retrieving_mixnode_list { - use super::*; - - #[test] - fn always_works_because_it_is_hardcoded() { - let directory = Client::new(); - let expected = fake_directory_mixes().as_slice().to_owned(); - - let mixes = directory.get_mixes(); - - assert_eq!(expected, mixes.as_slice()); - } -} - -#[cfg(test)] -mod retrieving_destinations { - use super::*; - - #[test] - fn always_works_because_it_is_hardcoded() { - let directory = Client::new(); - let expected = Destination { - address: [0u8;32], - identifier: [0u8; 16], - }; - - let destination = directory.get_destination(); - - assert_eq!(expected, destination); - } -} diff --git a/src/clients/directory/presence/mod.rs b/src/clients/directory/presence/mod.rs index e69de29bb2..270cb4e5ed 100644 --- a/src/clients/directory/presence/mod.rs +++ b/src/clients/directory/presence/mod.rs @@ -0,0 +1,2 @@ +pub mod requests; +pub mod models; diff --git a/src/clients/directory/models.rs b/src/clients/directory/presence/models.rs similarity index 57% rename from src/clients/directory/models.rs rename to src/clients/directory/presence/models.rs index 769b8fd6fb..34890b132d 100644 --- a/src/clients/directory/models.rs +++ b/src/clients/directory/presence/models.rs @@ -1,44 +1,27 @@ use serde::Deserialize; #[derive(Deserialize)] -pub struct CocoHostInfo{ - host_info: HostInfo, -} - -#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] pub struct CocoPresence { - coco_host_info: CocoHostInfo, - last_seen: i64, -} - -#[derive(Deserialize)] -pub struct HostInfo { host: String, pub_key: String, + last_seen: i64, } #[derive(Deserialize)] -pub struct MixHostInfo { - host_info: HostInfo, - layer: u64, -} - -#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] pub struct MixNodePresence{ - mix_host_info: MixHostInfo, + host: String, + pub_key: String, + layer: u64, last_seen: i64, } #[derive(Deserialize)] +#[serde(rename_all = "camelCase")] pub struct MixProviderPresence{ - mix_provider_host_info: MixProviderHostInfo, - -} - -#[derive(Deserialize)] -pub struct MixProviderHostInfo{ - host_info: HostInfo, - last_seen: i64, + host: String, + pub_key: String, } // Topology shows us the current state of the overall Nym network diff --git a/src/clients/directory/presence/requests.rs b/src/clients/directory/presence/requests.rs index e69de29bb2..346034b297 100644 --- a/src/clients/directory/presence/requests.rs +++ b/src/clients/directory/presence/requests.rs @@ -0,0 +1,244 @@ + + + +#[cfg(test)] +mod presence_tests { +// use super::*; + + mod fixtures { + fn topology_response_json() -> String { + r#"{ + "cocoNodes": [ + { + "host": "3.8.244.109:4000", + "pubKey": "AAAAAAAAAAEKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEFuhRpy4HfcuxwcRI9sIWMo_LVmbk19g1gfMRlBrmZqoEQL6rDApVLZ9eMp-5IQK8WLlZpWf4Zjy7kZolARAyp_rHUQkH4PrDjgoPrKbm6qK_iejYpL7qx28Q3VeInMpwMIMaSbbW9y36sEVtGc2I0Iu5vS0sp8ESiVlQ5NaBz72deZ8oKJJ4IEPPHP99-b0UQX80fVIrNM88mMzKy0bHri9NFlmIG-e0G1cqmw_ry3XWGQkcr1M5RuNa6oX50w5QawAEVxd5FP5bE8bS4x54Csof11sQWUTwMp6Q7_3H7ZCTSlKSqujlOhmfqSHfGPO2sDIYPHDhDzjakZpKAZWWhn_hiR6DfPpomQ01ZYUhVKKSMxz7_VPjsQplP0bZXA2gfnkADUN8UQ0N9g_usIw73r4aZsOviMsRM8oByvsjVfUWc4_HTLSdnQyImFkHz9CiCmrIYL2dYQRePRatWggvBAyeRzntxI4jDqLKiBdi54ZlAKgV6MCRaJ7Bu7BtmLXrtK4sawAED3QYxuvOSZrbZdUr4yG-U9yVvJ9Klkf-5Mo4EYp3qTL2KBB6_LrZepjAQqp486YkZ03mTIezcsZ48EboXVTWKBZ3QnTI5tX-j4gGxQb7klOJc97qJkDxsvpz4F0ChgCUIZhpIItWHia7_R3Gi-b5siLIdQdUho9isn3kiDGm6t0NED2Bgy3ZxxQwzqsBZm4kPr2_fPX4YyvIoP9895YcGjZyE5iiRC_TE41RJmB1GZYdxegTMq3lNDllKgiqaiPgawAEJASDkmZHTwlg9YOev5OWpQD-FnhPkqVNo_QcDyRu9eoGcWSGFp2sYqjG2SpmiXq0VNnAO7AcKxRzDFu7TjfhlU3Kt0uTKIcrWVU1zFNbJNMjYEq90pp50nowwx8INz20IXET2ZNX6kIXYFCsEvPLZFlG2OoL6xg3uQS1qMl3lIS_VxdO_JfVe0rT65WsJ_P4Nkc1jYiuNPHY6d_iFO0BVYqX0sOCX73GC_TT13BR0jnPwDAVw0rGtYHsXBb8TKOsawAEZIClauuT1V3qOZnb7uRZhFXO-PKTxgc1LCzJt2ChOrMZaBpjlkf3IPpJ2UF4JH4kGaDeBf2k_S-FLAs3drK21efbi5P6_a4QTxAiiRimXGoQIyvOg462s6kP_ZRFufo8YYQHS4olaOeqU4564dNskg_uBPsFMz_2GNOhmn_15cJqP1jfkyD49Z16GTS5YLHgVl9bJKqyvLuypsToLbt1BJzipEP0L2OohuRm-_MvqvwwWKyjNQsubgee1K728d9AawAEBkGggcNVCtXyhoSqi3_w0tVxtkAYeud8sBeAtZHGs06me_QL8co0MFLlO-zdkUb4ZBq08rFEbgLOma8_3whleM8NIPaHNISp1q3IsIhB5zdXcZoGsqLixODBFHtID3YEHAlr4f9T_yh11yJ95xGCl_6Y37hpwLQVGyrfSfccM24mVFqnV3TT5Wdq3ile-jesUx1Q2G1yK_xVqc6itmk-kDuBjyZgzYi1-jsIXAjnhM9G7t8J_Bv5yGGZhLK2dCzM=", + "type": "validator", + "lastSeen": 1575915097085539300 + }, + { + "host": "3.9.129.61:4000", + "pubKey": "AAAAAAAAAAMKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEEv6RMevAQmLGkeK0uJKnMPPAtm8GgXjWSQijYdnxlPh5SJSNeJUbPZKWFFWdk8yIFXKa8jnzETtdGFKgUUt5AVUDpTBmEdwaHCzlFhXrttshy0V5OhPUlV8cGABmxbagMYm0bFPg0r-snSkrB9YG6wqJYQVeIMOCGYCPbHmDA8R_0-h8VkRKWs1d9KvQOK4kShqgZtYN71KJW8uDE4q2jsGDVvxFt1AgmU9b93xsXF17KrpZy5WxlLZ73HtnTD_oawAED4vd_rK-Kx_n8x_OdDiiEOPUlYDlDCQUqenU9XHKH3B6ijfkJ368wd3LDDVStjDwNORrAyUSw_VlSNUpd1XLC8d17gTaIq5ZI2fWuwwZaoN1JCsYU8fQ6USgtIehQX7IPP8EkFuNmuCBCmpr4schtYniGe9J8Q4dsV-TYPr2uLJkdx1r7luzF--I22k7NfQQM14QDci_0kgrgmZ54CJGkjXyOhCppBXg3fqLC6aFvT3ZocfiiXBJt0huGgPMDtYsawAECLh8KUdNsDolERwJ8v04bS5jI_KKf7uUnCHWuCELwbJSUI3OK1ufS1qSpauvSzVQSbrhEzrEfwQn4VtxQxJlX4UdDU-R-hafiZvVC6DLLAbuORBAC3FScn9W58CnezH4DvCp_w7nftDfdxeuungbZT9XaxS3iNC6PnFsWF6WM3DxMwrzOrFe6wEEoTSPe1mcUDrtwM5UksIvJr6MBRAXrdl0IdBTQr7cLwKe_KYi4siwdjfJEJtOh7oxQBxBg2UkawAEJAPZK2Gg2MQwpxdDT24lNQHF7FVfkO_LuhJwn0RbwNDSVeA4P6-tWL5TkCpqr8xYHfwQ6Z3ILfpGCZr8PspwIoRzqZHQ16f8Pq9xnr0hLEI9BOQU0FS2EtuyPgju5iwsAJAfehUzu6kNLphuLGsXoIZdXDG5mbylwh9JzAVXTwgaR0hNqyXVJxgbt7jcYaSEBFcMGV-hjXyVVNzBleE-G9o_noI_KWU4Ce7K-qOMcewMKfy_VEw-gVaD6dHz6AMoawAEE9XuOLwRttvKybAssZ9gsK-_YRUwuFOeRDIr3NX___9bx6pCc18adCIlH_8EJWFwXZ05ZpNNE88mYx7ZQ3aqaArZJRoWeZeKhqH_s05V10xbzkYX71G5cqz--8vr9ZlQRb2BeETF_Tdq_PLk7qbT8WTGIoq7ZwyDRQTgzvkCgyzj_hBLh2o7sSVNgUo38SFUTMn7YtvVFYlSrTDE3WKE-T-nh5SWdDBxgDTc3Bw8JpzNH-WkoJ4Lim7sB4Op1gEUawAEW4-kenlffwsNr_3b3aV0YuusLpxB03sxPzQ5B0CWNiVtbja1Z4tWhKGUUrdq_eUgMV0y5Of-BqNi5FspAQnhJBFSSxtOzRGV1h3qyUTksfZyed9z8zPI-ZPP9XXm7hYgJgDz_kxte-NfS9UG9q5AZetHUN4kGxXutjjzfUQZ9yTvhBKgKgTI2Dp_R_jZrWQ8F1BoWzIJzjddT1K2MvCQEkARYw08isbOeFmCwgVUcjxYZO45WyOmLQA7QJRL9WvA=", + "type": "validator", + "lastSeen": 1575915097388409000 + }, + { + "host": "3.9.222.1:4000", + "pubKey": "AAAAAAAAAAQKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAECh9xcxpjOp1r7kiNIgrI9GgAlvXwgHkTchOxUiyOzTq6FDWdGN64KiC3NDeyGTg8FmzvGzS3jREeJqOdr4G9ZGtWkauAITgLFiH62t-YntRslhr8_1shxlmzKiNKJN_QFflEq79pZIlWtp3N8LIHMvXRtl-zt2DMze4s02XDmEkviyVE4CkQUDtCc-2MfPT4JcmEFqtFIxjrXn18SbYg3c6XUQHsGIkuDrKuCTRlpC8kvmM0uVoIeWdmwDlZk4jUawAEJhRwK5ozjqIWRP1bFzBPS9VhaJnfKU9PeFYtN5beiAHrYr2ylIB3yDfmAQUdKDowDUm5nfJATejEjEnrTGxh70QtfoNV391rSns3F71tBwY62KLaNr8qnVfeSFHV3FcQTMHHF_8mDb5_11Rj6aiMvW0y6eetHo7CDPMdEyDPmok_U2ZM5BzOUnwjT21HtnvcKxKKwHJ_QGfnAHPyDIhNOMgxJCrVazOidLCHeYGpyCLw1ipeTyKOQX0_ByB8dH6AawAEGV1GuF5SSlT67B1ityPJK2ZwXjeeKB4gGdCG3qRtWxLTZfGhVm7YAYm2f5tw_wrsJAZ9FubVhateGg0ZN67NxZtsvOOejXz6743f7ijnQopPgd_8pH-iVf6BEcSO8ZdcHxNRUTayzjVLs99bwMo2zaPevW4X4G_bN4mh---aPkdGYHwaiklzUhqJ-eqycrYAFyjyEXaPBXLQm1rpczqluNvnKbd8Q9LZWukgm7_uWv_HxufIvdWgoq8bAt78UU3oawAEP9VDehhqrQG5-WHMB66XVxo1TgMM8aVV0SwAq3lCRkpiFBz_9kw8T1F9Hx2AiNrEGT1QLbdMkpms1cG_5gBBahQofdt_NmUs1jfTFXY9iyMy1Q7A6ZYaLP8Z6q-orc1cKqySY-BJZQ_CpGFfXS0OVniFDQ6v78ytPK7K-yRgT1PxFgm3rZqrG0Tjbrpsg2PUL5S5fuXfMhUosP0uoLj0D1guWAR9Y7kfFBIXaTSFMoa8fghVBUTRNhK9f72a8SxQawAEOiv71taLjKqaaWQ_QjcDhWbvjG1EnsCyI0toNjGkcF19x4Vk-5NC96_4ioUGz404IC0XN03roRnibRT_78D9vZFVCWCqve9EjdF5TcApx03zIP4JT2g2q0MKIGgGrwt4Pz6LO6yOfMm7B8Yraps8IV-nP1w7K1m9XKP_FvH8egl5GHJe-_omlC2YyL_b28jMLENbxDFD-3KPjZFBhSLrRukX2PlayYTwEiTtokA2R9_11vQvJgP8KFEjGHg6zsAMawAEBn2H_hz2knb8ltnpEA5YSKVcV3nUtojkCNi_WUz7xUKd7efw1oI_lbnKrS7HkyC0JkQUZ1pCWUlSXNmgjMEhsn823a1LFzpV7rOv4vayYvvFX61hB9R78VjpyxJiYpDwRZLiUY3AK4WY8NqFDbjXR7rT4CkFHEf-VhSQQ8ZNvlpod1nmeVQVizHH9e7Tq7wsWz-LWEk3Hx6LmcrgDsL79LZYG9JXU5IdvG8RvLNx9cSwEI8yxcchpISAaot7UoYQ=", + "type": "validator", + "lastSeen": 1575915094734973000 + }, + { + "host": "3.9.102.214:4000", + "pubKey": "AAAAAAAAAAIKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEOVCUN3EwiVroS5-TOq2o7hYSxphK9X0G23N-IBZ0Tr1Rl8XEiJ-OEy0rqnAKwmhAZJWnx3u8oXqbZtOWIZmzQSpcoxhgwfhdmTZJCqT2RVzZyeFItX4sVeilEP3z2xdsJs8-a1kg6UZnx1s1BNLBo7eZrreZygWojPCIDBn03fSAflXoVc5PpY2CGy5MA_IgWgSYBHDdoZEtigp_amjqK7Us44Db20XpLxMXfbahiqa7WKNnMgi6Ca2H67VtaaD8awAEF3zbE1nZRAa7a8vbU25c80YBYJBaW8P6FwXQI-K0Xk5MakwYeMMnIrm6w6IS_0XAO5YlD453GLqnxY8H1BEnRpfOnT7PE4el9mJ8MuYQMo6R2up0lGCmYM0YA9FORjroM3ng69SEPfJPCReG7LfJkERl_m2U403ertDRBYrlqCDagDfyI500srBcMrjSvV3oNouyyx3yZUrjLQfbHhDteQFsYdmakJs8Y-Q9-5MXCcrz6Qa4xwv522Euv0CCxkHcawAEYjfsU_zDhUZA1ey1aquWXlFOnx-iEALqxW1slDYHwQ1M2SILc-v_E6i1doa5e_bAZHVezBHFAlaNAVedNyHFFJxYAqAK3hbzbvl2glw3Q6h_rTXElymloqtaqVFIJ-oUWWOHsZBmu8EDA-HzvGCiBa_GbRaVfh2lE4ObeMXoJrEm_5dbxxeEic2l3IYeIz40N9ooQQOkQcOZdY4AXWYCavIAwWEJBjLtptJgCLu9a_zM1S5GsiyJHpdDs46WbP0EawAEWZ-95Sf0YAHujxRNLdXgpqe0ZF8loVwzZfvyMvqaxF1Ug274BqHuY_c5NdPAzuqoTwjfEn8NKEoaNqlumM75FUYbaTd7mXvk4WVYWjVnkO40dfQjRB7DYhvj0LBlbndAJ4wJIA2ilPYgjZsXVbNNh3e2j3u9eABd0VaFMbSb8Sz5_31r8HzoWmPJs3HiyuyANGFUA6CvAnMN6K3b-D8BhFZU_nPUTgu80o8_n6LQt-XWbaC_mTHzsnOjzBiPJxlYawAEW3bmOEtStH2T8q7vMkhchImp2-hg9MFYGBmEe9sSByTn3NUf8eksqXOC1dUjHkXoZm298FgUYLkNdnlxWpf993j5mEDoFxjcTB7scBD7k6nu6Nrs_wK0-seS8gsHrx9UK7GwAsi10q82Cm4PFyAtrWjmy_d9WLHuZt6VIOKunTs8cf0FwNUiMcvZsruqIFJcP7iWxdiFdUkh65P_iCz1ZEjJcj2GEZoq4v3a3by1aizGPaaiKc1jd_T-XJg_YpncawAEWnstu5b9WiZv0x8xfsiMk6YRlU0Cnj5svxLLXz_8drvwAa--GBY5yH0ke2EM6udMEi2EPeFcGTe6Sjs0YEhSbY7Uad_8suD2J4tIWJSWBbiyvh7rSqzv57m7BlsVcHfQJn_wNH-UlC9xkx8vg-LwfN8_FlxvHNPTc7XZG3lKYbwpUWlZxAziOYT1VQ-2K2bQQBBMdix-ht_SjccL1Dc2dP5kDazQ8yZV_8xnyeheazEedWe63uutfkHlZRg9YwP8=", + "type": "validator", + "lastSeen": 1575915094967382800 + } + ], + "mixNodes": [ + { + "host": "35.176.155.107:1789", + "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + "layer": 3, + "lastSeen": 1575915096805374500 + }, + { + "host": "18.130.86.190:1789", + "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + "layer": 1, + "lastSeen": 1575915097370376000 + }, + { + "host": "3.10.22.152:1789", + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "layer": 1, + "lastSeen": 1575915097639423500 + }, + { + "host": "35.178.213.77:1789", + "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + "layer": 2, + "lastSeen": 1575915097895166500 + }, + { + "host": "52.56.99.196:1789", + "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + "layer": 2, + "lastSeen": 1575915096255174700 + }, + { + "host": "3.9.12.238:1789", + "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + "layer": 3, + "lastSeen": 1575915096497827600 + } + ], + "mixProviderNodes": [ + { + "host": "3.8.176.11:1789", + "pubKey": "54U6krAr-j9nQXFlsHk3io04_p0tctuqH71t7w_usgI=", + "registeredClients": [ + { + "pubKey": "zOqdJFH49HcgGSCRnmbXGzovnwRLEPN0YGN1SCafTyo=" + }, + { + "pubKey": "fy9xo69hZ2UJ9uxhIS1YzKHZsH8saV-02AiyCNXPNUc=" + }, + { + "pubKey": "6hFCz42d5AODAoMXqcBWtoOoZh-7hPMDXbLKKhS7x3I=" + }, + { + "pubKey": "pPZMDzw0FyZ-LBAhwCvjlPGj1p2bO_vaWbRBc7Ojq3Q=" + }, + { + "pubKey": "kjl5poXt2GdIrHLuMBjmTBSChV-zMqsXFBhKZoIREVI=" + }, + { + "pubKey": "T1jMGuk7-rcIUWnVopAsdGzhAJ7ZVymwON2LzjuOfnY=" + }, + { + "pubKey": "3X0eKPkflx5Vzok0Gk0jm5-YEfvPAuWP55ovyBUOtXA=" + }, + { + "pubKey": "5wC3i8rCZolLKbWJ9U6eLieXNGLKM21dtL6lR30u_hE=" + }, + { + "pubKey": "1P6p7fgjwjlEepD9JgbN1V-rk9n36-hCmPN5P6y62n4=" + }, + { + "pubKey": "aBjlLQKKFroqhX_kvYLnMm1uq3FJdQWqVy9Q35zzERA=" + }, + { + "pubKey": "I0gVOPj6lv9ha60xPYKeAgbeUU8pdyMD-Y7Nb1nS9EQ=" + }, + { + "pubKey": "WgdvQ74QH1uFDWDL2YeApvv7oniNGh9BQJ_HZam20QA=" + }, + { + "pubKey": "Mlw23KaSL2hyrIjEZM76bZStt2iMzxVAqXwO5clJfxg=" + }, + { + "pubKey": "F9xzbjnMQVN4ZidcqN2ip9kVnI9wbS39aVayZGiMihY=" + }, + { + "pubKey": "s6pfVkZrUG--RNjfzS55N2oPvFkMdvgb1LUut6gqRy4=" + }, + { + "pubKey": "bSi-9k0jJNKc8PGx8M3SWFaNpORFjYw-NkWXRZVRWGU=" + }, + { + "pubKey": "pz6ahQcGOQcZBFx1tGmzRngqk6BecXB_wFd4WVdOQDU=" + }, + { + "pubKey": "5sfwIMcG2zRCxhDh4D9Evw1WPI5bfKZAShM_6o9Pu1I=" + }, + { + "pubKey": "9fZnxXy9onGPpZ3Ygckqw0okqCw3di02sLr-NTBr4SE=" + }, + { + "pubKey": "Q0TbbggOwzZjalUdi5eEHVFi9VMv-rMm5mJPUZZs12A=" + }, + { + "pubKey": "aPNyox_qAIGFB2-wZ0lc9iAWDN6jzLojApSiWVFjCks=" + }, + { + "pubKey": "DUKLEsIGMw-ucs3DjS7Ag9qCb5-C_A84DuIsZuLkdwI=" + }, + { + "pubKey": "YV84vPoSrLf1p9Sw6FnnrcCpS3kvpJUfKyKpnwk8z0Q=" + }, + { + "pubKey": "_IYEzZQoBAYeTxqzpEe_ez1-7pn7aId8AKliazy0qlE=" + }, + { + "pubKey": "srkOAoVU-a02lnEsoH_wOLLw7HFx_xHIZUSbnhjFwDw=" + }, + { + "pubKey": "LxSCBn_OEQq-hI2xDi6bfGoioRO_lSTIq6AQ9l1k5jg=" + }, + { + "pubKey": "OC0OOqtGfAytgZjthpjoKeYNa0VrtzfgZ0iO5Fag5y8=" + }, + { + "pubKey": "ImVEch2focRhm1ial1gA6YJPr6WDyW3oh-OgYcO5Ll4=" + }, + { + "pubKey": "yTDnzLvEaSq0mC9xNrtyjpAKtsIU6yRuBepCuWQMBm4=" + }, + { + "pubKey": "-LCUUc46HuL7iUEOMkrlVAkvvulRiQ7dR1QYh7bkKxw=" + }, + { + "pubKey": "Bx1MGpISig25rqe7mhoX68EROUPPzmF7yGLYah9DPgM=" + }, + { + "pubKey": "Z4Nu6iwLmgJ93yoIFTbTEBeDAHRwS-vo1T_K2Kv1FQo=" + }, + { + "pubKey": "cKFAGxllwAmEXCtDxG_T1iEm3-lKWUVQxxpDBje6mQU=" + }, + { + "pubKey": "pQV40whlQWUSXtrNTTePzO6sdq3zr1JUIWZWvD443nY=" + }, + { + "pubKey": "6Bb5HwnVqJPy5wcNsaHY-0y__coZCE7XC80kUkesnRU=" + }, + { + "pubKey": "COGdpfhmzNGR6YX820GqJIkjOihL8mr6-h-d3JlTDFA=" + } + ], + "lastSeen": 1575915097358694100 + }, + { + "host": "35.178.212.193:1789", + "pubKey": "sA-sxi038pEbGy4lgZWG-RdHHDkA6kZzu44G0LUxFSc=", + "registeredClients": [ + { + "pubKey": "UE-7r6-bpw0b4T3GxOBVxlg02psx23DF2p5Tuf-OBSE=" + }, + { + "pubKey": "UnZuLpzq64_EPtIcr1Fd-5AESBCBLFnDMDsjUaOqrUA=" + }, + { + "pubKey": "4ExXPrW5w0nZIQ5ravBRT6H9r0RH0MXuOcGIF8HzUhg=" + }, + { + "pubKey": "wPsRpJPi1e2sjItyRKDkFACbxwu3Cw5GlYVPmdYxk2U=" + }, + { + "pubKey": "UfK5UvT3HUkT1SGbv1QGafy3in3uQ9a6NSy5EOT6k0k=" + }, + { + "pubKey": "5Giu-tJpGXU0S9Av75iAv5qDO0k6l8v_k9-UCcRUCl4=" + }, + { + "pubKey": "MnQxlmmKDybku4CfxsQQxfftilsaphF9Gq1w3MB1ZCE=" + }, + { + "pubKey": "GdP1fHVs2R65EkuWVWKZSz6WPDh0MgThyuBOv6_xsmQ=" + }, + { + "pubKey": "4JEtSrKsonmBuDvxJ9nITSu7iC4f8reutXRAVugPgS4=" + }, + { + "pubKey": "q4XyuUJbSGJaoRb3SmWzeX88V2dKB7sPTf72BAtQp3k=" + }, + { + "pubKey": "gTzKd1Ph5bpUw-JxTZiCe8RBfO-FsZiVYDYioQ-6dVg=" + }, + { + "pubKey": "NX4oaDLYEOmMUP_9pcEaZv5MJHJ4ZYAoxPQDxov7tRs=" + }, + { + "pubKey": "7fbk4oGQNlTW-tnWjVz8rWtKrtAicTsiNWgO98sqMyk=" + }, + { + "pubKey": "w1bfLpnd3rWu5JczB0nQfnE2S6nUCbx2AA7HDE48DQo=" + } + ], + "lastSeen": 1575915097869025000 + } + ] + }"#.to_string() + } + } +} diff --git a/src/main.rs b/src/main.rs index db0692ddee..894f1d0baf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,7 +54,7 @@ fn run(matches: &ArgMatches) { let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); // set up the route - let directory = directory::Client::new(); + let directory = directory::Client::new("https://directory.nymtech.net"); let route = directory.get_mixes(); let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); From e06a6f66eddbbb5be9e0b8175893664300a33e0d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 15:43:47 +0000 Subject: [PATCH 012/167] Tests running again --- src/clients/directory/healthcheck/requests.rs | 15 ++---------- src/clients/directory/mod.rs | 2 +- src/clients/mix.rs | 22 +++++++++--------- src/main.rs | 23 ++++++++++--------- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index dd08caa2f1..44787f6de1 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -1,6 +1,3 @@ -#[cfg(not(test))] -use mockito; - struct Requester { base_url: String } @@ -32,12 +29,10 @@ impl HealthCheckRequester for Requester { } } -struct HealthCheckResponse { - ok: bool, -} - mod healthcheck_requests { use super::*; + + #[cfg(test)] use mockito::mock; #[cfg(test)] @@ -72,9 +67,3 @@ mod healthcheck_requests { } } } - - -#[cfg(test)] -mod fixtures { - -} \ No newline at end of file diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 962fadd1e4..cf9c11fc52 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -8,7 +8,7 @@ mod healthcheck; mod metrics; mod presence; -trait DirectoryClient { +pub trait DirectoryClient { fn new(base_url: String) -> Self; fn get_topology(&self) -> Result; // fn send_provider_presence(&self) -> Result; diff --git a/src/clients/mix.rs b/src/clients/mix.rs index b9d78b241b..d7b24ba435 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -29,17 +29,17 @@ mod sending_a_sphinx_packet { #[test] fn works() { // arrange - let directory = Client::new(); - let message = "Hello, Sphinx!".as_bytes().to_vec(); - let mixes = directory.get_mixes(); - let destination = directory.get_destination(); - let delays = sphinx::header::delays::generate(2); - let packet = SphinxPacket::new(message, &mixes, &destination, &delays).unwrap(); - let mix_client = MixClient::new(); - let first_hop = mixes.first().unwrap(); - - // act - mix_client.send(packet, first_hop); +// let directory = Client::new(); +// let message = "Hello, Sphinx!".as_bytes().to_vec(); +// let mixes = directory.get_mixes(); +// let destination = directory.get_destination(); +// let delays = sphinx::header::delays::generate(2); +// let packet = SphinxPacket::new(message, &mixes, &destination, &delays).unwrap(); +// let mix_client = MixClient::new(); +// let first_hop = mixes.first().unwrap(); +// +// // act +// mix_client.send(packet, first_hop); // assert // wtf are we supposed to assert here? diff --git a/src/main.rs b/src/main.rs index 894f1d0baf..501733d9f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ use tokio::time::{Instant, interval_at}; use crate::clients::directory; use crate::clients::mix::MixClient; +use crate::clients::directory::{Client, DirectoryClient}; mod clients; @@ -54,20 +55,20 @@ fn run(matches: &ArgMatches) { let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); // set up the route - let directory = directory::Client::new("https://directory.nymtech.net"); - let route = directory.get_mixes(); - let destination = directory.get_destination(); + let directory= directory::Client::new("https://directory.nymtech.net".to_string()); +// let route = directory.get_mixes(); +// let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); - println!("delays: {:?}", delays); +// println!("delays: {:?}", delays); // build the packet - let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - - // send to mixnet - let mix_client = MixClient::new(); - let result = mix_client.send(packet, route.first().unwrap()).await; - println!("packet sent: {:?}", i); - i += 1; +// let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); +// +// // send to mixnet +// let mix_client = MixClient::new(); +// let result = mix_client.send(packet, route.first().unwrap()).await; +// println!("packet sent: {:?}", i); +// i += 1; } }) } From a2a87d72be59e35ebe1d35c1aa888da7f533bf48 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 15:49:13 +0000 Subject: [PATCH 013/167] Feeding a config object to the directory client --- src/clients/directory/mod.rs | 8 ++++++-- src/main.rs | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index cf9c11fc52..48f0b59a98 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -8,8 +8,12 @@ mod healthcheck; mod metrics; mod presence; +pub struct Config { + pub base_url: String, +} + pub trait DirectoryClient { - fn new(base_url: String) -> Self; + fn new(config : Config) -> Self; fn get_topology(&self) -> Result; // fn send_provider_presence(&self) -> Result; } @@ -17,7 +21,7 @@ pub trait DirectoryClient { pub struct Client {} impl DirectoryClient for Client { - fn new(base_url: String) -> Client { + fn new(config: Config) -> Client { let topology = retrieve_topology().unwrap(); Client {} } diff --git a/src/main.rs b/src/main.rs index 501733d9f5..7dbdbe919e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,7 +55,10 @@ fn run(matches: &ArgMatches) { let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); // set up the route - let directory= directory::Client::new("https://directory.nymtech.net".to_string()); + let directory_config = directory::Config { + base_url: "https://directory.nymtech.net".to_string() + }; + let directory= directory::Client::new(directory_config); // let route = directory.get_mixes(); // let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); From af28289904366cb7eca1c120ddddb00e55150f1e Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 16:12:11 +0000 Subject: [PATCH 014/167] directory: starting to work out how to store request types --- src/clients/directory/healthcheck/requests.rs | 6 +++--- src/clients/directory/mod.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index 44787f6de1..d973244eeb 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -1,14 +1,14 @@ -struct Requester { +pub struct Requester { base_url: String } -trait HealthCheckRequester { +pub trait HealthCheckRequester { fn new(base_url: String) -> Self; fn get(&self) -> bool; } impl HealthCheckRequester for Requester { - fn new(base_url: String) -> Requester { + fn new(base_url: String) -> Self { Requester { base_url, } diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 48f0b59a98..8d5615cda6 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,6 +1,7 @@ use sphinx::route::{Node as SphinxNode, Destination}; use crate::clients::directory::presence::models::Topology; use reqwest::Error; +use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckRequester}; //use serde::Deserialize; @@ -18,12 +19,17 @@ pub trait DirectoryClient { // fn send_provider_presence(&self) -> Result; } -pub struct Client {} +pub struct Client { + health_check: Requester, +} impl DirectoryClient for Client { fn new(config: Config) -> Client { let topology = retrieve_topology().unwrap(); - Client {} + let hcr: Requester = Requester::new(config.base_url); + Client { + health_check: hcr, + } } fn get_topology(&self) -> Result { From e47914a3921f8ddbb56214d569a2b928e07510de Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 16:54:00 +0000 Subject: [PATCH 015/167] directory: healthcheck requester now returns a Response<> --- src/clients/directory/healthcheck/requests.rs | 31 +++++++------------ src/clients/directory/mod.rs | 11 ++++++- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index d973244eeb..f221ea1831 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -1,10 +1,12 @@ +use reqwest::Response; + pub struct Requester { base_url: String } pub trait HealthCheckRequester { fn new(base_url: String) -> Self; - fn get(&self) -> bool; + fn get(&self) -> Result; } impl HealthCheckRequester for Requester { @@ -14,18 +16,9 @@ impl HealthCheckRequester for Requester { } } - fn get(&self) -> bool { + fn get(&self) -> Result { let url = format!("{}/healthcheck", self.base_url); - match reqwest::get(&url) { - Ok(response) => { - if response.status() == 200 { - true - } else { - false - } - }, - Err(e) => false, - } + reqwest::get(&url) } } @@ -40,30 +33,28 @@ mod healthcheck_requests { use super::*; #[test] - fn it_returns_false() { + #[should_panic] + fn it_returns_an_error() { let _m = mock("GET", "/healthcheck") .with_status(400) .create(); let req = Requester::new(mockito::server_url()); - - let expected = false; - assert_eq!(expected, req.get()); + assert_eq!(true, req.get().is_err()); } } #[cfg(test)] - mod on_a_200_with_ok_json { + mod on_a_200 { use super::*; #[test] - fn it_returns_true() { + fn it_returns_a_response_with_200_status() { let _m = mock("GET", "/healthcheck") .with_status(200) .create(); let req = Requester::new(mockito::server_url()); - let expected = true; - assert_eq!(expected, req.get()); + assert_eq!(true, req.get().is_ok()); } } } diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 8d5615cda6..45d713b450 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -15,12 +15,13 @@ pub struct Config { pub trait DirectoryClient { fn new(config : Config) -> Self; + fn health_check(&self) -> Result; fn get_topology(&self) -> Result; // fn send_provider_presence(&self) -> Result; } pub struct Client { - health_check: Requester, + pub health_check: Requester, } impl DirectoryClient for Client { @@ -32,6 +33,14 @@ impl DirectoryClient for Client { } } + fn health_check(&self) -> Result { + unimplemented!() +// match self.health_check.get() { +// true => Ok(true), +// false => Err("foo"), +// } + } + fn get_topology(&self) -> Result { unimplemented!() } From 63fa94394ad6466ec9dbdd773db1bba6dc500a92 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 16:54:37 +0000 Subject: [PATCH 016/167] Doing a healthcheck on the directory server before using it. --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main.rs b/src/main.rs index 7dbdbe919e..7e8c4b7604 100644 --- a/src/main.rs +++ b/src/main.rs @@ -54,11 +54,18 @@ fn run(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); + + // set up the route let directory_config = directory::Config { base_url: "https://directory.nymtech.net".to_string() }; let directory= directory::Client::new(directory_config); + + // make sure the Directory server is in fact running, panic if not + directory.health_check().expect("Directory health check failed, is the Directory server running?"); + + // let route = directory.get_mixes(); // let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); From e3c94b659297e083b819603a939ad0bb2842f45c Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 16:59:23 +0000 Subject: [PATCH 017/167] whitespace --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 7e8c4b7604..af2863d353 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,6 @@ fn run(matches: &ArgMatches) { // make sure the Directory server is in fact running, panic if not directory.health_check().expect("Directory health check failed, is the Directory server running?"); - // let route = directory.get_mixes(); // let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); From cd700a87609af6370a2404b3d40ecf835d9482c9 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 16:59:55 +0000 Subject: [PATCH 018/167] Having the full reqwest response returned --- src/clients/directory/healthcheck/requests.rs | 8 ++++---- src/clients/directory/mod.rs | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index f221ea1831..549f00ca80 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -6,7 +6,7 @@ pub struct Requester { pub trait HealthCheckRequester { fn new(base_url: String) -> Self; - fn get(&self) -> Result; + fn make_request(&self) -> Result; } impl HealthCheckRequester for Requester { @@ -16,7 +16,7 @@ impl HealthCheckRequester for Requester { } } - fn get(&self) -> Result { + fn make_request(&self) -> Result { let url = format!("{}/healthcheck", self.base_url); reqwest::get(&url) } @@ -39,7 +39,7 @@ mod healthcheck_requests { .with_status(400) .create(); let req = Requester::new(mockito::server_url()); - assert_eq!(true, req.get().is_err()); + assert_eq!(true, req.make_request().is_err()); } } @@ -54,7 +54,7 @@ mod healthcheck_requests { .create(); let req = Requester::new(mockito::server_url()); - assert_eq!(true, req.get().is_ok()); + assert_eq!(true, req.make_request().is_ok()); } } } diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 45d713b450..e2973013ae 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,6 +1,6 @@ use sphinx::route::{Node as SphinxNode, Destination}; use crate::clients::directory::presence::models::Topology; -use reqwest::Error; +use reqwest::{Error}; use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckRequester}; //use serde::Deserialize; @@ -15,7 +15,7 @@ pub struct Config { pub trait DirectoryClient { fn new(config : Config) -> Self; - fn health_check(&self) -> Result; + fn health_check(&self) -> Result; fn get_topology(&self) -> Result; // fn send_provider_presence(&self) -> Result; } @@ -33,12 +33,8 @@ impl DirectoryClient for Client { } } - fn health_check(&self) -> Result { - unimplemented!() -// match self.health_check.get() { -// true => Ok(true), -// false => Err("foo"), -// } + fn health_check(&self) -> Result { + self.health_check.make_request() } fn get_topology(&self) -> Result { From ed81b160107aff914100d3d73a3b2d6c798dc6b8 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 17:27:46 +0000 Subject: [PATCH 019/167] directory: using stored requester instead of proxy method --- src/clients/directory/healthcheck/requests.rs | 16 ++---- src/clients/directory/mod.rs | 2 +- src/main.rs | 51 ++++++++++--------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index 549f00ca80..652599b0b4 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -1,7 +1,7 @@ use reqwest::Response; pub struct Requester { - base_url: String + base_url: String, } pub trait HealthCheckRequester { @@ -11,13 +11,11 @@ pub trait HealthCheckRequester { impl HealthCheckRequester for Requester { fn new(base_url: String) -> Self { - Requester { - base_url, - } + Requester { base_url } } fn make_request(&self) -> Result { - let url = format!("{}/healthcheck", self.base_url); + let url = format!("{}/healthcheck", self.base_url); reqwest::get(&url) } } @@ -35,9 +33,7 @@ mod healthcheck_requests { #[test] #[should_panic] fn it_returns_an_error() { - let _m = mock("GET", "/healthcheck") - .with_status(400) - .create(); + let _m = mock("GET", "/healthcheck").with_status(400).create(); let req = Requester::new(mockito::server_url()); assert_eq!(true, req.make_request().is_err()); } @@ -49,9 +45,7 @@ mod healthcheck_requests { #[test] fn it_returns_a_response_with_200_status() { - let _m = mock("GET", "/healthcheck") - .with_status(200) - .create(); + let _m = mock("GET", "/healthcheck").with_status(200).create(); let req = Requester::new(mockito::server_url()); assert_eq!(true, req.make_request().is_ok()); diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index e2973013ae..690843549f 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -5,7 +5,7 @@ use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckReq //use serde::Deserialize; -mod healthcheck; +pub mod healthcheck; mod metrics; mod presence; diff --git a/src/main.rs b/src/main.rs index af2863d353..c2ee3ae463 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,18 +3,17 @@ use std::time::Duration; use clap::{App, Arg, ArgMatches, SubCommand}; use tokio::runtime::Runtime; -use tokio::time::{Instant, interval_at}; +use tokio::time::{interval_at, Instant}; use crate::clients::directory; -use crate::clients::mix::MixClient; -use crate::clients::directory::{Client, DirectoryClient}; +use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckRequester}; +use crate::clients::directory::DirectoryClient; mod clients; const TCP_SOCKET_TYPE: &str = "tcp"; const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; - fn execute(matches: ArgMatches) -> Result<(), String> { match matches.subcommand() { ("init", Some(m)) => Ok(init(m)), @@ -40,7 +39,10 @@ fn init(matches: &ArgMatches) { fn run(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); - println!("Going to start client with custom config of: {:?}", custom_cfg); + println!( + "Going to start client with custom config of: {:?}", + custom_cfg + ); // Create the runtime, probably later move it to Client struct itself? let mut rt = Runtime::new().unwrap(); @@ -54,30 +56,31 @@ fn run(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - - // set up the route let directory_config = directory::Config { - base_url: "https://directory.nymtech.net".to_string() + base_url: "https://directory.nymtech.net".to_string(), }; - let directory= directory::Client::new(directory_config); + let directory = clients::directory::Client::new(directory_config); // make sure the Directory server is in fact running, panic if not - directory.health_check().expect("Directory health check failed, is the Directory server running?"); + directory + .health_check + .make_request() + .expect("Directory health check failed, is the Directory server running?"); -// let route = directory.get_mixes(); -// let destination = directory.get_destination(); + // let route = directory.get_mixes(); + // let destination = directory.get_destination(); let delays = sphinx::header::delays::generate(2); -// println!("delays: {:?}", delays); + // println!("delays: {:?}", delays); // build the packet -// let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); -// -// // send to mixnet -// let mix_client = MixClient::new(); -// let result = mix_client.send(packet, route.first().unwrap()).await; -// println!("packet sent: {:?}", i); -// i += 1; + // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + // + // // send to mixnet + // let mix_client = MixClient::new(); + // let result = mix_client.send(packet, route.first().unwrap()).await; + // println!("packet sent: {:?}", i); + // i += 1; } }) } @@ -87,17 +90,19 @@ fn socket(matches: &ArgMatches) { let socket_type = match matches.value_of("socketType").unwrap() { TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, WEBSOCKET_SOCKET_TYPE => WEBSOCKET_SOCKET_TYPE, - other => panic!("Invalid socket type provided - {}", other) + other => panic!("Invalid socket type provided - {}", other), }; let port = match matches.value_of("port").unwrap().parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; - println!("Going to start socket client with custom config of: {:?}", custom_cfg); + println!( + "Going to start socket client with custom config of: {:?}", + custom_cfg + ); println!("Using the following socket type: {:?}", socket_type); println!("On the following port: {:?}", port); - } // TODO: perhaps more subcommands and/or args to distinguish between coco client and mix client From 3e7476092a924a34b03eff09e237a9ad038f95da Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 17:29:15 +0000 Subject: [PATCH 020/167] directory: removing proxy method --- src/clients/directory/mod.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 690843549f..a9ae39b49e 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -15,7 +15,6 @@ pub struct Config { pub trait DirectoryClient { fn new(config : Config) -> Self; - fn health_check(&self) -> Result; fn get_topology(&self) -> Result; // fn send_provider_presence(&self) -> Result; } @@ -33,10 +32,6 @@ impl DirectoryClient for Client { } } - fn health_check(&self) -> Result { - self.health_check.make_request() - } - fn get_topology(&self) -> Result { unimplemented!() } From 78d3cbbe2c613b91bb414c47b0a18c1e85267c5c Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 17:31:23 +0000 Subject: [PATCH 021/167] directory: shortening healthcheck request names --- src/clients/directory/healthcheck/requests.rs | 18 +++++++++--------- src/clients/directory/mod.rs | 6 +++--- src/main.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/healthcheck/requests.rs index 652599b0b4..bf9d8c4488 100644 --- a/src/clients/directory/healthcheck/requests.rs +++ b/src/clients/directory/healthcheck/requests.rs @@ -1,20 +1,20 @@ use reqwest::Response; -pub struct Requester { +pub struct Request { base_url: String, } pub trait HealthCheckRequester { fn new(base_url: String) -> Self; - fn make_request(&self) -> Result; + fn get(&self) -> Result; } -impl HealthCheckRequester for Requester { +impl HealthCheckRequester for Request { fn new(base_url: String) -> Self { - Requester { base_url } + Request { base_url } } - fn make_request(&self) -> Result { + fn get(&self) -> Result { let url = format!("{}/healthcheck", self.base_url); reqwest::get(&url) } @@ -34,8 +34,8 @@ mod healthcheck_requests { #[should_panic] fn it_returns_an_error() { let _m = mock("GET", "/healthcheck").with_status(400).create(); - let req = Requester::new(mockito::server_url()); - assert_eq!(true, req.make_request().is_err()); + let req = Request::new(mockito::server_url()); + assert_eq!(true, req.get().is_err()); } } @@ -46,9 +46,9 @@ mod healthcheck_requests { #[test] fn it_returns_a_response_with_200_status() { let _m = mock("GET", "/healthcheck").with_status(200).create(); - let req = Requester::new(mockito::server_url()); + let req = Request::new(mockito::server_url()); - assert_eq!(true, req.make_request().is_ok()); + assert_eq!(true, req.get().is_ok()); } } } diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index a9ae39b49e..440e893eb1 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,7 +1,7 @@ use sphinx::route::{Node as SphinxNode, Destination}; use crate::clients::directory::presence::models::Topology; use reqwest::{Error}; -use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckRequester}; +use crate::clients::directory::healthcheck::requests::{Request, HealthCheckRequester}; //use serde::Deserialize; @@ -20,13 +20,13 @@ pub trait DirectoryClient { } pub struct Client { - pub health_check: Requester, + pub health_check: Request, } impl DirectoryClient for Client { fn new(config: Config) -> Client { let topology = retrieve_topology().unwrap(); - let hcr: Requester = Requester::new(config.base_url); + let hcr: Request = Request::new(config.base_url); Client { health_check: hcr, } diff --git a/src/main.rs b/src/main.rs index c2ee3ae463..5d7fbcfe72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; use crate::clients::directory; -use crate::clients::directory::healthcheck::requests::{Requester, HealthCheckRequester}; +use crate::clients::directory::healthcheck::requests::{Request, HealthCheckRequester}; use crate::clients::directory::DirectoryClient; mod clients; @@ -65,7 +65,7 @@ fn run(matches: &ArgMatches) { // make sure the Directory server is in fact running, panic if not directory .health_check - .make_request() + .get() .expect("Directory health check failed, is the Directory server running?"); // let route = directory.get_mixes(); From e8c96da9da3bc3b19ae0039e6099fcd77132a4d3 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 17:39:05 +0000 Subject: [PATCH 022/167] Moving requests into their own directory --- src/clients/directory/healthcheck/mod.rs | 1 - src/clients/directory/mod.rs | 4 ++-- .../{healthcheck/requests.rs => requests/health_check_get.rs} | 0 src/clients/directory/requests/mod.rs | 1 + src/main.rs | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 src/clients/directory/healthcheck/mod.rs rename src/clients/directory/{healthcheck/requests.rs => requests/health_check_get.rs} (100%) create mode 100644 src/clients/directory/requests/mod.rs diff --git a/src/clients/directory/healthcheck/mod.rs b/src/clients/directory/healthcheck/mod.rs deleted file mode 100644 index 4e83d422e0..0000000000 --- a/src/clients/directory/healthcheck/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod requests; \ No newline at end of file diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 440e893eb1..d6b9c647ea 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,11 +1,11 @@ use sphinx::route::{Node as SphinxNode, Destination}; use crate::clients::directory::presence::models::Topology; use reqwest::{Error}; -use crate::clients::directory::healthcheck::requests::{Request, HealthCheckRequester}; +use crate::clients::directory::requests::health_check_get::{Request, HealthCheckRequester}; //use serde::Deserialize; -pub mod healthcheck; +pub mod requests; mod metrics; mod presence; diff --git a/src/clients/directory/healthcheck/requests.rs b/src/clients/directory/requests/health_check_get.rs similarity index 100% rename from src/clients/directory/healthcheck/requests.rs rename to src/clients/directory/requests/health_check_get.rs diff --git a/src/clients/directory/requests/mod.rs b/src/clients/directory/requests/mod.rs new file mode 100644 index 0000000000..5b431dea62 --- /dev/null +++ b/src/clients/directory/requests/mod.rs @@ -0,0 +1 @@ +pub mod health_check_get; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5d7fbcfe72..c0c6c0525c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; use crate::clients::directory; -use crate::clients::directory::healthcheck::requests::{Request, HealthCheckRequester}; use crate::clients::directory::DirectoryClient; +use crate::clients::directory::requests::health_check_get::HealthCheckRequester; mod clients; From 8056dd0fc0c136fae8e107d071e0aaa8daebd9fb Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 17:42:13 +0000 Subject: [PATCH 023/167] directory: setting up all requests --- src/clients/directory/requests/metrics_mixes_get.rs | 0 src/clients/directory/requests/metrics_mixes_post.rs | 0 src/clients/directory/requests/mod.rs | 8 +++++++- src/clients/directory/requests/presence_coconodes_post.rs | 0 src/clients/directory/requests/presence_mixnodes_post.rs | 0 src/clients/directory/requests/presence_providers_post.rs | 0 src/clients/directory/requests/presence_topology_get.rs | 0 7 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/clients/directory/requests/metrics_mixes_get.rs create mode 100644 src/clients/directory/requests/metrics_mixes_post.rs create mode 100644 src/clients/directory/requests/presence_coconodes_post.rs create mode 100644 src/clients/directory/requests/presence_mixnodes_post.rs create mode 100644 src/clients/directory/requests/presence_providers_post.rs create mode 100644 src/clients/directory/requests/presence_topology_get.rs diff --git a/src/clients/directory/requests/metrics_mixes_get.rs b/src/clients/directory/requests/metrics_mixes_get.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/clients/directory/requests/metrics_mixes_post.rs b/src/clients/directory/requests/metrics_mixes_post.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/clients/directory/requests/mod.rs b/src/clients/directory/requests/mod.rs index 5b431dea62..5205f4c9b0 100644 --- a/src/clients/directory/requests/mod.rs +++ b/src/clients/directory/requests/mod.rs @@ -1 +1,7 @@ -pub mod health_check_get; \ No newline at end of file +pub mod health_check_get; +pub mod metrics_mixes_get; +pub mod metrics_mixes_post; +pub mod presence_coconodes_post; +pub mod presence_mixnodes_post; +pub mod presence_providers_post; +pub mod presence_topology_get; \ No newline at end of file diff --git a/src/clients/directory/requests/presence_coconodes_post.rs b/src/clients/directory/requests/presence_coconodes_post.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/clients/directory/requests/presence_mixnodes_post.rs b/src/clients/directory/requests/presence_mixnodes_post.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs new file mode 100644 index 0000000000..e69de29bb2 From ce5af2bc04aea2778f9a33e0275a3f749c361160 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 18:02:07 +0000 Subject: [PATCH 024/167] directory: moving presence models --- src/clients/directory/metrics/mod.rs | 1 - src/clients/directory/metrics/requests.rs | 0 src/clients/directory/mod.rs | 3 +- .../{presence/requests.rs => presence.rs} | 43 +++++++++++++++---- src/clients/directory/presence/mod.rs | 2 - src/clients/directory/presence/models.rs | 34 --------------- 6 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 src/clients/directory/metrics/mod.rs delete mode 100644 src/clients/directory/metrics/requests.rs rename src/clients/directory/{presence/requests.rs => presence.rs} (95%) delete mode 100644 src/clients/directory/presence/mod.rs delete mode 100644 src/clients/directory/presence/models.rs diff --git a/src/clients/directory/metrics/mod.rs b/src/clients/directory/metrics/mod.rs deleted file mode 100644 index 4e83d422e0..0000000000 --- a/src/clients/directory/metrics/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod requests; \ No newline at end of file diff --git a/src/clients/directory/metrics/requests.rs b/src/clients/directory/metrics/requests.rs deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index d6b9c647ea..bd70ecafbd 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,12 +1,11 @@ use sphinx::route::{Node as SphinxNode, Destination}; -use crate::clients::directory::presence::models::Topology; use reqwest::{Error}; use crate::clients::directory::requests::health_check_get::{Request, HealthCheckRequester}; +use crate::clients::directory::presence::Topology; //use serde::Deserialize; pub mod requests; -mod metrics; mod presence; pub struct Config { diff --git a/src/clients/directory/presence/requests.rs b/src/clients/directory/presence.rs similarity index 95% rename from src/clients/directory/presence/requests.rs rename to src/clients/directory/presence.rs index 346034b297..c443957b2d 100644 --- a/src/clients/directory/presence/requests.rs +++ b/src/clients/directory/presence.rs @@ -1,13 +1,41 @@ +use serde::Deserialize; +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct CocoPresence { + host: String, + pub_key: String, + last_seen: i64, +} +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct MixNodePresence{ + host: String, + pub_key: String, + layer: u64, + last_seen: i64, +} -#[cfg(test)] -mod presence_tests { -// use super::*; +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct MixProviderPresence{ + host: String, + pub_key: String, +} - mod fixtures { - fn topology_response_json() -> String { - r#"{ +// Topology shows us the current state of the overall Nym network +#[derive(Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Topology { + coco_nodes: Vec, + mix_nodes: Vec, + mix_provider_nodes: Vec +} + +mod fixtures { + fn topology_response_json() -> String { + r#"{ "cocoNodes": [ { "host": "3.8.244.109:4000", @@ -239,6 +267,5 @@ mod presence_tests { } ] }"#.to_string() - } } -} +} \ No newline at end of file diff --git a/src/clients/directory/presence/mod.rs b/src/clients/directory/presence/mod.rs deleted file mode 100644 index 270cb4e5ed..0000000000 --- a/src/clients/directory/presence/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod requests; -pub mod models; diff --git a/src/clients/directory/presence/models.rs b/src/clients/directory/presence/models.rs deleted file mode 100644 index 34890b132d..0000000000 --- a/src/clients/directory/presence/models.rs +++ /dev/null @@ -1,34 +0,0 @@ -use serde::Deserialize; - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct CocoPresence { - host: String, - pub_key: String, - last_seen: i64, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MixNodePresence{ - host: String, - pub_key: String, - layer: u64, - last_seen: i64, -} - -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct MixProviderPresence{ - host: String, - pub_key: String, -} - -// Topology shows us the current state of the overall Nym network -#[derive(Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct Topology { - coco_nodes: Vec, - mix_nodes: Vec, - mix_provider_nodes: Vec -} From fc4e4168db2956167bead3673056ce5382a4ad98 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 18:24:51 +0000 Subject: [PATCH 025/167] WIP --- .../requests/presence_topology_get.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index e69de29bb2..28d230d283 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -0,0 +1,58 @@ +use reqwest::Response; +use crate::clients::directory::presence::Topology; + +use serde::Deserialize; + + +pub struct Request { + base_url: String, +} + +pub trait PresenceTopologyGetRequester { + fn new(base_url: String) -> Self; + fn get(&self) -> Result; +} + +impl PresenceTopologyGetRequester for Request { + fn new(base_url: String) -> Self { + Request { base_url } + } + + fn get(&self) -> Result { + let url = format!("{}/topology", self.base_url); + reqwest::get(&url)?.json()? + } +} + +mod healthcheck_requests { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + #[should_panic] + fn it_returns_an_error() { + let _m = mock("GET", "/healthcheck").with_status(400).create(); + let req = Request::new(mockito::server_url()); + assert_eq!(true, req.get().is_err()); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + + #[test] + fn it_returns_a_response_with_200_status() { + let _m = mock("GET", "/healthcheck").with_status(200).create(); + let req = Request::new(mockito::server_url()); + + assert_eq!(true, req.get().is_ok()); + } + } +} From c8c178c7e728e23e17afb4e35e578f12e2545b1a Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 18:34:08 +0000 Subject: [PATCH 026/167] Fixing compiler warning --- src/clients/directory/requests/health_check_get.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/clients/directory/requests/health_check_get.rs b/src/clients/directory/requests/health_check_get.rs index bf9d8c4488..b984471b1b 100644 --- a/src/clients/directory/requests/health_check_get.rs +++ b/src/clients/directory/requests/health_check_get.rs @@ -20,6 +20,7 @@ impl HealthCheckRequester for Request { } } +#[cfg(test)] mod healthcheck_requests { use super::*; From 492da937272e301ffc9e4a1d08d093ae2357a3fd Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 19:06:38 +0000 Subject: [PATCH 027/167] Adding serde_json, mostly for testing purposes --- Cargo.lock | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 824624b6e5..e92b1b450d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,6 +891,7 @@ dependencies = [ "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "sphinx 0.1.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 9679ba337c..52aa44a2c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ edition = "2018" clap = "2.33.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0.44" sphinx = { path = "../sphinx" } tokio = { version = "0.2", features = ["full"] } - [dev-dependencies] mockito = "0.22.0" \ No newline at end of file From d814a3c41ab71f756870a9a4b50adde4d2542163 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 19:16:48 +0000 Subject: [PATCH 028/167] directory: further tests on topology get request --- Cargo.toml | 4 +- src/clients/directory/mod.rs | 26 +- src/clients/directory/presence.rs | 263 +---------------- .../requests/presence_topology_get.rs | 278 +++++++++++++++++- src/clients/mix.rs | 33 ++- src/main.rs | 2 +- 6 files changed, 302 insertions(+), 304 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 52aa44a2c0..8e3a3a0d65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,9 @@ edition = "2018" clap = "2.33.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0.44" sphinx = { path = "../sphinx" } tokio = { version = "0.2", features = ["full"] } [dev-dependencies] -mockito = "0.22.0" \ No newline at end of file +mockito = "0.22.0" +serde_json = "1.0.44" diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index bd70ecafbd..ab35940484 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,21 +1,18 @@ -use sphinx::route::{Node as SphinxNode, Destination}; -use reqwest::{Error}; -use crate::clients::directory::requests::health_check_get::{Request, HealthCheckRequester}; use crate::clients::directory::presence::Topology; +use crate::clients::directory::requests::health_check_get::{HealthCheckRequester, Request}; +use reqwest::Error; -//use serde::Deserialize; - -pub mod requests; mod presence; +pub mod requests; pub struct Config { pub base_url: String, } pub trait DirectoryClient { - fn new(config : Config) -> Self; + fn new(config: Config) -> Self; fn get_topology(&self) -> Result; -// fn send_provider_presence(&self) -> Result; + // fn send_provider_presence(&self) -> Result; } pub struct Client { @@ -24,22 +21,11 @@ pub struct Client { impl DirectoryClient for Client { fn new(config: Config) -> Client { - let topology = retrieve_topology().unwrap(); let hcr: Request = Request::new(config.base_url); - Client { - health_check: hcr, - } + Client { health_check: hcr } } fn get_topology(&self) -> Result { unimplemented!() } } - -fn retrieve_topology() -> Result { - let topology: Topology = reqwest::get("https://directory.nymtech.net/api/presence/topology")? - .json()?; - Ok(topology) -} - - diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index c443957b2d..65148097e6 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -1,271 +1,34 @@ -use serde::Deserialize; +use serde::{Deserialize, Serialize}; -#[derive(Deserialize)] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CocoPresence { - host: String, - pub_key: String, - last_seen: i64, + pub host: String, + pub pub_key: String, + pub last_seen: i64, } -#[derive(Deserialize)] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub struct MixNodePresence{ +pub struct MixNodePresence { host: String, pub_key: String, layer: u64, last_seen: i64, } -#[derive(Deserialize)] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] -pub struct MixProviderPresence{ +pub struct MixProviderPresence { host: String, pub_key: String, } // Topology shows us the current state of the overall Nym network -#[derive(Deserialize)] +#[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Topology { - coco_nodes: Vec, - mix_nodes: Vec, - mix_provider_nodes: Vec + pub coco_nodes: Vec, + pub mix_nodes: Vec, + pub mix_provider_nodes: Vec, } - -mod fixtures { - fn topology_response_json() -> String { - r#"{ - "cocoNodes": [ - { - "host": "3.8.244.109:4000", - "pubKey": "AAAAAAAAAAEKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEFuhRpy4HfcuxwcRI9sIWMo_LVmbk19g1gfMRlBrmZqoEQL6rDApVLZ9eMp-5IQK8WLlZpWf4Zjy7kZolARAyp_rHUQkH4PrDjgoPrKbm6qK_iejYpL7qx28Q3VeInMpwMIMaSbbW9y36sEVtGc2I0Iu5vS0sp8ESiVlQ5NaBz72deZ8oKJJ4IEPPHP99-b0UQX80fVIrNM88mMzKy0bHri9NFlmIG-e0G1cqmw_ry3XWGQkcr1M5RuNa6oX50w5QawAEVxd5FP5bE8bS4x54Csof11sQWUTwMp6Q7_3H7ZCTSlKSqujlOhmfqSHfGPO2sDIYPHDhDzjakZpKAZWWhn_hiR6DfPpomQ01ZYUhVKKSMxz7_VPjsQplP0bZXA2gfnkADUN8UQ0N9g_usIw73r4aZsOviMsRM8oByvsjVfUWc4_HTLSdnQyImFkHz9CiCmrIYL2dYQRePRatWggvBAyeRzntxI4jDqLKiBdi54ZlAKgV6MCRaJ7Bu7BtmLXrtK4sawAED3QYxuvOSZrbZdUr4yG-U9yVvJ9Klkf-5Mo4EYp3qTL2KBB6_LrZepjAQqp486YkZ03mTIezcsZ48EboXVTWKBZ3QnTI5tX-j4gGxQb7klOJc97qJkDxsvpz4F0ChgCUIZhpIItWHia7_R3Gi-b5siLIdQdUho9isn3kiDGm6t0NED2Bgy3ZxxQwzqsBZm4kPr2_fPX4YyvIoP9895YcGjZyE5iiRC_TE41RJmB1GZYdxegTMq3lNDllKgiqaiPgawAEJASDkmZHTwlg9YOev5OWpQD-FnhPkqVNo_QcDyRu9eoGcWSGFp2sYqjG2SpmiXq0VNnAO7AcKxRzDFu7TjfhlU3Kt0uTKIcrWVU1zFNbJNMjYEq90pp50nowwx8INz20IXET2ZNX6kIXYFCsEvPLZFlG2OoL6xg3uQS1qMl3lIS_VxdO_JfVe0rT65WsJ_P4Nkc1jYiuNPHY6d_iFO0BVYqX0sOCX73GC_TT13BR0jnPwDAVw0rGtYHsXBb8TKOsawAEZIClauuT1V3qOZnb7uRZhFXO-PKTxgc1LCzJt2ChOrMZaBpjlkf3IPpJ2UF4JH4kGaDeBf2k_S-FLAs3drK21efbi5P6_a4QTxAiiRimXGoQIyvOg462s6kP_ZRFufo8YYQHS4olaOeqU4564dNskg_uBPsFMz_2GNOhmn_15cJqP1jfkyD49Z16GTS5YLHgVl9bJKqyvLuypsToLbt1BJzipEP0L2OohuRm-_MvqvwwWKyjNQsubgee1K728d9AawAEBkGggcNVCtXyhoSqi3_w0tVxtkAYeud8sBeAtZHGs06me_QL8co0MFLlO-zdkUb4ZBq08rFEbgLOma8_3whleM8NIPaHNISp1q3IsIhB5zdXcZoGsqLixODBFHtID3YEHAlr4f9T_yh11yJ95xGCl_6Y37hpwLQVGyrfSfccM24mVFqnV3TT5Wdq3ile-jesUx1Q2G1yK_xVqc6itmk-kDuBjyZgzYi1-jsIXAjnhM9G7t8J_Bv5yGGZhLK2dCzM=", - "type": "validator", - "lastSeen": 1575915097085539300 - }, - { - "host": "3.9.129.61:4000", - "pubKey": "AAAAAAAAAAMKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEEv6RMevAQmLGkeK0uJKnMPPAtm8GgXjWSQijYdnxlPh5SJSNeJUbPZKWFFWdk8yIFXKa8jnzETtdGFKgUUt5AVUDpTBmEdwaHCzlFhXrttshy0V5OhPUlV8cGABmxbagMYm0bFPg0r-snSkrB9YG6wqJYQVeIMOCGYCPbHmDA8R_0-h8VkRKWs1d9KvQOK4kShqgZtYN71KJW8uDE4q2jsGDVvxFt1AgmU9b93xsXF17KrpZy5WxlLZ73HtnTD_oawAED4vd_rK-Kx_n8x_OdDiiEOPUlYDlDCQUqenU9XHKH3B6ijfkJ368wd3LDDVStjDwNORrAyUSw_VlSNUpd1XLC8d17gTaIq5ZI2fWuwwZaoN1JCsYU8fQ6USgtIehQX7IPP8EkFuNmuCBCmpr4schtYniGe9J8Q4dsV-TYPr2uLJkdx1r7luzF--I22k7NfQQM14QDci_0kgrgmZ54CJGkjXyOhCppBXg3fqLC6aFvT3ZocfiiXBJt0huGgPMDtYsawAECLh8KUdNsDolERwJ8v04bS5jI_KKf7uUnCHWuCELwbJSUI3OK1ufS1qSpauvSzVQSbrhEzrEfwQn4VtxQxJlX4UdDU-R-hafiZvVC6DLLAbuORBAC3FScn9W58CnezH4DvCp_w7nftDfdxeuungbZT9XaxS3iNC6PnFsWF6WM3DxMwrzOrFe6wEEoTSPe1mcUDrtwM5UksIvJr6MBRAXrdl0IdBTQr7cLwKe_KYi4siwdjfJEJtOh7oxQBxBg2UkawAEJAPZK2Gg2MQwpxdDT24lNQHF7FVfkO_LuhJwn0RbwNDSVeA4P6-tWL5TkCpqr8xYHfwQ6Z3ILfpGCZr8PspwIoRzqZHQ16f8Pq9xnr0hLEI9BOQU0FS2EtuyPgju5iwsAJAfehUzu6kNLphuLGsXoIZdXDG5mbylwh9JzAVXTwgaR0hNqyXVJxgbt7jcYaSEBFcMGV-hjXyVVNzBleE-G9o_noI_KWU4Ce7K-qOMcewMKfy_VEw-gVaD6dHz6AMoawAEE9XuOLwRttvKybAssZ9gsK-_YRUwuFOeRDIr3NX___9bx6pCc18adCIlH_8EJWFwXZ05ZpNNE88mYx7ZQ3aqaArZJRoWeZeKhqH_s05V10xbzkYX71G5cqz--8vr9ZlQRb2BeETF_Tdq_PLk7qbT8WTGIoq7ZwyDRQTgzvkCgyzj_hBLh2o7sSVNgUo38SFUTMn7YtvVFYlSrTDE3WKE-T-nh5SWdDBxgDTc3Bw8JpzNH-WkoJ4Lim7sB4Op1gEUawAEW4-kenlffwsNr_3b3aV0YuusLpxB03sxPzQ5B0CWNiVtbja1Z4tWhKGUUrdq_eUgMV0y5Of-BqNi5FspAQnhJBFSSxtOzRGV1h3qyUTksfZyed9z8zPI-ZPP9XXm7hYgJgDz_kxte-NfS9UG9q5AZetHUN4kGxXutjjzfUQZ9yTvhBKgKgTI2Dp_R_jZrWQ8F1BoWzIJzjddT1K2MvCQEkARYw08isbOeFmCwgVUcjxYZO45WyOmLQA7QJRL9WvA=", - "type": "validator", - "lastSeen": 1575915097388409000 - }, - { - "host": "3.9.222.1:4000", - "pubKey": "AAAAAAAAAAQKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAECh9xcxpjOp1r7kiNIgrI9GgAlvXwgHkTchOxUiyOzTq6FDWdGN64KiC3NDeyGTg8FmzvGzS3jREeJqOdr4G9ZGtWkauAITgLFiH62t-YntRslhr8_1shxlmzKiNKJN_QFflEq79pZIlWtp3N8LIHMvXRtl-zt2DMze4s02XDmEkviyVE4CkQUDtCc-2MfPT4JcmEFqtFIxjrXn18SbYg3c6XUQHsGIkuDrKuCTRlpC8kvmM0uVoIeWdmwDlZk4jUawAEJhRwK5ozjqIWRP1bFzBPS9VhaJnfKU9PeFYtN5beiAHrYr2ylIB3yDfmAQUdKDowDUm5nfJATejEjEnrTGxh70QtfoNV391rSns3F71tBwY62KLaNr8qnVfeSFHV3FcQTMHHF_8mDb5_11Rj6aiMvW0y6eetHo7CDPMdEyDPmok_U2ZM5BzOUnwjT21HtnvcKxKKwHJ_QGfnAHPyDIhNOMgxJCrVazOidLCHeYGpyCLw1ipeTyKOQX0_ByB8dH6AawAEGV1GuF5SSlT67B1ityPJK2ZwXjeeKB4gGdCG3qRtWxLTZfGhVm7YAYm2f5tw_wrsJAZ9FubVhateGg0ZN67NxZtsvOOejXz6743f7ijnQopPgd_8pH-iVf6BEcSO8ZdcHxNRUTayzjVLs99bwMo2zaPevW4X4G_bN4mh---aPkdGYHwaiklzUhqJ-eqycrYAFyjyEXaPBXLQm1rpczqluNvnKbd8Q9LZWukgm7_uWv_HxufIvdWgoq8bAt78UU3oawAEP9VDehhqrQG5-WHMB66XVxo1TgMM8aVV0SwAq3lCRkpiFBz_9kw8T1F9Hx2AiNrEGT1QLbdMkpms1cG_5gBBahQofdt_NmUs1jfTFXY9iyMy1Q7A6ZYaLP8Z6q-orc1cKqySY-BJZQ_CpGFfXS0OVniFDQ6v78ytPK7K-yRgT1PxFgm3rZqrG0Tjbrpsg2PUL5S5fuXfMhUosP0uoLj0D1guWAR9Y7kfFBIXaTSFMoa8fghVBUTRNhK9f72a8SxQawAEOiv71taLjKqaaWQ_QjcDhWbvjG1EnsCyI0toNjGkcF19x4Vk-5NC96_4ioUGz404IC0XN03roRnibRT_78D9vZFVCWCqve9EjdF5TcApx03zIP4JT2g2q0MKIGgGrwt4Pz6LO6yOfMm7B8Yraps8IV-nP1w7K1m9XKP_FvH8egl5GHJe-_omlC2YyL_b28jMLENbxDFD-3KPjZFBhSLrRukX2PlayYTwEiTtokA2R9_11vQvJgP8KFEjGHg6zsAMawAEBn2H_hz2knb8ltnpEA5YSKVcV3nUtojkCNi_WUz7xUKd7efw1oI_lbnKrS7HkyC0JkQUZ1pCWUlSXNmgjMEhsn823a1LFzpV7rOv4vayYvvFX61hB9R78VjpyxJiYpDwRZLiUY3AK4WY8NqFDbjXR7rT4CkFHEf-VhSQQ8ZNvlpod1nmeVQVizHH9e7Tq7wsWz-LWEk3Hx6LmcrgDsL79LZYG9JXU5IdvG8RvLNx9cSwEI8yxcchpISAaot7UoYQ=", - "type": "validator", - "lastSeen": 1575915094734973000 - }, - { - "host": "3.9.102.214:4000", - "pubKey": "AAAAAAAAAAIKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEOVCUN3EwiVroS5-TOq2o7hYSxphK9X0G23N-IBZ0Tr1Rl8XEiJ-OEy0rqnAKwmhAZJWnx3u8oXqbZtOWIZmzQSpcoxhgwfhdmTZJCqT2RVzZyeFItX4sVeilEP3z2xdsJs8-a1kg6UZnx1s1BNLBo7eZrreZygWojPCIDBn03fSAflXoVc5PpY2CGy5MA_IgWgSYBHDdoZEtigp_amjqK7Us44Db20XpLxMXfbahiqa7WKNnMgi6Ca2H67VtaaD8awAEF3zbE1nZRAa7a8vbU25c80YBYJBaW8P6FwXQI-K0Xk5MakwYeMMnIrm6w6IS_0XAO5YlD453GLqnxY8H1BEnRpfOnT7PE4el9mJ8MuYQMo6R2up0lGCmYM0YA9FORjroM3ng69SEPfJPCReG7LfJkERl_m2U403ertDRBYrlqCDagDfyI500srBcMrjSvV3oNouyyx3yZUrjLQfbHhDteQFsYdmakJs8Y-Q9-5MXCcrz6Qa4xwv522Euv0CCxkHcawAEYjfsU_zDhUZA1ey1aquWXlFOnx-iEALqxW1slDYHwQ1M2SILc-v_E6i1doa5e_bAZHVezBHFAlaNAVedNyHFFJxYAqAK3hbzbvl2glw3Q6h_rTXElymloqtaqVFIJ-oUWWOHsZBmu8EDA-HzvGCiBa_GbRaVfh2lE4ObeMXoJrEm_5dbxxeEic2l3IYeIz40N9ooQQOkQcOZdY4AXWYCavIAwWEJBjLtptJgCLu9a_zM1S5GsiyJHpdDs46WbP0EawAEWZ-95Sf0YAHujxRNLdXgpqe0ZF8loVwzZfvyMvqaxF1Ug274BqHuY_c5NdPAzuqoTwjfEn8NKEoaNqlumM75FUYbaTd7mXvk4WVYWjVnkO40dfQjRB7DYhvj0LBlbndAJ4wJIA2ilPYgjZsXVbNNh3e2j3u9eABd0VaFMbSb8Sz5_31r8HzoWmPJs3HiyuyANGFUA6CvAnMN6K3b-D8BhFZU_nPUTgu80o8_n6LQt-XWbaC_mTHzsnOjzBiPJxlYawAEW3bmOEtStH2T8q7vMkhchImp2-hg9MFYGBmEe9sSByTn3NUf8eksqXOC1dUjHkXoZm298FgUYLkNdnlxWpf993j5mEDoFxjcTB7scBD7k6nu6Nrs_wK0-seS8gsHrx9UK7GwAsi10q82Cm4PFyAtrWjmy_d9WLHuZt6VIOKunTs8cf0FwNUiMcvZsruqIFJcP7iWxdiFdUkh65P_iCz1ZEjJcj2GEZoq4v3a3by1aizGPaaiKc1jd_T-XJg_YpncawAEWnstu5b9WiZv0x8xfsiMk6YRlU0Cnj5svxLLXz_8drvwAa--GBY5yH0ke2EM6udMEi2EPeFcGTe6Sjs0YEhSbY7Uad_8suD2J4tIWJSWBbiyvh7rSqzv57m7BlsVcHfQJn_wNH-UlC9xkx8vg-LwfN8_FlxvHNPTc7XZG3lKYbwpUWlZxAziOYT1VQ-2K2bQQBBMdix-ht_SjccL1Dc2dP5kDazQ8yZV_8xnyeheazEedWe63uutfkHlZRg9YwP8=", - "type": "validator", - "lastSeen": 1575915094967382800 - } - ], - "mixNodes": [ - { - "host": "35.176.155.107:1789", - "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", - "layer": 3, - "lastSeen": 1575915096805374500 - }, - { - "host": "18.130.86.190:1789", - "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", - "layer": 1, - "lastSeen": 1575915097370376000 - }, - { - "host": "3.10.22.152:1789", - "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", - "layer": 1, - "lastSeen": 1575915097639423500 - }, - { - "host": "35.178.213.77:1789", - "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", - "layer": 2, - "lastSeen": 1575915097895166500 - }, - { - "host": "52.56.99.196:1789", - "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", - "layer": 2, - "lastSeen": 1575915096255174700 - }, - { - "host": "3.9.12.238:1789", - "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", - "layer": 3, - "lastSeen": 1575915096497827600 - } - ], - "mixProviderNodes": [ - { - "host": "3.8.176.11:1789", - "pubKey": "54U6krAr-j9nQXFlsHk3io04_p0tctuqH71t7w_usgI=", - "registeredClients": [ - { - "pubKey": "zOqdJFH49HcgGSCRnmbXGzovnwRLEPN0YGN1SCafTyo=" - }, - { - "pubKey": "fy9xo69hZ2UJ9uxhIS1YzKHZsH8saV-02AiyCNXPNUc=" - }, - { - "pubKey": "6hFCz42d5AODAoMXqcBWtoOoZh-7hPMDXbLKKhS7x3I=" - }, - { - "pubKey": "pPZMDzw0FyZ-LBAhwCvjlPGj1p2bO_vaWbRBc7Ojq3Q=" - }, - { - "pubKey": "kjl5poXt2GdIrHLuMBjmTBSChV-zMqsXFBhKZoIREVI=" - }, - { - "pubKey": "T1jMGuk7-rcIUWnVopAsdGzhAJ7ZVymwON2LzjuOfnY=" - }, - { - "pubKey": "3X0eKPkflx5Vzok0Gk0jm5-YEfvPAuWP55ovyBUOtXA=" - }, - { - "pubKey": "5wC3i8rCZolLKbWJ9U6eLieXNGLKM21dtL6lR30u_hE=" - }, - { - "pubKey": "1P6p7fgjwjlEepD9JgbN1V-rk9n36-hCmPN5P6y62n4=" - }, - { - "pubKey": "aBjlLQKKFroqhX_kvYLnMm1uq3FJdQWqVy9Q35zzERA=" - }, - { - "pubKey": "I0gVOPj6lv9ha60xPYKeAgbeUU8pdyMD-Y7Nb1nS9EQ=" - }, - { - "pubKey": "WgdvQ74QH1uFDWDL2YeApvv7oniNGh9BQJ_HZam20QA=" - }, - { - "pubKey": "Mlw23KaSL2hyrIjEZM76bZStt2iMzxVAqXwO5clJfxg=" - }, - { - "pubKey": "F9xzbjnMQVN4ZidcqN2ip9kVnI9wbS39aVayZGiMihY=" - }, - { - "pubKey": "s6pfVkZrUG--RNjfzS55N2oPvFkMdvgb1LUut6gqRy4=" - }, - { - "pubKey": "bSi-9k0jJNKc8PGx8M3SWFaNpORFjYw-NkWXRZVRWGU=" - }, - { - "pubKey": "pz6ahQcGOQcZBFx1tGmzRngqk6BecXB_wFd4WVdOQDU=" - }, - { - "pubKey": "5sfwIMcG2zRCxhDh4D9Evw1WPI5bfKZAShM_6o9Pu1I=" - }, - { - "pubKey": "9fZnxXy9onGPpZ3Ygckqw0okqCw3di02sLr-NTBr4SE=" - }, - { - "pubKey": "Q0TbbggOwzZjalUdi5eEHVFi9VMv-rMm5mJPUZZs12A=" - }, - { - "pubKey": "aPNyox_qAIGFB2-wZ0lc9iAWDN6jzLojApSiWVFjCks=" - }, - { - "pubKey": "DUKLEsIGMw-ucs3DjS7Ag9qCb5-C_A84DuIsZuLkdwI=" - }, - { - "pubKey": "YV84vPoSrLf1p9Sw6FnnrcCpS3kvpJUfKyKpnwk8z0Q=" - }, - { - "pubKey": "_IYEzZQoBAYeTxqzpEe_ez1-7pn7aId8AKliazy0qlE=" - }, - { - "pubKey": "srkOAoVU-a02lnEsoH_wOLLw7HFx_xHIZUSbnhjFwDw=" - }, - { - "pubKey": "LxSCBn_OEQq-hI2xDi6bfGoioRO_lSTIq6AQ9l1k5jg=" - }, - { - "pubKey": "OC0OOqtGfAytgZjthpjoKeYNa0VrtzfgZ0iO5Fag5y8=" - }, - { - "pubKey": "ImVEch2focRhm1ial1gA6YJPr6WDyW3oh-OgYcO5Ll4=" - }, - { - "pubKey": "yTDnzLvEaSq0mC9xNrtyjpAKtsIU6yRuBepCuWQMBm4=" - }, - { - "pubKey": "-LCUUc46HuL7iUEOMkrlVAkvvulRiQ7dR1QYh7bkKxw=" - }, - { - "pubKey": "Bx1MGpISig25rqe7mhoX68EROUPPzmF7yGLYah9DPgM=" - }, - { - "pubKey": "Z4Nu6iwLmgJ93yoIFTbTEBeDAHRwS-vo1T_K2Kv1FQo=" - }, - { - "pubKey": "cKFAGxllwAmEXCtDxG_T1iEm3-lKWUVQxxpDBje6mQU=" - }, - { - "pubKey": "pQV40whlQWUSXtrNTTePzO6sdq3zr1JUIWZWvD443nY=" - }, - { - "pubKey": "6Bb5HwnVqJPy5wcNsaHY-0y__coZCE7XC80kUkesnRU=" - }, - { - "pubKey": "COGdpfhmzNGR6YX820GqJIkjOihL8mr6-h-d3JlTDFA=" - } - ], - "lastSeen": 1575915097358694100 - }, - { - "host": "35.178.212.193:1789", - "pubKey": "sA-sxi038pEbGy4lgZWG-RdHHDkA6kZzu44G0LUxFSc=", - "registeredClients": [ - { - "pubKey": "UE-7r6-bpw0b4T3GxOBVxlg02psx23DF2p5Tuf-OBSE=" - }, - { - "pubKey": "UnZuLpzq64_EPtIcr1Fd-5AESBCBLFnDMDsjUaOqrUA=" - }, - { - "pubKey": "4ExXPrW5w0nZIQ5ravBRT6H9r0RH0MXuOcGIF8HzUhg=" - }, - { - "pubKey": "wPsRpJPi1e2sjItyRKDkFACbxwu3Cw5GlYVPmdYxk2U=" - }, - { - "pubKey": "UfK5UvT3HUkT1SGbv1QGafy3in3uQ9a6NSy5EOT6k0k=" - }, - { - "pubKey": "5Giu-tJpGXU0S9Av75iAv5qDO0k6l8v_k9-UCcRUCl4=" - }, - { - "pubKey": "MnQxlmmKDybku4CfxsQQxfftilsaphF9Gq1w3MB1ZCE=" - }, - { - "pubKey": "GdP1fHVs2R65EkuWVWKZSz6WPDh0MgThyuBOv6_xsmQ=" - }, - { - "pubKey": "4JEtSrKsonmBuDvxJ9nITSu7iC4f8reutXRAVugPgS4=" - }, - { - "pubKey": "q4XyuUJbSGJaoRb3SmWzeX88V2dKB7sPTf72BAtQp3k=" - }, - { - "pubKey": "gTzKd1Ph5bpUw-JxTZiCe8RBfO-FsZiVYDYioQ-6dVg=" - }, - { - "pubKey": "NX4oaDLYEOmMUP_9pcEaZv5MJHJ4ZYAoxPQDxov7tRs=" - }, - { - "pubKey": "7fbk4oGQNlTW-tnWjVz8rWtKrtAicTsiNWgO98sqMyk=" - }, - { - "pubKey": "w1bfLpnd3rWu5JczB0nQfnE2S6nUCbx2AA7HDE48DQo=" - } - ], - "lastSeen": 1575915097869025000 - } - ] - }"#.to_string() - } -} \ No newline at end of file diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index 28d230d283..413ce41f32 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -1,9 +1,5 @@ -use reqwest::Response; use crate::clients::directory::presence::Topology; -use serde::Deserialize; - - pub struct Request { base_url: String, } @@ -20,39 +16,289 @@ impl PresenceTopologyGetRequester for Request { fn get(&self) -> Result { let url = format!("{}/topology", self.base_url); - reqwest::get(&url)?.json()? + let topology: Topology = reqwest::get(&url)?.json()?; + Ok(topology) } } -mod healthcheck_requests { +#[cfg(test)] +mod topology_requests { use super::*; - + use crate::clients::directory::presence::CocoPresence; #[cfg(test)] use mockito::mock; - #[cfg(test)] mod on_a_400_status { use super::*; - #[test] #[should_panic] - fn it_returns_an_error() { - let _m = mock("GET", "/healthcheck").with_status(400).create(); + fn it_panics() { + let _m = mock("GET", "/topology") + .with_status(400) + .with_body("badbody") + .create(); let req = Request::new(mockito::server_url()); - assert_eq!(true, req.get().is_err()); + req.get().unwrap(); } } - #[cfg(test)] mod on_a_200 { use super::*; - #[test] fn it_returns_a_response_with_200_status() { - let _m = mock("GET", "/healthcheck").with_status(200).create(); + let json = serde_json::to_string(&Topology { + coco_nodes: vec![CocoPresence { + host: "foo.org".to_string(), + last_seen: 12345, + pub_key: "key".to_string(), + }], + mix_nodes: vec![], + mix_provider_nodes: vec![], + }) + .unwrap(); + let _m = mock("GET", "/topology") + .with_status(200) + .with_body(json) + .create(); let req = Request::new(mockito::server_url()); - assert_eq!(true, req.get().is_ok()); } } + + // mod fixtures { + // fn topology_response_json() -> String { + // r#"{ + // "cocoNodes": [ + // { + // "host": "3.8.244.109:4000", + // "pubKey": "AAAAAAAAAAEKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEFuhRpy4HfcuxwcRI9sIWMo_LVmbk19g1gfMRlBrmZqoEQL6rDApVLZ9eMp-5IQK8WLlZpWf4Zjy7kZolARAyp_rHUQkH4PrDjgoPrKbm6qK_iejYpL7qx28Q3VeInMpwMIMaSbbW9y36sEVtGc2I0Iu5vS0sp8ESiVlQ5NaBz72deZ8oKJJ4IEPPHP99-b0UQX80fVIrNM88mMzKy0bHri9NFlmIG-e0G1cqmw_ry3XWGQkcr1M5RuNa6oX50w5QawAEVxd5FP5bE8bS4x54Csof11sQWUTwMp6Q7_3H7ZCTSlKSqujlOhmfqSHfGPO2sDIYPHDhDzjakZpKAZWWhn_hiR6DfPpomQ01ZYUhVKKSMxz7_VPjsQplP0bZXA2gfnkADUN8UQ0N9g_usIw73r4aZsOviMsRM8oByvsjVfUWc4_HTLSdnQyImFkHz9CiCmrIYL2dYQRePRatWggvBAyeRzntxI4jDqLKiBdi54ZlAKgV6MCRaJ7Bu7BtmLXrtK4sawAED3QYxuvOSZrbZdUr4yG-U9yVvJ9Klkf-5Mo4EYp3qTL2KBB6_LrZepjAQqp486YkZ03mTIezcsZ48EboXVTWKBZ3QnTI5tX-j4gGxQb7klOJc97qJkDxsvpz4F0ChgCUIZhpIItWHia7_R3Gi-b5siLIdQdUho9isn3kiDGm6t0NED2Bgy3ZxxQwzqsBZm4kPr2_fPX4YyvIoP9895YcGjZyE5iiRC_TE41RJmB1GZYdxegTMq3lNDllKgiqaiPgawAEJASDkmZHTwlg9YOev5OWpQD-FnhPkqVNo_QcDyRu9eoGcWSGFp2sYqjG2SpmiXq0VNnAO7AcKxRzDFu7TjfhlU3Kt0uTKIcrWVU1zFNbJNMjYEq90pp50nowwx8INz20IXET2ZNX6kIXYFCsEvPLZFlG2OoL6xg3uQS1qMl3lIS_VxdO_JfVe0rT65WsJ_P4Nkc1jYiuNPHY6d_iFO0BVYqX0sOCX73GC_TT13BR0jnPwDAVw0rGtYHsXBb8TKOsawAEZIClauuT1V3qOZnb7uRZhFXO-PKTxgc1LCzJt2ChOrMZaBpjlkf3IPpJ2UF4JH4kGaDeBf2k_S-FLAs3drK21efbi5P6_a4QTxAiiRimXGoQIyvOg462s6kP_ZRFufo8YYQHS4olaOeqU4564dNskg_uBPsFMz_2GNOhmn_15cJqP1jfkyD49Z16GTS5YLHgVl9bJKqyvLuypsToLbt1BJzipEP0L2OohuRm-_MvqvwwWKyjNQsubgee1K728d9AawAEBkGggcNVCtXyhoSqi3_w0tVxtkAYeud8sBeAtZHGs06me_QL8co0MFLlO-zdkUb4ZBq08rFEbgLOma8_3whleM8NIPaHNISp1q3IsIhB5zdXcZoGsqLixODBFHtID3YEHAlr4f9T_yh11yJ95xGCl_6Y37hpwLQVGyrfSfccM24mVFqnV3TT5Wdq3ile-jesUx1Q2G1yK_xVqc6itmk-kDuBjyZgzYi1-jsIXAjnhM9G7t8J_Bv5yGGZhLK2dCzM=", + // "type": "validator", + // "lastSeen": 1575915097085539300 + // }, + // { + // "host": "3.9.129.61:4000", + // "pubKey": "AAAAAAAAAAMKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEEv6RMevAQmLGkeK0uJKnMPPAtm8GgXjWSQijYdnxlPh5SJSNeJUbPZKWFFWdk8yIFXKa8jnzETtdGFKgUUt5AVUDpTBmEdwaHCzlFhXrttshy0V5OhPUlV8cGABmxbagMYm0bFPg0r-snSkrB9YG6wqJYQVeIMOCGYCPbHmDA8R_0-h8VkRKWs1d9KvQOK4kShqgZtYN71KJW8uDE4q2jsGDVvxFt1AgmU9b93xsXF17KrpZy5WxlLZ73HtnTD_oawAED4vd_rK-Kx_n8x_OdDiiEOPUlYDlDCQUqenU9XHKH3B6ijfkJ368wd3LDDVStjDwNORrAyUSw_VlSNUpd1XLC8d17gTaIq5ZI2fWuwwZaoN1JCsYU8fQ6USgtIehQX7IPP8EkFuNmuCBCmpr4schtYniGe9J8Q4dsV-TYPr2uLJkdx1r7luzF--I22k7NfQQM14QDci_0kgrgmZ54CJGkjXyOhCppBXg3fqLC6aFvT3ZocfiiXBJt0huGgPMDtYsawAECLh8KUdNsDolERwJ8v04bS5jI_KKf7uUnCHWuCELwbJSUI3OK1ufS1qSpauvSzVQSbrhEzrEfwQn4VtxQxJlX4UdDU-R-hafiZvVC6DLLAbuORBAC3FScn9W58CnezH4DvCp_w7nftDfdxeuungbZT9XaxS3iNC6PnFsWF6WM3DxMwrzOrFe6wEEoTSPe1mcUDrtwM5UksIvJr6MBRAXrdl0IdBTQr7cLwKe_KYi4siwdjfJEJtOh7oxQBxBg2UkawAEJAPZK2Gg2MQwpxdDT24lNQHF7FVfkO_LuhJwn0RbwNDSVeA4P6-tWL5TkCpqr8xYHfwQ6Z3ILfpGCZr8PspwIoRzqZHQ16f8Pq9xnr0hLEI9BOQU0FS2EtuyPgju5iwsAJAfehUzu6kNLphuLGsXoIZdXDG5mbylwh9JzAVXTwgaR0hNqyXVJxgbt7jcYaSEBFcMGV-hjXyVVNzBleE-G9o_noI_KWU4Ce7K-qOMcewMKfy_VEw-gVaD6dHz6AMoawAEE9XuOLwRttvKybAssZ9gsK-_YRUwuFOeRDIr3NX___9bx6pCc18adCIlH_8EJWFwXZ05ZpNNE88mYx7ZQ3aqaArZJRoWeZeKhqH_s05V10xbzkYX71G5cqz--8vr9ZlQRb2BeETF_Tdq_PLk7qbT8WTGIoq7ZwyDRQTgzvkCgyzj_hBLh2o7sSVNgUo38SFUTMn7YtvVFYlSrTDE3WKE-T-nh5SWdDBxgDTc3Bw8JpzNH-WkoJ4Lim7sB4Op1gEUawAEW4-kenlffwsNr_3b3aV0YuusLpxB03sxPzQ5B0CWNiVtbja1Z4tWhKGUUrdq_eUgMV0y5Of-BqNi5FspAQnhJBFSSxtOzRGV1h3qyUTksfZyed9z8zPI-ZPP9XXm7hYgJgDz_kxte-NfS9UG9q5AZetHUN4kGxXutjjzfUQZ9yTvhBKgKgTI2Dp_R_jZrWQ8F1BoWzIJzjddT1K2MvCQEkARYw08isbOeFmCwgVUcjxYZO45WyOmLQA7QJRL9WvA=", + // "type": "validator", + // "lastSeen": 1575915097388409000 + // }, + // { + // "host": "3.9.222.1:4000", + // "pubKey": "AAAAAAAAAAQKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAECh9xcxpjOp1r7kiNIgrI9GgAlvXwgHkTchOxUiyOzTq6FDWdGN64KiC3NDeyGTg8FmzvGzS3jREeJqOdr4G9ZGtWkauAITgLFiH62t-YntRslhr8_1shxlmzKiNKJN_QFflEq79pZIlWtp3N8LIHMvXRtl-zt2DMze4s02XDmEkviyVE4CkQUDtCc-2MfPT4JcmEFqtFIxjrXn18SbYg3c6XUQHsGIkuDrKuCTRlpC8kvmM0uVoIeWdmwDlZk4jUawAEJhRwK5ozjqIWRP1bFzBPS9VhaJnfKU9PeFYtN5beiAHrYr2ylIB3yDfmAQUdKDowDUm5nfJATejEjEnrTGxh70QtfoNV391rSns3F71tBwY62KLaNr8qnVfeSFHV3FcQTMHHF_8mDb5_11Rj6aiMvW0y6eetHo7CDPMdEyDPmok_U2ZM5BzOUnwjT21HtnvcKxKKwHJ_QGfnAHPyDIhNOMgxJCrVazOidLCHeYGpyCLw1ipeTyKOQX0_ByB8dH6AawAEGV1GuF5SSlT67B1ityPJK2ZwXjeeKB4gGdCG3qRtWxLTZfGhVm7YAYm2f5tw_wrsJAZ9FubVhateGg0ZN67NxZtsvOOejXz6743f7ijnQopPgd_8pH-iVf6BEcSO8ZdcHxNRUTayzjVLs99bwMo2zaPevW4X4G_bN4mh---aPkdGYHwaiklzUhqJ-eqycrYAFyjyEXaPBXLQm1rpczqluNvnKbd8Q9LZWukgm7_uWv_HxufIvdWgoq8bAt78UU3oawAEP9VDehhqrQG5-WHMB66XVxo1TgMM8aVV0SwAq3lCRkpiFBz_9kw8T1F9Hx2AiNrEGT1QLbdMkpms1cG_5gBBahQofdt_NmUs1jfTFXY9iyMy1Q7A6ZYaLP8Z6q-orc1cKqySY-BJZQ_CpGFfXS0OVniFDQ6v78ytPK7K-yRgT1PxFgm3rZqrG0Tjbrpsg2PUL5S5fuXfMhUosP0uoLj0D1guWAR9Y7kfFBIXaTSFMoa8fghVBUTRNhK9f72a8SxQawAEOiv71taLjKqaaWQ_QjcDhWbvjG1EnsCyI0toNjGkcF19x4Vk-5NC96_4ioUGz404IC0XN03roRnibRT_78D9vZFVCWCqve9EjdF5TcApx03zIP4JT2g2q0MKIGgGrwt4Pz6LO6yOfMm7B8Yraps8IV-nP1w7K1m9XKP_FvH8egl5GHJe-_omlC2YyL_b28jMLENbxDFD-3KPjZFBhSLrRukX2PlayYTwEiTtokA2R9_11vQvJgP8KFEjGHg6zsAMawAEBn2H_hz2knb8ltnpEA5YSKVcV3nUtojkCNi_WUz7xUKd7efw1oI_lbnKrS7HkyC0JkQUZ1pCWUlSXNmgjMEhsn823a1LFzpV7rOv4vayYvvFX61hB9R78VjpyxJiYpDwRZLiUY3AK4WY8NqFDbjXR7rT4CkFHEf-VhSQQ8ZNvlpod1nmeVQVizHH9e7Tq7wsWz-LWEk3Hx6LmcrgDsL79LZYG9JXU5IdvG8RvLNx9cSwEI8yxcchpISAaot7UoYQ=", + // "type": "validator", + // "lastSeen": 1575915094734973000 + // }, + // { + // "host": "3.9.102.214:4000", + // "pubKey": "AAAAAAAAAAIKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEOVCUN3EwiVroS5-TOq2o7hYSxphK9X0G23N-IBZ0Tr1Rl8XEiJ-OEy0rqnAKwmhAZJWnx3u8oXqbZtOWIZmzQSpcoxhgwfhdmTZJCqT2RVzZyeFItX4sVeilEP3z2xdsJs8-a1kg6UZnx1s1BNLBo7eZrreZygWojPCIDBn03fSAflXoVc5PpY2CGy5MA_IgWgSYBHDdoZEtigp_amjqK7Us44Db20XpLxMXfbahiqa7WKNnMgi6Ca2H67VtaaD8awAEF3zbE1nZRAa7a8vbU25c80YBYJBaW8P6FwXQI-K0Xk5MakwYeMMnIrm6w6IS_0XAO5YlD453GLqnxY8H1BEnRpfOnT7PE4el9mJ8MuYQMo6R2up0lGCmYM0YA9FORjroM3ng69SEPfJPCReG7LfJkERl_m2U403ertDRBYrlqCDagDfyI500srBcMrjSvV3oNouyyx3yZUrjLQfbHhDteQFsYdmakJs8Y-Q9-5MXCcrz6Qa4xwv522Euv0CCxkHcawAEYjfsU_zDhUZA1ey1aquWXlFOnx-iEALqxW1slDYHwQ1M2SILc-v_E6i1doa5e_bAZHVezBHFAlaNAVedNyHFFJxYAqAK3hbzbvl2glw3Q6h_rTXElymloqtaqVFIJ-oUWWOHsZBmu8EDA-HzvGCiBa_GbRaVfh2lE4ObeMXoJrEm_5dbxxeEic2l3IYeIz40N9ooQQOkQcOZdY4AXWYCavIAwWEJBjLtptJgCLu9a_zM1S5GsiyJHpdDs46WbP0EawAEWZ-95Sf0YAHujxRNLdXgpqe0ZF8loVwzZfvyMvqaxF1Ug274BqHuY_c5NdPAzuqoTwjfEn8NKEoaNqlumM75FUYbaTd7mXvk4WVYWjVnkO40dfQjRB7DYhvj0LBlbndAJ4wJIA2ilPYgjZsXVbNNh3e2j3u9eABd0VaFMbSb8Sz5_31r8HzoWmPJs3HiyuyANGFUA6CvAnMN6K3b-D8BhFZU_nPUTgu80o8_n6LQt-XWbaC_mTHzsnOjzBiPJxlYawAEW3bmOEtStH2T8q7vMkhchImp2-hg9MFYGBmEe9sSByTn3NUf8eksqXOC1dUjHkXoZm298FgUYLkNdnlxWpf993j5mEDoFxjcTB7scBD7k6nu6Nrs_wK0-seS8gsHrx9UK7GwAsi10q82Cm4PFyAtrWjmy_d9WLHuZt6VIOKunTs8cf0FwNUiMcvZsruqIFJcP7iWxdiFdUkh65P_iCz1ZEjJcj2GEZoq4v3a3by1aizGPaaiKc1jd_T-XJg_YpncawAEWnstu5b9WiZv0x8xfsiMk6YRlU0Cnj5svxLLXz_8drvwAa--GBY5yH0ke2EM6udMEi2EPeFcGTe6Sjs0YEhSbY7Uad_8suD2J4tIWJSWBbiyvh7rSqzv57m7BlsVcHfQJn_wNH-UlC9xkx8vg-LwfN8_FlxvHNPTc7XZG3lKYbwpUWlZxAziOYT1VQ-2K2bQQBBMdix-ht_SjccL1Dc2dP5kDazQ8yZV_8xnyeheazEedWe63uutfkHlZRg9YwP8=", + // "type": "validator", + // "lastSeen": 1575915094967382800 + // } + // ], + // "mixNodes": [ + // { + // "host": "35.176.155.107:1789", + // "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + // "layer": 3, + // "lastSeen": 1575915096805374500 + // }, + // { + // "host": "18.130.86.190:1789", + // "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + // "layer": 1, + // "lastSeen": 1575915097370376000 + // }, + // { + // "host": "3.10.22.152:1789", + // "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + // "layer": 1, + // "lastSeen": 1575915097639423500 + // }, + // { + // "host": "35.178.213.77:1789", + // "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + // "layer": 2, + // "lastSeen": 1575915097895166500 + // }, + // { + // "host": "52.56.99.196:1789", + // "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + // "layer": 2, + // "lastSeen": 1575915096255174700 + // }, + // { + // "host": "3.9.12.238:1789", + // "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + // "layer": 3, + // "lastSeen": 1575915096497827600 + // } + // ], + // "mixProviderNodes": [ + // { + // "host": "3.8.176.11:1789", + // "pubKey": "54U6krAr-j9nQXFlsHk3io04_p0tctuqH71t7w_usgI=", + // "registeredClients": [ + // { + // "pubKey": "zOqdJFH49HcgGSCRnmbXGzovnwRLEPN0YGN1SCafTyo=" + // }, + // { + // "pubKey": "fy9xo69hZ2UJ9uxhIS1YzKHZsH8saV-02AiyCNXPNUc=" + // }, + // { + // "pubKey": "6hFCz42d5AODAoMXqcBWtoOoZh-7hPMDXbLKKhS7x3I=" + // }, + // { + // "pubKey": "pPZMDzw0FyZ-LBAhwCvjlPGj1p2bO_vaWbRBc7Ojq3Q=" + // }, + // { + // "pubKey": "kjl5poXt2GdIrHLuMBjmTBSChV-zMqsXFBhKZoIREVI=" + // }, + // { + // "pubKey": "T1jMGuk7-rcIUWnVopAsdGzhAJ7ZVymwON2LzjuOfnY=" + // }, + // { + // "pubKey": "3X0eKPkflx5Vzok0Gk0jm5-YEfvPAuWP55ovyBUOtXA=" + // }, + // { + // "pubKey": "5wC3i8rCZolLKbWJ9U6eLieXNGLKM21dtL6lR30u_hE=" + // }, + // { + // "pubKey": "1P6p7fgjwjlEepD9JgbN1V-rk9n36-hCmPN5P6y62n4=" + // }, + // { + // "pubKey": "aBjlLQKKFroqhX_kvYLnMm1uq3FJdQWqVy9Q35zzERA=" + // }, + // { + // "pubKey": "I0gVOPj6lv9ha60xPYKeAgbeUU8pdyMD-Y7Nb1nS9EQ=" + // }, + // { + // "pubKey": "WgdvQ74QH1uFDWDL2YeApvv7oniNGh9BQJ_HZam20QA=" + // }, + // { + // "pubKey": "Mlw23KaSL2hyrIjEZM76bZStt2iMzxVAqXwO5clJfxg=" + // }, + // { + // "pubKey": "F9xzbjnMQVN4ZidcqN2ip9kVnI9wbS39aVayZGiMihY=" + // }, + // { + // "pubKey": "s6pfVkZrUG--RNjfzS55N2oPvFkMdvgb1LUut6gqRy4=" + // }, + // { + // "pubKey": "bSi-9k0jJNKc8PGx8M3SWFaNpORFjYw-NkWXRZVRWGU=" + // }, + // { + // "pubKey": "pz6ahQcGOQcZBFx1tGmzRngqk6BecXB_wFd4WVdOQDU=" + // }, + // { + // "pubKey": "5sfwIMcG2zRCxhDh4D9Evw1WPI5bfKZAShM_6o9Pu1I=" + // }, + // { + // "pubKey": "9fZnxXy9onGPpZ3Ygckqw0okqCw3di02sLr-NTBr4SE=" + // }, + // { + // "pubKey": "Q0TbbggOwzZjalUdi5eEHVFi9VMv-rMm5mJPUZZs12A=" + // }, + // { + // "pubKey": "aPNyox_qAIGFB2-wZ0lc9iAWDN6jzLojApSiWVFjCks=" + // }, + // { + // "pubKey": "DUKLEsIGMw-ucs3DjS7Ag9qCb5-C_A84DuIsZuLkdwI=" + // }, + // { + // "pubKey": "YV84vPoSrLf1p9Sw6FnnrcCpS3kvpJUfKyKpnwk8z0Q=" + // }, + // { + // "pubKey": "_IYEzZQoBAYeTxqzpEe_ez1-7pn7aId8AKliazy0qlE=" + // }, + // { + // "pubKey": "srkOAoVU-a02lnEsoH_wOLLw7HFx_xHIZUSbnhjFwDw=" + // }, + // { + // "pubKey": "LxSCBn_OEQq-hI2xDi6bfGoioRO_lSTIq6AQ9l1k5jg=" + // }, + // { + // "pubKey": "OC0OOqtGfAytgZjthpjoKeYNa0VrtzfgZ0iO5Fag5y8=" + // }, + // { + // "pubKey": "ImVEch2focRhm1ial1gA6YJPr6WDyW3oh-OgYcO5Ll4=" + // }, + // { + // "pubKey": "yTDnzLvEaSq0mC9xNrtyjpAKtsIU6yRuBepCuWQMBm4=" + // }, + // { + // "pubKey": "-LCUUc46HuL7iUEOMkrlVAkvvulRiQ7dR1QYh7bkKxw=" + // }, + // { + // "pubKey": "Bx1MGpISig25rqe7mhoX68EROUPPzmF7yGLYah9DPgM=" + // }, + // { + // "pubKey": "Z4Nu6iwLmgJ93yoIFTbTEBeDAHRwS-vo1T_K2Kv1FQo=" + // }, + // { + // "pubKey": "cKFAGxllwAmEXCtDxG_T1iEm3-lKWUVQxxpDBje6mQU=" + // }, + // { + // "pubKey": "pQV40whlQWUSXtrNTTePzO6sdq3zr1JUIWZWvD443nY=" + // }, + // { + // "pubKey": "6Bb5HwnVqJPy5wcNsaHY-0y__coZCE7XC80kUkesnRU=" + // }, + // { + // "pubKey": "COGdpfhmzNGR6YX820GqJIkjOihL8mr6-h-d3JlTDFA=" + // } + // ], + // "lastSeen": 1575915097358694100 + // }, + // { + // "host": "35.178.212.193:1789", + // "pubKey": "sA-sxi038pEbGy4lgZWG-RdHHDkA6kZzu44G0LUxFSc=", + // "registeredClients": [ + // { + // "pubKey": "UE-7r6-bpw0b4T3GxOBVxlg02psx23DF2p5Tuf-OBSE=" + // }, + // { + // "pubKey": "UnZuLpzq64_EPtIcr1Fd-5AESBCBLFnDMDsjUaOqrUA=" + // }, + // { + // "pubKey": "4ExXPrW5w0nZIQ5ravBRT6H9r0RH0MXuOcGIF8HzUhg=" + // }, + // { + // "pubKey": "wPsRpJPi1e2sjItyRKDkFACbxwu3Cw5GlYVPmdYxk2U=" + // }, + // { + // "pubKey": "UfK5UvT3HUkT1SGbv1QGafy3in3uQ9a6NSy5EOT6k0k=" + // }, + // { + // "pubKey": "5Giu-tJpGXU0S9Av75iAv5qDO0k6l8v_k9-UCcRUCl4=" + // }, + // { + // "pubKey": "MnQxlmmKDybku4CfxsQQxfftilsaphF9Gq1w3MB1ZCE=" + // }, + // { + // "pubKey": "GdP1fHVs2R65EkuWVWKZSz6WPDh0MgThyuBOv6_xsmQ=" + // }, + // { + // "pubKey": "4JEtSrKsonmBuDvxJ9nITSu7iC4f8reutXRAVugPgS4=" + // }, + // { + // "pubKey": "q4XyuUJbSGJaoRb3SmWzeX88V2dKB7sPTf72BAtQp3k=" + // }, + // { + // "pubKey": "gTzKd1Ph5bpUw-JxTZiCe8RBfO-FsZiVYDYioQ-6dVg=" + // }, + // { + // "pubKey": "NX4oaDLYEOmMUP_9pcEaZv5MJHJ4ZYAoxPQDxov7tRs=" + // }, + // { + // "pubKey": "7fbk4oGQNlTW-tnWjVz8rWtKrtAicTsiNWgO98sqMyk=" + // }, + // { + // "pubKey": "w1bfLpnd3rWu5JczB0nQfnE2S6nUCbx2AA7HDE48DQo=" + // } + // ], + // "lastSeen": 1575915097869025000 + // } + // ] + // }"#.to_string() + // } + // } } diff --git a/src/clients/mix.rs b/src/clients/mix.rs index d7b24ba435..b5f03a130f 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,6 +1,6 @@ use crate::clients::directory::Client; -use sphinx::SphinxPacket; use sphinx::route::Node as MixNode; +use sphinx::SphinxPacket; use tokio::prelude::*; pub struct MixClient {} @@ -11,7 +11,11 @@ impl MixClient { } // Sends a Sphinx packet to a mixnode. - pub async fn send(&self, packet: SphinxPacket, mix: &MixNode) -> Result<(), Box>{ + pub async fn send( + &self, + packet: SphinxPacket, + mix: &MixNode, + ) -> Result<(), Box> { let bytes = packet.to_bytes(); let mut stream = tokio::net::TcpStream::connect("127.0.0.1:8080").await?; @@ -20,7 +24,6 @@ impl MixClient { } } - #[cfg(test)] mod sending_a_sphinx_packet { use super::*; @@ -29,19 +32,19 @@ mod sending_a_sphinx_packet { #[test] fn works() { // arrange -// let directory = Client::new(); -// let message = "Hello, Sphinx!".as_bytes().to_vec(); -// let mixes = directory.get_mixes(); -// let destination = directory.get_destination(); -// let delays = sphinx::header::delays::generate(2); -// let packet = SphinxPacket::new(message, &mixes, &destination, &delays).unwrap(); -// let mix_client = MixClient::new(); -// let first_hop = mixes.first().unwrap(); -// -// // act -// mix_client.send(packet, first_hop); + // let directory = Client::new(); + // let message = "Hello, Sphinx!".as_bytes().to_vec(); + // let mixes = directory.get_mixes(); + // let destination = directory.get_destination(); + // let delays = sphinx::header::delays::generate(2); + // let packet = SphinxPacket::new(message, &mixes, &destination, &delays).unwrap(); + // let mix_client = MixClient::new(); + // let first_hop = mixes.first().unwrap(); + // + // // act + // mix_client.send(packet, first_hop); // assert // wtf are we supposed to assert here? } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index c0c6c0525c..db854f5e2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; use crate::clients::directory; -use crate::clients::directory::DirectoryClient; use crate::clients::directory::requests::health_check_get::HealthCheckRequester; +use crate::clients::directory::DirectoryClient; mod clients; From 8f2d5f970a9a0cea8e31aff91149ce0d60ff8de4 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 19:27:56 +0000 Subject: [PATCH 029/167] directory: adding path to request fields --- src/clients/directory/requests/presence_topology_get.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index 413ce41f32..8f3ecd2eb3 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -2,6 +2,7 @@ use crate::clients::directory::presence::Topology; pub struct Request { base_url: String, + path: String, } pub trait PresenceTopologyGetRequester { @@ -11,11 +12,11 @@ pub trait PresenceTopologyGetRequester { impl PresenceTopologyGetRequester for Request { fn new(base_url: String) -> Self { - Request { base_url } + Request { base_url, path: "/topology".to_string()} } fn get(&self) -> Result { - let url = format!("{}/topology", self.base_url); + let url = format!("{}{}", self.base_url, self.path); let topology: Topology = reqwest::get(&url)?.json()?; Ok(topology) } From 61c8ed9c2ec9f6364263cc2eb94530e5013b0535 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 19:28:15 +0000 Subject: [PATCH 030/167] directory: checking that topology is returned with data --- src/clients/directory/requests/presence_topology_get.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index 8f3ecd2eb3..dd6587c197 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -46,7 +46,7 @@ mod topology_requests { mod on_a_200 { use super::*; #[test] - fn it_returns_a_response_with_200_status() { + fn it_returns_a_response_with_200_status_and_a_correct_topology() { let json = serde_json::to_string(&Topology { coco_nodes: vec![CocoPresence { host: "foo.org".to_string(), @@ -62,7 +62,9 @@ mod topology_requests { .with_body(json) .create(); let req = Request::new(mockito::server_url()); - assert_eq!(true, req.get().is_ok()); + let resp = req.get(); + assert_eq!(true, resp.is_ok()); + assert_eq!(12345, resp.unwrap().coco_nodes.first().unwrap().last_seen) } } From 04612ca98bf6fddb529b2d3eab075f5109320949 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 10 Dec 2019 19:31:03 +0000 Subject: [PATCH 031/167] Ensuring that we can use the full glory of the topology fixture --- .../requests/presence_topology_get.rs | 488 +++++++++--------- 1 file changed, 240 insertions(+), 248 deletions(-) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index dd6587c197..cc0fc82b37 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -47,16 +47,7 @@ mod topology_requests { use super::*; #[test] fn it_returns_a_response_with_200_status_and_a_correct_topology() { - let json = serde_json::to_string(&Topology { - coco_nodes: vec![CocoPresence { - host: "foo.org".to_string(), - last_seen: 12345, - pub_key: "key".to_string(), - }], - mix_nodes: vec![], - mix_provider_nodes: vec![], - }) - .unwrap(); + let json = fixtures::topology_response_json(); let _m = mock("GET", "/topology") .with_status(200) .with_body(json) @@ -64,244 +55,245 @@ mod topology_requests { let req = Request::new(mockito::server_url()); let resp = req.get(); assert_eq!(true, resp.is_ok()); - assert_eq!(12345, resp.unwrap().coco_nodes.first().unwrap().last_seen) + assert_eq!(1575915097085539300, resp.unwrap().coco_nodes.first().unwrap().last_seen) } } - - // mod fixtures { - // fn topology_response_json() -> String { - // r#"{ - // "cocoNodes": [ - // { - // "host": "3.8.244.109:4000", - // "pubKey": "AAAAAAAAAAEKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEFuhRpy4HfcuxwcRI9sIWMo_LVmbk19g1gfMRlBrmZqoEQL6rDApVLZ9eMp-5IQK8WLlZpWf4Zjy7kZolARAyp_rHUQkH4PrDjgoPrKbm6qK_iejYpL7qx28Q3VeInMpwMIMaSbbW9y36sEVtGc2I0Iu5vS0sp8ESiVlQ5NaBz72deZ8oKJJ4IEPPHP99-b0UQX80fVIrNM88mMzKy0bHri9NFlmIG-e0G1cqmw_ry3XWGQkcr1M5RuNa6oX50w5QawAEVxd5FP5bE8bS4x54Csof11sQWUTwMp6Q7_3H7ZCTSlKSqujlOhmfqSHfGPO2sDIYPHDhDzjakZpKAZWWhn_hiR6DfPpomQ01ZYUhVKKSMxz7_VPjsQplP0bZXA2gfnkADUN8UQ0N9g_usIw73r4aZsOviMsRM8oByvsjVfUWc4_HTLSdnQyImFkHz9CiCmrIYL2dYQRePRatWggvBAyeRzntxI4jDqLKiBdi54ZlAKgV6MCRaJ7Bu7BtmLXrtK4sawAED3QYxuvOSZrbZdUr4yG-U9yVvJ9Klkf-5Mo4EYp3qTL2KBB6_LrZepjAQqp486YkZ03mTIezcsZ48EboXVTWKBZ3QnTI5tX-j4gGxQb7klOJc97qJkDxsvpz4F0ChgCUIZhpIItWHia7_R3Gi-b5siLIdQdUho9isn3kiDGm6t0NED2Bgy3ZxxQwzqsBZm4kPr2_fPX4YyvIoP9895YcGjZyE5iiRC_TE41RJmB1GZYdxegTMq3lNDllKgiqaiPgawAEJASDkmZHTwlg9YOev5OWpQD-FnhPkqVNo_QcDyRu9eoGcWSGFp2sYqjG2SpmiXq0VNnAO7AcKxRzDFu7TjfhlU3Kt0uTKIcrWVU1zFNbJNMjYEq90pp50nowwx8INz20IXET2ZNX6kIXYFCsEvPLZFlG2OoL6xg3uQS1qMl3lIS_VxdO_JfVe0rT65WsJ_P4Nkc1jYiuNPHY6d_iFO0BVYqX0sOCX73GC_TT13BR0jnPwDAVw0rGtYHsXBb8TKOsawAEZIClauuT1V3qOZnb7uRZhFXO-PKTxgc1LCzJt2ChOrMZaBpjlkf3IPpJ2UF4JH4kGaDeBf2k_S-FLAs3drK21efbi5P6_a4QTxAiiRimXGoQIyvOg462s6kP_ZRFufo8YYQHS4olaOeqU4564dNskg_uBPsFMz_2GNOhmn_15cJqP1jfkyD49Z16GTS5YLHgVl9bJKqyvLuypsToLbt1BJzipEP0L2OohuRm-_MvqvwwWKyjNQsubgee1K728d9AawAEBkGggcNVCtXyhoSqi3_w0tVxtkAYeud8sBeAtZHGs06me_QL8co0MFLlO-zdkUb4ZBq08rFEbgLOma8_3whleM8NIPaHNISp1q3IsIhB5zdXcZoGsqLixODBFHtID3YEHAlr4f9T_yh11yJ95xGCl_6Y37hpwLQVGyrfSfccM24mVFqnV3TT5Wdq3ile-jesUx1Q2G1yK_xVqc6itmk-kDuBjyZgzYi1-jsIXAjnhM9G7t8J_Bv5yGGZhLK2dCzM=", - // "type": "validator", - // "lastSeen": 1575915097085539300 - // }, - // { - // "host": "3.9.129.61:4000", - // "pubKey": "AAAAAAAAAAMKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEEv6RMevAQmLGkeK0uJKnMPPAtm8GgXjWSQijYdnxlPh5SJSNeJUbPZKWFFWdk8yIFXKa8jnzETtdGFKgUUt5AVUDpTBmEdwaHCzlFhXrttshy0V5OhPUlV8cGABmxbagMYm0bFPg0r-snSkrB9YG6wqJYQVeIMOCGYCPbHmDA8R_0-h8VkRKWs1d9KvQOK4kShqgZtYN71KJW8uDE4q2jsGDVvxFt1AgmU9b93xsXF17KrpZy5WxlLZ73HtnTD_oawAED4vd_rK-Kx_n8x_OdDiiEOPUlYDlDCQUqenU9XHKH3B6ijfkJ368wd3LDDVStjDwNORrAyUSw_VlSNUpd1XLC8d17gTaIq5ZI2fWuwwZaoN1JCsYU8fQ6USgtIehQX7IPP8EkFuNmuCBCmpr4schtYniGe9J8Q4dsV-TYPr2uLJkdx1r7luzF--I22k7NfQQM14QDci_0kgrgmZ54CJGkjXyOhCppBXg3fqLC6aFvT3ZocfiiXBJt0huGgPMDtYsawAECLh8KUdNsDolERwJ8v04bS5jI_KKf7uUnCHWuCELwbJSUI3OK1ufS1qSpauvSzVQSbrhEzrEfwQn4VtxQxJlX4UdDU-R-hafiZvVC6DLLAbuORBAC3FScn9W58CnezH4DvCp_w7nftDfdxeuungbZT9XaxS3iNC6PnFsWF6WM3DxMwrzOrFe6wEEoTSPe1mcUDrtwM5UksIvJr6MBRAXrdl0IdBTQr7cLwKe_KYi4siwdjfJEJtOh7oxQBxBg2UkawAEJAPZK2Gg2MQwpxdDT24lNQHF7FVfkO_LuhJwn0RbwNDSVeA4P6-tWL5TkCpqr8xYHfwQ6Z3ILfpGCZr8PspwIoRzqZHQ16f8Pq9xnr0hLEI9BOQU0FS2EtuyPgju5iwsAJAfehUzu6kNLphuLGsXoIZdXDG5mbylwh9JzAVXTwgaR0hNqyXVJxgbt7jcYaSEBFcMGV-hjXyVVNzBleE-G9o_noI_KWU4Ce7K-qOMcewMKfy_VEw-gVaD6dHz6AMoawAEE9XuOLwRttvKybAssZ9gsK-_YRUwuFOeRDIr3NX___9bx6pCc18adCIlH_8EJWFwXZ05ZpNNE88mYx7ZQ3aqaArZJRoWeZeKhqH_s05V10xbzkYX71G5cqz--8vr9ZlQRb2BeETF_Tdq_PLk7qbT8WTGIoq7ZwyDRQTgzvkCgyzj_hBLh2o7sSVNgUo38SFUTMn7YtvVFYlSrTDE3WKE-T-nh5SWdDBxgDTc3Bw8JpzNH-WkoJ4Lim7sB4Op1gEUawAEW4-kenlffwsNr_3b3aV0YuusLpxB03sxPzQ5B0CWNiVtbja1Z4tWhKGUUrdq_eUgMV0y5Of-BqNi5FspAQnhJBFSSxtOzRGV1h3qyUTksfZyed9z8zPI-ZPP9XXm7hYgJgDz_kxte-NfS9UG9q5AZetHUN4kGxXutjjzfUQZ9yTvhBKgKgTI2Dp_R_jZrWQ8F1BoWzIJzjddT1K2MvCQEkARYw08isbOeFmCwgVUcjxYZO45WyOmLQA7QJRL9WvA=", - // "type": "validator", - // "lastSeen": 1575915097388409000 - // }, - // { - // "host": "3.9.222.1:4000", - // "pubKey": "AAAAAAAAAAQKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAECh9xcxpjOp1r7kiNIgrI9GgAlvXwgHkTchOxUiyOzTq6FDWdGN64KiC3NDeyGTg8FmzvGzS3jREeJqOdr4G9ZGtWkauAITgLFiH62t-YntRslhr8_1shxlmzKiNKJN_QFflEq79pZIlWtp3N8LIHMvXRtl-zt2DMze4s02XDmEkviyVE4CkQUDtCc-2MfPT4JcmEFqtFIxjrXn18SbYg3c6XUQHsGIkuDrKuCTRlpC8kvmM0uVoIeWdmwDlZk4jUawAEJhRwK5ozjqIWRP1bFzBPS9VhaJnfKU9PeFYtN5beiAHrYr2ylIB3yDfmAQUdKDowDUm5nfJATejEjEnrTGxh70QtfoNV391rSns3F71tBwY62KLaNr8qnVfeSFHV3FcQTMHHF_8mDb5_11Rj6aiMvW0y6eetHo7CDPMdEyDPmok_U2ZM5BzOUnwjT21HtnvcKxKKwHJ_QGfnAHPyDIhNOMgxJCrVazOidLCHeYGpyCLw1ipeTyKOQX0_ByB8dH6AawAEGV1GuF5SSlT67B1ityPJK2ZwXjeeKB4gGdCG3qRtWxLTZfGhVm7YAYm2f5tw_wrsJAZ9FubVhateGg0ZN67NxZtsvOOejXz6743f7ijnQopPgd_8pH-iVf6BEcSO8ZdcHxNRUTayzjVLs99bwMo2zaPevW4X4G_bN4mh---aPkdGYHwaiklzUhqJ-eqycrYAFyjyEXaPBXLQm1rpczqluNvnKbd8Q9LZWukgm7_uWv_HxufIvdWgoq8bAt78UU3oawAEP9VDehhqrQG5-WHMB66XVxo1TgMM8aVV0SwAq3lCRkpiFBz_9kw8T1F9Hx2AiNrEGT1QLbdMkpms1cG_5gBBahQofdt_NmUs1jfTFXY9iyMy1Q7A6ZYaLP8Z6q-orc1cKqySY-BJZQ_CpGFfXS0OVniFDQ6v78ytPK7K-yRgT1PxFgm3rZqrG0Tjbrpsg2PUL5S5fuXfMhUosP0uoLj0D1guWAR9Y7kfFBIXaTSFMoa8fghVBUTRNhK9f72a8SxQawAEOiv71taLjKqaaWQ_QjcDhWbvjG1EnsCyI0toNjGkcF19x4Vk-5NC96_4ioUGz404IC0XN03roRnibRT_78D9vZFVCWCqve9EjdF5TcApx03zIP4JT2g2q0MKIGgGrwt4Pz6LO6yOfMm7B8Yraps8IV-nP1w7K1m9XKP_FvH8egl5GHJe-_omlC2YyL_b28jMLENbxDFD-3KPjZFBhSLrRukX2PlayYTwEiTtokA2R9_11vQvJgP8KFEjGHg6zsAMawAEBn2H_hz2knb8ltnpEA5YSKVcV3nUtojkCNi_WUz7xUKd7efw1oI_lbnKrS7HkyC0JkQUZ1pCWUlSXNmgjMEhsn823a1LFzpV7rOv4vayYvvFX61hB9R78VjpyxJiYpDwRZLiUY3AK4WY8NqFDbjXR7rT4CkFHEf-VhSQQ8ZNvlpod1nmeVQVizHH9e7Tq7wsWz-LWEk3Hx6LmcrgDsL79LZYG9JXU5IdvG8RvLNx9cSwEI8yxcchpISAaot7UoYQ=", - // "type": "validator", - // "lastSeen": 1575915094734973000 - // }, - // { - // "host": "3.9.102.214:4000", - // "pubKey": "AAAAAAAAAAIKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEOVCUN3EwiVroS5-TOq2o7hYSxphK9X0G23N-IBZ0Tr1Rl8XEiJ-OEy0rqnAKwmhAZJWnx3u8oXqbZtOWIZmzQSpcoxhgwfhdmTZJCqT2RVzZyeFItX4sVeilEP3z2xdsJs8-a1kg6UZnx1s1BNLBo7eZrreZygWojPCIDBn03fSAflXoVc5PpY2CGy5MA_IgWgSYBHDdoZEtigp_amjqK7Us44Db20XpLxMXfbahiqa7WKNnMgi6Ca2H67VtaaD8awAEF3zbE1nZRAa7a8vbU25c80YBYJBaW8P6FwXQI-K0Xk5MakwYeMMnIrm6w6IS_0XAO5YlD453GLqnxY8H1BEnRpfOnT7PE4el9mJ8MuYQMo6R2up0lGCmYM0YA9FORjroM3ng69SEPfJPCReG7LfJkERl_m2U403ertDRBYrlqCDagDfyI500srBcMrjSvV3oNouyyx3yZUrjLQfbHhDteQFsYdmakJs8Y-Q9-5MXCcrz6Qa4xwv522Euv0CCxkHcawAEYjfsU_zDhUZA1ey1aquWXlFOnx-iEALqxW1slDYHwQ1M2SILc-v_E6i1doa5e_bAZHVezBHFAlaNAVedNyHFFJxYAqAK3hbzbvl2glw3Q6h_rTXElymloqtaqVFIJ-oUWWOHsZBmu8EDA-HzvGCiBa_GbRaVfh2lE4ObeMXoJrEm_5dbxxeEic2l3IYeIz40N9ooQQOkQcOZdY4AXWYCavIAwWEJBjLtptJgCLu9a_zM1S5GsiyJHpdDs46WbP0EawAEWZ-95Sf0YAHujxRNLdXgpqe0ZF8loVwzZfvyMvqaxF1Ug274BqHuY_c5NdPAzuqoTwjfEn8NKEoaNqlumM75FUYbaTd7mXvk4WVYWjVnkO40dfQjRB7DYhvj0LBlbndAJ4wJIA2ilPYgjZsXVbNNh3e2j3u9eABd0VaFMbSb8Sz5_31r8HzoWmPJs3HiyuyANGFUA6CvAnMN6K3b-D8BhFZU_nPUTgu80o8_n6LQt-XWbaC_mTHzsnOjzBiPJxlYawAEW3bmOEtStH2T8q7vMkhchImp2-hg9MFYGBmEe9sSByTn3NUf8eksqXOC1dUjHkXoZm298FgUYLkNdnlxWpf993j5mEDoFxjcTB7scBD7k6nu6Nrs_wK0-seS8gsHrx9UK7GwAsi10q82Cm4PFyAtrWjmy_d9WLHuZt6VIOKunTs8cf0FwNUiMcvZsruqIFJcP7iWxdiFdUkh65P_iCz1ZEjJcj2GEZoq4v3a3by1aizGPaaiKc1jd_T-XJg_YpncawAEWnstu5b9WiZv0x8xfsiMk6YRlU0Cnj5svxLLXz_8drvwAa--GBY5yH0ke2EM6udMEi2EPeFcGTe6Sjs0YEhSbY7Uad_8suD2J4tIWJSWBbiyvh7rSqzv57m7BlsVcHfQJn_wNH-UlC9xkx8vg-LwfN8_FlxvHNPTc7XZG3lKYbwpUWlZxAziOYT1VQ-2K2bQQBBMdix-ht_SjccL1Dc2dP5kDazQ8yZV_8xnyeheazEedWe63uutfkHlZRg9YwP8=", - // "type": "validator", - // "lastSeen": 1575915094967382800 - // } - // ], - // "mixNodes": [ - // { - // "host": "35.176.155.107:1789", - // "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", - // "layer": 3, - // "lastSeen": 1575915096805374500 - // }, - // { - // "host": "18.130.86.190:1789", - // "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", - // "layer": 1, - // "lastSeen": 1575915097370376000 - // }, - // { - // "host": "3.10.22.152:1789", - // "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", - // "layer": 1, - // "lastSeen": 1575915097639423500 - // }, - // { - // "host": "35.178.213.77:1789", - // "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", - // "layer": 2, - // "lastSeen": 1575915097895166500 - // }, - // { - // "host": "52.56.99.196:1789", - // "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", - // "layer": 2, - // "lastSeen": 1575915096255174700 - // }, - // { - // "host": "3.9.12.238:1789", - // "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", - // "layer": 3, - // "lastSeen": 1575915096497827600 - // } - // ], - // "mixProviderNodes": [ - // { - // "host": "3.8.176.11:1789", - // "pubKey": "54U6krAr-j9nQXFlsHk3io04_p0tctuqH71t7w_usgI=", - // "registeredClients": [ - // { - // "pubKey": "zOqdJFH49HcgGSCRnmbXGzovnwRLEPN0YGN1SCafTyo=" - // }, - // { - // "pubKey": "fy9xo69hZ2UJ9uxhIS1YzKHZsH8saV-02AiyCNXPNUc=" - // }, - // { - // "pubKey": "6hFCz42d5AODAoMXqcBWtoOoZh-7hPMDXbLKKhS7x3I=" - // }, - // { - // "pubKey": "pPZMDzw0FyZ-LBAhwCvjlPGj1p2bO_vaWbRBc7Ojq3Q=" - // }, - // { - // "pubKey": "kjl5poXt2GdIrHLuMBjmTBSChV-zMqsXFBhKZoIREVI=" - // }, - // { - // "pubKey": "T1jMGuk7-rcIUWnVopAsdGzhAJ7ZVymwON2LzjuOfnY=" - // }, - // { - // "pubKey": "3X0eKPkflx5Vzok0Gk0jm5-YEfvPAuWP55ovyBUOtXA=" - // }, - // { - // "pubKey": "5wC3i8rCZolLKbWJ9U6eLieXNGLKM21dtL6lR30u_hE=" - // }, - // { - // "pubKey": "1P6p7fgjwjlEepD9JgbN1V-rk9n36-hCmPN5P6y62n4=" - // }, - // { - // "pubKey": "aBjlLQKKFroqhX_kvYLnMm1uq3FJdQWqVy9Q35zzERA=" - // }, - // { - // "pubKey": "I0gVOPj6lv9ha60xPYKeAgbeUU8pdyMD-Y7Nb1nS9EQ=" - // }, - // { - // "pubKey": "WgdvQ74QH1uFDWDL2YeApvv7oniNGh9BQJ_HZam20QA=" - // }, - // { - // "pubKey": "Mlw23KaSL2hyrIjEZM76bZStt2iMzxVAqXwO5clJfxg=" - // }, - // { - // "pubKey": "F9xzbjnMQVN4ZidcqN2ip9kVnI9wbS39aVayZGiMihY=" - // }, - // { - // "pubKey": "s6pfVkZrUG--RNjfzS55N2oPvFkMdvgb1LUut6gqRy4=" - // }, - // { - // "pubKey": "bSi-9k0jJNKc8PGx8M3SWFaNpORFjYw-NkWXRZVRWGU=" - // }, - // { - // "pubKey": "pz6ahQcGOQcZBFx1tGmzRngqk6BecXB_wFd4WVdOQDU=" - // }, - // { - // "pubKey": "5sfwIMcG2zRCxhDh4D9Evw1WPI5bfKZAShM_6o9Pu1I=" - // }, - // { - // "pubKey": "9fZnxXy9onGPpZ3Ygckqw0okqCw3di02sLr-NTBr4SE=" - // }, - // { - // "pubKey": "Q0TbbggOwzZjalUdi5eEHVFi9VMv-rMm5mJPUZZs12A=" - // }, - // { - // "pubKey": "aPNyox_qAIGFB2-wZ0lc9iAWDN6jzLojApSiWVFjCks=" - // }, - // { - // "pubKey": "DUKLEsIGMw-ucs3DjS7Ag9qCb5-C_A84DuIsZuLkdwI=" - // }, - // { - // "pubKey": "YV84vPoSrLf1p9Sw6FnnrcCpS3kvpJUfKyKpnwk8z0Q=" - // }, - // { - // "pubKey": "_IYEzZQoBAYeTxqzpEe_ez1-7pn7aId8AKliazy0qlE=" - // }, - // { - // "pubKey": "srkOAoVU-a02lnEsoH_wOLLw7HFx_xHIZUSbnhjFwDw=" - // }, - // { - // "pubKey": "LxSCBn_OEQq-hI2xDi6bfGoioRO_lSTIq6AQ9l1k5jg=" - // }, - // { - // "pubKey": "OC0OOqtGfAytgZjthpjoKeYNa0VrtzfgZ0iO5Fag5y8=" - // }, - // { - // "pubKey": "ImVEch2focRhm1ial1gA6YJPr6WDyW3oh-OgYcO5Ll4=" - // }, - // { - // "pubKey": "yTDnzLvEaSq0mC9xNrtyjpAKtsIU6yRuBepCuWQMBm4=" - // }, - // { - // "pubKey": "-LCUUc46HuL7iUEOMkrlVAkvvulRiQ7dR1QYh7bkKxw=" - // }, - // { - // "pubKey": "Bx1MGpISig25rqe7mhoX68EROUPPzmF7yGLYah9DPgM=" - // }, - // { - // "pubKey": "Z4Nu6iwLmgJ93yoIFTbTEBeDAHRwS-vo1T_K2Kv1FQo=" - // }, - // { - // "pubKey": "cKFAGxllwAmEXCtDxG_T1iEm3-lKWUVQxxpDBje6mQU=" - // }, - // { - // "pubKey": "pQV40whlQWUSXtrNTTePzO6sdq3zr1JUIWZWvD443nY=" - // }, - // { - // "pubKey": "6Bb5HwnVqJPy5wcNsaHY-0y__coZCE7XC80kUkesnRU=" - // }, - // { - // "pubKey": "COGdpfhmzNGR6YX820GqJIkjOihL8mr6-h-d3JlTDFA=" - // } - // ], - // "lastSeen": 1575915097358694100 - // }, - // { - // "host": "35.178.212.193:1789", - // "pubKey": "sA-sxi038pEbGy4lgZWG-RdHHDkA6kZzu44G0LUxFSc=", - // "registeredClients": [ - // { - // "pubKey": "UE-7r6-bpw0b4T3GxOBVxlg02psx23DF2p5Tuf-OBSE=" - // }, - // { - // "pubKey": "UnZuLpzq64_EPtIcr1Fd-5AESBCBLFnDMDsjUaOqrUA=" - // }, - // { - // "pubKey": "4ExXPrW5w0nZIQ5ravBRT6H9r0RH0MXuOcGIF8HzUhg=" - // }, - // { - // "pubKey": "wPsRpJPi1e2sjItyRKDkFACbxwu3Cw5GlYVPmdYxk2U=" - // }, - // { - // "pubKey": "UfK5UvT3HUkT1SGbv1QGafy3in3uQ9a6NSy5EOT6k0k=" - // }, - // { - // "pubKey": "5Giu-tJpGXU0S9Av75iAv5qDO0k6l8v_k9-UCcRUCl4=" - // }, - // { - // "pubKey": "MnQxlmmKDybku4CfxsQQxfftilsaphF9Gq1w3MB1ZCE=" - // }, - // { - // "pubKey": "GdP1fHVs2R65EkuWVWKZSz6WPDh0MgThyuBOv6_xsmQ=" - // }, - // { - // "pubKey": "4JEtSrKsonmBuDvxJ9nITSu7iC4f8reutXRAVugPgS4=" - // }, - // { - // "pubKey": "q4XyuUJbSGJaoRb3SmWzeX88V2dKB7sPTf72BAtQp3k=" - // }, - // { - // "pubKey": "gTzKd1Ph5bpUw-JxTZiCe8RBfO-FsZiVYDYioQ-6dVg=" - // }, - // { - // "pubKey": "NX4oaDLYEOmMUP_9pcEaZv5MJHJ4ZYAoxPQDxov7tRs=" - // }, - // { - // "pubKey": "7fbk4oGQNlTW-tnWjVz8rWtKrtAicTsiNWgO98sqMyk=" - // }, - // { - // "pubKey": "w1bfLpnd3rWu5JczB0nQfnE2S6nUCbx2AA7HDE48DQo=" - // } - // ], - // "lastSeen": 1575915097869025000 - // } - // ] - // }"#.to_string() - // } - // } + #[cfg(test)] + pub mod fixtures { + #[cfg(test)] + pub fn topology_response_json() -> String { + r#"{ + "cocoNodes": [ + { + "host": "3.8.244.109:4000", + "pubKey": "AAAAAAAAAAEKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEFuhRpy4HfcuxwcRI9sIWMo_LVmbk19g1gfMRlBrmZqoEQL6rDApVLZ9eMp-5IQK8WLlZpWf4Zjy7kZolARAyp_rHUQkH4PrDjgoPrKbm6qK_iejYpL7qx28Q3VeInMpwMIMaSbbW9y36sEVtGc2I0Iu5vS0sp8ESiVlQ5NaBz72deZ8oKJJ4IEPPHP99-b0UQX80fVIrNM88mMzKy0bHri9NFlmIG-e0G1cqmw_ry3XWGQkcr1M5RuNa6oX50w5QawAEVxd5FP5bE8bS4x54Csof11sQWUTwMp6Q7_3H7ZCTSlKSqujlOhmfqSHfGPO2sDIYPHDhDzjakZpKAZWWhn_hiR6DfPpomQ01ZYUhVKKSMxz7_VPjsQplP0bZXA2gfnkADUN8UQ0N9g_usIw73r4aZsOviMsRM8oByvsjVfUWc4_HTLSdnQyImFkHz9CiCmrIYL2dYQRePRatWggvBAyeRzntxI4jDqLKiBdi54ZlAKgV6MCRaJ7Bu7BtmLXrtK4sawAED3QYxuvOSZrbZdUr4yG-U9yVvJ9Klkf-5Mo4EYp3qTL2KBB6_LrZepjAQqp486YkZ03mTIezcsZ48EboXVTWKBZ3QnTI5tX-j4gGxQb7klOJc97qJkDxsvpz4F0ChgCUIZhpIItWHia7_R3Gi-b5siLIdQdUho9isn3kiDGm6t0NED2Bgy3ZxxQwzqsBZm4kPr2_fPX4YyvIoP9895YcGjZyE5iiRC_TE41RJmB1GZYdxegTMq3lNDllKgiqaiPgawAEJASDkmZHTwlg9YOev5OWpQD-FnhPkqVNo_QcDyRu9eoGcWSGFp2sYqjG2SpmiXq0VNnAO7AcKxRzDFu7TjfhlU3Kt0uTKIcrWVU1zFNbJNMjYEq90pp50nowwx8INz20IXET2ZNX6kIXYFCsEvPLZFlG2OoL6xg3uQS1qMl3lIS_VxdO_JfVe0rT65WsJ_P4Nkc1jYiuNPHY6d_iFO0BVYqX0sOCX73GC_TT13BR0jnPwDAVw0rGtYHsXBb8TKOsawAEZIClauuT1V3qOZnb7uRZhFXO-PKTxgc1LCzJt2ChOrMZaBpjlkf3IPpJ2UF4JH4kGaDeBf2k_S-FLAs3drK21efbi5P6_a4QTxAiiRimXGoQIyvOg462s6kP_ZRFufo8YYQHS4olaOeqU4564dNskg_uBPsFMz_2GNOhmn_15cJqP1jfkyD49Z16GTS5YLHgVl9bJKqyvLuypsToLbt1BJzipEP0L2OohuRm-_MvqvwwWKyjNQsubgee1K728d9AawAEBkGggcNVCtXyhoSqi3_w0tVxtkAYeud8sBeAtZHGs06me_QL8co0MFLlO-zdkUb4ZBq08rFEbgLOma8_3whleM8NIPaHNISp1q3IsIhB5zdXcZoGsqLixODBFHtID3YEHAlr4f9T_yh11yJ95xGCl_6Y37hpwLQVGyrfSfccM24mVFqnV3TT5Wdq3ile-jesUx1Q2G1yK_xVqc6itmk-kDuBjyZgzYi1-jsIXAjnhM9G7t8J_Bv5yGGZhLK2dCzM=", + "type": "validator", + "lastSeen": 1575915097085539300 + }, + { + "host": "3.9.129.61:4000", + "pubKey": "AAAAAAAAAAMKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEEv6RMevAQmLGkeK0uJKnMPPAtm8GgXjWSQijYdnxlPh5SJSNeJUbPZKWFFWdk8yIFXKa8jnzETtdGFKgUUt5AVUDpTBmEdwaHCzlFhXrttshy0V5OhPUlV8cGABmxbagMYm0bFPg0r-snSkrB9YG6wqJYQVeIMOCGYCPbHmDA8R_0-h8VkRKWs1d9KvQOK4kShqgZtYN71KJW8uDE4q2jsGDVvxFt1AgmU9b93xsXF17KrpZy5WxlLZ73HtnTD_oawAED4vd_rK-Kx_n8x_OdDiiEOPUlYDlDCQUqenU9XHKH3B6ijfkJ368wd3LDDVStjDwNORrAyUSw_VlSNUpd1XLC8d17gTaIq5ZI2fWuwwZaoN1JCsYU8fQ6USgtIehQX7IPP8EkFuNmuCBCmpr4schtYniGe9J8Q4dsV-TYPr2uLJkdx1r7luzF--I22k7NfQQM14QDci_0kgrgmZ54CJGkjXyOhCppBXg3fqLC6aFvT3ZocfiiXBJt0huGgPMDtYsawAECLh8KUdNsDolERwJ8v04bS5jI_KKf7uUnCHWuCELwbJSUI3OK1ufS1qSpauvSzVQSbrhEzrEfwQn4VtxQxJlX4UdDU-R-hafiZvVC6DLLAbuORBAC3FScn9W58CnezH4DvCp_w7nftDfdxeuungbZT9XaxS3iNC6PnFsWF6WM3DxMwrzOrFe6wEEoTSPe1mcUDrtwM5UksIvJr6MBRAXrdl0IdBTQr7cLwKe_KYi4siwdjfJEJtOh7oxQBxBg2UkawAEJAPZK2Gg2MQwpxdDT24lNQHF7FVfkO_LuhJwn0RbwNDSVeA4P6-tWL5TkCpqr8xYHfwQ6Z3ILfpGCZr8PspwIoRzqZHQ16f8Pq9xnr0hLEI9BOQU0FS2EtuyPgju5iwsAJAfehUzu6kNLphuLGsXoIZdXDG5mbylwh9JzAVXTwgaR0hNqyXVJxgbt7jcYaSEBFcMGV-hjXyVVNzBleE-G9o_noI_KWU4Ce7K-qOMcewMKfy_VEw-gVaD6dHz6AMoawAEE9XuOLwRttvKybAssZ9gsK-_YRUwuFOeRDIr3NX___9bx6pCc18adCIlH_8EJWFwXZ05ZpNNE88mYx7ZQ3aqaArZJRoWeZeKhqH_s05V10xbzkYX71G5cqz--8vr9ZlQRb2BeETF_Tdq_PLk7qbT8WTGIoq7ZwyDRQTgzvkCgyzj_hBLh2o7sSVNgUo38SFUTMn7YtvVFYlSrTDE3WKE-T-nh5SWdDBxgDTc3Bw8JpzNH-WkoJ4Lim7sB4Op1gEUawAEW4-kenlffwsNr_3b3aV0YuusLpxB03sxPzQ5B0CWNiVtbja1Z4tWhKGUUrdq_eUgMV0y5Of-BqNi5FspAQnhJBFSSxtOzRGV1h3qyUTksfZyed9z8zPI-ZPP9XXm7hYgJgDz_kxte-NfS9UG9q5AZetHUN4kGxXutjjzfUQZ9yTvhBKgKgTI2Dp_R_jZrWQ8F1BoWzIJzjddT1K2MvCQEkARYw08isbOeFmCwgVUcjxYZO45WyOmLQA7QJRL9WvA=", + "type": "validator", + "lastSeen": 1575915097388409000 + }, + { + "host": "3.9.222.1:4000", + "pubKey": "AAAAAAAAAAQKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAECh9xcxpjOp1r7kiNIgrI9GgAlvXwgHkTchOxUiyOzTq6FDWdGN64KiC3NDeyGTg8FmzvGzS3jREeJqOdr4G9ZGtWkauAITgLFiH62t-YntRslhr8_1shxlmzKiNKJN_QFflEq79pZIlWtp3N8LIHMvXRtl-zt2DMze4s02XDmEkviyVE4CkQUDtCc-2MfPT4JcmEFqtFIxjrXn18SbYg3c6XUQHsGIkuDrKuCTRlpC8kvmM0uVoIeWdmwDlZk4jUawAEJhRwK5ozjqIWRP1bFzBPS9VhaJnfKU9PeFYtN5beiAHrYr2ylIB3yDfmAQUdKDowDUm5nfJATejEjEnrTGxh70QtfoNV391rSns3F71tBwY62KLaNr8qnVfeSFHV3FcQTMHHF_8mDb5_11Rj6aiMvW0y6eetHo7CDPMdEyDPmok_U2ZM5BzOUnwjT21HtnvcKxKKwHJ_QGfnAHPyDIhNOMgxJCrVazOidLCHeYGpyCLw1ipeTyKOQX0_ByB8dH6AawAEGV1GuF5SSlT67B1ityPJK2ZwXjeeKB4gGdCG3qRtWxLTZfGhVm7YAYm2f5tw_wrsJAZ9FubVhateGg0ZN67NxZtsvOOejXz6743f7ijnQopPgd_8pH-iVf6BEcSO8ZdcHxNRUTayzjVLs99bwMo2zaPevW4X4G_bN4mh---aPkdGYHwaiklzUhqJ-eqycrYAFyjyEXaPBXLQm1rpczqluNvnKbd8Q9LZWukgm7_uWv_HxufIvdWgoq8bAt78UU3oawAEP9VDehhqrQG5-WHMB66XVxo1TgMM8aVV0SwAq3lCRkpiFBz_9kw8T1F9Hx2AiNrEGT1QLbdMkpms1cG_5gBBahQofdt_NmUs1jfTFXY9iyMy1Q7A6ZYaLP8Z6q-orc1cKqySY-BJZQ_CpGFfXS0OVniFDQ6v78ytPK7K-yRgT1PxFgm3rZqrG0Tjbrpsg2PUL5S5fuXfMhUosP0uoLj0D1guWAR9Y7kfFBIXaTSFMoa8fghVBUTRNhK9f72a8SxQawAEOiv71taLjKqaaWQ_QjcDhWbvjG1EnsCyI0toNjGkcF19x4Vk-5NC96_4ioUGz404IC0XN03roRnibRT_78D9vZFVCWCqve9EjdF5TcApx03zIP4JT2g2q0MKIGgGrwt4Pz6LO6yOfMm7B8Yraps8IV-nP1w7K1m9XKP_FvH8egl5GHJe-_omlC2YyL_b28jMLENbxDFD-3KPjZFBhSLrRukX2PlayYTwEiTtokA2R9_11vQvJgP8KFEjGHg6zsAMawAEBn2H_hz2knb8ltnpEA5YSKVcV3nUtojkCNi_WUz7xUKd7efw1oI_lbnKrS7HkyC0JkQUZ1pCWUlSXNmgjMEhsn823a1LFzpV7rOv4vayYvvFX61hB9R78VjpyxJiYpDwRZLiUY3AK4WY8NqFDbjXR7rT4CkFHEf-VhSQQ8ZNvlpod1nmeVQVizHH9e7Tq7wsWz-LWEk3Hx6LmcrgDsL79LZYG9JXU5IdvG8RvLNx9cSwEI8yxcchpISAaot7UoYQ=", + "type": "validator", + "lastSeen": 1575915094734973000 + }, + { + "host": "3.9.102.214:4000", + "pubKey": "AAAAAAAAAAIKwAECSqKy8I8KkSYIBSctxRBRxuR61PpAOwK0UQtkeuPRdwusAyaoBbvv1IBWyMEhvbgT4CtgUnGfYH2s06CIJ09lWWvQ0Jkgthq12mG73H9QSTNM8RITlF1X5ax9BV0EK34M5dUncn1uEYzJzcbaLjUarf2bqoy906dtQpppUWDRLJI6ycw7rKKJ4ZNUhgi4KAEGBsSgLqc0zDKs0rArwouZyz4ofoWnY68mdJKrVy6Zqz83DSdc7B2hqqkHX_Bfeb4SwAEOVCUN3EwiVroS5-TOq2o7hYSxphK9X0G23N-IBZ0Tr1Rl8XEiJ-OEy0rqnAKwmhAZJWnx3u8oXqbZtOWIZmzQSpcoxhgwfhdmTZJCqT2RVzZyeFItX4sVeilEP3z2xdsJs8-a1kg6UZnx1s1BNLBo7eZrreZygWojPCIDBn03fSAflXoVc5PpY2CGy5MA_IgWgSYBHDdoZEtigp_amjqK7Us44Db20XpLxMXfbahiqa7WKNnMgi6Ca2H67VtaaD8awAEF3zbE1nZRAa7a8vbU25c80YBYJBaW8P6FwXQI-K0Xk5MakwYeMMnIrm6w6IS_0XAO5YlD453GLqnxY8H1BEnRpfOnT7PE4el9mJ8MuYQMo6R2up0lGCmYM0YA9FORjroM3ng69SEPfJPCReG7LfJkERl_m2U403ertDRBYrlqCDagDfyI500srBcMrjSvV3oNouyyx3yZUrjLQfbHhDteQFsYdmakJs8Y-Q9-5MXCcrz6Qa4xwv522Euv0CCxkHcawAEYjfsU_zDhUZA1ey1aquWXlFOnx-iEALqxW1slDYHwQ1M2SILc-v_E6i1doa5e_bAZHVezBHFAlaNAVedNyHFFJxYAqAK3hbzbvl2glw3Q6h_rTXElymloqtaqVFIJ-oUWWOHsZBmu8EDA-HzvGCiBa_GbRaVfh2lE4ObeMXoJrEm_5dbxxeEic2l3IYeIz40N9ooQQOkQcOZdY4AXWYCavIAwWEJBjLtptJgCLu9a_zM1S5GsiyJHpdDs46WbP0EawAEWZ-95Sf0YAHujxRNLdXgpqe0ZF8loVwzZfvyMvqaxF1Ug274BqHuY_c5NdPAzuqoTwjfEn8NKEoaNqlumM75FUYbaTd7mXvk4WVYWjVnkO40dfQjRB7DYhvj0LBlbndAJ4wJIA2ilPYgjZsXVbNNh3e2j3u9eABd0VaFMbSb8Sz5_31r8HzoWmPJs3HiyuyANGFUA6CvAnMN6K3b-D8BhFZU_nPUTgu80o8_n6LQt-XWbaC_mTHzsnOjzBiPJxlYawAEW3bmOEtStH2T8q7vMkhchImp2-hg9MFYGBmEe9sSByTn3NUf8eksqXOC1dUjHkXoZm298FgUYLkNdnlxWpf993j5mEDoFxjcTB7scBD7k6nu6Nrs_wK0-seS8gsHrx9UK7GwAsi10q82Cm4PFyAtrWjmy_d9WLHuZt6VIOKunTs8cf0FwNUiMcvZsruqIFJcP7iWxdiFdUkh65P_iCz1ZEjJcj2GEZoq4v3a3by1aizGPaaiKc1jd_T-XJg_YpncawAEWnstu5b9WiZv0x8xfsiMk6YRlU0Cnj5svxLLXz_8drvwAa--GBY5yH0ke2EM6udMEi2EPeFcGTe6Sjs0YEhSbY7Uad_8suD2J4tIWJSWBbiyvh7rSqzv57m7BlsVcHfQJn_wNH-UlC9xkx8vg-LwfN8_FlxvHNPTc7XZG3lKYbwpUWlZxAziOYT1VQ-2K2bQQBBMdix-ht_SjccL1Dc2dP5kDazQ8yZV_8xnyeheazEedWe63uutfkHlZRg9YwP8=", + "type": "validator", + "lastSeen": 1575915094967382800 + } + ], + "mixNodes": [ + { + "host": "35.176.155.107:1789", + "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + "layer": 3, + "lastSeen": 1575915096805374500 + }, + { + "host": "18.130.86.190:1789", + "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + "layer": 1, + "lastSeen": 1575915097370376000 + }, + { + "host": "3.10.22.152:1789", + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "layer": 1, + "lastSeen": 1575915097639423500 + }, + { + "host": "35.178.213.77:1789", + "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + "layer": 2, + "lastSeen": 1575915097895166500 + }, + { + "host": "52.56.99.196:1789", + "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + "layer": 2, + "lastSeen": 1575915096255174700 + }, + { + "host": "3.9.12.238:1789", + "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + "layer": 3, + "lastSeen": 1575915096497827600 + } + ], + "mixProviderNodes": [ + { + "host": "3.8.176.11:1789", + "pubKey": "54U6krAr-j9nQXFlsHk3io04_p0tctuqH71t7w_usgI=", + "registeredClients": [ + { + "pubKey": "zOqdJFH49HcgGSCRnmbXGzovnwRLEPN0YGN1SCafTyo=" + }, + { + "pubKey": "fy9xo69hZ2UJ9uxhIS1YzKHZsH8saV-02AiyCNXPNUc=" + }, + { + "pubKey": "6hFCz42d5AODAoMXqcBWtoOoZh-7hPMDXbLKKhS7x3I=" + }, + { + "pubKey": "pPZMDzw0FyZ-LBAhwCvjlPGj1p2bO_vaWbRBc7Ojq3Q=" + }, + { + "pubKey": "kjl5poXt2GdIrHLuMBjmTBSChV-zMqsXFBhKZoIREVI=" + }, + { + "pubKey": "T1jMGuk7-rcIUWnVopAsdGzhAJ7ZVymwON2LzjuOfnY=" + }, + { + "pubKey": "3X0eKPkflx5Vzok0Gk0jm5-YEfvPAuWP55ovyBUOtXA=" + }, + { + "pubKey": "5wC3i8rCZolLKbWJ9U6eLieXNGLKM21dtL6lR30u_hE=" + }, + { + "pubKey": "1P6p7fgjwjlEepD9JgbN1V-rk9n36-hCmPN5P6y62n4=" + }, + { + "pubKey": "aBjlLQKKFroqhX_kvYLnMm1uq3FJdQWqVy9Q35zzERA=" + }, + { + "pubKey": "I0gVOPj6lv9ha60xPYKeAgbeUU8pdyMD-Y7Nb1nS9EQ=" + }, + { + "pubKey": "WgdvQ74QH1uFDWDL2YeApvv7oniNGh9BQJ_HZam20QA=" + }, + { + "pubKey": "Mlw23KaSL2hyrIjEZM76bZStt2iMzxVAqXwO5clJfxg=" + }, + { + "pubKey": "F9xzbjnMQVN4ZidcqN2ip9kVnI9wbS39aVayZGiMihY=" + }, + { + "pubKey": "s6pfVkZrUG--RNjfzS55N2oPvFkMdvgb1LUut6gqRy4=" + }, + { + "pubKey": "bSi-9k0jJNKc8PGx8M3SWFaNpORFjYw-NkWXRZVRWGU=" + }, + { + "pubKey": "pz6ahQcGOQcZBFx1tGmzRngqk6BecXB_wFd4WVdOQDU=" + }, + { + "pubKey": "5sfwIMcG2zRCxhDh4D9Evw1WPI5bfKZAShM_6o9Pu1I=" + }, + { + "pubKey": "9fZnxXy9onGPpZ3Ygckqw0okqCw3di02sLr-NTBr4SE=" + }, + { + "pubKey": "Q0TbbggOwzZjalUdi5eEHVFi9VMv-rMm5mJPUZZs12A=" + }, + { + "pubKey": "aPNyox_qAIGFB2-wZ0lc9iAWDN6jzLojApSiWVFjCks=" + }, + { + "pubKey": "DUKLEsIGMw-ucs3DjS7Ag9qCb5-C_A84DuIsZuLkdwI=" + }, + { + "pubKey": "YV84vPoSrLf1p9Sw6FnnrcCpS3kvpJUfKyKpnwk8z0Q=" + }, + { + "pubKey": "_IYEzZQoBAYeTxqzpEe_ez1-7pn7aId8AKliazy0qlE=" + }, + { + "pubKey": "srkOAoVU-a02lnEsoH_wOLLw7HFx_xHIZUSbnhjFwDw=" + }, + { + "pubKey": "LxSCBn_OEQq-hI2xDi6bfGoioRO_lSTIq6AQ9l1k5jg=" + }, + { + "pubKey": "OC0OOqtGfAytgZjthpjoKeYNa0VrtzfgZ0iO5Fag5y8=" + }, + { + "pubKey": "ImVEch2focRhm1ial1gA6YJPr6WDyW3oh-OgYcO5Ll4=" + }, + { + "pubKey": "yTDnzLvEaSq0mC9xNrtyjpAKtsIU6yRuBepCuWQMBm4=" + }, + { + "pubKey": "-LCUUc46HuL7iUEOMkrlVAkvvulRiQ7dR1QYh7bkKxw=" + }, + { + "pubKey": "Bx1MGpISig25rqe7mhoX68EROUPPzmF7yGLYah9DPgM=" + }, + { + "pubKey": "Z4Nu6iwLmgJ93yoIFTbTEBeDAHRwS-vo1T_K2Kv1FQo=" + }, + { + "pubKey": "cKFAGxllwAmEXCtDxG_T1iEm3-lKWUVQxxpDBje6mQU=" + }, + { + "pubKey": "pQV40whlQWUSXtrNTTePzO6sdq3zr1JUIWZWvD443nY=" + }, + { + "pubKey": "6Bb5HwnVqJPy5wcNsaHY-0y__coZCE7XC80kUkesnRU=" + }, + { + "pubKey": "COGdpfhmzNGR6YX820GqJIkjOihL8mr6-h-d3JlTDFA=" + } + ], + "lastSeen": 1575915097358694100 + }, + { + "host": "35.178.212.193:1789", + "pubKey": "sA-sxi038pEbGy4lgZWG-RdHHDkA6kZzu44G0LUxFSc=", + "registeredClients": [ + { + "pubKey": "UE-7r6-bpw0b4T3GxOBVxlg02psx23DF2p5Tuf-OBSE=" + }, + { + "pubKey": "UnZuLpzq64_EPtIcr1Fd-5AESBCBLFnDMDsjUaOqrUA=" + }, + { + "pubKey": "4ExXPrW5w0nZIQ5ravBRT6H9r0RH0MXuOcGIF8HzUhg=" + }, + { + "pubKey": "wPsRpJPi1e2sjItyRKDkFACbxwu3Cw5GlYVPmdYxk2U=" + }, + { + "pubKey": "UfK5UvT3HUkT1SGbv1QGafy3in3uQ9a6NSy5EOT6k0k=" + }, + { + "pubKey": "5Giu-tJpGXU0S9Av75iAv5qDO0k6l8v_k9-UCcRUCl4=" + }, + { + "pubKey": "MnQxlmmKDybku4CfxsQQxfftilsaphF9Gq1w3MB1ZCE=" + }, + { + "pubKey": "GdP1fHVs2R65EkuWVWKZSz6WPDh0MgThyuBOv6_xsmQ=" + }, + { + "pubKey": "4JEtSrKsonmBuDvxJ9nITSu7iC4f8reutXRAVugPgS4=" + }, + { + "pubKey": "q4XyuUJbSGJaoRb3SmWzeX88V2dKB7sPTf72BAtQp3k=" + }, + { + "pubKey": "gTzKd1Ph5bpUw-JxTZiCe8RBfO-FsZiVYDYioQ-6dVg=" + }, + { + "pubKey": "NX4oaDLYEOmMUP_9pcEaZv5MJHJ4ZYAoxPQDxov7tRs=" + }, + { + "pubKey": "7fbk4oGQNlTW-tnWjVz8rWtKrtAicTsiNWgO98sqMyk=" + }, + { + "pubKey": "w1bfLpnd3rWu5JczB0nQfnE2S6nUCbx2AA7HDE48DQo=" + } + ], + "lastSeen": 1575915097869025000 + } + ] + }"#.to_string() + } + } } From 44089ed558b5fefca7e4c254cdd0103490955e43 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:33:27 +0000 Subject: [PATCH 032/167] Re-enabling directory requests in `run` --- src/main.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index db854f5e2e..600a9efb2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,10 @@ use tokio::time::{interval_at, Instant}; use crate::clients::directory; use crate::clients::directory::requests::health_check_get::HealthCheckRequester; +use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; +use sphinx::route::Destination; +use crate::clients::mix::MixClient; mod clients; @@ -68,19 +71,22 @@ fn run(matches: &ArgMatches) { .get() .expect("Directory health check failed, is the Directory server running?"); - // let route = directory.get_mixes(); - // let destination = directory.get_destination(); + let topology = directory + .presence_topology + .get() + .expect("Failed to retrieve network topology."); + let route = topology.mix_nodes; + let destination = get_destination(); let delays = sphinx::header::delays::generate(2); - // println!("delays: {:?}", delays); // build the packet - // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - // - // // send to mixnet - // let mix_client = MixClient::new(); - // let result = mix_client.send(packet, route.first().unwrap()).await; - // println!("packet sent: {:?}", i); - // i += 1; +// let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); +// +// // send to mixnet +// let mix_client = MixClient::new(); +// let result = mix_client.send(packet, route.first().unwrap()).await; +// println!("packet sent: {:?}", i); +// i += 1; } }) } @@ -171,3 +177,11 @@ fn main() { process::exit(1); } } + +// TODO: where do we retrieve this guy from? +fn get_destination() -> Destination { + Destination { + address: [0u8;32], + identifier: [0u8; 16], + } +} \ No newline at end of file From 48501b93057921fc71cbf6549d2346de82397938 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:34:03 +0000 Subject: [PATCH 033/167] Cleaning up junk methods in directory mod --- src/clients/directory/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index ab35940484..ec4b80c132 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -11,8 +11,6 @@ pub struct Config { pub trait DirectoryClient { fn new(config: Config) -> Self; - fn get_topology(&self) -> Result; - // fn send_provider_presence(&self) -> Result; } pub struct Client { From e1f5de6cb7d272aaa3510a3e9471140ae40567ef Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:34:34 +0000 Subject: [PATCH 034/167] Tightening up path usage in requests --- .../directory/requests/health_check_get.rs | 16 ++++++---- .../requests/presence_topology_get.rs | 29 +++++++++++-------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/clients/directory/requests/health_check_get.rs b/src/clients/directory/requests/health_check_get.rs index b984471b1b..2f8518a060 100644 --- a/src/clients/directory/requests/health_check_get.rs +++ b/src/clients/directory/requests/health_check_get.rs @@ -2,6 +2,7 @@ use reqwest::Response; pub struct Request { base_url: String, + path: String, } pub trait HealthCheckRequester { @@ -11,11 +12,14 @@ pub trait HealthCheckRequester { impl HealthCheckRequester for Request { fn new(base_url: String) -> Self { - Request { base_url } + Request { + base_url, + path: "/api/healthcheck".to_string(), + } } fn get(&self) -> Result { - let url = format!("{}/healthcheck", self.base_url); + let url = format!("{}{}", self.base_url, self.path); reqwest::get(&url) } } @@ -34,9 +38,9 @@ mod healthcheck_requests { #[test] #[should_panic] fn it_returns_an_error() { - let _m = mock("GET", "/healthcheck").with_status(400).create(); + let _m = mock("GET", "/api/healthcheck").with_status(400).create(); let req = Request::new(mockito::server_url()); - assert_eq!(true, req.get().is_err()); + assert!(req.get().is_err()); } } @@ -46,10 +50,10 @@ mod healthcheck_requests { #[test] fn it_returns_a_response_with_200_status() { - let _m = mock("GET", "/healthcheck").with_status(200).create(); + let _m = mock("GET", "/api/healthcheck").with_status(200).create(); let req = Request::new(mockito::server_url()); - assert_eq!(true, req.get().is_ok()); + assert!(req.get().is_ok()); } } } diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index cc0fc82b37..c91c94a4d9 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -12,7 +12,10 @@ pub trait PresenceTopologyGetRequester { impl PresenceTopologyGetRequester for Request { fn new(base_url: String) -> Self { - Request { base_url, path: "/topology".to_string()} + Request { + base_url, + path: "/api/presence/topology".to_string(), + } } fn get(&self) -> Result { @@ -25,7 +28,6 @@ impl PresenceTopologyGetRequester for Request { #[cfg(test)] mod topology_requests { use super::*; - use crate::clients::directory::presence::CocoPresence; #[cfg(test)] use mockito::mock; #[cfg(test)] @@ -34,7 +36,7 @@ mod topology_requests { #[test] #[should_panic] fn it_panics() { - let _m = mock("GET", "/topology") + let _m = mock("GET", "/api/presence/topology") .with_status(400) .with_body("badbody") .create(); @@ -48,21 +50,24 @@ mod topology_requests { #[test] fn it_returns_a_response_with_200_status_and_a_correct_topology() { let json = fixtures::topology_response_json(); - let _m = mock("GET", "/topology") + let _m = mock("GET", "/api/presence/topology") .with_status(200) .with_body(json) .create(); let req = Request::new(mockito::server_url()); - let resp = req.get(); - assert_eq!(true, resp.is_ok()); - assert_eq!(1575915097085539300, resp.unwrap().coco_nodes.first().unwrap().last_seen) + let result = req.get(); + assert_eq!(true, result.is_ok()); + assert_eq!( + 1575915097085539300, + result.unwrap().coco_nodes.first().unwrap().last_seen + ) } } #[cfg(test)] - pub mod fixtures { + pub mod fixtures { #[cfg(test)] - pub fn topology_response_json() -> String { - r#"{ + pub fn topology_response_json() -> String { + r#"{ "cocoNodes": [ { "host": "3.8.244.109:4000", @@ -294,6 +299,6 @@ mod topology_requests { } ] }"#.to_string() - } - } + } + } } From 2e55719a8a76929e1f6b16042a5bd27d0810925a Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:34:54 +0000 Subject: [PATCH 035/167] DirectoryClient cleanup --- src/clients/directory/mod.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index ec4b80c132..5a12fcdb43 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,6 +1,12 @@ use crate::clients::directory::presence::Topology; -use crate::clients::directory::requests::health_check_get::{HealthCheckRequester, Request}; +use crate::clients::directory::requests::health_check_get::{ + HealthCheckRequester, Request as HealthCheckRequest, +}; +use crate::clients::directory::requests::presence_topology_get::{ + PresenceTopologyGetRequester, Request as PresenceTopologyRequest, +}; use reqwest::Error; +use sphinx::route::Destination; mod presence; pub mod requests; @@ -14,16 +20,18 @@ pub trait DirectoryClient { } pub struct Client { - pub health_check: Request, + pub health_check: HealthCheckRequest, + pub presence_topology: PresenceTopologyRequest, } impl DirectoryClient for Client { fn new(config: Config) -> Client { - let hcr: Request = Request::new(config.base_url); - Client { health_check: hcr } - } - - fn get_topology(&self) -> Result { - unimplemented!() + let health_check: HealthCheckRequest = HealthCheckRequest::new(config.base_url.clone()); + let presence_topology: PresenceTopologyRequest = + PresenceTopologyRequest::new(config.base_url.clone()); + Client { + health_check, + presence_topology, + } } } From 59487255025f69d483549469b7d73768b764310d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:46:09 +0000 Subject: [PATCH 036/167] main: extracting the run command into its own module --- src/main.rs | 75 +++-------------------------------------------------- src/run.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 72 deletions(-) create mode 100644 src/run.rs diff --git a/src/main.rs b/src/main.rs index 600a9efb2c..2e051cb438 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,8 @@ -use std::process; -use std::time::Duration; - use clap::{App, Arg, ArgMatches, SubCommand}; -use tokio::runtime::Runtime; -use tokio::time::{interval_at, Instant}; - -use crate::clients::directory; -use crate::clients::directory::requests::health_check_get::HealthCheckRequester; -use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; -use crate::clients::directory::DirectoryClient; -use sphinx::route::Destination; -use crate::clients::mix::MixClient; +use std::process; mod clients; +mod run; const TCP_SOCKET_TYPE: &str = "tcp"; const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; @@ -20,7 +10,7 @@ const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; fn execute(matches: ArgMatches) -> Result<(), String> { match matches.subcommand() { ("init", Some(m)) => Ok(init(m)), - ("run", Some(m)) => Ok(run(m)), + ("run", Some(m)) => Ok(run::run(m)), ("socket", Some(m)) => Ok(socket(m)), _ => Err(String::from("Unknown command")), @@ -40,57 +30,6 @@ fn init(matches: &ArgMatches) { ); } -fn run(matches: &ArgMatches) { - let custom_cfg = matches.value_of("customCfg"); - println!( - "Going to start client with custom config of: {:?}", - custom_cfg - ); - - // Create the runtime, probably later move it to Client struct itself? - let mut rt = Runtime::new().unwrap(); - - // Spawn the root task - rt.block_on(async { - let start = Instant::now() + Duration::from_nanos(1000); - let mut interval = interval_at(start, Duration::from_millis(5000)); - let mut i: usize = 0; - loop { - interval.tick().await; - let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - - // set up the route - let directory_config = directory::Config { - base_url: "https://directory.nymtech.net".to_string(), - }; - let directory = clients::directory::Client::new(directory_config); - - // make sure the Directory server is in fact running, panic if not - directory - .health_check - .get() - .expect("Directory health check failed, is the Directory server running?"); - - let topology = directory - .presence_topology - .get() - .expect("Failed to retrieve network topology."); - let route = topology.mix_nodes; - let destination = get_destination(); - let delays = sphinx::header::delays::generate(2); - - // build the packet -// let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); -// -// // send to mixnet -// let mix_client = MixClient::new(); -// let result = mix_client.send(packet, route.first().unwrap()).await; -// println!("packet sent: {:?}", i); -// i += 1; - } - }) -} - fn socket(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); let socket_type = match matches.value_of("socketType").unwrap() { @@ -177,11 +116,3 @@ fn main() { process::exit(1); } } - -// TODO: where do we retrieve this guy from? -fn get_destination() -> Destination { - Destination { - address: [0u8;32], - identifier: [0u8; 16], - } -} \ No newline at end of file diff --git a/src/run.rs b/src/run.rs new file mode 100644 index 0000000000..3bba5ec848 --- /dev/null +++ b/src/run.rs @@ -0,0 +1,68 @@ +use crate::clients::directory; +use crate::clients::directory::requests::health_check_get::HealthCheckRequester; +use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; +use crate::clients::directory::DirectoryClient; +use clap::ArgMatches; +use sphinx::route::Destination; +use std::time::Duration; +use tokio::runtime::Runtime; +use tokio::time::{interval_at, Instant}; + +pub fn run(matches: &ArgMatches) { + let custom_cfg = matches.value_of("customCfg"); + println!( + "Going to start client with custom config of: {:?}", + custom_cfg + ); + + // Create the runtime, probably later move it to Client struct itself? + let mut rt = Runtime::new().unwrap(); + + // Spawn the root task + rt.block_on(async { + let start = Instant::now() + Duration::from_nanos(1000); + let mut interval = interval_at(start, Duration::from_millis(5000)); + let mut i: usize = 0; + loop { + interval.tick().await; + let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); + + // set up the route + let directory_config = directory::Config { + base_url: "https://directory.nymtech.net".to_string(), + }; + let directory = directory::Client::new(directory_config); + + // make sure the Directory server is in fact running, panic if not + directory + .health_check + .get() + .expect("Directory health check failed, is the Directory server running?"); + + let topology = directory + .presence_topology + .get() + .expect("Failed to retrieve network topology."); + let route = topology.mix_nodes; + let destination = get_destination(); + let delays = sphinx::header::delays::generate(2); + + // build the packet + // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + // + // // send to mixnet + // let mix_client = MixClient::new(); + // let result = mix_client.send(packet, route.first().unwrap()).await; + // println!("packet sent: {:?}", i); + // i += 1; + } + }) +} + +// TODO: where do we retrieve this guy from? +fn get_destination() -> Destination { + Destination { + address: [0u8; 32], + identifier: [0u8; 16], + } +} From 1b70bd4d5abf5e9007654ab7eeba5610a2553dbf Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:51:14 +0000 Subject: [PATCH 037/167] main: extracting init and socket commands. --- src/init.rs | 14 ++++++++++++++ src/main.rs | 39 ++++----------------------------------- src/run.rs | 9 +++++---- src/socket.rs | 21 +++++++++++++++++++++ 4 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 src/init.rs create mode 100644 src/socket.rs diff --git a/src/init.rs b/src/init.rs new file mode 100644 index 0000000000..53fad233d0 --- /dev/null +++ b/src/init.rs @@ -0,0 +1,14 @@ +use clap::ArgMatches; + +pub fn init(matches: &ArgMatches) { + println!("Running client init!"); + + // don't unwrap it, pass it as it is, if it's None, choose a random + let provider_id = matches.value_of("providerID"); + let init_local = matches.is_present("local"); + + println!( + "client init goes here with providerID: {:?} and running locally: {:?}", + provider_id, init_local + ); +} diff --git a/src/main.rs b/src/main.rs index 2e051cb438..6f554a32a7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,54 +2,23 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use std::process; mod clients; +mod init; mod run; +mod socket; const TCP_SOCKET_TYPE: &str = "tcp"; const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; fn execute(matches: ArgMatches) -> Result<(), String> { match matches.subcommand() { - ("init", Some(m)) => Ok(init(m)), + ("init", Some(m)) => Ok(init::init(m)), ("run", Some(m)) => Ok(run::run(m)), - ("socket", Some(m)) => Ok(socket(m)), + ("socket", Some(m)) => Ok(socket::socket(m)), _ => Err(String::from("Unknown command")), } } -fn init(matches: &ArgMatches) { - println!("Running client init!"); - - // don't unwrap it, pass it as it is, if it's None, choose a random - let provider_id = matches.value_of("providerID"); - let init_local = matches.is_present("local"); - - println!( - "client init goes here with providerID: {:?} and running locally: {:?}", - provider_id, init_local - ); -} - -fn socket(matches: &ArgMatches) { - let custom_cfg = matches.value_of("customCfg"); - let socket_type = match matches.value_of("socketType").unwrap() { - TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, - WEBSOCKET_SOCKET_TYPE => WEBSOCKET_SOCKET_TYPE, - other => panic!("Invalid socket type provided - {}", other), - }; - let port = match matches.value_of("port").unwrap().parse::() { - Ok(n) => n, - Err(err) => panic!("Invalid port value provided - {:?}", err), - }; - - println!( - "Going to start socket client with custom config of: {:?}", - custom_cfg - ); - println!("Using the following socket type: {:?}", socket_type); - println!("On the following port: {:?}", port); -} - // TODO: perhaps more subcommands and/or args to distinguish between coco client and mix client fn main() { let arg_matches = App::new("Nym Client") diff --git a/src/run.rs b/src/run.rs index 3bba5ec848..a8e5ad054a 100644 --- a/src/run.rs +++ b/src/run.rs @@ -2,6 +2,7 @@ use crate::clients::directory; use crate::clients::directory::requests::health_check_get::HealthCheckRequester; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; +use crate::clients::mix::MixClient; use clap::ArgMatches; use sphinx::route::Destination; use std::time::Duration; @@ -50,11 +51,11 @@ pub fn run(matches: &ArgMatches) { // build the packet // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); // - // // send to mixnet - // let mix_client = MixClient::new(); + // send to mixnet + let mix_client = MixClient::new(); // let result = mix_client.send(packet, route.first().unwrap()).await; - // println!("packet sent: {:?}", i); - // i += 1; + println!("packet sent: {:?}", i); + i += 1; } }) } diff --git a/src/socket.rs b/src/socket.rs new file mode 100644 index 0000000000..e741b6aa51 --- /dev/null +++ b/src/socket.rs @@ -0,0 +1,21 @@ +use clap::ArgMatches; + +pub fn socket(matches: &ArgMatches) { + let custom_cfg = matches.value_of("customCfg"); + let socket_type = match matches.value_of("socketType").unwrap() { + TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, + WEBSOCKET_SOCKET_TYPE => WEBSOCKET_SOCKET_TYPE, + other => panic!("Invalid socket type provided - {}", other), + }; + let port = match matches.value_of("port").unwrap().parse::() { + Ok(n) => n, + Err(err) => panic!("Invalid port value provided - {:?}", err), + }; + + println!( + "Going to start socket client with custom config of: {:?}", + custom_cfg + ); + println!("Using the following socket type: {:?}", socket_type); + println!("On the following port: {:?}", port); +} From 372d21f44eb091484f260352ab4330aaa3208d6c Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:57:01 +0000 Subject: [PATCH 038/167] commands: grouping into a subdirectory and cleaning up execution --- src/{ => commands}/init.rs | 2 +- src/commands/mod.rs | 3 +++ src/{ => commands}/run.rs | 2 +- src/{ => commands}/socket.rs | 2 +- src/main.rs | 25 +++++++++++-------------- 5 files changed, 17 insertions(+), 17 deletions(-) rename src/{ => commands}/init.rs (90%) create mode 100644 src/commands/mod.rs rename src/{ => commands}/run.rs (98%) rename src/{ => commands}/socket.rs (94%) diff --git a/src/init.rs b/src/commands/init.rs similarity index 90% rename from src/init.rs rename to src/commands/init.rs index 53fad233d0..42e846d2dd 100644 --- a/src/init.rs +++ b/src/commands/init.rs @@ -1,6 +1,6 @@ use clap::ArgMatches; -pub fn init(matches: &ArgMatches) { +pub fn execute(matches: &ArgMatches) { println!("Running client init!"); // don't unwrap it, pass it as it is, if it's None, choose a random diff --git a/src/commands/mod.rs b/src/commands/mod.rs new file mode 100644 index 0000000000..3336430356 --- /dev/null +++ b/src/commands/mod.rs @@ -0,0 +1,3 @@ +pub mod init; +pub mod run; +pub mod socket; \ No newline at end of file diff --git a/src/run.rs b/src/commands/run.rs similarity index 98% rename from src/run.rs rename to src/commands/run.rs index a8e5ad054a..a73c82e2ad 100644 --- a/src/run.rs +++ b/src/commands/run.rs @@ -9,7 +9,7 @@ use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; -pub fn run(matches: &ArgMatches) { +pub fn execute(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); println!( "Going to start client with custom config of: {:?}", diff --git a/src/socket.rs b/src/commands/socket.rs similarity index 94% rename from src/socket.rs rename to src/commands/socket.rs index e741b6aa51..09cc09a557 100644 --- a/src/socket.rs +++ b/src/commands/socket.rs @@ -1,6 +1,6 @@ use clap::ArgMatches; -pub fn socket(matches: &ArgMatches) { +pub fn execute(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); let socket_type = match matches.value_of("socketType").unwrap() { TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, diff --git a/src/main.rs b/src/main.rs index 6f554a32a7..3157b047c0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,24 +2,11 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use std::process; mod clients; -mod init; -mod run; -mod socket; +mod commands; const TCP_SOCKET_TYPE: &str = "tcp"; const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; -fn execute(matches: ArgMatches) -> Result<(), String> { - match matches.subcommand() { - ("init", Some(m)) => Ok(init::init(m)), - ("run", Some(m)) => Ok(run::run(m)), - ("socket", Some(m)) => Ok(socket::socket(m)), - - _ => Err(String::from("Unknown command")), - } -} - -// TODO: perhaps more subcommands and/or args to distinguish between coco client and mix client fn main() { let arg_matches = App::new("Nym Client") .version("0.1.0") @@ -85,3 +72,13 @@ fn main() { process::exit(1); } } + +fn execute(matches: ArgMatches) -> Result<(), String> { + match matches.subcommand() { + ("init", Some(m)) => Ok(commands::init::execute(m)), + ("run", Some(m)) => Ok(commands::run::execute(m)), + ("socket", Some(m)) => Ok(commands::socket::execute(m)), + + _ => Err(String::from("Unknown command")), + } +} \ No newline at end of file From c5c4cec7418420dd73e2e7985fe23f59e863687e Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 00:58:37 +0000 Subject: [PATCH 039/167] commands: removing redundant directory server check --- src/commands/run.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index a73c82e2ad..59e35c504d 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -34,12 +34,6 @@ pub fn execute(matches: &ArgMatches) { }; let directory = directory::Client::new(directory_config); - // make sure the Directory server is in fact running, panic if not - directory - .health_check - .get() - .expect("Directory health check failed, is the Directory server running?"); - let topology = directory .presence_topology .get() From d55e7482ed7a9e7d142556ad849aa535d6418b80 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 01:06:17 +0000 Subject: [PATCH 040/167] Fixing warning --- src/clients/directory/requests/presence_topology_get.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index c91c94a4d9..a2eaa55966 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -38,7 +38,7 @@ mod topology_requests { fn it_panics() { let _m = mock("GET", "/api/presence/topology") .with_status(400) - .with_body("badbody") + .with_body("bad body") .create(); let req = Request::new(mockito::server_url()); req.get().unwrap(); From c4fc537930b724f62439b0db14d0e8c18cea1833 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 10:36:23 +0000 Subject: [PATCH 041/167] Adding a file for the Provider client to eventually live in --- src/clients/provider.rs | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/clients/provider.rs diff --git a/src/clients/provider.rs b/src/clients/provider.rs new file mode 100644 index 0000000000..e69de29bb2 From df1ec3f76bdb34d0f1a7cc52e8215d4fae6ea8f2 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 10:36:35 +0000 Subject: [PATCH 042/167] directory: calling assert on mocks --- src/clients/directory/requests/health_check_get.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clients/directory/requests/health_check_get.rs b/src/clients/directory/requests/health_check_get.rs index 2f8518a060..a6e4174e87 100644 --- a/src/clients/directory/requests/health_check_get.rs +++ b/src/clients/directory/requests/health_check_get.rs @@ -41,6 +41,8 @@ mod healthcheck_requests { let _m = mock("GET", "/api/healthcheck").with_status(400).create(); let req = Request::new(mockito::server_url()); assert!(req.get().is_err()); + _m.assert(); + } } @@ -52,8 +54,8 @@ mod healthcheck_requests { fn it_returns_a_response_with_200_status() { let _m = mock("GET", "/api/healthcheck").with_status(200).create(); let req = Request::new(mockito::server_url()); - assert!(req.get().is_ok()); + _m.assert(); } } } From 16d5ca40e2d37c6e722e30edb61b3a426da80fb0 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 10:36:43 +0000 Subject: [PATCH 043/167] Fixing up client mod --- src/clients/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index d862db038d..e0ee8b42df 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,3 +1,4 @@ pub mod directory; pub mod mix; -mod validator; +pub mod provider; +pub mod validator; From ffa2967a00a8d5140dc1bb9f0914492179fd21cb Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 10:37:59 +0000 Subject: [PATCH 044/167] directory: calling assert on topology mocks --- src/clients/directory/requests/presence_topology_get.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/clients/directory/requests/presence_topology_get.rs b/src/clients/directory/requests/presence_topology_get.rs index a2eaa55966..fb99fdce6f 100644 --- a/src/clients/directory/requests/presence_topology_get.rs +++ b/src/clients/directory/requests/presence_topology_get.rs @@ -42,6 +42,7 @@ mod topology_requests { .create(); let req = Request::new(mockito::server_url()); req.get().unwrap(); + _m.assert(); } } #[cfg(test)] @@ -60,7 +61,8 @@ mod topology_requests { assert_eq!( 1575915097085539300, result.unwrap().coco_nodes.first().unwrap().last_seen - ) + ); + _m.assert(); } } #[cfg(test)] From 5e734d1dcea92088e1ed7729c0d9940ac00591b1 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 11:00:16 +0000 Subject: [PATCH 045/167] directory: retrieving mixmetrics complete --- src/clients/directory/metrics.rs | 10 + src/clients/directory/mod.rs | 1 + .../directory/requests/metrics_mixes_get.rs | 240 ++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 src/clients/directory/metrics.rs diff --git a/src/clients/directory/metrics.rs b/src/clients/directory/metrics.rs new file mode 100644 index 0000000000..8bf1aa7b93 --- /dev/null +++ b/src/clients/directory/metrics.rs @@ -0,0 +1,10 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct MixMetric { + pub pub_key: String, + pub received: u64, + pub sent: HashMap, +} diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 5a12fcdb43..0ae7a5caa3 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -8,6 +8,7 @@ use crate::clients::directory::requests::presence_topology_get::{ use reqwest::Error; use sphinx::route::Destination; +mod metrics; mod presence; pub mod requests; diff --git a/src/clients/directory/requests/metrics_mixes_get.rs b/src/clients/directory/requests/metrics_mixes_get.rs index e69de29bb2..1df474a32d 100644 --- a/src/clients/directory/requests/metrics_mixes_get.rs +++ b/src/clients/directory/requests/metrics_mixes_get.rs @@ -0,0 +1,240 @@ +use crate::clients::directory::metrics::MixMetric; +use reqwest::Response; + +pub struct Request { + base_url: String, + path: String, +} + +pub trait MetricsMixRequester { + fn new(base_url: String) -> Self; + fn get(&self) -> Result, reqwest::Error>; +} + +impl MetricsMixRequester for Request { + fn new(base_url: String) -> Self { + Request { + base_url, + path: "/api/metrics/mixes".to_string(), + } + } + + fn get(&self) -> Result, reqwest::Error> { + let url = format!("{}{}", self.base_url, self.path); + let mix_metric_vec = reqwest::get(&url)?.json()?; + Ok(mix_metric_vec) + } +} + +#[cfg(test)] +mod metrics_get_request { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + #[should_panic] + fn it_returns_an_error() { + let _m = mock("GET", "/api/metrics/mixes").with_status(400).create(); + let req = Request::new(mockito::server_url()); + req.get().unwrap(); + _m.assert(); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + #[test] + fn it_returns_a_response_with_200_status_and_a_correct_topology() { + let json = fixtures::mix_metrics_response_json(); + let _m = mock("GET", "/api/metrics/mixes") + .with_status(200) + .with_body(json) + .create(); + let req = Request::new(mockito::server_url()); + let result = req.get(); + assert_eq!(true, result.is_ok()); + assert_eq!( + "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + result.unwrap().first().unwrap().pub_key + ); + _m.assert(); + } + } + + #[cfg(test)] + mod fixtures { + #[cfg(test)] + pub fn mix_metrics_response_json() -> String { + r#"[ + { + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "sent": { + "35.178.213.77:1789": 1, + "52.56.99.196:1789": 2 + }, + "received": 10, + "timestamp": 1576061080635800000 + }, + { + "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + "sent": { + "3.8.176.11:1789": 2, + "35.178.212.193:1789": 2 + }, + "received": 4, + "timestamp": 1576061080806225700 + }, + { + "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + "sent": { + "3.9.12.238:1789": 3 + }, + "received": 3, + "timestamp": 1576061080894667300 + }, + { + "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + "sent": { + "3.9.12.238:1789": 5, + "35.176.155.107:1789": 3 + }, + "received": 8, + "timestamp": 1576061081254846500 + }, + { + "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + "sent": { + "35.178.213.77:1789": 4, + "52.56.99.196:1789": 6 + }, + "received": 19, + "timestamp": 1576061081371549000 + }, + { + "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + "sent": { + "3.8.176.11:1789": 4, + "35.178.212.193:1789": 2 + }, + "received": 6, + "timestamp": 1576061081498404900 + }, + { + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "sent": { + "35.178.213.77:1789": 2, + "52.56.99.196:1789": 3 + }, + "received": 6, + "timestamp": 1576061081637625000 + }, + { + "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + "sent": { + "3.8.176.11:1789": 5, + "35.178.212.193:1789": 4 + }, + "received": 9, + "timestamp": 1576061081805484800 + }, + { + "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + "sent": { + "3.9.12.238:1789": 4, + "35.176.155.107:1789": 4 + }, + "received": 8, + "timestamp": 1576061081896562400 + }, + { + "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + "sent": { + "3.9.12.238:1789": 2, + "35.176.155.107:1789": 4 + }, + "received": 6, + "timestamp": 1576061079255938600 + }, + { + "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + "sent": { + "35.178.213.77:1789": 6 + }, + "received": 10, + "timestamp": 1576061079370829300 + }, + { + "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + "sent": { + "3.8.176.11:1789": 2, + "35.178.212.193:1789": 5 + }, + "received": 7, + "timestamp": 1576061079497993200 + }, + { + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "sent": { + "35.178.213.77:1789": 5, + "52.56.99.196:1789": 2 + }, + "received": 13, + "timestamp": 1576061079637208600 + }, + { + "pubKey": "zSob16499jT7C3S3ky4GihNOjlU6aLfSRkf1xAxOwV0=", + "sent": { + "3.8.176.11:1789": 5, + "35.178.212.193:1789": 4 + }, + "received": 9, + "timestamp": 1576061079806557200 + }, + { + "pubKey": "nkkrUjgL8UJk05QydvWvFSvtRB6nmeV8RMvH5540J3s=", + "sent": { + "3.9.12.238:1789": 2, + "35.176.155.107:1789": 7 + }, + "received": 9, + "timestamp": 1576061079895988000 + }, + { + "pubKey": "whHuBuEc6zyOZOquKbuATaH4Crml61V_3Y-MztpWhF4=", + "sent": { + "3.9.12.238:1789": 3, + "35.176.155.107:1789": 2 + }, + "received": 5, + "timestamp": 1576061080255701500 + }, + { + "pubKey": "vCdpFc0NvW0NSqsuTxtjFtiSY35aXesgT3JNA8sSIXk=", + "sent": { + "35.178.213.77:1789": 3, + "52.56.99.196:1789": 3 + }, + "received": 7, + "timestamp": 1576061080370956300 + }, + { + "pubKey": "vk5Sr-Xyi0cTbugACv8U42ZJ6hs6cGDox0rpmXY94Fc=", + "sent": { + "3.8.176.11:1789": 5, + "35.178.212.193:1789": 1 + }, + "received": 6, + "timestamp": 1576061080501732900 + } + ]"# + .to_string() + } + } +} From 288c414075e60f234bda6b306812820135d4462b Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 11:01:16 +0000 Subject: [PATCH 046/167] directory: removing unused imports --- src/clients/directory/mod.rs | 3 --- src/clients/directory/requests/metrics_mixes_get.rs | 1 - 2 files changed, 4 deletions(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 0ae7a5caa3..760cde04aa 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,12 +1,9 @@ -use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::health_check_get::{ HealthCheckRequester, Request as HealthCheckRequest, }; use crate::clients::directory::requests::presence_topology_get::{ PresenceTopologyGetRequester, Request as PresenceTopologyRequest, }; -use reqwest::Error; -use sphinx::route::Destination; mod metrics; mod presence; diff --git a/src/clients/directory/requests/metrics_mixes_get.rs b/src/clients/directory/requests/metrics_mixes_get.rs index 1df474a32d..763f03972c 100644 --- a/src/clients/directory/requests/metrics_mixes_get.rs +++ b/src/clients/directory/requests/metrics_mixes_get.rs @@ -1,5 +1,4 @@ use crate::clients::directory::metrics::MixMetric; -use reqwest::Response; pub struct Request { base_url: String, From 8df4f91c22710046d05a5be3486f39e1ad1e07fe Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 11:14:46 +0000 Subject: [PATCH 047/167] directory: adding a PersistedMixMetric model (has a timestamp) --- src/clients/directory/metrics.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/clients/directory/metrics.rs b/src/clients/directory/metrics.rs index 8bf1aa7b93..94d7c909b6 100644 --- a/src/clients/directory/metrics.rs +++ b/src/clients/directory/metrics.rs @@ -1,6 +1,15 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; +#[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PersistedMixMetric { + pub pub_key: String, + pub received: u64, + pub sent: HashMap, + pub timestamp: u64, +} + #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixMetric { From d879192d837f6f0b8f544a3136721dd15dcddbb6 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 11:15:06 +0000 Subject: [PATCH 048/167] directory: using new PersistedMixMetric model --- src/clients/directory/requests/metrics_mixes_get.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/clients/directory/requests/metrics_mixes_get.rs b/src/clients/directory/requests/metrics_mixes_get.rs index 763f03972c..c43541cdce 100644 --- a/src/clients/directory/requests/metrics_mixes_get.rs +++ b/src/clients/directory/requests/metrics_mixes_get.rs @@ -1,4 +1,4 @@ -use crate::clients::directory::metrics::MixMetric; +use crate::clients::directory::metrics::PersistedMixMetric; pub struct Request { base_url: String, @@ -7,7 +7,7 @@ pub struct Request { pub trait MetricsMixRequester { fn new(base_url: String) -> Self; - fn get(&self) -> Result, reqwest::Error>; + fn get(&self) -> Result, reqwest::Error>; } impl MetricsMixRequester for Request { @@ -18,7 +18,7 @@ impl MetricsMixRequester for Request { } } - fn get(&self) -> Result, reqwest::Error> { + fn get(&self) -> Result, reqwest::Error> { let url = format!("{}{}", self.base_url, self.path); let mix_metric_vec = reqwest::get(&url)?.json()?; Ok(mix_metric_vec) @@ -60,8 +60,8 @@ mod metrics_get_request { let result = req.get(); assert_eq!(true, result.is_ok()); assert_eq!( - "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", - result.unwrap().first().unwrap().pub_key + 1576061080635800000, + result.unwrap().first().unwrap().timestamp ); _m.assert(); } From 3a57939d55cc0b264ad7a923aa92534c3b9f7a51 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 11:53:28 +0000 Subject: [PATCH 049/167] directory: metrics_mixes_post complete --- .../directory/requests/metrics_mixes_post.rs | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/src/clients/directory/requests/metrics_mixes_post.rs b/src/clients/directory/requests/metrics_mixes_post.rs index e69de29bb2..4414e8e195 100644 --- a/src/clients/directory/requests/metrics_mixes_post.rs +++ b/src/clients/directory/requests/metrics_mixes_post.rs @@ -0,0 +1,98 @@ +use crate::clients::directory::metrics::MixMetric; +use reqwest::Response; + +pub struct Request { + base_url: String, + path: String, +} + +pub trait MetricsMixPoster { + fn new(base_url: String) -> Self; + fn post(&self, metric: MixMetric) -> Result; +} + +impl MetricsMixPoster for Request { + fn new(base_url: String) -> Self { + Request { + base_url, + path: "/api/metrics/mixes".to_string(), + } + } + + fn post(&self, metric: MixMetric) -> Result { + let url = format!("{}{}", self.base_url, self.path); + let client = reqwest::Client::new(); + let mix_metric_vec = client.post(&url).json(&metric).send()?; + Ok(mix_metric_vec) + } +} + +#[cfg(test)] +mod metrics_get_request { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + fn it_returns_an_error() { + let _m = mock("POST", "/api/metrics/mixes").with_status(400).create(); + let req = Request::new(mockito::server_url()); + let metric = fixtures::new_metric(); + let result = req.post(metric); + assert_eq!(400, result.unwrap().status()); + _m.assert(); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + #[test] + fn it_returns_a_response_with_200() { + let json = fixtures::mix_metrics_response_json(); + let _m = mock("POST", "/api/metrics/mixes") + .with_status(201) + .with_body(json) + .create(); + let req = Request::new(mockito::server_url()); + let metric = fixtures::new_metric(); + let result = req.post(metric); + assert_eq!(true, result.is_ok()); + _m.assert(); + } + } + + #[cfg(test)] + mod fixtures { + use crate::clients::directory::metrics::MixMetric; + + pub fn new_metric() -> MixMetric { + MixMetric { + pub_key: "abc".to_string(), + received: 666, + sent: Default::default(), + } + } + + #[cfg(test)] + pub fn mix_metrics_response_json() -> String { + r#" + { + "pubKey": "OwOqwWjh_IlnaWS2PxO6odnhNahOYpRCkju50beQCTA=", + "sent": { + "35.178.213.77:1789": 1, + "52.56.99.196:1789": 2 + }, + "received": 10, + "timestamp": 1576061080635800000 + } + "# + .to_string() + } + } +} From 190172778714daa123b14049fdc1a654aa3a006d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 14:07:38 +0000 Subject: [PATCH 050/167] directory: coconodes presence now working --- .../requests/presence_coconodes_post.rs | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/clients/directory/requests/presence_coconodes_post.rs b/src/clients/directory/requests/presence_coconodes_post.rs index e69de29bb2..c1e30b145e 100644 --- a/src/clients/directory/requests/presence_coconodes_post.rs +++ b/src/clients/directory/requests/presence_coconodes_post.rs @@ -0,0 +1,86 @@ +use crate::clients::directory::presence::CocoPresence; +use reqwest::Response; + +pub struct Request { + base_url: String, + path: String, +} + +pub trait PresenceCocoNodesPoster { + fn new(base_url: String) -> Self; + fn post(&self, presence: CocoPresence) -> Result; +} + +impl PresenceCocoNodesPoster for Request { + fn new(base_url: String) -> Self { + Request { + base_url, + path: "/api/presence/coconodes".to_string(), + } + } + + fn post(&self, presence: CocoPresence) -> Result { + let url = format!("{}{}", self.base_url, self.path); + let client = reqwest::Client::new(); + let p = client.post(&url).json(&presence).send()?; + Ok(p) + } +} + +#[cfg(test)] +mod metrics_get_request { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + fn it_returns_an_error() { + let _m = mock("POST", "/api/presence/coconodes") + .with_status(400) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(400, result.unwrap().status()); + _m.assert(); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + #[test] + fn it_returns_a_response_with_201() { + let json = r#"{ + "ok": true + }"#; + let _m = mock("POST", "/api/presence/coconodes") + .with_status(201) + .with_body(json) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(true, result.is_ok()); + _m.assert(); + } + } + + #[cfg(test)] + mod fixtures { + use crate::clients::directory::presence::CocoPresence; + + pub fn new_presence() -> CocoPresence { + CocoPresence { + host: "foo.com".to_string(), + pub_key: "abc".to_string(), + last_seen: 666, + } + } + } +} From decebcf93fa0c4faa892509ad70a8d412660f80c Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 14:10:41 +0000 Subject: [PATCH 051/167] directory: presence mixnode post now working --- src/clients/directory/presence.rs | 8 +- .../requests/presence_mixnodes_post.rs | 87 +++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 65148097e6..77e114aaa5 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -11,10 +11,10 @@ pub struct CocoPresence { #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixNodePresence { - host: String, - pub_key: String, - layer: u64, - last_seen: i64, + pub host: String, + pub pub_key: String, + pub layer: u64, + pub last_seen: i64, } #[derive(Deserialize, Serialize)] diff --git a/src/clients/directory/requests/presence_mixnodes_post.rs b/src/clients/directory/requests/presence_mixnodes_post.rs index e69de29bb2..4bb0686ba3 100644 --- a/src/clients/directory/requests/presence_mixnodes_post.rs +++ b/src/clients/directory/requests/presence_mixnodes_post.rs @@ -0,0 +1,87 @@ +use crate::clients::directory::presence::MixNodePresence; +use reqwest::Response; + +pub struct Request { + base_url: String, + path: String, +} + +pub trait PresenceMixNodesPoster { + fn new(base_url: String) -> Self; + fn post(&self, presence: MixNodePresence) -> Result; +} + +impl PresenceMixNodesPoster for Request { + fn new(base_url: String) -> Self { + Request { + base_url, + path: "/api/presence/mixnodes".to_string(), + } + } + + fn post(&self, presence: MixNodePresence) -> Result { + let url = format!("{}{}", self.base_url, self.path); + let client = reqwest::Client::new(); + let p = client.post(&url).json(&presence).send()?; + Ok(p) + } +} + +#[cfg(test)] +mod metrics_get_request { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + fn it_returns_an_error() { + let _m = mock("POST", "/api/presence/mixnodes") + .with_status(400) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(400, result.unwrap().status()); + _m.assert(); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + #[test] + fn it_returns_a_response_with_201() { + let json = r#"{ + "ok": true + }"#; + let _m = mock("POST", "/api/presence/mixnodes") + .with_status(201) + .with_body(json) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(true, result.is_ok()); + _m.assert(); + } + } + + #[cfg(test)] + mod fixtures { + use crate::clients::directory::presence::MixNodePresence; + + pub fn new_presence() -> MixNodePresence { + MixNodePresence { + host: "foo.com".to_string(), + pub_key: "abc".to_string(), + last_seen: 666, + layer: 1, + } + } + } +} From 5c59cb5c3d2e89a877336e2d116facdf404b2d48 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 14:15:52 +0000 Subject: [PATCH 052/167] directory: presence for providers now working --- src/clients/directory/presence.rs | 4 +- .../requests/presence_providers_post.rs | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 77e114aaa5..9fab6c1bd5 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -20,8 +20,8 @@ pub struct MixNodePresence { #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixProviderPresence { - host: String, - pub_key: String, + pub host: String, + pub pub_key: String, } // Topology shows us the current state of the overall Nym network diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index e69de29bb2..8819926802 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -0,0 +1,84 @@ +use crate::clients::directory::presence::MixProviderPresence; +use reqwest::Response; + +pub struct Request { + base_url: String, + path: String, +} + +pub trait PresenceMixProviderPoster { + fn new(base_url: String) -> Self; + fn post(&self, presence: MixProviderPresence) -> Result; +} + +impl PresenceMixProviderPoster for Request { + fn new(base_url: String) -> Self { + Request { + base_url, + path: "/api/presence/providers".to_string(), + } + } + + fn post(&self, presence: MixProviderPresence) -> Result { + let url = format!("{}{}", self.base_url, self.path); + let client = reqwest::Client::new(); + let p = client.post(&url).json(&presence).send()?; + Ok(p) + } +} + +#[cfg(test)] +mod metrics_get_request { + use super::*; + + #[cfg(test)] + use mockito::mock; + + #[cfg(test)] + mod on_a_400_status { + use super::*; + + #[test] + fn it_returns_an_error() { + let _m = mock("POST", "/api/presence/providers") + .with_status(400) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(400, result.unwrap().status()); + _m.assert(); + } + } + + #[cfg(test)] + mod on_a_200 { + use super::*; + #[test] + fn it_returns_a_response_with_201() { + let json = r#"{ + "ok": true + }"#; + let _m = mock("POST", "/api/presence/providers") + .with_status(201) + .with_body(json) + .create(); + let req = Request::new(mockito::server_url()); + let presence = fixtures::new_presence(); + let result = req.post(presence); + assert_eq!(true, result.is_ok()); + _m.assert(); + } + } + #[cfg(test)] + mod fixtures { + use crate::clients::directory::presence::MixProviderPresence; + + pub fn new_presence() -> MixProviderPresence { + MixProviderPresence { + host: "foo.com".to_string(), + pub_key: "abc".to_string(), + } + } + } +} From 456494f05f4b4564fcc22bd6e6fe1907832bf05a Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 11 Dec 2019 15:17:47 +0000 Subject: [PATCH 053/167] Requests for messages --- src/clients/provider.rs | 160 ++++++++++++++++++++++++++++++++++++++++ src/commands/run.rs | 48 ++++++------ 2 files changed, 186 insertions(+), 22 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index e69de29bb2..967d01d088 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -0,0 +1,160 @@ +use sphinx::route::Node as MixNode; +use sphinx::SphinxPacket; +use tokio::prelude::*; + +const PULL_REQUEST_MESSAGE_PREFIX: [u8; 2] = [1, 0]; +const REGISTER_MESSAGE_PREFIX: [u8; 2] = [0, 1]; + +// TODO: how to do it more nicely, considering all requests implement same trait that is exercised here? +pub enum ProviderRequests { + PullMessages(PullRequest), + Register(RegisterRequest), +} + +impl ProviderRequests { + fn to_bytes(&self) -> Vec { + use ProviderRequests::*; + match self { + PullMessages(pr) => pr.to_bytes(), + Register(pr) => pr.to_bytes(), + } + } + + fn from_bytes(bytes: &[u8]) -> Result { + use ProviderRequests::*; + if bytes.len() < 2 { + return Err(ProviderRequestError::UnmarshalError); + } + let mut received_prefix = [0; 2]; + received_prefix.copy_from_slice(&bytes[..2]); + match received_prefix { + PULL_REQUEST_MESSAGE_PREFIX => Ok(PullMessages(PullRequest::from_bytes(bytes)?)), + REGISTER_MESSAGE_PREFIX => Ok(Register(RegisterRequest::from_bytes(bytes)?)), + _ => Err(ProviderRequestError::UnmarshalErrorIncorrectPrefix), + } + } +} + +#[derive(Debug)] +pub enum ProviderRequestError { + MarshalError, + UnmarshalError, + UnmarshalErrorIncorrectPrefix, +} + +pub trait ProviderRequest where Self: Sized { + fn get_prefix() -> [u8; 2]; + fn to_bytes(&self) -> Vec; + fn from_bytes(bytes: &[u8]) -> Result; +} + +pub struct PullRequest { + // TODO: public keys, signatures, tokens, etc. basically some kind of authentication bs + destination_address: sphinx::route::DestinationAddressBytes, +} + +impl PullRequest { + pub(crate) fn new(destination_address: sphinx::route::DestinationAddressBytes) -> Self { + PullRequest { + destination_address + } + } +} + +impl ProviderRequest for PullRequest { + fn get_prefix() -> [u8; 2] { + PULL_REQUEST_MESSAGE_PREFIX + } + + fn to_bytes(&self) -> Vec { + Self::get_prefix().to_vec().into_iter().chain(self.destination_address.iter().cloned()).collect() + } + + fn from_bytes(bytes: &[u8]) -> Result { + if bytes.len() != 2 + 32 { + return Err(ProviderRequestError::UnmarshalError); + } + + let mut received_prefix = [0u8; 2]; + received_prefix.copy_from_slice(&bytes[..2]); + if received_prefix != Self::get_prefix() { + return Err(ProviderRequestError::UnmarshalErrorIncorrectPrefix); + } + + let mut destination_address = [0u8; 32]; + destination_address.copy_from_slice(&bytes[2..]); + + Ok(PullRequest { + destination_address, + }) + } +} + + +pub struct RegisterRequest {} + +impl ProviderRequest for RegisterRequest { + fn get_prefix() -> [u8; 2] { + unimplemented!() + } + + fn to_bytes(&self) -> Vec { + unimplemented!() + } + + fn from_bytes(bytes: &[u8]) -> Result { + unimplemented!() + } +} + +pub struct ProviderClient {} + + +impl ProviderClient { + pub fn new() -> Self { + ProviderClient {} + } + + pub async fn send( + &self, +// provider: &MixNode, + ) -> Result<(), Box> { + let address = [0; 32]; + let pull_request = PullRequest::new(address); + let bytes = pull_request.to_bytes(); + + let mut stream = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; + stream.write_all(&bytes[..]).await?; + Ok(()) + } +} + +#[cfg(test)] +mod creating_pull_request { + use super::*; + + #[test] + fn it_is_possible_to_recover_it_from_bytes() { + let address = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]; + let pull_request = PullRequest::new(address); + let bytes = pull_request.to_bytes(); + + let recovered = PullRequest::from_bytes(&bytes).unwrap(); + assert_eq!(address, recovered.destination_address); + } + + #[test] + fn it_is_possible_to_recover_it_from_bytes_with_enum_wrapper() { + let address = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]; + let pull_request = PullRequest::new(address); + let bytes = pull_request.to_bytes(); + + let recovered = ProviderRequests::from_bytes(&bytes).unwrap(); + match recovered { + ProviderRequests::PullMessages(req) => assert_eq!(address, req.destination_address), + _ => panic!("expected to recover pull request!"), + } + } +} + + diff --git a/src/commands/run.rs b/src/commands/run.rs index 59e35c504d..fe715f7e11 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -8,6 +8,7 @@ use sphinx::route::Destination; use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; +use crate::clients::provider::ProviderClient; pub fn execute(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); @@ -26,30 +27,33 @@ pub fn execute(matches: &ArgMatches) { let mut i: usize = 0; loop { interval.tick().await; - let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - - // set up the route - let directory_config = directory::Config { - base_url: "https://directory.nymtech.net".to_string(), - }; - let directory = directory::Client::new(directory_config); - - let topology = directory - .presence_topology - .get() - .expect("Failed to retrieve network topology."); - let route = topology.mix_nodes; - let destination = get_destination(); - let delays = sphinx::header::delays::generate(2); - - // build the packet - // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - // - // send to mixnet - let mix_client = MixClient::new(); - // let result = mix_client.send(packet, route.first().unwrap()).await; +// let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); +// +// // set up the route +// let directory_config = directory::Config { +// base_url: "https://directory.nymtech.net".to_string(), +// }; +// let directory = directory::Client::new(directory_config); +// +// let topology = directory +// .presence_topology +// .get() +// .expect("Failed to retrieve network topology."); +// let route = topology.mix_nodes; +// let destination = get_destination(); +// let delays = sphinx::header::delays::generate(2); +// +// // build the packet +// // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); +// // +// // send to mixnet +// let mix_client = MixClient::new(); +// // let result = mix_client.send(packet, route.first().unwrap()).await; println!("packet sent: {:?}", i); i += 1; + + let provider_client = ProviderClient::new(); + provider_client.send().await.unwrap(); } }) } From 84ce1611a1909bae7436c4b00f682c685d233b7e Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 15:33:27 +0000 Subject: [PATCH 054/167] client: packets are sending! --- Cargo.lock | 8 ++++++++ Cargo.toml | 2 ++ src/commands/run.rs | 39 ++++++++++++++++++++++++++++++++++----- src/main.rs | 5 +---- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e92b1b450d..3c8a32db30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,6 +113,11 @@ dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.2.1" @@ -887,7 +892,9 @@ dependencies = [ name = "nym-client" version = "0.1.0" dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1811,6 +1818,7 @@ dependencies = [ "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" diff --git a/Cargo.toml b/Cargo.toml index 8e3a3a0d65..e088f736c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +base64 = "0.11.0" clap = "2.33.0" +curve25519-dalek = "1.2.3" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } diff --git a/src/commands/run.rs b/src/commands/run.rs index 59e35c504d..614799eaea 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -3,8 +3,11 @@ use crate::clients::directory::requests::health_check_get::HealthCheckRequester; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; +use base64; use clap::ArgMatches; +use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::Destination; +use sphinx::route::Node as SphinxNode; use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; @@ -28,7 +31,6 @@ pub fn execute(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - // set up the route let directory_config = directory::Config { base_url: "https://directory.nymtech.net".to_string(), }; @@ -38,22 +40,49 @@ pub fn execute(matches: &ArgMatches) { .presence_topology .get() .expect("Failed to retrieve network topology."); - let route = topology.mix_nodes; + let mut route = vec![]; + let route_len = 3; + let nodes = topology.mix_nodes.iter(); + for mix in nodes.take(route_len) { + let mut address_vector = mix.host.as_bytes().to_vec(); + if address_vector.len() != 32 { + address_vector.resize(32, 0) + } + assert!(address_vector.len() <= 32); + let mut address_bytes = [0; 32]; + address_bytes.copy_from_slice(&address_vector[..]); + + let key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); + assert!(key_bytes.len() == 32); + let mut arr = [0; 32]; + arr.copy_from_slice(&key_bytes); + let mp = MontgomeryPoint(arr); + let sphinx_node = SphinxNode { + address: address_bytes, + pub_key: mp, + }; + route.push(sphinx_node); + } let destination = get_destination(); - let delays = sphinx::header::delays::generate(2); + let delays = sphinx::header::delays::generate(route_len); // build the packet - // let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + let packet = + sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); // // send to mixnet let mix_client = MixClient::new(); - // let result = mix_client.send(packet, route.first().unwrap()).await; + let result = mix_client.send(packet, route.first().unwrap()).await; println!("packet sent: {:?}", i); i += 1; } }) } +fn zero_pad_to(bytes: Vec, length: usize) -> Vec { + vec![0u8; length] +} + // TODO: where do we retrieve this guy from? fn get_destination() -> Destination { Destination { diff --git a/src/main.rs b/src/main.rs index 3157b047c0..77d309f519 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,6 @@ use std::process; mod clients; mod commands; -const TCP_SOCKET_TYPE: &str = "tcp"; -const WEBSOCKET_SOCKET_TYPE: &str = "websocket"; - fn main() { let arg_matches = App::new("Nym Client") .version("0.1.0") @@ -81,4 +78,4 @@ fn execute(matches: ArgMatches) -> Result<(), String> { _ => Err(String::from("Unknown command")), } -} \ No newline at end of file +} From 639187776ee6d87d8139294986e466257075d625 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 11 Dec 2019 15:50:29 +0000 Subject: [PATCH 055/167] Moved provider requests to subcrate in sfw provider --- Cargo.lock | 8 +++ Cargo.toml | 2 + src/clients/provider.rs | 136 +--------------------------------------- 3 files changed, 11 insertions(+), 135 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e92b1b450d..2ce803ba88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -892,6 +892,7 @@ dependencies = [ "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", + "sfw-provider-requests 0.1.0", "sphinx 0.1.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1322,6 +1323,13 @@ dependencies = [ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sfw-provider-requests" +version = "0.1.0" +dependencies = [ + "sphinx 0.1.0", +] + [[package]] name = "sha2" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 8e3a3a0d65..6485f5366c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,8 @@ clap = "2.33.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } +sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } + tokio = { version = "0.2", features = ["full"] } [dev-dependencies] diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 967d01d088..9bfe304a7b 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,111 +1,7 @@ use sphinx::route::Node as MixNode; use sphinx::SphinxPacket; use tokio::prelude::*; - -const PULL_REQUEST_MESSAGE_PREFIX: [u8; 2] = [1, 0]; -const REGISTER_MESSAGE_PREFIX: [u8; 2] = [0, 1]; - -// TODO: how to do it more nicely, considering all requests implement same trait that is exercised here? -pub enum ProviderRequests { - PullMessages(PullRequest), - Register(RegisterRequest), -} - -impl ProviderRequests { - fn to_bytes(&self) -> Vec { - use ProviderRequests::*; - match self { - PullMessages(pr) => pr.to_bytes(), - Register(pr) => pr.to_bytes(), - } - } - - fn from_bytes(bytes: &[u8]) -> Result { - use ProviderRequests::*; - if bytes.len() < 2 { - return Err(ProviderRequestError::UnmarshalError); - } - let mut received_prefix = [0; 2]; - received_prefix.copy_from_slice(&bytes[..2]); - match received_prefix { - PULL_REQUEST_MESSAGE_PREFIX => Ok(PullMessages(PullRequest::from_bytes(bytes)?)), - REGISTER_MESSAGE_PREFIX => Ok(Register(RegisterRequest::from_bytes(bytes)?)), - _ => Err(ProviderRequestError::UnmarshalErrorIncorrectPrefix), - } - } -} - -#[derive(Debug)] -pub enum ProviderRequestError { - MarshalError, - UnmarshalError, - UnmarshalErrorIncorrectPrefix, -} - -pub trait ProviderRequest where Self: Sized { - fn get_prefix() -> [u8; 2]; - fn to_bytes(&self) -> Vec; - fn from_bytes(bytes: &[u8]) -> Result; -} - -pub struct PullRequest { - // TODO: public keys, signatures, tokens, etc. basically some kind of authentication bs - destination_address: sphinx::route::DestinationAddressBytes, -} - -impl PullRequest { - pub(crate) fn new(destination_address: sphinx::route::DestinationAddressBytes) -> Self { - PullRequest { - destination_address - } - } -} - -impl ProviderRequest for PullRequest { - fn get_prefix() -> [u8; 2] { - PULL_REQUEST_MESSAGE_PREFIX - } - - fn to_bytes(&self) -> Vec { - Self::get_prefix().to_vec().into_iter().chain(self.destination_address.iter().cloned()).collect() - } - - fn from_bytes(bytes: &[u8]) -> Result { - if bytes.len() != 2 + 32 { - return Err(ProviderRequestError::UnmarshalError); - } - - let mut received_prefix = [0u8; 2]; - received_prefix.copy_from_slice(&bytes[..2]); - if received_prefix != Self::get_prefix() { - return Err(ProviderRequestError::UnmarshalErrorIncorrectPrefix); - } - - let mut destination_address = [0u8; 32]; - destination_address.copy_from_slice(&bytes[2..]); - - Ok(PullRequest { - destination_address, - }) - } -} - - -pub struct RegisterRequest {} - -impl ProviderRequest for RegisterRequest { - fn get_prefix() -> [u8; 2] { - unimplemented!() - } - - fn to_bytes(&self) -> Vec { - unimplemented!() - } - - fn from_bytes(bytes: &[u8]) -> Result { - unimplemented!() - } -} +use sfw_provider_requests::*; pub struct ProviderClient {} @@ -128,33 +24,3 @@ impl ProviderClient { Ok(()) } } - -#[cfg(test)] -mod creating_pull_request { - use super::*; - - #[test] - fn it_is_possible_to_recover_it_from_bytes() { - let address = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]; - let pull_request = PullRequest::new(address); - let bytes = pull_request.to_bytes(); - - let recovered = PullRequest::from_bytes(&bytes).unwrap(); - assert_eq!(address, recovered.destination_address); - } - - #[test] - fn it_is_possible_to_recover_it_from_bytes_with_enum_wrapper() { - let address = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2]; - let pull_request = PullRequest::new(address); - let bytes = pull_request.to_bytes(); - - let recovered = ProviderRequests::from_bytes(&bytes).unwrap(); - match recovered { - ProviderRequests::PullMessages(req) => assert_eq!(address, req.destination_address), - _ => panic!("expected to recover pull request!"), - } - } -} - - From 46b3f7d860c9b8096dedfc958988e987789b82fd Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 16:00:36 +0000 Subject: [PATCH 056/167] Exposing presence module --- src/clients/directory/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 760cde04aa..892b3105b7 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -6,7 +6,7 @@ use crate::clients::directory::requests::presence_topology_get::{ }; mod metrics; -mod presence; +pub mod presence; pub mod requests; pub struct Config { From f435eae5aa14f3fe7ec3d990a0fac65ebff054ec Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 16:18:53 +0000 Subject: [PATCH 057/167] run: starting to name some functions --- src/commands/run.rs | 76 +++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 614799eaea..24e1653dc3 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,5 +1,5 @@ use crate::clients::directory; -use crate::clients::directory::requests::health_check_get::HealthCheckRequester; +use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; @@ -31,38 +31,10 @@ pub fn execute(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - let directory_config = directory::Config { - base_url: "https://directory.nymtech.net".to_string(), - }; - let directory = directory::Client::new(directory_config); - - let topology = directory - .presence_topology - .get() - .expect("Failed to retrieve network topology."); - let mut route = vec![]; let route_len = 3; - let nodes = topology.mix_nodes.iter(); - for mix in nodes.take(route_len) { - let mut address_vector = mix.host.as_bytes().to_vec(); - if address_vector.len() != 32 { - address_vector.resize(32, 0) - } - assert!(address_vector.len() <= 32); - let mut address_bytes = [0; 32]; - address_bytes.copy_from_slice(&address_vector[..]); - let key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); - assert!(key_bytes.len() == 32); - let mut arr = [0; 32]; - arr.copy_from_slice(&key_bytes); - let mp = MontgomeryPoint(arr); - let sphinx_node = SphinxNode { - address: address_bytes, - pub_key: mp, - }; - route.push(sphinx_node); - } + // data needed to generate a new Sphinx packet + let route = get_route(route_len); let destination = get_destination(); let delays = sphinx::header::delays::generate(route_len); @@ -79,8 +51,46 @@ pub fn execute(matches: &ArgMatches) { }) } -fn zero_pad_to(bytes: Vec, length: usize) -> Vec { - vec![0u8; length] +fn get_route(route_len: usize) -> Vec { + let directory_config = directory::Config { + base_url: "https://directory.nymtech.net".to_string(), + }; + let directory = directory::Client::new(directory_config); + + let topology = directory + .presence_topology + .get() + .expect("Failed to retrieve network topology."); + let route = route_from(topology, route_len); + route +} + +fn route_from(topology: Topology, route_len: usize) -> Vec { + let mut route = vec![]; + let nodes = topology.mix_nodes.iter(); + for mix in nodes.take(route_len) { + let address_bytes = zero_pad_to_32_bytes(mix.host.as_bytes().to_vec()); + let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); + let key_bytes = zero_pad_to_32_bytes(decoded_key_bytes); + let key = MontgomeryPoint(key_bytes); + let sphinx_node = SphinxNode { + address: address_bytes, + pub_key: key, + }; + route.push(sphinx_node); + } + route +} + +fn zero_pad_to_32_bytes(mut bytes: Vec) -> [u8; 32] { + assert!(bytes.len() <= 32); + if bytes.len() != 32 { + bytes.resize(32, 0); + } + let mut padded_bytes = [0; 32]; + padded_bytes.copy_from_slice(&bytes[..]); + assert!(padded_bytes.len() == 32); + padded_bytes } // TODO: where do we retrieve this guy from? From 71527eebf74c4167c1fd32d107702545ab51d9ab Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 16:35:39 +0000 Subject: [PATCH 058/167] run: looking a little cleaner --- src/commands/run.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 24e1653dc3..9db06fc569 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,5 +1,5 @@ use crate::clients::directory; -use crate::clients::directory::presence::Topology; +use crate::clients::directory::presence::{MixNodePresence, Topology}; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; @@ -19,13 +19,16 @@ pub fn execute(matches: &ArgMatches) { custom_cfg ); + // Grab the network topology from the remote directory server + let topology = get_topology(); + // Create the runtime, probably later move it to Client struct itself? let mut rt = Runtime::new().unwrap(); // Spawn the root task rt.block_on(async { let start = Instant::now() + Duration::from_nanos(1000); - let mut interval = interval_at(start, Duration::from_millis(5000)); + let mut interval = interval_at(start, Duration::from_millis(1000)); let mut i: usize = 0; loop { interval.tick().await; @@ -34,14 +37,14 @@ pub fn execute(matches: &ArgMatches) { let route_len = 3; // data needed to generate a new Sphinx packet - let route = get_route(route_len); + let route = route_from(&topology, route_len); let destination = get_destination(); let delays = sphinx::header::delays::generate(route_len); // build the packet let packet = sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - // + // send to mixnet let mix_client = MixClient::new(); let result = mix_client.send(packet, route.first().unwrap()).await; @@ -51,7 +54,7 @@ pub fn execute(matches: &ArgMatches) { }) } -fn get_route(route_len: usize) -> Vec { +fn get_topology() -> Topology { let directory_config = directory::Config { base_url: "https://directory.nymtech.net".to_string(), }; @@ -61,11 +64,10 @@ fn get_route(route_len: usize) -> Vec { .presence_topology .get() .expect("Failed to retrieve network topology."); - let route = route_from(topology, route_len); - route + topology } -fn route_from(topology: Topology, route_len: usize) -> Vec { +fn route_from(topology: &Topology, route_len: usize) -> Vec { let mut route = vec![]; let nodes = topology.mix_nodes.iter(); for mix in nodes.take(route_len) { From 39bbecb55d4187d7053f30a495a0eff9e0d01eaa Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 11 Dec 2019 16:42:25 +0000 Subject: [PATCH 059/167] Closing socket to server on being done --- src/clients/provider.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 9bfe304a7b..eaba6db9b8 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -2,6 +2,7 @@ use sphinx::route::Node as MixNode; use sphinx::SphinxPacket; use tokio::prelude::*; use sfw_provider_requests::*; +use std::net::Shutdown; pub struct ProviderClient {} @@ -19,8 +20,20 @@ impl ProviderClient { let pull_request = PullRequest::new(address); let bytes = pull_request.to_bytes(); - let mut stream = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; - stream.write_all(&bytes[..]).await?; + let mut socket = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; + socket.write_all(&bytes[..]).await?; + if let Err(e) = socket.shutdown(Shutdown::Write) { + eprintln!("failed to close write part of the socket; err = {:?}", e) + } + + let mut response = Vec::new(); + socket.read_to_end(&mut response).await?; + if let Err(e) = socket.shutdown(Shutdown::Read) { + eprintln!("failed to close read part of the socket; err = {:?}", e) + } + + println!("Received the following response: {:?}", response); + Ok(()) } } From eccf5abb7a64939cc0ddc923f537bc820c042fc7 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 16:58:58 +0000 Subject: [PATCH 060/167] Extracting bytes function into its own utility --- src/commands/run.rs | 16 +++--------- src/main.rs | 1 + src/utils/bytes.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++ src/utils/mod.rs | 1 + 4 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 src/utils/bytes.rs create mode 100644 src/utils/mod.rs diff --git a/src/commands/run.rs b/src/commands/run.rs index 9db06fc569..0ce7a25f79 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -3,6 +3,7 @@ use crate::clients::directory::presence::{MixNodePresence, Topology}; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; +use crate::utils::bytes; use base64; use clap::ArgMatches; use curve25519_dalek::montgomery::MontgomeryPoint; @@ -71,9 +72,9 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { let mut route = vec![]; let nodes = topology.mix_nodes.iter(); for mix in nodes.take(route_len) { - let address_bytes = zero_pad_to_32_bytes(mix.host.as_bytes().to_vec()); + let address_bytes = bytes::zero_pad_to_32(mix.host.as_bytes().to_vec()); let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); - let key_bytes = zero_pad_to_32_bytes(decoded_key_bytes); + let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); let key = MontgomeryPoint(key_bytes); let sphinx_node = SphinxNode { address: address_bytes, @@ -84,17 +85,6 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { route } -fn zero_pad_to_32_bytes(mut bytes: Vec) -> [u8; 32] { - assert!(bytes.len() <= 32); - if bytes.len() != 32 { - bytes.resize(32, 0); - } - let mut padded_bytes = [0; 32]; - padded_bytes.copy_from_slice(&bytes[..]); - assert!(padded_bytes.len() == 32); - padded_bytes -} - // TODO: where do we retrieve this guy from? fn get_destination() -> Destination { Destination { diff --git a/src/main.rs b/src/main.rs index 77d309f519..04b0432aa7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use std::process; mod clients; mod commands; +mod utils; fn main() { let arg_matches = App::new("Nym Client") diff --git a/src/utils/bytes.rs b/src/utils/bytes.rs new file mode 100644 index 0000000000..92ec2fea37 --- /dev/null +++ b/src/utils/bytes.rs @@ -0,0 +1,64 @@ +pub fn zero_pad_to_32(mut bytes: Vec) -> [u8; 32] { + assert!(bytes.len() <= 32); + if bytes.len() != 32 { + bytes.resize(32, 0); + } + let mut padded_bytes = [0; 32]; + padded_bytes.copy_from_slice(&bytes[..]); + assert!(padded_bytes.len() == 32); + padded_bytes +} + +#[cfg(test)] +mod zero_padding_to_32_bytes { + use super::*; + + #[cfg(test)] + mod with_empty_input { + use super::*; + + #[test] + fn it_returns_32_zeros() { + let input = vec![]; + let result = zero_pad_to_32(input); + assert_eq!([0u8; 32], result); + } + } + + #[cfg(test)] + mod with_all_bytes_set_to_1 { + use super::*; + #[test] + fn it_returns_32_ones() { + let input = vec![1u8; 32]; + let result = zero_pad_to_32(input); + assert_eq!([1u8; 32], result); + } + } + + #[cfg(test)] + mod with_3_bytes_set { + use super::*; + #[test] + fn it_returns_input_zero_padded_to_32_bytes() { + let input = vec![1u8; 3]; + let result = zero_pad_to_32(input); + let expected_content = vec![ + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ]; + assert_eq!(expected_content, result.to_vec()); + } + } + + #[cfg(test)] + mod with_oversized_input { + use super::*; + #[test] + #[should_panic] + fn it_panics() { + let input = vec![1u8; 33]; + zero_pad_to_32(input); + } + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000000..ad0049c4c2 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod bytes; From 64b43875a838bf14b9b41af2f43bde4cf3e4c932 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Wed, 11 Dec 2019 17:17:29 +0000 Subject: [PATCH 061/167] directory: wire up all requests so that they're available for use --- src/clients/directory/mod.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index 760cde04aa..5952490d4c 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -1,6 +1,21 @@ use crate::clients::directory::requests::health_check_get::{ HealthCheckRequester, Request as HealthCheckRequest, }; +use crate::clients::directory::requests::metrics_mixes_get::{ + MetricsMixRequester, Request as MetricsMixRequest, +}; +use crate::clients::directory::requests::metrics_mixes_post::{ + MetricsMixPoster, Request as MetricsMixPost, +}; +use crate::clients::directory::requests::presence_coconodes_post::{ + PresenceCocoNodesPoster, Request as PresenceCocoNodesPost, +}; +use crate::clients::directory::requests::presence_mixnodes_post::{ + PresenceMixNodesPoster, Request as PresenceMixNodesPost, +}; +use crate::clients::directory::requests::presence_providers_post::{ + PresenceMixProviderPoster, Request as PresenceProvidersPost, +}; use crate::clients::directory::requests::presence_topology_get::{ PresenceTopologyGetRequester, Request as PresenceTopologyRequest, }; @@ -19,16 +34,34 @@ pub trait DirectoryClient { pub struct Client { pub health_check: HealthCheckRequest, + pub metrics_mixes: MetricsMixRequest, + pub metrics_post: MetricsMixPost, + pub presence_coconodes_post: PresenceCocoNodesPost, + pub presence_mix_nodes_post: PresenceMixNodesPost, + pub presence_providers_post: PresenceProvidersPost, pub presence_topology: PresenceTopologyRequest, } impl DirectoryClient for Client { fn new(config: Config) -> Client { let health_check: HealthCheckRequest = HealthCheckRequest::new(config.base_url.clone()); + let metrics_mixes: MetricsMixRequest = MetricsMixRequest::new(config.base_url.clone()); + let metrics_post: MetricsMixPost = MetricsMixPost::new(config.base_url.clone()); let presence_topology: PresenceTopologyRequest = PresenceTopologyRequest::new(config.base_url.clone()); + let presence_coconodes_post: PresenceCocoNodesPost = + PresenceCocoNodesPost::new(config.base_url.clone()); + let presence_mix_nodes_post: PresenceMixNodesPost = + PresenceMixNodesPost::new(config.base_url.clone()); + let presence_providers_post: PresenceProvidersPost = + PresenceProvidersPost::new(config.base_url.clone()); Client { health_check, + metrics_mixes, + metrics_post, + presence_coconodes_post, + presence_mix_nodes_post, + presence_providers_post, presence_topology, } } From ecef8379b075e88177897844d904f7971248b530 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 11:34:16 +0000 Subject: [PATCH 062/167] Cargo: adding pem dependencies. --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + 2 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3c8a32db30..90e37f266a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -896,6 +896,7 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", @@ -962,6 +963,16 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pem" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1913,6 +1924,7 @@ dependencies = [ "checksum openssl-sys 0.9.53 (registry+https://github.com/rust-lang/crates.io-index)" = "465d16ae7fc0e313318f7de5cecf57b2fbe7511fd213978b457e1c96ff46736f" "checksum parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +"checksum pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1581760c757a756a41f0ee3ff01256227bdf64cb752839779b95ffb01c59793" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" diff --git a/Cargo.toml b/Cargo.toml index e088f736c6..184fe290c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" base64 = "0.11.0" clap = "2.33.0" curve25519-dalek = "1.2.3" +pem = "0.7.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } From 45176a7ce0af0181c46d8bd1a7ecd0e322f137e1 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 11:34:40 +0000 Subject: [PATCH 063/167] main: messing with args and adding banner --- src/main.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 77d309f519..91f0882300 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,21 @@ fn main() { .about("Implementation of the Nym Client") .subcommand( SubCommand::with_name("init") - .about("Initialise a Nym client") - .arg(Arg::with_name("providerID") - .short("pid") - .long("providerID") - .help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen") + .about("Initialise a Nym client. Do this first!") + .arg(Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnet-client we want to create config for.") + .takes_value(true) + ) + .arg(Arg::with_name("provider") + .long("provider") + .help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen.") .takes_value(true) ) .arg(Arg::with_name("local") - .short("loc") .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(true) ) ) .subcommand( @@ -65,7 +69,7 @@ fn main() { .get_matches(); if let Err(e) = execute(arg_matches) { - println!("Application error: {}", e); + println!("{}", e); process::exit(1); } } @@ -76,6 +80,23 @@ fn execute(matches: ArgMatches) -> Result<(), String> { ("run", Some(m)) => Ok(commands::run::execute(m)), ("socket", Some(m)) => Ok(commands::socket::execute(m)), - _ => Err(String::from("Unknown command")), + _ => Err(banner()), } } + +fn banner() -> String { + return r#" + + _ __ _ _ _ __ ___ + | '_ \| | | | '_ \ _ \ + | | | | |_| | | | | | | + |_| |_|\__, |_| |_| |_| + |___/ + + (client) + + usage: --help to see available options. + + "# + .to_string(); +} From 9ecff9b5bfe83d6e82bdffefd5fe486bcd9b4a52 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 11:34:50 +0000 Subject: [PATCH 064/167] init: writing pem files --- src/commands/init.rs | 45 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/src/commands/init.rs b/src/commands/init.rs index 42e846d2dd..5c689e4ab4 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,14 +1,51 @@ use clap::ArgMatches; +use pem::{encode, Pem}; +use std::fs::File; +use std::io::prelude::*; pub fn execute(matches: &ArgMatches) { - println!("Running client init!"); + println!("Initialising client..."); // don't unwrap it, pass it as it is, if it's None, choose a random - let provider_id = matches.value_of("providerID"); + let id = matches.value_of("id"); + let provider_id = matches.value_of("provider"); let init_local = matches.is_present("local"); println!( - "client init goes here with providerID: {:?} and running locally: {:?}", - provider_id, init_local + "id: {:?}, provider: {:?}, local: {:?}", + id, provider_id, init_local + ); + + write_pem_files(); +} + +fn write_pem_files() { + let key_directory = String::from("/home/dave/.nym/clients/foomp/config"); + std::fs::create_dir_all(key_directory.clone()).unwrap(); + + let (private, public) = sphinx::crypto::keygen(); + write_pem_file( + key_directory.clone(), + String::from("secret.pem"), + private.to_bytes().to_vec(), + String::from("SPHINX CURVE25519 PRIVATE KEY"), + ); + write_pem_file( + key_directory.clone(), + String::from("public.pem"), + public.to_bytes().to_vec(), + String::from("SPHINX CURVE25519 PUBLIC KEY"), ); } + +fn write_pem_file(directory: String, filename: String, data: Vec, tag: String) { + let pem = Pem { + tag, + contents: data, + }; + let key = encode(&pem); + + let full_path = directory + "/" + &filename; + let mut file = File::create(full_path).unwrap(); + file.write_all(key.as_bytes()).unwrap(); +} From 67b21b1cd1b1eb44dd49b9d03c6176abbe001082 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 11:35:11 +0000 Subject: [PATCH 065/167] cargo: adding directories dependency --- Cargo.lock | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 70 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 90e37f266a..a64896ea13 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,11 @@ name = "arrayref" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "arrayvec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "assert-json-diff" version = "1.0.1" @@ -134,6 +139,16 @@ dependencies = [ "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "blake2b_simd" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-buffer" version = "0.7.3" @@ -253,6 +268,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "constant_time_eq" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cookie" version = "0.12.0" @@ -393,6 +413,26 @@ dependencies = [ "generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "directories" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dirs-sys" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dtoa" version = "0.4.4" @@ -895,6 +935,7 @@ dependencies = [ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1180,6 +1221,17 @@ name = "redox_syscall" version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "redox_users" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "1.3.1" @@ -1237,6 +1289,16 @@ dependencies = [ "winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rust-argon2" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rustc-demangle" version = "0.1.16" @@ -1823,6 +1885,7 @@ dependencies = [ "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arc-swap 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d7b8a9123b8027467bce0099fe556c628a53c8d83df0507084c31e9ba2e39aff" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" +"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" "checksum assert-json-diff 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9881d306dee755eccf052d652b774a6b2861e86b4772f555262130e58e4f81d2" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" @@ -1832,6 +1895,7 @@ dependencies = [ "checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" +"checksum blake2b_simd 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b83b7baab1e671718d78204225800d6b170e648188ac7dc992e9d6bddf87d0c0" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" @@ -1847,6 +1911,7 @@ dependencies = [ "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum colored 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "433e7ac7d511768127ed85b0c4947f47a254131e37864b2dc13f52aa32cd37e5" +"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum cookie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5" "checksum cookie_store 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46750b3f362965f197996c4448e4a0935e791bf7d6631bfce9ee0af3d24c919c" "checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" @@ -1862,6 +1927,8 @@ dependencies = [ "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +"checksum directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c" +"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum encoding_rs 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)" = "87240518927716f79692c2ed85bfe6e98196d18c6401ec75355760233a7e12e9" @@ -1950,10 +2017,12 @@ dependencies = [ "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecedbca3bf205f8d8f5c2b44d83cd0690e39ee84b951ed649e9f1841132b66d" "checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd" "checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)" = "2c2064233e442ce85c77231ebd67d9eca395207dec2127fe0bbedde4bd29a650" +"checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8" diff --git a/Cargo.toml b/Cargo.toml index 184fe290c3..ccb79ed681 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" base64 = "0.11.0" clap = "2.33.0" curve25519-dalek = "1.2.3" +directories = "2.0" pem = "0.7.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } From 4ed7f6a31ff8508db5075cad9f6e0b0aa608b7b0 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 12:30:35 +0000 Subject: [PATCH 066/167] Changing to lower-level "dirs" crate for base directory config --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a64896ea13..cc01296146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -414,7 +414,7 @@ dependencies = [ ] [[package]] -name = "directories" +name = "dirs" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ @@ -935,7 +935,7 @@ dependencies = [ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1927,7 +1927,7 @@ dependencies = [ "checksum curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7dcd30ba50cdf88b55b033456138b7c0ac4afdc436d82e1b79f370f24cc66d" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -"checksum directories 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c" +"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" diff --git a/Cargo.toml b/Cargo.toml index ccb79ed681..7125852925 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" base64 = "0.11.0" clap = "2.33.0" curve25519-dalek = "1.2.3" -directories = "2.0" +dirs = "2.0.2" pem = "0.7.0" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } From 53408ef393f6ab0fad07cf4c9a66a8ded42dfe6d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 12:40:21 +0000 Subject: [PATCH 067/167] main: splitting banner and usage into separate functions --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 91f0882300..9460439f72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ fn main() { .long("id") .help("Id of the nym-mixnet-client we want to create config for.") .takes_value(true) + .required(true) ) .arg(Arg::with_name("provider") .long("provider") @@ -80,10 +81,14 @@ fn execute(matches: ArgMatches) -> Result<(), String> { ("run", Some(m)) => Ok(commands::run::execute(m)), ("socket", Some(m)) => Ok(commands::socket::execute(m)), - _ => Err(banner()), + _ => Err(usage()), } } +fn usage() -> String { + banner() + "usage: --help to see available options." +} + fn banner() -> String { return r#" @@ -95,8 +100,6 @@ fn banner() -> String { (client) - usage: --help to see available options. - "# .to_string(); } From 98194790965a771cfd369f41f44169f1ce9297fa Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 12:40:47 +0000 Subject: [PATCH 068/167] init: using proper directory commands and displaying banner during init --- src/commands/init.rs | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/commands/init.rs b/src/commands/init.rs index 5c689e4ab4..3552597aae 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,51 +1,60 @@ +use crate::banner; use clap::ArgMatches; +use dirs; use pem::{encode, Pem}; use std::fs::File; use std::io::prelude::*; pub fn execute(matches: &ArgMatches) { + println!("{}", banner()); println!("Initialising client..."); + let id = matches.value_of("id").unwrap(); // required for now + // don't unwrap it, pass it as it is, if it's None, choose a random - let id = matches.value_of("id"); - let provider_id = matches.value_of("provider"); - let init_local = matches.is_present("local"); + let _provider_id = matches.value_of("provider"); + let _init_local = matches.is_present("local"); - println!( - "id: {:?}, provider: {:?}, local: {:?}", - id, provider_id, init_local - ); + let os_config_dir = dirs::config_dir().unwrap(); + let nym_client_config_dir = os_config_dir.join("nym").join("clients").join(id); - write_pem_files(); + println!("Writing keypairs to {:?}...", nym_client_config_dir); + write_pem_files(nym_client_config_dir); + + println!("Client configuration completed.\n\n\n") } -fn write_pem_files() { - let key_directory = String::from("/home/dave/.nym/clients/foomp/config"); - std::fs::create_dir_all(key_directory.clone()).unwrap(); +fn write_pem_files(nym_client_config_dir: std::path::PathBuf) { + std::fs::create_dir_all(nym_client_config_dir.clone()).unwrap(); let (private, public) = sphinx::crypto::keygen(); write_pem_file( - key_directory.clone(), - String::from("secret.pem"), + nym_client_config_dir.clone(), + String::from("private.pem"), private.to_bytes().to_vec(), String::from("SPHINX CURVE25519 PRIVATE KEY"), ); write_pem_file( - key_directory.clone(), + nym_client_config_dir.clone(), String::from("public.pem"), public.to_bytes().to_vec(), String::from("SPHINX CURVE25519 PUBLIC KEY"), ); } -fn write_pem_file(directory: String, filename: String, data: Vec, tag: String) { +fn write_pem_file( + nym_client_config_dir: std::path::PathBuf, + filename: String, + data: Vec, + tag: String, +) { let pem = Pem { tag, contents: data, }; let key = encode(&pem); - let full_path = directory + "/" + &filename; + let full_path = nym_client_config_dir.join(filename); let mut file = File::create(full_path).unwrap(); file.write_all(key.as_bytes()).unwrap(); } From fe45a5382ebdf8d83588d085ae3d66a8ae2e6ecc Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 12:50:46 +0000 Subject: [PATCH 069/167] utils: removing useless assert --- src/utils/bytes.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/bytes.rs b/src/utils/bytes.rs index 92ec2fea37..6079fa8385 100644 --- a/src/utils/bytes.rs +++ b/src/utils/bytes.rs @@ -5,7 +5,6 @@ pub fn zero_pad_to_32(mut bytes: Vec) -> [u8; 32] { } let mut padded_bytes = [0; 32]; padded_bytes.copy_from_slice(&bytes[..]); - assert!(padded_bytes.len() == 32); padded_bytes } From 536d86d6e3780c9309c92a5f7b9297c4d8668f70 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Thu, 12 Dec 2019 13:56:31 +0000 Subject: [PATCH 070/167] Retrieving stored messages --- src/clients/provider.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index eaba6db9b8..fbf644b58c 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -3,6 +3,9 @@ use sphinx::SphinxPacket; use tokio::prelude::*; use sfw_provider_requests::*; use std::net::Shutdown; +use std::time::Duration; +use sfw_provider_requests::requests::{PullRequest, ProviderRequest}; +use sfw_provider_requests::responses::{PullResponse, ProviderResponse}; pub struct ProviderClient {} @@ -12,15 +15,17 @@ impl ProviderClient { ProviderClient {} } - pub async fn send( + pub async fn retrieve_messages( &self, // provider: &MixNode, ) -> Result<(), Box> { - let address = [0; 32]; + let address = [42; 32]; let pull_request = PullRequest::new(address); let bytes = pull_request.to_bytes(); let mut socket = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; + println!("keep alive: {:?}", socket.keepalive()); + socket.set_keepalive(Some(tokio::time::Duration::from_secs(2))); socket.write_all(&bytes[..]).await?; if let Err(e) = socket.shutdown(Shutdown::Write) { eprintln!("failed to close write part of the socket; err = {:?}", e) @@ -33,7 +38,10 @@ impl ProviderClient { } println!("Received the following response: {:?}", response); - + let parsed_response = PullResponse::from_bytes(&response).unwrap(); + for message in parsed_response.messages { + println!("Received: {:?}", String::from_utf8(message).unwrap()) + } Ok(()) } } From f28eac7f94601fbc8663975c1bf33b5dddae87a0 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Thu, 12 Dec 2019 14:01:02 +0000 Subject: [PATCH 071/167] changed default destination address to be non-zero --- src/commands/run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 67926ccc00..c892fe6a08 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -92,7 +92,7 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { // TODO: where do we retrieve this guy from? fn get_destination() -> Destination { Destination { - address: [0u8; 32], - identifier: [0u8; 16], + address: [42u8; 32], + identifier: [1u8; 16], } } From ccca67acd5bc0c1036192803abe95b67a165303d Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Thu, 12 Dec 2019 14:15:08 +0000 Subject: [PATCH 072/167] Zeroed public keys to match local deployment + provider 'polling' --- src/commands/run.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index c892fe6a08..aa6cd27ce4 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -36,7 +36,7 @@ pub fn execute(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - let route_len = 3; + let route_len = 2; // data needed to generate a new Sphinx packet let route = route_from(&topology, route_len); @@ -53,8 +53,13 @@ pub fn execute(matches: &ArgMatches) { println!("packet sent: {:?}", i); i += 1; - let provider_client = ProviderClient::new(); - provider_client.send().await.unwrap(); + // retrieve messages every now and then + if i % 3 == 0 { + interval.tick().await; + println!("going to retrieve messages!"); + let provider_client = ProviderClient::new(); + provider_client.retrieve_messages().await.unwrap(); + } } }) } @@ -80,10 +85,13 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); let key = MontgomeryPoint(key_bytes); - let sphinx_node = SphinxNode { + let mut sphinx_node = SphinxNode { address: address_bytes, pub_key: key, }; + + // temporary to make it work locally: + sphinx_node.pub_key = Default::default(); route.push(sphinx_node); } route From 14f0c1afbff432f795676a93a30897cf1ccf06c3 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 14:22:22 +0000 Subject: [PATCH 073/167] Refactored so that we have sane persistence functions --- src/commands/init.rs | 51 +++++-------------------------------- src/identity/mixnet.rs | 22 ++++++++++++++++ src/identity/mod.rs | 1 + src/identity/validators.rs | 1 + src/main.rs | 2 ++ src/persistence/mod.rs | 1 + src/persistence/pemstore.rs | 41 +++++++++++++++++++++++++++++ src/persistence/toml.rs | 1 + 8 files changed, 75 insertions(+), 45 deletions(-) create mode 100644 src/identity/mixnet.rs create mode 100644 src/identity/mod.rs create mode 100644 src/identity/validators.rs create mode 100644 src/persistence/mod.rs create mode 100644 src/persistence/pemstore.rs create mode 100644 src/persistence/toml.rs diff --git a/src/commands/init.rs b/src/commands/init.rs index 3552597aae..9bc9db962d 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,60 +1,21 @@ use crate::banner; +use crate::identity::mixnet; +use crate::persistence::pemstore::PemStore; use clap::ArgMatches; use dirs; -use pem::{encode, Pem}; -use std::fs::File; -use std::io::prelude::*; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); println!("Initialising client..."); let id = matches.value_of("id").unwrap(); // required for now - - // don't unwrap it, pass it as it is, if it's None, choose a random - let _provider_id = matches.value_of("provider"); - let _init_local = matches.is_present("local"); - - let os_config_dir = dirs::config_dir().unwrap(); + let os_config_dir = dirs::config_dir().unwrap(); // grabs the OS default config dir let nym_client_config_dir = os_config_dir.join("nym").join("clients").join(id); println!("Writing keypairs to {:?}...", nym_client_config_dir); - write_pem_files(nym_client_config_dir); + let mix_keys = mixnet::KeyPair::new(); + let pem_store = PemStore::new(); + pem_store.write(mix_keys, nym_client_config_dir); println!("Client configuration completed.\n\n\n") } - -fn write_pem_files(nym_client_config_dir: std::path::PathBuf) { - std::fs::create_dir_all(nym_client_config_dir.clone()).unwrap(); - - let (private, public) = sphinx::crypto::keygen(); - write_pem_file( - nym_client_config_dir.clone(), - String::from("private.pem"), - private.to_bytes().to_vec(), - String::from("SPHINX CURVE25519 PRIVATE KEY"), - ); - write_pem_file( - nym_client_config_dir.clone(), - String::from("public.pem"), - public.to_bytes().to_vec(), - String::from("SPHINX CURVE25519 PUBLIC KEY"), - ); -} - -fn write_pem_file( - nym_client_config_dir: std::path::PathBuf, - filename: String, - data: Vec, - tag: String, -) { - let pem = Pem { - tag, - contents: data, - }; - let key = encode(&pem); - - let full_path = nym_client_config_dir.join(filename); - let mut file = File::create(full_path).unwrap(); - file.write_all(key.as_bytes()).unwrap(); -} diff --git a/src/identity/mixnet.rs b/src/identity/mixnet.rs new file mode 100644 index 0000000000..ae6a169d68 --- /dev/null +++ b/src/identity/mixnet.rs @@ -0,0 +1,22 @@ +use curve25519_dalek::montgomery::MontgomeryPoint; +use curve25519_dalek::scalar::Scalar; + +pub struct KeyPair { + pub private: Scalar, + pub public: MontgomeryPoint, +} + +impl KeyPair { + pub fn new() -> KeyPair { + let (private, public) = sphinx::crypto::keygen(); + KeyPair { private, public } + } + + pub fn private_bytes(&self) -> Vec { + self.private.to_bytes().to_vec() + } + + pub fn public_bytes(&self) -> Vec { + self.public.to_bytes().to_vec() + } +} diff --git a/src/identity/mod.rs b/src/identity/mod.rs new file mode 100644 index 0000000000..ae7f01c0eb --- /dev/null +++ b/src/identity/mod.rs @@ -0,0 +1 @@ +pub mod mixnet; diff --git a/src/identity/validators.rs b/src/identity/validators.rs new file mode 100644 index 0000000000..b18c85b0b2 --- /dev/null +++ b/src/identity/validators.rs @@ -0,0 +1 @@ +// TODO types for Validator keys will go in here once we hook this up. diff --git a/src/main.rs b/src/main.rs index ea6fabb444..2d2ce6f7e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ use std::process; mod clients; mod commands; +mod identity; +mod persistence; mod utils; fn main() { diff --git a/src/persistence/mod.rs b/src/persistence/mod.rs new file mode 100644 index 0000000000..c21f39e57f --- /dev/null +++ b/src/persistence/mod.rs @@ -0,0 +1 @@ +pub mod pemstore; diff --git a/src/persistence/pemstore.rs b/src/persistence/pemstore.rs new file mode 100644 index 0000000000..e8091f091e --- /dev/null +++ b/src/persistence/pemstore.rs @@ -0,0 +1,41 @@ +use crate::identity::mixnet::KeyPair; +use pem::{encode, Pem}; +use std::fs::File; +use std::io::prelude::*; +use std::path::PathBuf; + +pub struct PemStore {} + +impl PemStore { + pub fn new() -> PemStore { + PemStore {} + } + pub fn write(&self, key_pair: KeyPair, path: PathBuf) { + std::fs::create_dir_all(path.clone()).unwrap(); + + self.write_pem_file( + path.clone(), + String::from("private.pem"), + key_pair.private_bytes(), + String::from("SPHINX CURVE25519 PRIVATE KEY"), + ); + self.write_pem_file( + path.clone(), + String::from("public.pem"), + key_pair.public_bytes(), + String::from("SPHINX CURVE25519 PUBLIC KEY"), + ); + } + + fn write_pem_file(&self, path: PathBuf, filename: String, data: Vec, tag: String) { + let pem = Pem { + tag, + contents: data, + }; + let key = encode(&pem); + + let full_path = path.join(filename); + let mut file = File::create(full_path).unwrap(); + file.write_all(key.as_bytes()).unwrap(); + } +} diff --git a/src/persistence/toml.rs b/src/persistence/toml.rs new file mode 100644 index 0000000000..f4f5578ad0 --- /dev/null +++ b/src/persistence/toml.rs @@ -0,0 +1 @@ +// TODO: we can put all the TOML config templating code in here once we get to that. From 71f06b1efcd50ec2528cdd2db5a3fb0b4469c921 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 15:36:18 +0000 Subject: [PATCH 074/167] persistence: pem storage now working --- src/commands/init.rs | 13 +++++---- src/commands/run.rs | 7 ++--- src/identity/mixnet.rs | 13 +++++++++ src/persistence/mod.rs | 1 + src/persistence/pathfinder.rs | 21 +++++++++++++++ src/persistence/pemstore.rs | 50 ++++++++++++++++++++++++++--------- 6 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 src/persistence/pathfinder.rs diff --git a/src/commands/init.rs b/src/commands/init.rs index 9bc9db962d..00af80c1f5 100644 --- a/src/commands/init.rs +++ b/src/commands/init.rs @@ -1,21 +1,20 @@ use crate::banner; use crate::identity::mixnet; +use crate::persistence::pathfinder::Pathfinder; use crate::persistence::pemstore::PemStore; use clap::ArgMatches; -use dirs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); println!("Initialising client..."); - let id = matches.value_of("id").unwrap(); // required for now - let os_config_dir = dirs::config_dir().unwrap(); // grabs the OS default config dir - let nym_client_config_dir = os_config_dir.join("nym").join("clients").join(id); + let id = matches.value_of("id").unwrap().to_string(); // required for now + let pathfinder = Pathfinder::new(id); - println!("Writing keypairs to {:?}...", nym_client_config_dir); + println!("Writing keypairs to {:?}...", pathfinder.config_dir); let mix_keys = mixnet::KeyPair::new(); - let pem_store = PemStore::new(); - pem_store.write(mix_keys, nym_client_config_dir); + let pem_store = PemStore::new(pathfinder); + pem_store.write(mix_keys); println!("Client configuration completed.\n\n\n") } diff --git a/src/commands/run.rs b/src/commands/run.rs index 0ce7a25f79..b7bec29923 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,5 +1,5 @@ use crate::clients::directory; -use crate::clients::directory::presence::{MixNodePresence, Topology}; +use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; @@ -15,10 +15,7 @@ use tokio::time::{interval_at, Instant}; pub fn execute(matches: &ArgMatches) { let custom_cfg = matches.value_of("customCfg"); - println!( - "Going to start client with custom config of: {:?}", - custom_cfg - ); + println!("Starting client with config: {:?}", custom_cfg); // Grab the network topology from the remote directory server let topology = get_topology(); diff --git a/src/identity/mixnet.rs b/src/identity/mixnet.rs index ae6a169d68..83507d7d70 100644 --- a/src/identity/mixnet.rs +++ b/src/identity/mixnet.rs @@ -1,6 +1,7 @@ use curve25519_dalek::montgomery::MontgomeryPoint; use curve25519_dalek::scalar::Scalar; +// This keypair serves as the user's identity within the Mixnet pub struct KeyPair { pub private: Scalar, pub public: MontgomeryPoint, @@ -12,6 +13,18 @@ impl KeyPair { KeyPair { private, public } } + pub fn from_bytes(private_bytes: Vec, public_bytes: Vec) -> KeyPair { + let mut bytes = [0; 32]; + bytes.copy_from_slice(&private_bytes[..]); + let private = Scalar::from_canonical_bytes(bytes).unwrap(); + + let mut bytes = [0; 32]; + bytes.copy_from_slice(&public_bytes[..]); + let public = MontgomeryPoint(bytes); + + KeyPair { private, public } + } + pub fn private_bytes(&self) -> Vec { self.private.to_bytes().to_vec() } diff --git a/src/persistence/mod.rs b/src/persistence/mod.rs index c21f39e57f..bc1ad593bd 100644 --- a/src/persistence/mod.rs +++ b/src/persistence/mod.rs @@ -1 +1,2 @@ +pub mod pathfinder; pub mod pemstore; diff --git a/src/persistence/pathfinder.rs b/src/persistence/pathfinder.rs new file mode 100644 index 0000000000..08110b9ae8 --- /dev/null +++ b/src/persistence/pathfinder.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; + +pub struct Pathfinder { + pub config_dir: PathBuf, + pub private_mix_key: PathBuf, + pub public_mix_key: PathBuf, +} + +impl Pathfinder { + pub fn new(id: String) -> Pathfinder { + let os_config_dir = dirs::config_dir().unwrap(); // grabs the OS default config dir + let config_dir = os_config_dir.join("nym").join("clients").join(id); + let private_mix_key = config_dir.join("private.pem"); + let public_mix_key = config_dir.join("public.pem"); + Pathfinder { + config_dir, + private_mix_key, + public_mix_key, + } + } +} diff --git a/src/persistence/pemstore.rs b/src/persistence/pemstore.rs index e8091f091e..0f367b48e7 100644 --- a/src/persistence/pemstore.rs +++ b/src/persistence/pemstore.rs @@ -1,41 +1,65 @@ use crate::identity::mixnet::KeyPair; -use pem::{encode, Pem}; +use crate::persistence::pathfinder::Pathfinder; +use pem::{encode, parse, Pem}; use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; -pub struct PemStore {} +pub struct PemStore { + config_dir: PathBuf, + private_mix_key: PathBuf, + public_mix_key: PathBuf, +} impl PemStore { - pub fn new() -> PemStore { - PemStore {} + pub fn new(pathfinder: Pathfinder) -> PemStore { + PemStore { + config_dir: pathfinder.config_dir, + private_mix_key: pathfinder.private_mix_key, + public_mix_key: pathfinder.public_mix_key, + } } - pub fn write(&self, key_pair: KeyPair, path: PathBuf) { - std::fs::create_dir_all(path.clone()).unwrap(); + + pub fn read(&self) -> KeyPair { + let private = self.read_file(self.private_mix_key.clone()); + let public = self.read_file(self.public_mix_key.clone()); + + KeyPair::from_bytes(private, public) + } + + pub fn read_file(&self, filepath: PathBuf) -> Vec { + let mut pem_bytes = File::open(filepath).unwrap(); + let mut buf = Vec::new(); + pem_bytes.read_to_end(&mut buf).unwrap(); + let pem = parse(&buf).unwrap(); + pem.contents + } + // This should be refactored and made more generic for when we have other kinds of + // KeyPairs that we want to persist (e.g. validator keypairs, or keys for + // signing vs encryption). However, for the moment, it does the job. + pub fn write(&self, key_pair: KeyPair) { + std::fs::create_dir_all(self.config_dir.clone()).unwrap(); self.write_pem_file( - path.clone(), - String::from("private.pem"), + self.private_mix_key.clone(), key_pair.private_bytes(), String::from("SPHINX CURVE25519 PRIVATE KEY"), ); self.write_pem_file( - path.clone(), - String::from("public.pem"), + self.public_mix_key.clone(), key_pair.public_bytes(), String::from("SPHINX CURVE25519 PUBLIC KEY"), ); } - fn write_pem_file(&self, path: PathBuf, filename: String, data: Vec, tag: String) { + fn write_pem_file(&self, filepath: PathBuf, data: Vec, tag: String) { let pem = Pem { tag, contents: data, }; let key = encode(&pem); - let full_path = path.join(filename); - let mut file = File::create(full_path).unwrap(); + let mut file = File::create(filepath).unwrap(); file.write_all(key.as_bytes()).unwrap(); } } From 722f2daaef5b9d788ec8bec45881aa5b9c448c34 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 15:40:24 +0000 Subject: [PATCH 075/167] pemstore: read_file can be private --- src/persistence/pemstore.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/persistence/pemstore.rs b/src/persistence/pemstore.rs index 0f367b48e7..c935fab437 100644 --- a/src/persistence/pemstore.rs +++ b/src/persistence/pemstore.rs @@ -27,7 +27,7 @@ impl PemStore { KeyPair::from_bytes(private, public) } - pub fn read_file(&self, filepath: PathBuf) -> Vec { + fn read_file(&self, filepath: PathBuf) -> Vec { let mut pem_bytes = File::open(filepath).unwrap(); let mut buf = Vec::new(); pem_bytes.read_to_end(&mut buf).unwrap(); From 1468deb2c0c8a032a2fd03b1a26920ac18b98507 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 12 Dec 2019 16:45:39 +0000 Subject: [PATCH 076/167] main: banner formatting --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index ea6fabb444..c9eaf03d40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,7 +87,7 @@ fn execute(matches: ArgMatches) -> Result<(), String> { } fn usage() -> String { - banner() + "usage: --help to see available options." + banner() + "usage: --help to see available options.\n\n" } fn banner() -> String { From 9114a10880e03f67e43442bddd8e8b559f5d44a6 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Thu, 12 Dec 2019 17:23:03 +0000 Subject: [PATCH 077/167] Initial structure for starting all traffic streams --- Cargo.lock | 109 ++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- src/clients/mod.rs | 49 ++++++++++++++++++++ src/commands/run.rs | 34 +++++++------- 4 files changed, 176 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4d5176172..233600748a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -537,6 +537,29 @@ name = "futures" version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-channel" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-core" version = "0.3.1" @@ -551,6 +574,60 @@ dependencies = [ "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-executor" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-io" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures-macro" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-sink" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures-task" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures-util" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "generic-array" version = "0.12.3" @@ -936,6 +1013,7 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1030,6 +1108,11 @@ name = "pin-project-lite" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "pin-utils" +version = "0.1.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pkg-config" version = "0.3.17" @@ -1040,6 +1123,21 @@ name = "ppv-lite86" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro-hack" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-nested" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "proc-macro2" version = "1.0.6" @@ -1952,8 +2050,16 @@ dependencies = [ "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" +"checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987" +"checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" "checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" +"checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231" +"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff" +"checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764" +"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" +"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" +"checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" @@ -2003,8 +2109,11 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" +"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" +"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3bbaa49075179162b49acac1c6aa45fb4dafb5f13cf6794276d77bc7fd95757b" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" diff --git a/Cargo.toml b/Cargo.toml index b745efc446..f019dbcb7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } - +futures = "0.3.1" tokio = { version = "0.2", features = ["full"] } [dev-dependencies] diff --git a/src/clients/mod.rs b/src/clients/mod.rs index e0ee8b42df..bad816a794 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,4 +1,53 @@ +use sphinx::route::DestinationAddressBytes; +use tokio::runtime::Runtime; + pub mod directory; pub mod mix; pub mod provider; pub mod validator; + +struct Client { + // to be replaced by something else I guess + address: DestinationAddressBytes +} + +type TripleFutureResult = (Result<(), Box>, Result<(), Box>, Result<(), Box>); + +impl Client { + pub fn new(address: DestinationAddressBytes) -> Self { + Client { + address + } + } + + async fn start_loop_cover_traffic_stream(&self) -> Result<(), Box> { + unimplemented!() + } + + async fn control_out_queue(&self) -> Result<(), Box> { + unimplemented!() + } + + + async fn start_provider_polling(&self) -> Result<(), Box> { + unimplemented!() + } + + + async fn start_traffic(&self) -> TripleFutureResult { + futures::future::join3(self.start_loop_cover_traffic_stream(), self.control_out_queue(), self.start_provider_polling()).await + } + + pub fn start(&self) -> Result<(), Box> { + let mut rt = Runtime::new()?; + + rt.block_on(async { + let future_results = self.start_traffic().await; + assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); + }); + + // this line in theory should never be reached as the runtime should be permanently blocked on traffic senders + eprintln!("The client went kaput..."); + Ok(()) + } +} \ No newline at end of file diff --git a/src/commands/run.rs b/src/commands/run.rs index aa6cd27ce4..48474bc1a6 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -34,23 +34,23 @@ pub fn execute(matches: &ArgMatches) { let mut i: usize = 0; loop { interval.tick().await; - let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - - let route_len = 2; - - // data needed to generate a new Sphinx packet - let route = route_from(&topology, route_len); - let destination = get_destination(); - let delays = sphinx::header::delays::generate(route_len); - - // build the packet - let packet = - sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); - - // send to mixnet - let mix_client = MixClient::new(); - let result = mix_client.send(packet, route.first().unwrap()).await; - println!("packet sent: {:?}", i); +// let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); +// +// let route_len = 2; +// +// // data needed to generate a new Sphinx packet +// let route = route_from(&topology, route_len); +// let destination = get_destination(); +// let delays = sphinx::header::delays::generate(route_len); +// +// // build the packet +// let packet = +// sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); +// +// // send to mixnet +// let mix_client = MixClient::new(); +// let result = mix_client.send(packet, route.first().unwrap()).await; +// println!("packet sent: {:?}", i); i += 1; // retrieve messages every now and then From eee87a4d45541e6a232ee4bb8d3c35efb31375de Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 11:23:25 +0000 Subject: [PATCH 078/167] Sampling poisson distribution --- Cargo.toml | 4 +++- src/utils/mod.rs | 1 + src/utils/poisson.rs | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/utils/poisson.rs diff --git a/Cargo.toml b/Cargo.toml index f019dbcb7f..17043400e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,14 @@ base64 = "0.11.0" clap = "2.33.0" curve25519-dalek = "1.2.3" dirs = "2.0.2" +futures = "0.3.1" pem = "0.7.0" +rand = "0.7.2" +rand_distr = "0.2.2" reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } -futures = "0.3.1" tokio = { version = "0.2", features = ["full"] } [dev-dependencies] diff --git a/src/utils/mod.rs b/src/utils/mod.rs index ad0049c4c2..2e504a1581 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1 +1,2 @@ pub mod bytes; +pub mod poisson; diff --git a/src/utils/poisson.rs b/src/utils/poisson.rs new file mode 100644 index 0000000000..d4991f0dd8 --- /dev/null +++ b/src/utils/poisson.rs @@ -0,0 +1,6 @@ +use rand_distr::{Distribution, Exp}; + +pub fn sample(average_delay: f64) -> f64 { + let exp = Exp::new(1.0 / average_delay).unwrap(); + exp.sample(&mut rand::thread_rng()) +} From 59b931b919294cf2c64b0deff89d855fc3cd9e3e Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 11:36:02 +0000 Subject: [PATCH 079/167] Basic delay loop for cover traffic stream --- Cargo.lock | 2 ++ src/clients/mod.rs | 48 +++++++++++++++++++++---- src/commands/run.rs | 86 ++++++++++++++++++++++++--------------------- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 233600748a..f33fb06525 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1016,6 +1016,8 @@ dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/clients/mod.rs b/src/clients/mod.rs index bad816a794..076ec7d1ae 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,36 +1,68 @@ use sphinx::route::DestinationAddressBytes; use tokio::runtime::Runtime; +use futures::channel::mpsc; +use std::time::Duration; +use crate::utils; pub mod directory; pub mod mix; pub mod provider; pub mod validator; -struct Client { + +// TODO: put that in config once it exists +const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; // assume seconds +const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; +const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; + +// provider-poller sends polls service provider; receives messages +// provider-poller sends (TX) to ReceivedBufferController (RX) +// ReceivedBufferController sends (TX) to ... ??Client?? +// outQueueController sends (TX) to TrafficStreamController (RX) +// TrafficStreamController sends messages to mixnet +// ... ??Client?? sends (TX) to outQueueController (RX) +// Loop cover traffic stream just sends messages to mixnet without any channel communication + +pub struct NymClient { // to be replaced by something else I guess address: DestinationAddressBytes } type TripleFutureResult = (Result<(), Box>, Result<(), Box>, Result<(), Box>); -impl Client { +impl NymClient { pub fn new(address: DestinationAddressBytes) -> Self { - Client { + NymClient { address } } async fn start_loop_cover_traffic_stream(&self) -> Result<(), Box> { - unimplemented!() + loop { + let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); + let delay_duration = Duration::from_secs_f64(delay); + println!("waiting for {:?}", delay_duration); + tokio::time::delay_for(delay_duration).await; + println!("waited {:?} - time to send cover message!", delay_duration); + } + } async fn control_out_queue(&self) -> Result<(), Box> { - unimplemented!() + loop { + println!("here I will be sending real traffic (or loop cover if nothing is available)"); + let delay_duration = Duration::from_secs_f64(10.0); + tokio::time::delay_for(delay_duration).await; + } } async fn start_provider_polling(&self) -> Result<(), Box> { - unimplemented!() + loop { + println!("here I will be polling provider for messages"); + let delay_duration = Duration::from_secs_f64(10.0); + tokio::time::delay_for(delay_duration).await; + } } @@ -39,8 +71,12 @@ impl Client { } pub fn start(&self) -> Result<(), Box> { + println!("starting nym client"); let mut rt = Runtime::new()?; +// let (out_queue_tx, out_queue_rx) = mpsc::unbounded(); + + rt.block_on(async { let future_results = self.start_traffic().await; assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); diff --git a/src/commands/run.rs b/src/commands/run.rs index 48474bc1a6..a73d83401b 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -4,6 +4,7 @@ use crate::clients::directory::requests::presence_topology_get::PresenceTopology use crate::clients::directory::DirectoryClient; use crate::clients::mix::MixClient; use crate::clients::provider::ProviderClient; +use crate::clients::NymClient; use crate::utils::bytes; use base64; use clap::ArgMatches; @@ -21,47 +22,52 @@ pub fn execute(matches: &ArgMatches) { custom_cfg ); - // Grab the network topology from the remote directory server - let topology = get_topology(); + // todo: to be taken from config or something + let my_address = [42u8; 32]; + let client = NymClient::new(my_address); + client.start().unwrap(); - // Create the runtime, probably later move it to Client struct itself? - let mut rt = Runtime::new().unwrap(); - - // Spawn the root task - rt.block_on(async { - let start = Instant::now() + Duration::from_nanos(1000); - let mut interval = interval_at(start, Duration::from_millis(1000)); - let mut i: usize = 0; - loop { - interval.tick().await; -// let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); -// -// let route_len = 2; -// -// // data needed to generate a new Sphinx packet -// let route = route_from(&topology, route_len); -// let destination = get_destination(); -// let delays = sphinx::header::delays::generate(route_len); -// -// // build the packet -// let packet = -// sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); -// -// // send to mixnet -// let mix_client = MixClient::new(); -// let result = mix_client.send(packet, route.first().unwrap()).await; -// println!("packet sent: {:?}", i); - i += 1; - - // retrieve messages every now and then - if i % 3 == 0 { - interval.tick().await; - println!("going to retrieve messages!"); - let provider_client = ProviderClient::new(); - provider_client.retrieve_messages().await.unwrap(); - } - } - }) + // // Grab the network topology from the remote directory server + // let topology = get_topology(); + // + // // Create the runtime, probably later move it to Client struct itself? + // let mut rt = Runtime::new().unwrap(); + // + // // Spawn the root task + // rt.block_on(async { + // let start = Instant::now() + Duration::from_nanos(1000); + // let mut interval = interval_at(start, Duration::from_millis(1000)); + // let mut i: usize = 0; + // loop { + // interval.tick().await; + //// let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); + //// + //// let route_len = 2; + //// + //// // data needed to generate a new Sphinx packet + //// let route = route_from(&topology, route_len); + //// let destination = get_destination(); + //// let delays = sphinx::header::delays::generate(route_len); + //// + //// // build the packet + //// let packet = + //// sphinx::SphinxPacket::new(message, &route[..], &destination, &delays).unwrap(); + //// + //// // send to mixnet + //// let mix_client = MixClient::new(); + //// let result = mix_client.send(packet, route.first().unwrap()).await; + //// println!("packet sent: {:?}", i); + // i += 1; + // + // // retrieve messages every now and then + // if i % 3 == 0 { + // interval.tick().await; + // println!("going to retrieve messages!"); + // let provider_client = ProviderClient::new(); + // provider_client.retrieve_messages().await.unwrap(); + // } + // } + // }) } fn get_topology() -> Topology { From 19819729a14f365593dcff8256ed3c42643909b4 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 12:23:53 +0000 Subject: [PATCH 080/167] Sending messages via channel to mix traffic controller --- src/clients/mod.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 076ec7d1ae..f57d48ceb8 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -3,6 +3,7 @@ use tokio::runtime::Runtime; use futures::channel::mpsc; use std::time::Duration; use crate::utils; +use futures::{future, Future, Stream, Sink, StreamExt, SinkExt}; pub mod directory; pub mod mix; @@ -23,6 +24,18 @@ const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; // ... ??Client?? sends (TX) to outQueueController (RX) // Loop cover traffic stream just sends messages to mixnet without any channel communication +struct MixTrafficController; + +impl MixTrafficController { + async fn run(rx: mpsc::Receiver>) { + rx.for_each(move |message| { + println!("here i will be sending {:?} to a mixnode!", message); + + future::ready(()) + }).await + } +} + pub struct NymClient { // to be replaced by something else I guess address: DestinationAddressBytes @@ -37,13 +50,15 @@ impl NymClient { } } - async fn start_loop_cover_traffic_stream(&self) -> Result<(), Box> { + async fn start_loop_cover_traffic_stream(&self, mut tx: mpsc::Sender>) -> Result<(), Box> { loop { let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); println!("waiting for {:?}", delay_duration); tokio::time::delay_for(delay_duration).await; println!("waited {:?} - time to send cover message!", delay_duration); + let dummy_message = vec![1,2,3]; + tx.send(dummy_message).await; } } @@ -67,16 +82,17 @@ impl NymClient { async fn start_traffic(&self) -> TripleFutureResult { - futures::future::join3(self.start_loop_cover_traffic_stream(), self.control_out_queue(), self.start_provider_polling()).await + let mix_chan_buf_size = 64; + let (mix_tx, mix_rx) = mpsc::channel(mix_chan_buf_size); + + tokio::spawn(MixTrafficController::run(mix_rx)); + futures::future::join3(self.start_loop_cover_traffic_stream(mix_tx), self.control_out_queue(), self.start_provider_polling()).await } pub fn start(&self) -> Result<(), Box> { println!("starting nym client"); let mut rt = Runtime::new()?; -// let (out_queue_tx, out_queue_rx) = mpsc::unbounded(); - - rt.block_on(async { let future_results = self.start_traffic().await; assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); From 27bf01eb28ba7f7336124f0195b30593eb3de984 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 12:42:18 +0000 Subject: [PATCH 081/167] Input channel created on new --- src/clients/mod.rs | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index f57d48ceb8..cb956ba2b6 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -12,8 +12,10 @@ pub mod validator; // TODO: put that in config once it exists -const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; // assume seconds -const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; +const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; +// assume seconds +const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; +// assume seconds; const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; // provider-poller sends polls service provider; receives messages @@ -38,32 +40,38 @@ impl MixTrafficController { pub struct NymClient { // to be replaced by something else I guess - address: DestinationAddressBytes + address: DestinationAddressBytes, + pub input_tx: mpsc::UnboundedSender>, + // to be used by "send" function or socket, etc + input_rx: mpsc::UnboundedReceiver>, } type TripleFutureResult = (Result<(), Box>, Result<(), Box>, Result<(), Box>); impl NymClient { pub fn new(address: DestinationAddressBytes) -> Self { + let (input_tx, input_rx) = mpsc::unbounded::>(); + NymClient { - address + address, + input_tx, + input_rx, } } - async fn start_loop_cover_traffic_stream(&self, mut tx: mpsc::Sender>) -> Result<(), Box> { + async fn start_loop_cover_traffic_stream(mut tx: mpsc::Sender>) -> Result<(), Box> { loop { let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); println!("waiting for {:?}", delay_duration); tokio::time::delay_for(delay_duration).await; println!("waited {:?} - time to send cover message!", delay_duration); - let dummy_message = vec![1,2,3]; - tx.send(dummy_message).await; + let dummy_message = vec![1, 2, 3]; + tx.send(dummy_message).await?; } - } - async fn control_out_queue(&self) -> Result<(), Box> { + async fn control_out_queue(mut mix_tx: mpsc::Sender>, mut input_rx: mpsc::UnboundedReceiver>) -> Result<(), Box> { loop { println!("here I will be sending real traffic (or loop cover if nothing is available)"); let delay_duration = Duration::from_secs_f64(10.0); @@ -72,7 +80,7 @@ impl NymClient { } - async fn start_provider_polling(&self) -> Result<(), Box> { + async fn start_provider_polling() -> Result<(), Box> { loop { println!("here I will be polling provider for messages"); let delay_duration = Duration::from_secs_f64(10.0); @@ -81,20 +89,21 @@ impl NymClient { } - async fn start_traffic(&self) -> TripleFutureResult { + pub fn start(self) -> Result<(), Box> { + println!("starting nym client"); + let mix_chan_buf_size = 64; let (mix_tx, mix_rx) = mpsc::channel(mix_chan_buf_size); - tokio::spawn(MixTrafficController::run(mix_rx)); - futures::future::join3(self.start_loop_cover_traffic_stream(mix_tx), self.control_out_queue(), self.start_provider_polling()).await - } - - pub fn start(&self) -> Result<(), Box> { - println!("starting nym client"); let mut rt = Runtime::new()?; + rt.spawn(MixTrafficController::run(mix_rx)); + rt.block_on(async { - let future_results = self.start_traffic().await; + let future_results = futures::future::join3( + NymClient::start_loop_cover_traffic_stream(mix_tx.clone()), + NymClient::control_out_queue(mix_tx, self.input_rx), + NymClient::start_provider_polling()).await; assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); }); From b0d31a88d54459fb363f5512f17be2ceceec66e1 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Fri, 13 Dec 2019 12:44:46 +0000 Subject: [PATCH 082/167] cargo: set up as a lib --- Cargo.toml | 4 ++++ src/lib.rs | 1 + 2 files changed, 5 insertions(+) create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index b745efc446..42a07e2328 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,10 @@ version = "0.1.0" authors = ["Dave Hrycyszyn "] edition = "2018" +[lib] +name = "nym_client" +path = "src/lib.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000..705f46dba5 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod clients; From f8c6f4633c18b792d5222bdb11d7e0de503c5558 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Fri, 13 Dec 2019 12:47:19 +0000 Subject: [PATCH 083/167] Passing models by reference to keep borrow checker happy --- src/clients/directory/requests/metrics_mixes_post.rs | 8 ++++---- src/clients/directory/requests/presence_coconodes_post.rs | 8 ++++---- src/clients/directory/requests/presence_mixnodes_post.rs | 8 ++++---- src/clients/directory/requests/presence_providers_post.rs | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/clients/directory/requests/metrics_mixes_post.rs b/src/clients/directory/requests/metrics_mixes_post.rs index 4414e8e195..b7d412af81 100644 --- a/src/clients/directory/requests/metrics_mixes_post.rs +++ b/src/clients/directory/requests/metrics_mixes_post.rs @@ -8,7 +8,7 @@ pub struct Request { pub trait MetricsMixPoster { fn new(base_url: String) -> Self; - fn post(&self, metric: MixMetric) -> Result; + fn post(&self, metric: &MixMetric) -> Result; } impl MetricsMixPoster for Request { @@ -19,7 +19,7 @@ impl MetricsMixPoster for Request { } } - fn post(&self, metric: MixMetric) -> Result { + fn post(&self, metric: &MixMetric) -> Result { let url = format!("{}{}", self.base_url, self.path); let client = reqwest::Client::new(); let mix_metric_vec = client.post(&url).json(&metric).send()?; @@ -43,7 +43,7 @@ mod metrics_get_request { let _m = mock("POST", "/api/metrics/mixes").with_status(400).create(); let req = Request::new(mockito::server_url()); let metric = fixtures::new_metric(); - let result = req.post(metric); + let result = req.post(&metric); assert_eq!(400, result.unwrap().status()); _m.assert(); } @@ -61,7 +61,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let metric = fixtures::new_metric(); - let result = req.post(metric); + let result = req.post(&metric); assert_eq!(true, result.is_ok()); _m.assert(); } diff --git a/src/clients/directory/requests/presence_coconodes_post.rs b/src/clients/directory/requests/presence_coconodes_post.rs index c1e30b145e..bc5f3aaf42 100644 --- a/src/clients/directory/requests/presence_coconodes_post.rs +++ b/src/clients/directory/requests/presence_coconodes_post.rs @@ -8,7 +8,7 @@ pub struct Request { pub trait PresenceCocoNodesPoster { fn new(base_url: String) -> Self; - fn post(&self, presence: CocoPresence) -> Result; + fn post(&self, presence: &CocoPresence) -> Result; } impl PresenceCocoNodesPoster for Request { @@ -19,7 +19,7 @@ impl PresenceCocoNodesPoster for Request { } } - fn post(&self, presence: CocoPresence) -> Result { + fn post(&self, presence: &CocoPresence) -> Result { let url = format!("{}{}", self.base_url, self.path); let client = reqwest::Client::new(); let p = client.post(&url).json(&presence).send()?; @@ -45,7 +45,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(400, result.unwrap().status()); _m.assert(); } @@ -65,7 +65,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(true, result.is_ok()); _m.assert(); } diff --git a/src/clients/directory/requests/presence_mixnodes_post.rs b/src/clients/directory/requests/presence_mixnodes_post.rs index 4bb0686ba3..8781b9a3dc 100644 --- a/src/clients/directory/requests/presence_mixnodes_post.rs +++ b/src/clients/directory/requests/presence_mixnodes_post.rs @@ -8,7 +8,7 @@ pub struct Request { pub trait PresenceMixNodesPoster { fn new(base_url: String) -> Self; - fn post(&self, presence: MixNodePresence) -> Result; + fn post(&self, presence: &MixNodePresence) -> Result; } impl PresenceMixNodesPoster for Request { @@ -19,7 +19,7 @@ impl PresenceMixNodesPoster for Request { } } - fn post(&self, presence: MixNodePresence) -> Result { + fn post(&self, presence: &MixNodePresence) -> Result { let url = format!("{}{}", self.base_url, self.path); let client = reqwest::Client::new(); let p = client.post(&url).json(&presence).send()?; @@ -45,7 +45,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(400, result.unwrap().status()); _m.assert(); } @@ -65,7 +65,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(true, result.is_ok()); _m.assert(); } diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index 8819926802..c79dbd3a68 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -8,7 +8,7 @@ pub struct Request { pub trait PresenceMixProviderPoster { fn new(base_url: String) -> Self; - fn post(&self, presence: MixProviderPresence) -> Result; + fn post(&self, presence: &MixProviderPresence) -> Result; } impl PresenceMixProviderPoster for Request { @@ -19,7 +19,7 @@ impl PresenceMixProviderPoster for Request { } } - fn post(&self, presence: MixProviderPresence) -> Result { + fn post(&self, presence: &MixProviderPresence) -> Result { let url = format!("{}{}", self.base_url, self.path); let client = reqwest::Client::new(); let p = client.post(&url).json(&presence).send()?; @@ -45,7 +45,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(400, result.unwrap().status()); _m.assert(); } @@ -65,7 +65,7 @@ mod metrics_get_request { .create(); let req = Request::new(mockito::server_url()); let presence = fixtures::new_presence(); - let result = req.post(presence); + let result = req.post(&presence); assert_eq!(true, result.is_ok()); _m.assert(); } From 7dcc81eab48e7a54ff1325ac7aaf561577023f39 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 13:12:03 +0000 Subject: [PATCH 084/167] Creating dummy sphinx loop message --- src/utils/mod.rs | 1 + src/utils/sphinx.rs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/utils/sphinx.rs diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 2e504a1581..d213166bdc 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod bytes; pub mod poisson; +pub mod sphinx; diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs new file mode 100644 index 0000000000..6b0fc2e505 --- /dev/null +++ b/src/utils/sphinx.rs @@ -0,0 +1,33 @@ +use crate::utils::bytes; +use sphinx::route::{Destination, DestinationAddressBytes, Node, SURBIdentifier}; + +const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; + +pub fn loop_cover_message( + our_address: DestinationAddressBytes, + surb_id: SURBIdentifier, +) -> Vec { + let dummy_route = vec![ + Node::new( + bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec()), + Default::default(), + ), + Node::new( + bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()), + Default::default(), + ), + ]; + + let destination = Destination::new(our_address, surb_id); + let delays = sphinx::header::delays::generate(dummy_route.len()); + + // build the packet + let packet = sphinx::SphinxPacket::new( + LOOP_COVER_MESSAGE_PAYLOAD.to_vec(), + &dummy_route[..], + &destination, + &delays, + ) + .unwrap(); + packet.to_bytes() +} From dfece9bda5b485b48ed6aa0ee9736251096b69c8 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Dec 2019 16:03:19 +0000 Subject: [PATCH 085/167] Working loop cover traffic --- src/clients/mix.rs | 5 +++-- src/clients/mod.rs | 46 ++++++++++++++++++++++++++++++--------------- src/utils/sphinx.rs | 14 +++++++------- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/clients/mix.rs b/src/clients/mix.rs index b5f03a130f..43e7f1199d 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -2,6 +2,7 @@ use crate::clients::directory::Client; use sphinx::route::Node as MixNode; use sphinx::SphinxPacket; use tokio::prelude::*; +use std::net::SocketAddr; pub struct MixClient {} @@ -14,11 +15,11 @@ impl MixClient { pub async fn send( &self, packet: SphinxPacket, - mix: &MixNode, + mix_addr: SocketAddr, ) -> Result<(), Box> { let bytes = packet.to_bytes(); - let mut stream = tokio::net::TcpStream::connect("127.0.0.1:8080").await?; + let mut stream = tokio::net::TcpStream::connect(mix_addr).await?; stream.write_all(&bytes[..]).await?; Ok(()) } diff --git a/src/clients/mod.rs b/src/clients/mod.rs index cb956ba2b6..0bc5d39f8d 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,9 +1,11 @@ -use sphinx::route::DestinationAddressBytes; +use sphinx::route::{DestinationAddressBytes, NodeAddressBytes, Destination}; use tokio::runtime::Runtime; use futures::channel::mpsc; use std::time::Duration; use crate::utils; -use futures::{future, Future, Stream, Sink, StreamExt, SinkExt}; +use futures::{future, StreamExt, SinkExt}; +use crate::clients::mix::MixClient; +use sphinx::SphinxPacket; pub mod directory; pub mod mix; @@ -18,6 +20,7 @@ const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; + // provider-poller sends polls service provider; receives messages // provider-poller sends (TX) to ReceivedBufferController (RX) // ReceivedBufferController sends (TX) to ... ??Client?? @@ -26,15 +29,28 @@ const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; // ... ??Client?? sends (TX) to outQueueController (RX) // Loop cover traffic stream just sends messages to mixnet without any channel communication +struct MixMessage(NodeAddressBytes, SphinxPacket); + struct MixTrafficController; -impl MixTrafficController { - async fn run(rx: mpsc::Receiver>) { - rx.for_each(move |message| { - println!("here i will be sending {:?} to a mixnode!", message); - future::ready(()) - }).await + +impl MixTrafficController { + // this was way more difficult to implement than what this code may suggest... + async fn run(mut rx: mpsc::UnboundedReceiver) { + let mix_client = MixClient::new(); + while let Some(mix_message) = rx.next().await { + println!("got a mix_message for {:?}", mix_message.0); + + println!("here i will be sending sphinx packet to a mixnode ({:?}!", mix_message.0); + // here NodeAddressBytes would be transformed into a SocketAddr with SOME library call... + let node_net_address = "127.0.0.1:8080"; + let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; + match send_res { + Ok(_) => println!("We successfully sent the message!"), + Err(e) => eprintln!("We failed to send the message :( - {:?}", e), + }; + } } } @@ -59,19 +75,19 @@ impl NymClient { } } - async fn start_loop_cover_traffic_stream(mut tx: mpsc::Sender>) -> Result<(), Box> { + async fn start_loop_cover_traffic_stream(mut tx: mpsc::UnboundedSender, our_info: Destination) -> Result<(), Box> { loop { let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); println!("waiting for {:?}", delay_duration); tokio::time::delay_for(delay_duration).await; + let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); println!("waited {:?} - time to send cover message!", delay_duration); - let dummy_message = vec![1, 2, 3]; - tx.send(dummy_message).await?; + tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } } - async fn control_out_queue(mut mix_tx: mpsc::Sender>, mut input_rx: mpsc::UnboundedReceiver>) -> Result<(), Box> { + async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver>) -> Result<(), Box> { loop { println!("here I will be sending real traffic (or loop cover if nothing is available)"); let delay_duration = Duration::from_secs_f64(10.0); @@ -92,8 +108,8 @@ impl NymClient { pub fn start(self) -> Result<(), Box> { println!("starting nym client"); - let mix_chan_buf_size = 64; - let (mix_tx, mix_rx) = mpsc::channel(mix_chan_buf_size); + let (mix_tx, mix_rx) = mpsc::unbounded(); + let our_info = Destination::new(self.address, Default::default()); let mut rt = Runtime::new()?; @@ -101,7 +117,7 @@ impl NymClient { rt.block_on(async { let future_results = futures::future::join3( - NymClient::start_loop_cover_traffic_stream(mix_tx.clone()), + NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), our_info), NymClient::control_out_queue(mix_tx, self.input_rx), NymClient::start_provider_polling()).await; assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 6b0fc2e505..eafd399fa2 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -1,17 +1,16 @@ use crate::utils::bytes; -use sphinx::route::{Destination, DestinationAddressBytes, Node, SURBIdentifier}; +use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; +use sphinx::SphinxPacket; const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; pub fn loop_cover_message( our_address: DestinationAddressBytes, surb_id: SURBIdentifier, -) -> Vec { +) -> (NodeAddressBytes, SphinxPacket) { + let first_node_address = bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec()); let dummy_route = vec![ - Node::new( - bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec()), - Default::default(), - ), + Node::new(first_node_address, Default::default()), Node::new( bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()), Default::default(), @@ -29,5 +28,6 @@ pub fn loop_cover_message( &delays, ) .unwrap(); - packet.to_bytes() + + (first_node_address, packet) } From 2a7fdeeccb7aa16bda5f97c7a47e48229e6c0465 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 15:37:07 +0000 Subject: [PATCH 086/167] presence: fixed incorrect URL for provider presence --- src/clients/directory/requests/presence_providers_post.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index c79dbd3a68..5a41fac824 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -15,7 +15,7 @@ impl PresenceMixProviderPoster for Request { fn new(base_url: String) -> Self { Request { base_url, - path: "/api/presence/providers".to_string(), + path: "/api/presence/mixproviders".to_string(), } } From fdd8cc85c7aed333936f116df5a757752c7a3b10 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 15:37:40 +0000 Subject: [PATCH 087/167] presence: added registered_clients to the provider model --- src/clients/directory/presence.rs | 7 +++++++ src/clients/directory/requests/presence_providers_post.rs | 1 + 2 files changed, 8 insertions(+) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 9fab6c1bd5..62968eae19 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -22,6 +22,13 @@ pub struct MixNodePresence { pub struct MixProviderPresence { pub host: String, pub pub_key: String, + pub registered_clients: Vec, +} + +#[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct MixProviderClient { + pub pub_key: String, } // Topology shows us the current state of the overall Nym network diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index 5a41fac824..dfe89f0c17 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -78,6 +78,7 @@ mod metrics_get_request { MixProviderPresence { host: "foo.com".to_string(), pub_key: "abc".to_string(), + registered_clients: vec![], } } } From 522c3d869cd646973ea9ad4c114c2572aac05139 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 16:16:56 +0000 Subject: [PATCH 088/167] cargo: adding ws crate to enable websockets --- Cargo.lock | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d4d5176172..ec7632c9b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -739,6 +739,11 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.66" @@ -834,6 +839,17 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "mio-extras" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio-named-pipes" version = "0.1.6" @@ -944,6 +960,7 @@ dependencies = [ "sfw-provider-requests 0.1.0", "sphinx 0.1.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ws 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1410,6 +1427,17 @@ dependencies = [ "sphinx 0.1.0", ] +[[package]] +name = "sha-1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.0" @@ -1875,6 +1903,23 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ws" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -1973,6 +2018,7 @@ dependencies = [ "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum lioness 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ae926706ba42c425c9457121178330d75e273df2e82e28b758faf3de3a9acb9" "checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" @@ -1985,6 +2031,7 @@ dependencies = [ "checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" "checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" "checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" @@ -2044,6 +2091,7 @@ dependencies = [ "checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" +"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum signal-hook-registry 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" @@ -2096,4 +2144,5 @@ dependencies = [ "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" +"checksum ws 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a2c47b5798ccc774ffb93ff536aec7c4275d722fd9c740c83cdd1af1f2d94" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index 42a07e2328..13776b879a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ reqwest = "0.9.22" serde = { version = "1.0", features = ["derive"] } sphinx = { path = "../sphinx" } sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } - tokio = { version = "0.2", features = ["full"] } +ws = "0.9.1" [dev-dependencies] mockito = "0.22.0" From 066e0fa67b71849f6ea82fd1608816b8f9dd3ae8 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 16:57:11 +0000 Subject: [PATCH 089/167] sockets: setting up websockets feature. --- src/commands/mod.rs | 3 ++- src/commands/socket.rs | 21 --------------------- src/commands/tcpsocket.rs | 10 ++++++++++ src/commands/websocket.rs | 23 +++++++++++++++++++++++ src/sockets/mod.rs | 1 + src/sockets/tcp.rs | 0 src/sockets/ws.rs | 30 ++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 22 deletions(-) delete mode 100644 src/commands/socket.rs create mode 100644 src/commands/tcpsocket.rs create mode 100644 src/commands/websocket.rs create mode 100644 src/sockets/mod.rs create mode 100644 src/sockets/tcp.rs create mode 100644 src/sockets/ws.rs diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 3336430356..83edeba8a9 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,4 @@ pub mod init; pub mod run; -pub mod socket; \ No newline at end of file +pub mod tcpsocket; +pub mod websocket; diff --git a/src/commands/socket.rs b/src/commands/socket.rs deleted file mode 100644 index 09cc09a557..0000000000 --- a/src/commands/socket.rs +++ /dev/null @@ -1,21 +0,0 @@ -use clap::ArgMatches; - -pub fn execute(matches: &ArgMatches) { - let custom_cfg = matches.value_of("customCfg"); - let socket_type = match matches.value_of("socketType").unwrap() { - TCP_SOCKET_TYPE => TCP_SOCKET_TYPE, - WEBSOCKET_SOCKET_TYPE => WEBSOCKET_SOCKET_TYPE, - other => panic!("Invalid socket type provided - {}", other), - }; - let port = match matches.value_of("port").unwrap().parse::() { - Ok(n) => n, - Err(err) => panic!("Invalid port value provided - {:?}", err), - }; - - println!( - "Going to start socket client with custom config of: {:?}", - custom_cfg - ); - println!("Using the following socket type: {:?}", socket_type); - println!("On the following port: {:?}", port); -} diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs new file mode 100644 index 0000000000..79adfb29e6 --- /dev/null +++ b/src/commands/tcpsocket.rs @@ -0,0 +1,10 @@ +use clap::ArgMatches; + +pub fn execute(matches: &ArgMatches) { + let port = match matches.value_of("port").unwrap().parse::() { + Ok(n) => n, + Err(err) => panic!("Invalid port value provided - {:?}", err), + }; + + println!("On the following port: {:?}", port); +} diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs new file mode 100644 index 0000000000..7d9889019c --- /dev/null +++ b/src/commands/websocket.rs @@ -0,0 +1,23 @@ +use crate::banner; +use crate::sockets::ws; +use clap::ArgMatches; +use std::net::ToSocketAddrs; + +pub fn execute(matches: &ArgMatches) { + let port = match matches.value_of("port").unwrap().parse::() { + Ok(n) => n, + Err(err) => panic!("Invalid port value provided - {:?}", err), + }; + + println!("{}", banner()); + println!("Starting websocket on port: {:?}", port); + println!("Listening for messages..."); + + let socket_address = ("127.0.0.1", port) + .to_socket_addrs() + .expect("Failed to combine host and port") + .next() + .expect("Failed to extract the socket address from the iterator"); + + ws::start(socket_address); +} diff --git a/src/sockets/mod.rs b/src/sockets/mod.rs new file mode 100644 index 0000000000..6757c99679 --- /dev/null +++ b/src/sockets/mod.rs @@ -0,0 +1 @@ +pub mod ws; diff --git a/src/sockets/tcp.rs b/src/sockets/tcp.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs new file mode 100644 index 0000000000..ee99ced4b6 --- /dev/null +++ b/src/sockets/ws.rs @@ -0,0 +1,30 @@ +use std::net::SocketAddr; +use ws::{listen, CloseCode, Handler, Message, Result, Sender}; + +struct Server { + out: Sender, +} + +impl Handler for Server { + fn on_message(&mut self, msg: Message) -> Result<()> { + foomp(); + // Echo the message back + self.out.send(msg) + } + + fn on_close(&mut self, code: CloseCode, reason: &str) { + match code { + CloseCode::Normal => println!("The client is done with the connection."), + CloseCode::Away => println!("The client is leaving the site."), + _ => println!("The client encountered an error: {}", reason), + } + } +} + +pub fn start(socket_address: SocketAddr) { + listen(socket_address, |out| Server { out: out }).unwrap() +} + +fn foomp() { + println!("FOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMMMMPPPPPPPPPPPPPPPPP"); +} From 3d812a36d6e329831d3f738ca3fcbd161638b47e Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 16:57:32 +0000 Subject: [PATCH 090/167] main: changing structure of socket args, removing unused args --- src/main.rs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index cf053edfac..996efb014b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod clients; mod commands; mod identity; mod persistence; +mod sockets; mod utils; fn main() { @@ -44,23 +45,20 @@ fn main() { ) ) .subcommand( - SubCommand::with_name("socket") - .about("Run a background Nym client listening on a specified socket") + SubCommand::with_name("tcpsocket") + .about("Run Nym client that listens for bytes on a TCP socket") .arg( - Arg::with_name("customCfg") - .short("cfg") - .long("customCfg") - .help("Path to custom configuration file of the client") + Arg::with_name("port") + .short("p") + .long("port") + .help("Port to listen on") .takes_value(true) + .required(true), ) - .arg( - Arg::with_name("socketType") - .short("s") - .long("socketType") - .help("Type of the socket we want to run on (tcp / websocket)") - .takes_value(true) - .required(true) - ) + ) + .subcommand( + SubCommand::with_name("websocket") + .about("Run Nym client that listens on a websocket") .arg( Arg::with_name("port") .short("p") @@ -82,8 +80,8 @@ fn execute(matches: ArgMatches) -> Result<(), String> { match matches.subcommand() { ("init", Some(m)) => Ok(commands::init::execute(m)), ("run", Some(m)) => Ok(commands::run::execute(m)), - ("socket", Some(m)) => Ok(commands::socket::execute(m)), - + ("tcpsocket", Some(m)) => Ok(commands::tcpsocket::execute(m)), + ("websocket", Some(m)) => Ok(commands::websocket::execute(m)), _ => Err(usage()), } } From 00e0a61237a807b7c2021967bd8ab0385e35fc76 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 16:57:59 +0000 Subject: [PATCH 091/167] mix client: commenting unused code --- src/clients/mix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clients/mix.rs b/src/clients/mix.rs index b5f03a130f..84ea3df07c 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -26,8 +26,8 @@ impl MixClient { #[cfg(test)] mod sending_a_sphinx_packet { - use super::*; - use sphinx::SphinxPacket; + // use super::*; + // use sphinx::SphinxPacket; #[test] fn works() { From 13d14cff955af89f6aeade4be7a4d8b7ff0a5766 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 16:58:31 +0000 Subject: [PATCH 092/167] presence provider: fixing tests --- src/clients/directory/requests/presence_providers_post.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index dfe89f0c17..26cbf7576e 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -40,7 +40,7 @@ mod metrics_get_request { #[test] fn it_returns_an_error() { - let _m = mock("POST", "/api/presence/providers") + let _m = mock("POST", "/api/presence/mixproviders") .with_status(400) .create(); let req = Request::new(mockito::server_url()); @@ -59,7 +59,7 @@ mod metrics_get_request { let json = r#"{ "ok": true }"#; - let _m = mock("POST", "/api/presence/providers") + let _m = mock("POST", "/api/presence/mixproviders") .with_status(201) .with_body(json) .create(); From 631827f5eb2aed055d598cffd99468c56fa2d6be Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Sat, 14 Dec 2019 17:09:00 +0000 Subject: [PATCH 093/167] websocket: demonstrating send message in Rust code. --- src/sockets/ws.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index ee99ced4b6..f4a08b4ceb 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -7,7 +7,7 @@ struct Server { impl Handler for Server { fn on_message(&mut self, msg: Message) -> Result<()> { - foomp(); + foomp(msg.clone()); // Echo the message back self.out.send(msg) } @@ -16,7 +16,9 @@ impl Handler for Server { match code { CloseCode::Normal => println!("The client is done with the connection."), CloseCode::Away => println!("The client is leaving the site."), - _ => println!("The client encountered an error: {}", reason), + _ => { + println!("The client encountered an error: {}", reason); + } } } } @@ -25,6 +27,8 @@ pub fn start(socket_address: SocketAddr) { listen(socket_address, |out| Server { out: out }).unwrap() } -fn foomp() { - println!("FOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMMMMPPPPPPPPPPPPPPPPP"); +// Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts +// the `send_message` functionality. +fn foomp(msg: Message) { + println!("Foomp!: {:?}", msg); } From c3eedb709a573253d5f35b47b48c54cdb886a1d2 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 10:55:57 +0000 Subject: [PATCH 094/167] Fixing URL for provdiders client --- src/clients/directory/requests/presence_providers_post.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/clients/directory/requests/presence_providers_post.rs b/src/clients/directory/requests/presence_providers_post.rs index dfe89f0c17..26cbf7576e 100644 --- a/src/clients/directory/requests/presence_providers_post.rs +++ b/src/clients/directory/requests/presence_providers_post.rs @@ -40,7 +40,7 @@ mod metrics_get_request { #[test] fn it_returns_an_error() { - let _m = mock("POST", "/api/presence/providers") + let _m = mock("POST", "/api/presence/mixproviders") .with_status(400) .create(); let req = Request::new(mockito::server_url()); @@ -59,7 +59,7 @@ mod metrics_get_request { let json = r#"{ "ok": true }"#; - let _m = mock("POST", "/api/presence/providers") + let _m = mock("POST", "/api/presence/mixproviders") .with_status(201) .with_body(json) .create(); From a472c23b48819271f50d568e01a7dea50259a054 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 16 Dec 2019 10:59:11 +0000 Subject: [PATCH 095/167] Managed to combine cover traffic stream with out queue --- src/clients/mod.rs | 93 ++++++++++++++++++++++++++++++++++----------- src/utils/sphinx.rs | 19 +++++---- 2 files changed, 81 insertions(+), 31 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 0bc5d39f8d..fe93c65260 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -3,9 +3,14 @@ use tokio::runtime::Runtime; use futures::channel::mpsc; use std::time::Duration; use crate::utils; -use futures::{future, StreamExt, SinkExt}; +use futures::{StreamExt, SinkExt, Stream, TryStreamExt}; use crate::clients::mix::MixClient; use sphinx::SphinxPacket; +use futures::Future; +use futures::future; +use futures::task::{Context, Poll}; +use std::pin::Pin; +use futures::select; pub mod directory; pub mod mix; @@ -34,22 +39,19 @@ struct MixMessage(NodeAddressBytes, SphinxPacket); struct MixTrafficController; - impl MixTrafficController { // this was way more difficult to implement than what this code may suggest... async fn run(mut rx: mpsc::UnboundedReceiver) { let mix_client = MixClient::new(); while let Some(mix_message) = rx.next().await { - println!("got a mix_message for {:?}", mix_message.0); - - println!("here i will be sending sphinx packet to a mixnode ({:?}!", mix_message.0); + println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0); // here NodeAddressBytes would be transformed into a SocketAddr with SOME library call... let node_net_address = "127.0.0.1:8080"; - let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; - match send_res { - Ok(_) => println!("We successfully sent the message!"), - Err(e) => eprintln!("We failed to send the message :( - {:?}", e), - }; +// let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; +// match send_res { +// Ok(_) => println!("We successfully sent the message!"), +// Err(e) => eprintln!("We failed to send the message :( - {:?}", e), +// }; } } } @@ -57,16 +59,38 @@ impl MixTrafficController { pub struct NymClient { // to be replaced by something else I guess address: DestinationAddressBytes, - pub input_tx: mpsc::UnboundedSender>, + pub input_tx: mpsc::UnboundedSender, // to be used by "send" function or socket, etc - input_rx: mpsc::UnboundedReceiver>, + input_rx: mpsc::UnboundedReceiver, } type TripleFutureResult = (Result<(), Box>, Result<(), Box>, Result<(), Box>); +//struct OutQueueFuture { +// +//} +// +//impl OutQueueFuture { +// fn poll_data(&mut self, cx: &mut Context) -> Poll<()> { +// use Poll::*; +// +// } +//} +// +//impl Future for OutQueueFuture { +// type Output = (); +// +// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { +// unimplemented!() +// } +//} + +#[derive(Debug)] +pub struct InputMessage(Destination, Vec); + impl NymClient { pub fn new(address: DestinationAddressBytes) -> Self { - let (input_tx, input_rx) = mpsc::unbounded::>(); + let (input_tx, input_rx) = mpsc::unbounded::(); NymClient { address, @@ -77,20 +101,35 @@ impl NymClient { async fn start_loop_cover_traffic_stream(mut tx: mpsc::UnboundedSender, our_info: Destination) -> Result<(), Box> { loop { + println!("[LOOP COVER TRAFFIC STREAM] - next cover message!"); let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); - println!("waiting for {:?}", delay_duration); tokio::time::delay_for(delay_duration).await; let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); - println!("waited {:?} - time to send cover message!", delay_duration); tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } } - async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver>) -> Result<(), Box> { + async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver, our_info: Destination) -> Result<(), Box> { loop { - println!("here I will be sending real traffic (or loop cover if nothing is available)"); - let delay_duration = Duration::from_secs_f64(10.0); + println!("[OUT QUEUE] here I will be sending real traffic (or loop cover if nothing is available)"); + select! { + real_message = input_rx.next() => { + println!("[OUT QUEUE] - we got a real message!"); + let real_message = real_message.expect("The channel must have closed! - if the client hasn't crashed, it should have!"); + println!("real: {:?}", real_message); + let encapsulated_message = utils::sphinx::encapsulate_message(real_message.0, real_message.1); + mix_tx.send(MixMessage(encapsulated_message.0, encapsulated_message.1)).await?; + }, + + default => { + println!("[OUT QUEUE] - no real message - going to send extra loop cover"); + let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); + mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?; + } + }; + + let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; } } @@ -98,7 +137,7 @@ impl NymClient { async fn start_provider_polling() -> Result<(), Box> { loop { - println!("here I will be polling provider for messages"); +// println!("here I will be polling provider for messages"); let delay_duration = Duration::from_secs_f64(10.0); tokio::time::delay_for(delay_duration).await; } @@ -109,16 +148,24 @@ impl NymClient { println!("starting nym client"); let (mix_tx, mix_rx) = mpsc::unbounded(); - let our_info = Destination::new(self.address, Default::default()); let mut rt = Runtime::new()?; - rt.spawn(MixTrafficController::run(mix_rx)); + let tmp_dest = Destination::new(self.address, Default::default()); + let mut foo_tx = self.input_tx.clone(); +// just to send something after a delay to the input channel + rt.spawn(async move { + tokio::time::delay_for(Duration::from_secs(8)).await; + let tmp_message = vec![5, 23, 62, 6, 236]; + println!("SENDING TMP MESSAGE!"); + foo_tx.send(InputMessage(tmp_dest, tmp_message)).await.unwrap(); + }); + rt.block_on(async { let future_results = futures::future::join3( - NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), our_info), - NymClient::control_out_queue(mix_tx, self.input_rx), + NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default())), + NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default())), NymClient::start_provider_polling()).await; assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); }); diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index eafd399fa2..48165259e0 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -8,6 +8,16 @@ pub fn loop_cover_message( our_address: DestinationAddressBytes, surb_id: SURBIdentifier, ) -> (NodeAddressBytes, SphinxPacket) { + let destination = Destination::new(our_address, surb_id); + + encapsulate_message(destination, LOOP_COVER_MESSAGE_PAYLOAD.to_vec()) +} + +pub fn encapsulate_message( + recipient: Destination, + message: Vec, +) -> (NodeAddressBytes, SphinxPacket) { + // here we would be getting topology, etc let first_node_address = bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec()); let dummy_route = vec![ Node::new(first_node_address, Default::default()), @@ -17,17 +27,10 @@ pub fn loop_cover_message( ), ]; - let destination = Destination::new(our_address, surb_id); let delays = sphinx::header::delays::generate(dummy_route.len()); // build the packet - let packet = sphinx::SphinxPacket::new( - LOOP_COVER_MESSAGE_PAYLOAD.to_vec(), - &dummy_route[..], - &destination, - &delays, - ) - .unwrap(); + let packet = sphinx::SphinxPacket::new(message, &dummy_route[..], &recipient, &delays).unwrap(); (first_node_address, packet) } From b32e1575a38a80ee5499c7c6b6e970891287a755 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 11:41:00 +0000 Subject: [PATCH 096/167] main: removed unused customcfg option --- src/main.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index cf053edfac..e9a2a27091 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,21 +26,14 @@ fn main() { .help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen.") .takes_value(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(true) - ) ) .subcommand( SubCommand::with_name("run") .about("Run a persistent Nym client process") - .arg( - Arg::with_name("customCfg") - .short("cfg") - .long("customCfg") - .help("Path to custom configuration file of the client") - .takes_value(true) + .arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(false) ) ) .subcommand( From d9a603aa1f394aa5ce34afd9ef580d6cad60508e Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 11:41:18 +0000 Subject: [PATCH 097/167] run command: added the ability to start with a local directory server --- src/commands/run.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 9a72186984..c6567fe037 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -15,11 +15,11 @@ use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; pub fn execute(matches: &ArgMatches) { - let custom_cfg = matches.value_of("customCfg"); - println!("Starting client with config: {:?}", custom_cfg); + let is_local = matches.is_present("local"); + println!("Starting client, local: {:?}", is_local); // Grab the network topology from the remote directory server - let topology = get_topology(); + let topology = get_topology(is_local); // Create the runtime, probably later move it to Client struct itself? let mut rt = Runtime::new().unwrap(); @@ -61,10 +61,14 @@ pub fn execute(matches: &ArgMatches) { }) } -fn get_topology() -> Topology { - let directory_config = directory::Config { - base_url: "https://directory.nymtech.net".to_string(), +fn get_topology(is_local: bool) -> Topology { + let url = if is_local { + "http://localhost:8080".to_string() + } else { + "https://directory.nymtech.net".to_string() }; + println!("Using directory server: {:?}", url); + let directory_config = directory::Config { base_url: url }; let directory = directory::Client::new(directory_config); let topology = directory From f5f2ecb65e0c323a2d9f7259604a56ffabe44571 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 16 Dec 2019 11:43:15 +0000 Subject: [PATCH 098/167] Some cleanup + sample message sending --- src/clients/mod.rs | 62 ++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index fe93c65260..c512a8e11c 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -3,13 +3,9 @@ use tokio::runtime::Runtime; use futures::channel::mpsc; use std::time::Duration; use crate::utils; -use futures::{StreamExt, SinkExt, Stream, TryStreamExt}; +use futures::{StreamExt, SinkExt}; use crate::clients::mix::MixClient; use sphinx::SphinxPacket; -use futures::Future; -use futures::future; -use futures::task::{Context, Poll}; -use std::pin::Pin; use futures::select; pub mod directory; @@ -47,11 +43,11 @@ impl MixTrafficController { println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0); // here NodeAddressBytes would be transformed into a SocketAddr with SOME library call... let node_net_address = "127.0.0.1:8080"; -// let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; -// match send_res { -// Ok(_) => println!("We successfully sent the message!"), -// Err(e) => eprintln!("We failed to send the message :( - {:?}", e), -// }; + let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; + match send_res { + Ok(_) => println!("We successfully sent the message!"), + Err(e) => eprintln!("We failed to send the message :( - {:?}", e), + }; } } } @@ -64,29 +60,9 @@ pub struct NymClient { input_rx: mpsc::UnboundedReceiver, } -type TripleFutureResult = (Result<(), Box>, Result<(), Box>, Result<(), Box>); - -//struct OutQueueFuture { -// -//} -// -//impl OutQueueFuture { -// fn poll_data(&mut self, cx: &mut Context) -> Poll<()> { -// use Poll::*; -// -// } -//} -// -//impl Future for OutQueueFuture { -// type Output = (); -// -// fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { -// unimplemented!() -// } -//} #[derive(Debug)] -pub struct InputMessage(Destination, Vec); +pub struct InputMessage(pub Destination, pub Vec); impl NymClient { pub fn new(address: DestinationAddressBytes) -> Self { @@ -127,7 +103,8 @@ impl NymClient { let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } - }; + } + ; let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; @@ -137,8 +114,8 @@ impl NymClient { async fn start_provider_polling() -> Result<(), Box> { loop { -// println!("here I will be polling provider for messages"); - let delay_duration = Duration::from_secs_f64(10.0); + println!("[FETCH MSG] - Polling provider..."); + let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; } } @@ -152,14 +129,14 @@ impl NymClient { let mut rt = Runtime::new()?; rt.spawn(MixTrafficController::run(mix_rx)); - let tmp_dest = Destination::new(self.address, Default::default()); - let mut foo_tx = self.input_tx.clone(); -// just to send something after a delay to the input channel + let foomp = Destination::new(self.address, Default::default()); + + let mut input_channel = self.input_tx.clone(); rt.spawn(async move { - tokio::time::delay_for(Duration::from_secs(8)).await; - let tmp_message = vec![5, 23, 62, 6, 236]; - println!("SENDING TMP MESSAGE!"); - foo_tx.send(InputMessage(tmp_dest, tmp_message)).await.unwrap(); + let test_message = b"foomp".to_vec(); + let recipient = foomp; + let input_message = InputMessage(recipient, test_message); + input_channel.send(input_message).await.unwrap(); }); rt.block_on(async { @@ -167,6 +144,9 @@ impl NymClient { NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default())), NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default())), NymClient::start_provider_polling()).await; + + // start websocket handler here + assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); }); From 5dacb4d92d07fe2b9b28d1596f2d193f99942bbb Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 14:50:25 +0000 Subject: [PATCH 099/167] lib: re-exporting identity and persistence. --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 705f46dba5..ab56f42ee8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1 +1,3 @@ pub mod clients; +pub mod identity; +pub mod persistence; From 8ac6a84a557c43e7509c0488968426f33d8663a7 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:15:28 +0000 Subject: [PATCH 100/167] mixclient: using constant sized bytes for addressing --- src/clients/mix.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 84ea3df07c..0150bc5c45 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,6 +1,6 @@ -use crate::clients::directory::Client; use sphinx::route::Node as MixNode; use sphinx::SphinxPacket; +use std::net::{Ipv4Addr, SocketAddrV4}; use tokio::prelude::*; pub struct MixClient {} @@ -18,7 +18,12 @@ impl MixClient { ) -> Result<(), Box> { let bytes = packet.to_bytes(); - let mut stream = tokio::net::TcpStream::connect("127.0.0.1:8080").await?; + let b = mix.address; + let host = Ipv4Addr::new(b[0], b[1], b[2], b[3]); + let port: u16 = u16::from_be_bytes([b[4], b[5]]); + let socket_address = SocketAddrV4::new(host, port); + + let mut stream = tokio::net::TcpStream::connect(socket_address).await?; stream.write_all(&bytes[..]).await?; Ok(()) } From 9fe1d236944c3c01f31447f227dc87539f819c33 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:16:02 +0000 Subject: [PATCH 101/167] provider client: fixing warning on unused keepalive check --- src/clients/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index fbf644b58c..b723a9fda0 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -25,7 +25,7 @@ impl ProviderClient { let mut socket = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; println!("keep alive: {:?}", socket.keepalive()); - socket.set_keepalive(Some(tokio::time::Duration::from_secs(2))); + socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); socket.write_all(&bytes[..]).await?; if let Err(e) = socket.shutdown(Shutdown::Write) { eprintln!("failed to close write part of the socket; err = {:?}", e) From ad0f61ec3b466ca5839e9d87cccc8be2177e5d31 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:19:26 +0000 Subject: [PATCH 102/167] rustfmt --- src/clients/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index b723a9fda0..04805142cb 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -17,7 +17,7 @@ impl ProviderClient { pub async fn retrieve_messages( &self, -// provider: &MixNode, + // provider: &MixNode, ) -> Result<(), Box> { let address = [42; 32]; let pull_request = PullRequest::new(address); From 02986bb2a06302bfaf7f19cfe40453097dd511b0 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:19:36 +0000 Subject: [PATCH 103/167] rustfmt --- src/clients/provider.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 04805142cb..e5a283e495 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,11 +1,9 @@ +use sfw_provider_requests::requests::{ProviderRequest, PullRequest}; +use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; use sphinx::route::Node as MixNode; -use sphinx::SphinxPacket; -use tokio::prelude::*; -use sfw_provider_requests::*; use std::net::Shutdown; -use std::time::Duration; -use sfw_provider_requests::requests::{PullRequest, ProviderRequest}; -use sfw_provider_requests::responses::{PullResponse, ProviderResponse}; +use tokio::prelude::*; +use tokio::time::Duration; pub struct ProviderClient {} From a25af016a66ad8696058859896be25a384519fac Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:19:44 +0000 Subject: [PATCH 104/167] rustfmt --- src/clients/provider.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index e5a283e495..42f8e45c8a 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -7,7 +7,6 @@ use tokio::time::Duration; pub struct ProviderClient {} - impl ProviderClient { pub fn new() -> Self { ProviderClient {} From 4a4976d56f36bbcc280869a7c62dff76f680ba78 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:20:16 +0000 Subject: [PATCH 105/167] run: serializing host address to bytes in constant-size format --- src/commands/run.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index c6567fe037..2a0939e0ce 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -82,22 +82,30 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { let mut route = vec![]; let nodes = topology.mix_nodes.iter(); for mix in nodes.take(route_len) { - let address_bytes = bytes::zero_pad_to_32(mix.host.as_bytes().to_vec()); + let address_bytes = socket_bytes_from_string(mix.host.clone()); let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); let key = MontgomeryPoint(key_bytes); - let mut sphinx_node = SphinxNode { + let sphinx_node = SphinxNode { address: address_bytes, pub_key: key, }; - - // temporary to make it work locally: - sphinx_node.pub_key = Default::default(); route.push(sphinx_node); } route } +fn socket_bytes_from_string(address: String) -> [u8; 32] { + let socket: SocketAddrV4 = address.parse().unwrap(); + let host_bytes = socket.ip().octets(); + let port_bytes = socket.port().to_be_bytes(); + let mut address_bytes = [0u8; 32]; + address_bytes.copy_from_slice(&host_bytes); + address_bytes[4] = port_bytes[0]; + address_bytes[5] = port_bytes[1]; + address_bytes +} + // TODO: where do we retrieve this guy from? fn get_destination() -> Destination { Destination { From 4fbe24041949875962d2c3563285e74ceb717a00 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:20:25 +0000 Subject: [PATCH 106/167] rustfmt --- src/commands/run.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 2a0939e0ce..052538ca53 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -46,7 +46,10 @@ pub fn execute(matches: &ArgMatches) { // send to mixnet let mix_client = MixClient::new(); - let result = mix_client.send(packet, route.first().unwrap()).await; + mix_client + .send(packet, route.first().unwrap()) + .await + .unwrap(); println!("packet sent: {:?}", i); i += 1; From b1f4b22e9f8077cd07f81f3c447ad66c1260b401 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:20:41 +0000 Subject: [PATCH 107/167] run: socket address imports --- src/commands/run.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/commands/run.rs b/src/commands/run.rs index 052538ca53..2ebeea8470 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -10,6 +10,7 @@ use clap::ArgMatches; use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::Destination; use sphinx::route::Node as SphinxNode; +use std::net::{Ipv4Addr, SocketAddrV4}; use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; From 82cf0502b8cd626b9b55b978ea7cf578d9297a73 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 16 Dec 2019 16:20:50 +0000 Subject: [PATCH 108/167] rustfmt --- src/identity/mixnet.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/identity/mixnet.rs b/src/identity/mixnet.rs index 83507d7d70..3783dffd97 100644 --- a/src/identity/mixnet.rs +++ b/src/identity/mixnet.rs @@ -17,11 +17,9 @@ impl KeyPair { let mut bytes = [0; 32]; bytes.copy_from_slice(&private_bytes[..]); let private = Scalar::from_canonical_bytes(bytes).unwrap(); - let mut bytes = [0; 32]; bytes.copy_from_slice(&public_bytes[..]); let public = MontgomeryPoint(bytes); - KeyPair { private, public } } From 29106cef6f8b2a6928fe1bea355ae8aa3b728bc1 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 16 Dec 2019 17:47:11 +0000 Subject: [PATCH 109/167] This should have been 10 separate commits --- src/clients/directory/mod.rs | 2 +- src/clients/mix.rs | 1 + src/clients/mod.rs | 6 ++-- src/commands/run.rs | 47 +-------------------------- src/lib.rs | 1 + src/utils/mod.rs | 1 + src/utils/sphinx.rs | 27 +++++++++------- src/utils/topology.rs | 61 ++++++++++++++++++++++++++++++++++++ 8 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 src/utils/topology.rs diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index bc670ac822..a9ff9e4df8 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -20,7 +20,7 @@ use crate::clients::directory::requests::presence_topology_get::{ PresenceTopologyGetRequester, Request as PresenceTopologyRequest, }; -mod metrics; +pub mod metrics; pub mod presence; pub mod requests; diff --git a/src/clients/mix.rs b/src/clients/mix.rs index f8e07c2787..65480bf539 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -23,6 +23,7 @@ impl MixClient { let host = Ipv4Addr::new(b[0], b[1], b[2], b[3]); let port: u16 = u16::from_be_bytes([b[4], b[5]]); let socket_address = SocketAddrV4::new(host, port); + println!("socket addr: {:?}", socket_address); let mut stream = tokio::net::TcpStream::connect(socket_address).await?; stream.write_all(&bytes[..]).await?; diff --git a/src/clients/mod.rs b/src/clients/mod.rs index c512a8e11c..b07ca9a7d7 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -15,7 +15,7 @@ pub mod validator; // TODO: put that in config once it exists -const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; +const LOOP_COVER_AVERAGE_DELAY: f64 = 0.5; // assume seconds const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; @@ -41,9 +41,7 @@ impl MixTrafficController { let mix_client = MixClient::new(); while let Some(mix_message) = rx.next().await { println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0); - // here NodeAddressBytes would be transformed into a SocketAddr with SOME library call... - let node_net_address = "127.0.0.1:8080"; - let send_res = mix_client.send(mix_message.1, node_net_address.parse().unwrap()).await; + let send_res = mix_client.send(mix_message.1, mix_message.0).await; match send_res { Ok(_) => println!("We successfully sent the message!"), Err(e) => eprintln!("We failed to send the message :( - {:?}", e), diff --git a/src/commands/run.rs b/src/commands/run.rs index d9f3d6c973..d0b7ea3596 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -25,7 +25,7 @@ pub fn execute(matches: &ArgMatches) { let client = NymClient::new(my_address); client.start().unwrap(); // Grab the network topology from the remote directory server - let topology = get_topology(is_local); + // let topology = get_topology(is_local); // // Grab the network topology from the remote directory server // let topology = get_topology(); @@ -111,51 +111,6 @@ pub fn execute(matches: &ArgMatches) { // }) } -fn get_topology(is_local: bool) -> Topology { - let url = if is_local { - "http://localhost:8080".to_string() - } else { - "https://directory.nymtech.net".to_string() - }; - println!("Using directory server: {:?}", url); - let directory_config = directory::Config { base_url: url }; - let directory = directory::Client::new(directory_config); - - let topology = directory - .presence_topology - .get() - .expect("Failed to retrieve network topology."); - topology -} - -fn route_from(topology: &Topology, route_len: usize) -> Vec { - let mut route = vec![]; - let nodes = topology.mix_nodes.iter(); - for mix in nodes.take(route_len) { - let address_bytes = socket_bytes_from_string(mix.host.clone()); - let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); - let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); - let key = MontgomeryPoint(key_bytes); - let sphinx_node = SphinxNode { - address: address_bytes, - pub_key: key, - }; - route.push(sphinx_node); - } - route -} - -fn socket_bytes_from_string(address: String) -> [u8; 32] { - let socket: SocketAddrV4 = address.parse().unwrap(); - let host_bytes = socket.ip().octets(); - let port_bytes = socket.port().to_be_bytes(); - let mut address_bytes = [0u8; 32]; - address_bytes.copy_from_slice(&host_bytes); - address_bytes[4] = port_bytes[0]; - address_bytes[5] = port_bytes[1]; - address_bytes -} - // TODO: where do we retrieve this guy from? fn get_destination() -> Destination { Destination { diff --git a/src/lib.rs b/src/lib.rs index ab56f42ee8..0574ba4a4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod clients; pub mod identity; pub mod persistence; +pub mod utils; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index d213166bdc..ee03437270 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ pub mod bytes; pub mod poisson; pub mod sphinx; +pub mod topology; diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 48165259e0..6ce8baa32d 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -1,4 +1,4 @@ -use crate::utils::bytes; +use crate::utils::{bytes, topology}; use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; @@ -18,19 +18,24 @@ pub fn encapsulate_message( message: Vec, ) -> (NodeAddressBytes, SphinxPacket) { // here we would be getting topology, etc - let first_node_address = bytes::zero_pad_to_32("127.0.0.1:8080".as_bytes().to_vec()); - let dummy_route = vec![ - Node::new(first_node_address, Default::default()), - Node::new( - bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()), - Default::default(), - ), - ]; - let delays = sphinx::header::delays::generate(dummy_route.len()); + let topology = topology::get_topology(true); + let mixes_route = topology::route_from(&topology, 1); + + let provider = Node::new( + topology::socket_bytes_from_string("127.0.0.1:8081".to_string()), + // bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()), + Default::default(), + ); + + let route = [mixes_route, vec![provider]].concat(); + + let delays = sphinx::header::delays::generate(route.len()); // build the packet - let packet = sphinx::SphinxPacket::new(message, &dummy_route[..], &recipient, &delays).unwrap(); + let packet = sphinx::SphinxPacket::new(message, &route[..], &recipient, &delays).unwrap(); + + let first_node_address = route.first().unwrap().address; (first_node_address, packet) } diff --git a/src/utils/topology.rs b/src/utils/topology.rs new file mode 100644 index 0000000000..35ee9c2f1f --- /dev/null +++ b/src/utils/topology.rs @@ -0,0 +1,61 @@ +use crate::clients::directory; +use crate::clients::directory::presence::Topology; +use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; +use crate::clients::directory::DirectoryClient; +use crate::clients::mix::MixClient; +use crate::clients::provider::ProviderClient; +use crate::utils::bytes; +use curve25519_dalek::montgomery::MontgomeryPoint; +use sphinx::route::Node as SphinxNode; +use std::net::SocketAddrV4; +use std::string::ToString; + +pub(crate) fn get_topology(is_local: bool) -> Topology { + let url = if is_local { + "http://localhost:8080".to_string() + } else { + "https://directory.nymtech.net".to_string() + }; + println!("Using directory server: {:?}", url); + let directory_config = directory::Config { base_url: url }; + let directory = directory::Client::new(directory_config); + + let topology = directory + .presence_topology + .get() + .expect("Failed to retrieve network topology."); + topology +} + +pub(crate) fn route_from(topology: &Topology, route_len: usize) -> Vec { + let mut route = vec![]; + let nodes = topology.mix_nodes.iter(); + for mix in nodes.take(route_len) { + let address_bytes = socket_bytes_from_string(mix.host.clone()); + let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); + let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); + let key = MontgomeryPoint(key_bytes); + let sphinx_node = SphinxNode { + address: address_bytes, + pub_key: key, + }; + route.push(sphinx_node); + } + route +} + +pub(crate) fn socket_bytes_from_string(address: String) -> [u8; 32] { + let socket: SocketAddrV4 = address.parse().unwrap(); + let host_bytes = socket.ip().octets(); + let port_bytes = socket.port().to_be_bytes(); + let mut address_bytes = [0u8; 32]; + + address_bytes[0] = host_bytes[0]; + address_bytes[1] = host_bytes[1]; + address_bytes[2] = host_bytes[2]; + address_bytes[3] = host_bytes[3]; + + address_bytes[4] = port_bytes[0]; + address_bytes[5] = port_bytes[1]; + address_bytes +} From 2cb4c89c8f15e3987b7f928242fa88a9206a1d79 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:17:00 +0000 Subject: [PATCH 110/167] presence: removing last_seen, it's set by server --- src/clients/directory/presence.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 62968eae19..422d4c096c 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -14,7 +14,6 @@ pub struct MixNodePresence { pub host: String, pub pub_key: String, pub layer: u64, - pub last_seen: i64, } #[derive(Deserialize, Serialize)] From 7fea03b57dd6b96363c8f22b977dcb9e63cad86c Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:17:16 +0000 Subject: [PATCH 111/167] Removing unused import --- src/clients/provider.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 42f8e45c8a..2abeb43cce 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,6 +1,5 @@ use sfw_provider_requests::requests::{ProviderRequest, PullRequest}; use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; -use sphinx::route::Node as MixNode; use std::net::Shutdown; use tokio::prelude::*; use tokio::time::Duration; From 92eccb096a1c9c03aa9f0aa044c22f16c69e48fb Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:18:00 +0000 Subject: [PATCH 112/167] Removing unused imports, commenting weird SocketAddr code --- src/commands/run.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 2ebeea8470..d9ee52a977 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -10,7 +10,7 @@ use clap::ArgMatches; use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::Destination; use sphinx::route::Node as SphinxNode; -use std::net::{Ipv4Addr, SocketAddrV4}; +use std::net::SocketAddrV4; use std::time::Duration; use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; @@ -34,7 +34,7 @@ pub fn execute(matches: &ArgMatches) { interval.tick().await; let message = format!("Hello, Sphinx {}", i).as_bytes().to_vec(); - let route_len = 2; + let route_len = 1; // TODO: kill magic number // data needed to generate a new Sphinx packet let route = route_from(&topology, route_len); @@ -99,6 +99,8 @@ fn route_from(topology: &Topology, route_len: usize) -> Vec { route } +// Parses a String socket address, then returns it as a +// 4+2 byte array, zero-padded to a constant size of 32 bytes. fn socket_bytes_from_string(address: String) -> [u8; 32] { let socket: SocketAddrV4 = address.parse().unwrap(); let host_bytes = socket.ip().octets(); From 65ae5c4cec5dd9e3185047b01b1129d6e9d85591 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:19:09 +0000 Subject: [PATCH 113/167] presence: fixing post request test --- src/clients/directory/requests/presence_mixnodes_post.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/clients/directory/requests/presence_mixnodes_post.rs b/src/clients/directory/requests/presence_mixnodes_post.rs index 8781b9a3dc..c68187b425 100644 --- a/src/clients/directory/requests/presence_mixnodes_post.rs +++ b/src/clients/directory/requests/presence_mixnodes_post.rs @@ -79,7 +79,6 @@ mod metrics_get_request { MixNodePresence { host: "foo.com".to_string(), pub_key: "abc".to_string(), - last_seen: 666, layer: 1, } } From 808a79062fb73f456f469ec612223d90de468220 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:30:48 +0000 Subject: [PATCH 114/167] Adding last_seen back in as I don't feel like making a persisted version of the model just now --- src/clients/directory/presence.rs | 1 + src/clients/directory/requests/presence_mixnodes_post.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 422d4c096c..0410479a8d 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -14,6 +14,7 @@ pub struct MixNodePresence { pub host: String, pub pub_key: String, pub layer: u64, + pub last_seen: u64, } #[derive(Deserialize, Serialize)] diff --git a/src/clients/directory/requests/presence_mixnodes_post.rs b/src/clients/directory/requests/presence_mixnodes_post.rs index c68187b425..c0250f959e 100644 --- a/src/clients/directory/requests/presence_mixnodes_post.rs +++ b/src/clients/directory/requests/presence_mixnodes_post.rs @@ -80,6 +80,7 @@ mod metrics_get_request { host: "foo.com".to_string(), pub_key: "abc".to_string(), layer: 1, + last_seen: 0, } } } From 11c6c0f78a27b515df04e3cdadf07893a3958928 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 10:35:15 +0000 Subject: [PATCH 115/167] directory: metrics module needs to be public --- src/clients/directory/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/directory/mod.rs b/src/clients/directory/mod.rs index bc670ac822..a9ff9e4df8 100644 --- a/src/clients/directory/mod.rs +++ b/src/clients/directory/mod.rs @@ -20,7 +20,7 @@ use crate::clients::directory::requests::presence_topology_get::{ PresenceTopologyGetRequester, Request as PresenceTopologyRequest, }; -mod metrics; +pub mod metrics; pub mod presence; pub mod requests; From a978e6db9bffeab3fdc966440c1e997e60fa8978 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 10:46:34 +0000 Subject: [PATCH 116/167] Uncommited work before switching websocket implementation --- src/clients/directory/presence.rs | 10 ++++---- src/clients/mod.rs | 39 ++++++++++++++++++------------- src/commands/run.rs | 3 ++- src/utils/sphinx.rs | 6 +++-- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 62968eae19..20b666f171 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct CocoPresence { pub host: String, @@ -8,7 +8,7 @@ pub struct CocoPresence { pub last_seen: i64, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct MixNodePresence { pub host: String, @@ -17,7 +17,7 @@ pub struct MixNodePresence { pub last_seen: i64, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct MixProviderPresence { pub host: String, @@ -25,14 +25,14 @@ pub struct MixProviderPresence { pub registered_clients: Vec, } -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct MixProviderClient { pub pub_key: String, } // Topology shows us the current state of the overall Nym network -#[derive(Deserialize, Serialize)] +#[derive(Deserialize, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct Topology { pub coco_nodes: Vec, diff --git a/src/clients/mod.rs b/src/clients/mod.rs index b07ca9a7d7..97b833f1b7 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -7,6 +7,8 @@ use futures::{StreamExt, SinkExt}; use crate::clients::mix::MixClient; use sphinx::SphinxPacket; use futures::select; +use crate::utils::topology::get_topology; +use crate::clients::directory::presence::Topology; pub mod directory; pub mod mix; @@ -56,6 +58,8 @@ pub struct NymClient { pub input_tx: mpsc::UnboundedSender, // to be used by "send" function or socket, etc input_rx: mpsc::UnboundedReceiver, + + is_local: bool, } @@ -63,28 +67,29 @@ pub struct NymClient { pub struct InputMessage(pub Destination, pub Vec); impl NymClient { - pub fn new(address: DestinationAddressBytes) -> Self { + pub fn new(address: DestinationAddressBytes, is_local: bool) -> Self { let (input_tx, input_rx) = mpsc::unbounded::(); NymClient { address, input_tx, input_rx, + is_local, } } - async fn start_loop_cover_traffic_stream(mut tx: mpsc::UnboundedSender, our_info: Destination) -> Result<(), Box> { + async fn start_loop_cover_traffic_stream(mut tx: mpsc::UnboundedSender, our_info: Destination, topology: &Topology) -> Result<(), Box> { loop { println!("[LOOP COVER TRAFFIC STREAM] - next cover message!"); let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); tokio::time::delay_for(delay_duration).await; - let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); + let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } } - async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver, our_info: Destination) -> Result<(), Box> { + async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver, our_info: Destination, topology: &Topology) -> Result<(), Box> { loop { println!("[OUT QUEUE] here I will be sending real traffic (or loop cover if nothing is available)"); select! { @@ -92,13 +97,13 @@ impl NymClient { println!("[OUT QUEUE] - we got a real message!"); let real_message = real_message.expect("The channel must have closed! - if the client hasn't crashed, it should have!"); println!("real: {:?}", real_message); - let encapsulated_message = utils::sphinx::encapsulate_message(real_message.0, real_message.1); + let encapsulated_message = utils::sphinx::encapsulate_message(real_message.0, real_message.1, topology); mix_tx.send(MixMessage(encapsulated_message.0, encapsulated_message.1)).await?; }, default => { println!("[OUT QUEUE] - no real message - going to send extra loop cover"); - let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier); + let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } } @@ -127,20 +132,22 @@ impl NymClient { let mut rt = Runtime::new()?; rt.spawn(MixTrafficController::run(mix_rx)); - let foomp = Destination::new(self.address, Default::default()); +// let foomp = Destination::new(self.address, Default::default()); +// +// let mut input_channel = self.input_tx.clone(); +// rt.spawn(async move { +// let test_message = b"foomp".to_vec(); +// let recipient = foomp; +// let input_message = InputMessage(recipient, test_message); +// input_channel.send(input_message).await.unwrap(); +// }); - let mut input_channel = self.input_tx.clone(); - rt.spawn(async move { - let test_message = b"foomp".to_vec(); - let recipient = foomp; - let input_message = InputMessage(recipient, test_message); - input_channel.send(input_message).await.unwrap(); - }); + let topology = get_topology(self.is_local); rt.block_on(async { let future_results = futures::future::join3( - NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default())), - NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default())), + NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default()), &topology.clone()), + NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default()), &topology.clone()), NymClient::start_provider_polling()).await; // start websocket handler here diff --git a/src/commands/run.rs b/src/commands/run.rs index d0b7ea3596..4e30fdad53 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -22,7 +22,8 @@ pub fn execute(matches: &ArgMatches) { // todo: to be taken from config or something let my_address = [42u8; 32]; - let client = NymClient::new(my_address); + let is_local = true; + let client = NymClient::new(my_address, is_local); client.start().unwrap(); // Grab the network topology from the remote directory server // let topology = get_topology(is_local); diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 6ce8baa32d..2d0219b54b 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -1,3 +1,4 @@ +use crate::clients::directory::presence::Topology; use crate::utils::{bytes, topology}; use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; @@ -7,19 +8,20 @@ const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; pub fn loop_cover_message( our_address: DestinationAddressBytes, surb_id: SURBIdentifier, + topology: &Topology, ) -> (NodeAddressBytes, SphinxPacket) { let destination = Destination::new(our_address, surb_id); - encapsulate_message(destination, LOOP_COVER_MESSAGE_PAYLOAD.to_vec()) + encapsulate_message(destination, LOOP_COVER_MESSAGE_PAYLOAD.to_vec(), topology) } pub fn encapsulate_message( recipient: Destination, message: Vec, + topology: &Topology, ) -> (NodeAddressBytes, SphinxPacket) { // here we would be getting topology, etc - let topology = topology::get_topology(true); let mixes_route = topology::route_from(&topology, 1); let provider = Node::new( From d0a07ac006996b01ca23d9dcc4cdaf133961cede Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 10:53:06 +0000 Subject: [PATCH 117/167] stash pop --- Cargo.lock | 29 ++++++---- Cargo.toml | 4 +- src/clients/mod.rs | 109 +++++++++++++++++++++++++------------- src/commands/websocket.rs | 2 +- src/sockets/ws.rs | 78 +++++++++++++++++++++++---- 5 files changed, 162 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b061f193c..1db7bd75cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ name = "assert-json-diff" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -292,7 +292,7 @@ dependencies = [ "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "publicsuffix 1.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -671,6 +671,11 @@ dependencies = [ "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hex" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hkdf" version = "0.8.0" @@ -1030,12 +1035,13 @@ dependencies = [ "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", "pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_distr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "sfw-provider-requests 0.1.0", "sphinx 0.1.0", @@ -1393,7 +1399,7 @@ dependencies = [ "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1483,15 +1489,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.103" +version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1506,7 +1512,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1516,7 +1522,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2111,6 +2117,7 @@ dependencies = [ "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" +"checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" "checksum hkdf 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" "checksum http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" @@ -2198,8 +2205,8 @@ dependencies = [ "checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "1217f97ab8e8904b57dd22eb61cde455fa7446a9c1cf43966066da047c1f3702" -"checksum serde_derive 1.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c6faef9a2e64b0064f48570289b4bf8823b7581f1d6157c1b52152306651d0" +"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" "checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" diff --git a/Cargo.toml b/Cargo.toml index 6f7837feec..2cef8f55f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,11 +16,13 @@ clap = "2.33.0" curve25519-dalek = "1.2.3" dirs = "2.0.2" futures = "0.3.1" +hex = "0.4.0" pem = "0.7.0" rand = "0.7.2" rand_distr = "0.2.2" reqwest = "0.9.22" -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0.104", features = ["derive"] } +serde_json = "1.0.44" sphinx = { path = "../sphinx" } sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } tokio = { version = "0.2", features = ["full"] } diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 97b833f1b7..c9037bed97 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,21 +1,20 @@ -use sphinx::route::{DestinationAddressBytes, NodeAddressBytes, Destination}; -use tokio::runtime::Runtime; -use futures::channel::mpsc; -use std::time::Duration; -use crate::utils; -use futures::{StreamExt, SinkExt}; -use crate::clients::mix::MixClient; -use sphinx::SphinxPacket; -use futures::select; -use crate::utils::topology::get_topology; use crate::clients::directory::presence::Topology; +use crate::clients::mix::MixClient; +use crate::utils; +use crate::utils::topology::get_topology; +use futures::channel::mpsc; +use futures::select; +use futures::{SinkExt, StreamExt}; +use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; +use sphinx::SphinxPacket; +use std::time::Duration; +use tokio::runtime::Runtime; pub mod directory; pub mod mix; pub mod provider; pub mod validator; - // TODO: put that in config once it exists const LOOP_COVER_AVERAGE_DELAY: f64 = 0.5; // assume seconds @@ -23,7 +22,6 @@ const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; - // provider-poller sends polls service provider; receives messages // provider-poller sends (TX) to ReceivedBufferController (RX) // ReceivedBufferController sends (TX) to ... ??Client?? @@ -36,13 +34,15 @@ struct MixMessage(NodeAddressBytes, SphinxPacket); struct MixTrafficController; - impl MixTrafficController { // this was way more difficult to implement than what this code may suggest... async fn run(mut rx: mpsc::UnboundedReceiver) { let mix_client = MixClient::new(); while let Some(mix_message) = rx.next().await { - println!("[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", mix_message.0); + println!( + "[MIX TRAFFIC CONTROL] - got a mix_message for {:?}", + mix_message.0 + ); let send_res = mix_client.send(mix_message.1, mix_message.0).await; match send_res { Ok(_) => println!("We successfully sent the message!"), @@ -62,7 +62,6 @@ pub struct NymClient { is_local: bool, } - #[derive(Debug)] pub struct InputMessage(pub Destination, pub Vec); @@ -78,18 +77,29 @@ impl NymClient { } } - async fn start_loop_cover_traffic_stream(mut tx: mpsc::UnboundedSender, our_info: Destination, topology: &Topology) -> Result<(), Box> { + async fn start_loop_cover_traffic_stream( + mut tx: mpsc::UnboundedSender, + our_info: Destination, + topology: &Topology, + ) -> Result<(), Box> { loop { println!("[LOOP COVER TRAFFIC STREAM] - next cover message!"); let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); tokio::time::delay_for(delay_duration).await; - let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); - tx.send(MixMessage(cover_message.0, cover_message.1)).await?; + let cover_message = + utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); + tx.send(MixMessage(cover_message.0, cover_message.1)) + .await?; } } - async fn control_out_queue(mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver, our_info: Destination, topology: &Topology) -> Result<(), Box> { + async fn control_out_queue( + mut mix_tx: mpsc::UnboundedSender, + mut input_rx: mpsc::UnboundedReceiver, + our_info: Destination, + topology: &Topology, + ) -> Result<(), Box> { loop { println!("[OUT QUEUE] here I will be sending real traffic (or loop cover if nothing is available)"); select! { @@ -106,15 +116,13 @@ impl NymClient { let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?; } - } - ; + }; let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; } } - async fn start_provider_polling() -> Result<(), Box> { loop { println!("[FETCH MSG] - Polling provider..."); @@ -123,7 +131,6 @@ impl NymClient { } } - pub fn start(self) -> Result<(), Box> { println!("starting nym client"); @@ -132,31 +139,59 @@ impl NymClient { let mut rt = Runtime::new()?; rt.spawn(MixTrafficController::run(mix_rx)); -// let foomp = Destination::new(self.address, Default::default()); -// -// let mut input_channel = self.input_tx.clone(); -// rt.spawn(async move { -// let test_message = b"foomp".to_vec(); -// let recipient = foomp; -// let input_message = InputMessage(recipient, test_message); -// input_channel.send(input_message).await.unwrap(); -// }); + // let foomp = Destination::new(self.address, Default::default()); + // + // let mut input_channel = self.input_tx.clone(); + // rt.spawn(async move { + // let test_message = b"foomp".to_vec(); + // let recipient = foomp; + // let input_message = InputMessage(recipient, test_message); + // input_channel.send(input_message).await.unwrap(); + // }); let topology = get_topology(self.is_local); + let mut input_channel = self.input_tx.clone(); + + let bar = self.address.clone(); + + rt.spawn(async move { + loop { + let foomp = Destination::new(bar, Default::default()); + + let test_message = b"foomp".to_vec(); + let recipient = foomp; + let input_message = InputMessage(recipient, test_message); + input_channel.send(input_message).await.unwrap(); + tokio::time::delay_for(Duration::from_secs(1)).await; + } + }); rt.block_on(async { let future_results = futures::future::join3( - NymClient::start_loop_cover_traffic_stream(mix_tx.clone(), Destination::new(self.address, Default::default()), &topology.clone()), - NymClient::control_out_queue(mix_tx, self.input_rx, Destination::new(self.address, Default::default()), &topology.clone()), - NymClient::start_provider_polling()).await; + NymClient::start_loop_cover_traffic_stream( + mix_tx.clone(), + Destination::new(self.address, Default::default()), + &topology.clone(), + ), + NymClient::control_out_queue( + mix_tx, + self.input_rx, + Destination::new(self.address, Default::default()), + &topology.clone(), + ), + NymClient::start_provider_polling(), + ) + .await; // start websocket handler here - assert!(future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok()); + assert!( + future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() + ); }); // this line in theory should never be reached as the runtime should be permanently blocked on traffic senders eprintln!("The client went kaput..."); Ok(()) } -} \ No newline at end of file +} diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 7d9889019c..c5ecfabd81 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -19,5 +19,5 @@ pub fn execute(matches: &ArgMatches) { .next() .expect("Failed to extract the socket address from the iterator"); - ws::start(socket_address); + // ws::start(socket_address); } diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index f4a08b4ceb..85f82d46e8 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,15 +1,39 @@ +use crate::clients::InputMessage; +use futures::channel::mpsc; +use hex::FromHexError; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use sphinx::route::Destination; use std::net::SocketAddr; -use ws::{listen, CloseCode, Handler, Message, Result, Sender}; +use ws::{listen, CloseCode, Handler, Message, Sender}; + +#[derive(Debug)] +enum WebSocketError { + InvalidDestinationEncoding, + InvalidDestinationLength, +} + +impl From for WebSocketError { + fn from(_: FromHexError) -> Self { + use WebSocketError::*; + + InvalidDestinationEncoding + } +} struct Server { out: Sender, + input_tx: mpsc::UnboundedSender, } impl Handler for Server { - fn on_message(&mut self, msg: Message) -> Result<()> { - foomp(msg.clone()); + fn on_message(&mut self, msg: Message) -> ws::Result<()> { + let parsed_msg = Server::parse_message(msg.clone()); + + println!("msg: {:?}", parsed_msg); // Echo the message back - self.out.send(msg) + // self.out.send(msg) + Ok(()) } fn on_close(&mut self, code: CloseCode, reason: &str) { @@ -23,12 +47,46 @@ impl Handler for Server { } } -pub fn start(socket_address: SocketAddr) { - listen(socket_address, |out| Server { out: out }).unwrap() +impl Server { + // Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts + // the `send_message` functionality. + fn parse_message(msg: Message) -> Result { + let text_msg = match msg { + Message::Text(msg) => msg, + Message::Binary(_) => panic!("binary messages are not supported!"), + }; + + let raw_msg: ClientMessageJSON = serde_json::from_str(&text_msg).unwrap(); + let address_vec = hex::decode(raw_msg.recipient_address)?; + + if address_vec.len() != 32 { + return Err(WebSocketError::InvalidDestinationLength); + } + + let mut address = [0; 32]; + address.copy_from_slice(&address_vec); + + let dummy_surb = [0; 16]; + + Ok(InputMessage( + Destination::new(address, dummy_surb), + raw_msg.message.into_bytes(), + )) + } } -// Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts -// the `send_message` functionality. -fn foomp(msg: Message) { - println!("Foomp!: {:?}", msg); +pub fn start(socket_address: SocketAddr, input_tx: mpsc::UnboundedSender) { + // listen("127.0.0.1:3012", |out| { + // async move |msg| { + // out.send(msg) + // } + // }); + + // listen(socket_address, |out| Server { out, input_tx }).unwrap() +} + +#[derive(Serialize, Deserialize, Debug)] +struct ClientMessageJSON { + message: String, + recipient_address: String, } From ef15eb06ce77fad891b2e81e4480c48aa559ac25 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 10:57:33 +0000 Subject: [PATCH 118/167] Outdated comment --- src/utils/sphinx.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 2d0219b54b..2a6fe01150 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -20,13 +20,10 @@ pub fn encapsulate_message( message: Vec, topology: &Topology, ) -> (NodeAddressBytes, SphinxPacket) { - // here we would be getting topology, etc - let mixes_route = topology::route_from(&topology, 1); let provider = Node::new( topology::socket_bytes_from_string("127.0.0.1:8081".to_string()), - // bytes::zero_pad_to_32("127.0.0.1:8081".as_bytes().to_vec()), Default::default(), ); From a3f0e74dc724ca8dde0234e5e59dc838164f0f44 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 11:06:35 +0000 Subject: [PATCH 119/167] Allowing the client to run all its traffic stream in parallel rather than just concurrently --- src/clients/mod.rs | 98 +++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index c9037bed97..76f5dfa1f7 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -9,6 +9,7 @@ use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; use sphinx::SphinxPacket; use std::time::Duration; use tokio::runtime::Runtime; +use futures::future::{join3, join4}; pub mod directory; pub mod mix; @@ -80,17 +81,17 @@ impl NymClient { async fn start_loop_cover_traffic_stream( mut tx: mpsc::UnboundedSender, our_info: Destination, - topology: &Topology, - ) -> Result<(), Box> { + topology: Topology, + ) { loop { println!("[LOOP COVER TRAFFIC STREAM] - next cover message!"); let delay = utils::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); tokio::time::delay_for(delay_duration).await; let cover_message = - utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); + utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, &topology); tx.send(MixMessage(cover_message.0, cover_message.1)) - .await?; + .await.unwrap(); } } @@ -98,8 +99,8 @@ impl NymClient { mut mix_tx: mpsc::UnboundedSender, mut input_rx: mpsc::UnboundedReceiver, our_info: Destination, - topology: &Topology, - ) -> Result<(), Box> { + topology: Topology, + ) { loop { println!("[OUT QUEUE] here I will be sending real traffic (or loop cover if nothing is available)"); select! { @@ -107,14 +108,14 @@ impl NymClient { println!("[OUT QUEUE] - we got a real message!"); let real_message = real_message.expect("The channel must have closed! - if the client hasn't crashed, it should have!"); println!("real: {:?}", real_message); - let encapsulated_message = utils::sphinx::encapsulate_message(real_message.0, real_message.1, topology); - mix_tx.send(MixMessage(encapsulated_message.0, encapsulated_message.1)).await?; + let encapsulated_message = utils::sphinx::encapsulate_message(real_message.0, real_message.1, &topology); + mix_tx.send(MixMessage(encapsulated_message.0, encapsulated_message.1)).await.unwrap(); }, default => { println!("[OUT QUEUE] - no real message - going to send extra loop cover"); - let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, topology); - mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await?; + let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, &topology); + mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await.unwrap(); } }; @@ -123,7 +124,8 @@ impl NymClient { } } - async fn start_provider_polling() -> Result<(), Box> { + // TODO: proper return type + async fn start_provider_polling() { loop { println!("[FETCH MSG] - Polling provider..."); let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); @@ -135,58 +137,48 @@ impl NymClient { println!("starting nym client"); let (mix_tx, mix_rx) = mpsc::unbounded(); - let mut rt = Runtime::new()?; - rt.spawn(MixTrafficController::run(mix_rx)); - // let foomp = Destination::new(self.address, Default::default()); - // - // let mut input_channel = self.input_tx.clone(); - // rt.spawn(async move { - // let test_message = b"foomp".to_vec(); - // let recipient = foomp; - // let input_message = InputMessage(recipient, test_message); - // input_channel.send(input_message).await.unwrap(); - // }); let topology = get_topology(self.is_local); - let mut input_channel = self.input_tx.clone(); - let bar = self.address.clone(); - rt.spawn(async move { - loop { - let foomp = Destination::new(bar, Default::default()); +// let mut input_channel = self.input_tx.clone(); +// let bar = self.address.clone(); +// rt.spawn(async move { +// loop { +// let foomp = Destination::new(bar, Default::default()); +// +// let test_message = b"foomp".to_vec(); +// let recipient = foomp; +// let input_message = InputMessage(recipient, test_message); +// input_channel.send(input_message).await.unwrap(); +// tokio::time::delay_for(Duration::from_secs(1)).await; +// } +// }); - let test_message = b"foomp".to_vec(); - let recipient = foomp; - let input_message = InputMessage(recipient, test_message); - input_channel.send(input_message).await.unwrap(); - tokio::time::delay_for(Duration::from_secs(1)).await; - } - }); + let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); + let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( + mix_tx.clone(), + Destination::new(self.address, Default::default()), + topology.clone(), + )); + + let out_queue_control_future = rt.spawn(NymClient::control_out_queue( + mix_tx, + self.input_rx, + Destination::new(self.address, Default::default()), + topology.clone(), + )); + + let provider_polling_future = rt.spawn(NymClient::start_provider_polling()); + + // TODO: websocket handler future rt.block_on(async { - let future_results = futures::future::join3( - NymClient::start_loop_cover_traffic_stream( - mix_tx.clone(), - Destination::new(self.address, Default::default()), - &topology.clone(), - ), - NymClient::control_out_queue( - mix_tx, - self.input_rx, - Destination::new(self.address, Default::default()), - &topology.clone(), - ), - NymClient::start_provider_polling(), - ) - .await; - - // start websocket handler here - + let future_results = join4(mix_traffic_future, loop_cover_traffic_future, out_queue_control_future, provider_polling_future).await; assert!( - future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() + future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() && future_results.3.is_ok() ); }); From 40bec843972261c2c6ec50dacd12e1590167a2d0 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 11:07:06 +0000 Subject: [PATCH 120/167] Removed unused join3 import --- src/clients/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 76f5dfa1f7..eedf26b14c 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -9,7 +9,7 @@ use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; use sphinx::SphinxPacket; use std::time::Duration; use tokio::runtime::Runtime; -use futures::future::{join3, join4}; +use futures::future::join4; pub mod directory; pub mod mix; @@ -117,7 +117,8 @@ impl NymClient { let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, &topology); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await.unwrap(); } - }; + } + ; let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; From b741c23a7cf7d3e140188bc98a19445655104597 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 11:30:16 +0000 Subject: [PATCH 121/167] presence: adding comparison and debug to presence models --- src/clients/directory/presence.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/clients/directory/presence.rs b/src/clients/directory/presence.rs index 0410479a8d..1d2e56f7e1 100644 --- a/src/clients/directory/presence.rs +++ b/src/clients/directory/presence.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct CocoPresence { pub host: String, @@ -8,7 +8,7 @@ pub struct CocoPresence { pub last_seen: i64, } -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixNodePresence { pub host: String, @@ -17,7 +17,7 @@ pub struct MixNodePresence { pub last_seen: u64, } -#[derive(Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixProviderPresence { pub host: String, @@ -25,14 +25,14 @@ pub struct MixProviderPresence { pub registered_clients: Vec, } -#[derive(Deserialize, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct MixProviderClient { pub pub_key: String, } // Topology shows us the current state of the overall Nym network -#[derive(Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct Topology { pub coco_nodes: Vec, From 3ddde4c8ef2c38327377a1642f66614cd658c0b5 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 12:17:49 +0000 Subject: [PATCH 122/167] New websocket handler with working async --- Cargo.lock | 107 ++++++++++++++-------- Cargo.toml | 6 +- src/commands/websocket.rs | 2 +- src/sockets/ws.rs | 183 +++++++++++++++++++++++++------------- 4 files changed, 194 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1db7bd75cb..eb8d66ab7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -789,6 +789,14 @@ dependencies = [ "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "input_buffer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "iovec" version = "0.1.4" @@ -821,11 +829,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.2.66" @@ -921,17 +924,6 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio-named-pipes" version = "0.1.6" @@ -1046,7 +1038,8 @@ dependencies = [ "sfw-provider-requests 0.1.0", "sphinx 0.1.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ws 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2)", + "tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1128,6 +1121,24 @@ name = "percent-encoding" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "pin-project" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pin-project-internal 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "pin-project-internal" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pin-project-lite" version = "0.1.1" @@ -1857,6 +1868,18 @@ dependencies = [ "tokio-executor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-tungstenite" +version = "0.10.0" +source = "git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2#6dc2018cbfe8fe7ddd75ff977343086503135b38" +dependencies = [ + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-project 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "try-lock" version = "0.2.2" @@ -1870,6 +1893,25 @@ dependencies = [ "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tungstenite" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "input_buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "typenum" version = "1.11.2" @@ -1929,6 +1971,11 @@ dependencies = [ "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "utf-8" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "uuid" version = "0.7.4" @@ -2009,23 +2056,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ws" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", - "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -2128,12 +2158,12 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d7b3ea5827fcb9d4fda14bf4da5f136f0db2ae9c8f4bd4e2d1c6fde4e6db2" +"checksum input_buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e1b822cc844905551931d6f81608ed5f50a79c1078a4e2b4d42dbc7c1eedfbf" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" "checksum lioness 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ae926706ba42c425c9457121178330d75e273df2e82e28b758faf3de3a9acb9" "checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" @@ -2146,7 +2176,6 @@ dependencies = [ "checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599" "checksum miniz_oxide 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" "checksum mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)" = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" -"checksum mio-extras 2.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" "checksum mio-named-pipes 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" @@ -2164,6 +2193,8 @@ dependencies = [ "checksum pem 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1581760c757a756a41f0ee3ff01256227bdf64cb752839779b95ffb01c59793" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +"checksum pin-project 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "94b90146c7216e4cb534069fb91366de4ea0ea353105ee45ed297e2d1619e469" +"checksum pin-project-internal 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "44ca92f893f0656d3cba8158dd0f2b99b94de256a4a54e870bd6922fcc6c8355" "checksum pin-project-lite 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f0af6cbca0e6e3ce8692ee19fb8d734b641899e07b68eb73e9bbbd32f1703991" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)" = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" @@ -2239,8 +2270,10 @@ dependencies = [ "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c32ffea4827978e9aa392d2f743d973c1dfa3730a2ed3f22ce1e6984da848c" "checksum tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1739638e364e558128461fc1ad84d997702c8e31c2e6b18fb99842268199e827" +"checksum tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2)" = "" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" +"checksum tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8a0c2bd5aeb7dcd2bb32e472c8872759308495e5eccc942e929a513cd8d36110" "checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -2249,6 +2282,7 @@ dependencies = [ "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" +"checksum utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" "checksum uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "90dbc611eb48397705a6b0f6e917da23ae517e4d127123d2cf7674206627d32a" "checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" @@ -2262,5 +2296,4 @@ dependencies = [ "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum winreg 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -"checksum ws 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a2c47b5798ccc774ffb93ff536aec7c4275d722fd9c740c83cdd1af1f2d94" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index 2cef8f55f0..0ca4ee4fd7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,10 @@ serde_json = "1.0.44" sphinx = { path = "../sphinx" } sfw-provider-requests = { path = "../nym-sfw-provider/sfw-provider-requests" } tokio = { version = "0.2", features = ["full"] } -ws = "0.9.1" +tungstenite = "0.9.2" + +# putting this explicitly below everything and most likely, the next time we look into it, it will already have a proper release +tokio-tungstenite = { git = "https://github.com/dbcfd/tokio-tungstenite", branch = "tokio2" } [dev-dependencies] mockito = "0.22.0" -serde_json = "1.0.44" diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index c5ecfabd81..7d9889019c 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -19,5 +19,5 @@ pub fn execute(matches: &ArgMatches) { .next() .expect("Failed to extract the socket address from the iterator"); - // ws::start(socket_address); + ws::start(socket_address); } diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index 85f82d46e8..832f5d5da9 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,11 +1,24 @@ use crate::clients::InputMessage; use futures::channel::mpsc; +use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; +use futures::stream::Stream; +use futures::Future; +use futures::{SinkExt, StreamExt}; use hex::FromHexError; use serde::{Deserialize, Serialize}; use serde_json::Value; use sphinx::route::Destination; use std::net::SocketAddr; -use ws::{listen, CloseCode, Handler, Message, Sender}; +use tokio::runtime::Runtime; +use tokio_tungstenite::accept_async; +use tungstenite::protocol::Message; +use std::time::Duration; + +struct Connection { + address: SocketAddr, + rx: UnboundedReceiver, + tx: UnboundedSender, +} #[derive(Debug)] enum WebSocketError { @@ -21,72 +34,114 @@ impl From for WebSocketError { } } -struct Server { - out: Sender, - input_tx: mpsc::UnboundedSender, -} - -impl Handler for Server { - fn on_message(&mut self, msg: Message) -> ws::Result<()> { - let parsed_msg = Server::parse_message(msg.clone()); - - println!("msg: {:?}", parsed_msg); - // Echo the message back - // self.out.send(msg) - Ok(()) - } - - fn on_close(&mut self, code: CloseCode, reason: &str) { - match code { - CloseCode::Normal => println!("The client is done with the connection."), - CloseCode::Away => println!("The client is leaving the site."), - _ => { - println!("The client encountered an error: {}", reason); - } - } - } -} - -impl Server { - // Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts - // the `send_message` functionality. - fn parse_message(msg: Message) -> Result { - let text_msg = match msg { - Message::Text(msg) => msg, - Message::Binary(_) => panic!("binary messages are not supported!"), - }; - - let raw_msg: ClientMessageJSON = serde_json::from_str(&text_msg).unwrap(); - let address_vec = hex::decode(raw_msg.recipient_address)?; - - if address_vec.len() != 32 { - return Err(WebSocketError::InvalidDestinationLength); - } - - let mut address = [0; 32]; - address.copy_from_slice(&address_vec); - - let dummy_surb = [0; 16]; - - Ok(InputMessage( - Destination::new(address, dummy_surb), - raw_msg.message.into_bytes(), - )) - } -} - -pub fn start(socket_address: SocketAddr, input_tx: mpsc::UnboundedSender) { - // listen("127.0.0.1:3012", |out| { - // async move |msg| { - // out.send(msg) - // } - // }); - - // listen(socket_address, |out| Server { out, input_tx }).unwrap() -} #[derive(Serialize, Deserialize, Debug)] struct ClientMessageJSON { message: String, recipient_address: String, } + +fn dummy_response() -> Message { + Message::Text("foomp".to_string()) +} + +async fn handle_connection(conn: Connection) { + let mut conn = conn; + while let Some(msg) = conn.rx.next().await { + println!("Received a message from {}: {}", conn.address, msg); + // TODO: currently only hardcoded sends are supported + let parsed_message = parse_message(msg); + println!("parsed: {:?}", parsed_message); + println!("test async pre wait"); + + tokio::time::delay_for(Duration::from_secs(2)).await; + + println!("test async post wait"); + conn + .tx + .unbounded_send(dummy_response()) + .expect("Failed to forward message"); + } +} + +// Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts +// the `send_message` functionality. +fn parse_message(msg: Message) -> Result { + let text_msg = match msg { + Message::Text(msg) => msg, + Message::Binary(_) => panic!("binary messages are not supported!"), + Message::Close(_) => panic!("todo: handle close!"), + _ => panic!("Other types of messages are also unsupported!"), + }; + + let raw_msg: ClientMessageJSON = serde_json::from_str(&text_msg).unwrap(); + let address_vec = hex::decode(raw_msg.recipient_address)?; + + if address_vec.len() != 32 { + return Err(WebSocketError::InvalidDestinationLength); + } + + let mut address = [0; 32]; + address.copy_from_slice(&address_vec); + + let dummy_surb = [0; 16]; + + Ok(InputMessage( + Destination::new(address, dummy_surb), + raw_msg.message.into_bytes(), + )) +} + +async fn accept_connection(stream: tokio::net::TcpStream) { + let address = stream + .peer_addr() + .expect("connected streams should have a peer address"); + println!("Peer address: {}", address); + + let mut ws_stream = tokio_tungstenite::accept_async(stream) + .await + .expect("Error during the websocket handshake occurred"); + + println!("New WebSocket connection: {}", address); + + // Create a channel for our stream, which other sockets will use to + // send us messages. Then register our address with the stream to send + // data to us. + let (msg_tx, msg_rx) = futures::channel::mpsc::unbounded(); + let (response_tx, mut response_rx) = futures::channel::mpsc::unbounded(); + let conn = Connection { + address, + rx: msg_rx, + tx: response_tx, + }; + tokio::spawn(handle_connection(conn)); + + while let Some(message) = ws_stream.next().await { + let message = message.expect("Failed to get request"); + msg_tx + .unbounded_send(message) + .expect("Failed to forward request"); + if let Some(resp) = response_rx.next().await { + ws_stream.send(resp).await.expect("Failed to send response"); + } + } +} + + + +pub fn start(address: SocketAddr) -> Result<(), Box> { + let mut rt = Runtime::new()?; + + rt.block_on(async { + let mut listener = tokio::net::TcpListener::bind(address).await?; + + while let Ok((stream, _)) = listener.accept().await { + // TODO: should it rather be rt.spawn? + tokio::spawn(accept_connection(stream)); + } + + eprintln!("The websocket went kaput..."); + Ok(()) + }) +} + From ca3cf706e4d6ceb9a79adb66ed0bbfc459d8c829 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 12:36:40 +0000 Subject: [PATCH 123/167] Added local flag to socket startups --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6dc3ea6c3e..6efd6bb882 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use clap::{App, Arg, ArgMatches, SubCommand}; use std::process; -mod clients; +pub mod clients; mod commands; mod identity; mod persistence; @@ -48,6 +48,11 @@ fn main() { .takes_value(true) .required(true), ) + .arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(false) + ) ) .subcommand( SubCommand::with_name("websocket") @@ -60,6 +65,11 @@ fn main() { .takes_value(true) .required(true), ) + .arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(false) + ) ) .get_matches(); From c508d1518dac571723221175ab1e9683c40b53d8 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 12:42:10 +0000 Subject: [PATCH 124/167] provider: using provider from topology instead of hardcoded --- src/clients/provider.rs | 5 +++-- src/commands/run.rs | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 2abeb43cce..e0b03dbaec 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,6 +1,7 @@ use sfw_provider_requests::requests::{ProviderRequest, PullRequest}; use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; use std::net::Shutdown; +use std::net::SocketAddrV4; use tokio::prelude::*; use tokio::time::Duration; @@ -13,13 +14,13 @@ impl ProviderClient { pub async fn retrieve_messages( &self, - // provider: &MixNode, + provider: &SocketAddrV4, ) -> Result<(), Box> { let address = [42; 32]; let pull_request = PullRequest::new(address); let bytes = pull_request.to_bytes(); - let mut socket = tokio::net::TcpStream::connect("127.0.0.1:9000").await?; + let mut socket = tokio::net::TcpStream::connect(provider).await?; println!("keep alive: {:?}", socket.keepalive()); socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); socket.write_all(&bytes[..]).await?; diff --git a/src/commands/run.rs b/src/commands/run.rs index d9ee52a977..f1e7218fdf 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -21,6 +21,13 @@ pub fn execute(matches: &ArgMatches) { // Grab the network topology from the remote directory server let topology = get_topology(is_local); + let provider_address: SocketAddrV4 = topology + .mix_provider_nodes + .first() + .unwrap() + .host + .parse() + .unwrap(); // Create the runtime, probably later move it to Client struct itself? let mut rt = Runtime::new().unwrap(); @@ -59,7 +66,10 @@ pub fn execute(matches: &ArgMatches) { interval.tick().await; println!("going to retrieve messages!"); let provider_client = ProviderClient::new(); - provider_client.retrieve_messages().await.unwrap(); + provider_client + .retrieve_messages(&provider_address) + .await + .unwrap(); } } }) @@ -106,7 +116,10 @@ fn socket_bytes_from_string(address: String) -> [u8; 32] { let host_bytes = socket.ip().octets(); let port_bytes = socket.port().to_be_bytes(); let mut address_bytes = [0u8; 32]; - address_bytes.copy_from_slice(&host_bytes); + address_bytes[0] = host_bytes[0]; + address_bytes[1] = host_bytes[1]; + address_bytes[2] = host_bytes[2]; + address_bytes[3] = host_bytes[3]; address_bytes[4] = port_bytes[0]; address_bytes[5] = port_bytes[1]; address_bytes From 8bf9dabdf138400b63a417456edef4bda85e10cf Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 14:09:41 +0000 Subject: [PATCH 125/167] Import cleanup --- src/clients/mix.rs | 3 +-- src/commands/run.rs | 26 +------------------------- src/utils/topology.rs | 2 -- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 65480bf539..2dcc178182 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,6 +1,5 @@ -use sphinx::route::{Node as MixNode, NodeAddressBytes}; +use sphinx::route::NodeAddressBytes; use sphinx::SphinxPacket; -use std::net::SocketAddr; use std::net::{Ipv4Addr, SocketAddrV4}; use tokio::prelude::*; diff --git a/src/commands/run.rs b/src/commands/run.rs index 5f3e5af77f..9fcb99fe41 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,37 +1,13 @@ -use crate::clients::directory; -use crate::clients::directory::presence::Topology; -use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; -use crate::clients::directory::DirectoryClient; -use crate::clients::mix::MixClient; -use crate::clients::provider::ProviderClient; use crate::clients::NymClient; -use crate::utils::bytes; -use base64; use clap::ArgMatches; -use curve25519_dalek::montgomery::MontgomeryPoint; -use sphinx::route::Destination; -use sphinx::route::Node as SphinxNode; -use std::net::SocketAddrV4; -use std::time::Duration; -use tokio::runtime::Runtime; -use tokio::time::{interval_at, Instant}; pub fn execute(matches: &ArgMatches) { let is_local = matches.is_present("local"); println!("Starting client, local: {:?}", is_local); - // todo: to be taken from config or something + // TODO: to be taken from config or something let my_address = [42u8; 32]; let is_local = true; let client = NymClient::new(my_address, is_local); client.start().unwrap(); - // Grab the network topology from the remote directory server -} - -// TODO: where do we retrieve this guy from? -fn get_destination() -> Destination { - Destination { - address: [42u8; 32], - identifier: [1u8; 16], - } } diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 35ee9c2f1f..6bc8e59169 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -2,8 +2,6 @@ use crate::clients::directory; use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; -use crate::clients::mix::MixClient; -use crate::clients::provider::ProviderClient; use crate::utils::bytes; use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::Node as SphinxNode; From a42dd55320dd9b5dbc8b6771bbc480ea46b2da9d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 14:47:45 +0000 Subject: [PATCH 126/167] main: adding "id" parameter back onto "run" command --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index 6dc3ea6c3e..2c45340ff3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,12 @@ fn main() { .subcommand( SubCommand::with_name("run") .about("Run a persistent Nym client process") + .arg(Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnet-client we want to run.") + .takes_value(true) + .required(true) + ) .arg(Arg::with_name("local") .long("local") .help("Flag to indicate whether the client is expected to run on the local deployment.") From 74e0fb849be3dcf79233501217673a9192dbc16d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 14:48:20 +0000 Subject: [PATCH 127/167] keys: relying on the type system to ensure keys are 32 byte arrays --- src/identity/mixnet.rs | 8 ++++---- src/persistence/pemstore.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/identity/mixnet.rs b/src/identity/mixnet.rs index 3783dffd97..10e081a4fa 100644 --- a/src/identity/mixnet.rs +++ b/src/identity/mixnet.rs @@ -23,11 +23,11 @@ impl KeyPair { KeyPair { private, public } } - pub fn private_bytes(&self) -> Vec { - self.private.to_bytes().to_vec() + pub fn private_bytes(&self) -> [u8; 32] { + self.private.to_bytes() } - pub fn public_bytes(&self) -> Vec { - self.public.to_bytes().to_vec() + pub fn public_bytes(&self) -> [u8; 32] { + self.public.to_bytes() } } diff --git a/src/persistence/pemstore.rs b/src/persistence/pemstore.rs index c935fab437..02c1f5db00 100644 --- a/src/persistence/pemstore.rs +++ b/src/persistence/pemstore.rs @@ -52,10 +52,10 @@ impl PemStore { ); } - fn write_pem_file(&self, filepath: PathBuf, data: Vec, tag: String) { + fn write_pem_file(&self, filepath: PathBuf, data: [u8; 32], tag: String) { let pem = Pem { tag, - contents: data, + contents: data.to_vec(), }; let key = encode(&pem); From 127f6b4047a48c709974b79b733a1f1292a33f0d Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 14:48:44 +0000 Subject: [PATCH 128/167] run: reading the client's keypair from disk whenever it's run --- src/commands/run.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 9fcb99fe41..e6eec43bdd 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,13 +1,23 @@ use crate::clients::NymClient; +use crate::identity::mixnet; +use crate::persistence::pathfinder::Pathfinder; +use crate::persistence::pemstore::PemStore; use clap::ArgMatches; pub fn execute(matches: &ArgMatches) { let is_local = matches.is_present("local"); + + let id = matches.value_of("id").unwrap().to_string(); println!("Starting client, local: {:?}", is_local); - // TODO: to be taken from config or something - let my_address = [42u8; 32]; - let is_local = true; - let client = NymClient::new(my_address, is_local); + let keypair = read_keypair_from_disk(id); + let client = NymClient::new(keypair.public_bytes(), is_local); client.start().unwrap(); } + +fn read_keypair_from_disk(id: String) -> mixnet::KeyPair { + let pathfinder = Pathfinder::new(id); + let pem_store = PemStore::new(pathfinder); + let keypair = pem_store.read(); + keypair +} From ddaf4b6a863eb3507803b2a74012e5855ca3cdad Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 14:50:36 +0000 Subject: [PATCH 129/167] commands: using Nym banner on client start --- src/commands/run.rs | 3 +++ src/commands/websocket.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/commands/run.rs b/src/commands/run.rs index e6eec43bdd..fa9d16728b 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,3 +1,4 @@ +use crate::banner; use crate::clients::NymClient; use crate::identity::mixnet; use crate::persistence::pathfinder::Pathfinder; @@ -5,6 +6,8 @@ use crate::persistence::pemstore::PemStore; use clap::ArgMatches; pub fn execute(matches: &ArgMatches) { + println!("{}", banner()); + let is_local = matches.is_present("local"); let id = matches.value_of("id").unwrap().to_string(); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 7d9889019c..dcf80afc06 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -4,6 +4,8 @@ use clap::ArgMatches; use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { + println!("{}", banner()); + let port = match matches.value_of("port").unwrap().parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), From e1822495a64f099d2f76508a8366e2522bb1ef8a Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 15:04:25 +0000 Subject: [PATCH 130/167] socket clients: setting up with id and local parameters --- src/commands/run.rs | 16 +++------------- src/commands/tcpsocket.rs | 27 +++++++++++++++++++++++++-- src/commands/websocket.rs | 12 ++++++++++-- src/main.rs | 25 +++++++++++++++++++++++-- src/persistence/pemstore.rs | 7 +++++++ src/sockets/mod.rs | 1 + src/sockets/tcp.rs | 5 +++++ 7 files changed, 74 insertions(+), 19 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index fa9d16728b..dc19422b96 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,26 +1,16 @@ use crate::banner; use crate::clients::NymClient; -use crate::identity::mixnet; -use crate::persistence::pathfinder::Pathfinder; -use crate::persistence::pemstore::PemStore; +use crate::persistence::pemstore; use clap::ArgMatches; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); let is_local = matches.is_present("local"); - let id = matches.value_of("id").unwrap().to_string(); - println!("Starting client, local: {:?}", is_local); + println!("Starting client..."); - let keypair = read_keypair_from_disk(id); + let keypair = pemstore::read_keypair_from_disk(id); let client = NymClient::new(keypair.public_bytes(), is_local); client.start().unwrap(); } - -fn read_keypair_from_disk(id: String) -> mixnet::KeyPair { - let pathfinder = Pathfinder::new(id); - let pem_store = PemStore::new(pathfinder); - let keypair = pem_store.read(); - keypair -} diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index 79adfb29e6..1e3a21f1d1 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -1,10 +1,33 @@ +use crate::banner; +use crate::clients::NymClient; +use crate::persistence::pemstore; +use crate::sockets::tcp; + use clap::ArgMatches; +use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { - let port = match matches.value_of("port").unwrap().parse::() { + println!("{}", banner()); + + let is_local = matches.is_present("local"); + let id = matches.value_of("id").unwrap().to_string(); + let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; - println!("On the following port: {:?}", port); + println!("Starting TCP socket on port: {:?}", port); + println!("Listening for messages..."); + + let socket_address = ("127.0.0.1", port) + .to_socket_addrs() + .expect("Failed to combine host and port") + .next() + .expect("Failed to extract the socket address from the iterator"); + + let keypair = pemstore::read_keypair_from_disk(id); + let _client = NymClient::new(keypair.public_bytes(), is_local); + // Question: should we be passing the client into the TCP socket somehow next? + + tcp::start(socket_address); } diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index dcf80afc06..cdad955d2a 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -1,17 +1,21 @@ use crate::banner; +use crate::clients::NymClient; +use crate::persistence::pemstore; use crate::sockets::ws; + use clap::ArgMatches; use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - let port = match matches.value_of("port").unwrap().parse::() { + let is_local = matches.is_present("local"); + let id = matches.value_of("id").unwrap().to_string(); + let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; - println!("{}", banner()); println!("Starting websocket on port: {:?}", port); println!("Listening for messages..."); @@ -21,5 +25,9 @@ pub fn execute(matches: &ArgMatches) { .next() .expect("Failed to extract the socket address from the iterator"); + let keypair = pemstore::read_keypair_from_disk(id); + let _client = NymClient::new(keypair.public_bytes(), is_local); + // Question: should we be passing the client into the websocket somehow next? + ws::start(socket_address); } diff --git a/src/main.rs b/src/main.rs index 2c45340ff3..c6ae48c2f5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,9 +50,19 @@ fn main() { Arg::with_name("port") .short("p") .long("port") - .help("Port to listen on") + .help("Port for TCP socket to listen on") .takes_value(true) .required(true), + ).arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(false) + ) + .arg(Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnet-client we want to run.") + .takes_value(true) + .required(true) ) ) .subcommand( @@ -62,10 +72,21 @@ fn main() { Arg::with_name("port") .short("p") .long("port") - .help("Port to listen on") + .help("Port for websocket to listen on") .takes_value(true) .required(true), ) + .arg(Arg::with_name("local") + .long("local") + .help("Flag to indicate whether the client is expected to run on the local deployment.") + .takes_value(false) + ) + .arg(Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnet-client we want to run.") + .takes_value(true) + .required(true) + ) ) .get_matches(); diff --git a/src/persistence/pemstore.rs b/src/persistence/pemstore.rs index 02c1f5db00..037c6ab58a 100644 --- a/src/persistence/pemstore.rs +++ b/src/persistence/pemstore.rs @@ -5,6 +5,13 @@ use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; +pub fn read_keypair_from_disk(id: String) -> KeyPair { + let pathfinder = Pathfinder::new(id); + let pem_store = PemStore::new(pathfinder); + let keypair = pem_store.read(); + keypair +} + pub struct PemStore { config_dir: PathBuf, private_mix_key: PathBuf, diff --git a/src/sockets/mod.rs b/src/sockets/mod.rs index 6757c99679..86dd43f872 100644 --- a/src/sockets/mod.rs +++ b/src/sockets/mod.rs @@ -1 +1,2 @@ +pub mod tcp; pub mod ws; diff --git a/src/sockets/tcp.rs b/src/sockets/tcp.rs index e69de29bb2..a9475ab1cb 100644 --- a/src/sockets/tcp.rs +++ b/src/sockets/tcp.rs @@ -0,0 +1,5 @@ +use std::net::SocketAddr; + +pub fn start(_socket_address: SocketAddr) { + println!("TCP server time!!!"); +} From c02a44fbce5eccf88e2484cd0e069fc536272de2 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 15:21:48 +0000 Subject: [PATCH 131/167] Ability to send mix messages from websocket --- src/clients/mod.rs | 31 ++----- src/commands/run.rs | 16 ++-- src/commands/websocket.rs | 12 ++- src/lib.rs | 1 + src/sockets/ws.rs | 179 ++++++++++++++++++++++++-------------- 5 files changed, 141 insertions(+), 98 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index eedf26b14c..cd0ccc099a 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -9,7 +9,9 @@ use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; use sphinx::SphinxPacket; use std::time::Duration; use tokio::runtime::Runtime; -use futures::future::join4; +use futures::future::join5; +use crate::sockets::ws; +use std::net::SocketAddr; pub mod directory; pub mod mix; @@ -17,7 +19,7 @@ pub mod provider; pub mod validator; // TODO: put that in config once it exists -const LOOP_COVER_AVERAGE_DELAY: f64 = 0.5; +const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; // assume seconds const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; // assume seconds; @@ -134,30 +136,14 @@ impl NymClient { } } - pub fn start(self) -> Result<(), Box> { + pub fn start(self, socket_address: SocketAddr) -> Result<(), Box> { println!("starting nym client"); let (mix_tx, mix_rx) = mpsc::unbounded(); let mut rt = Runtime::new()?; - let topology = get_topology(self.is_local); - -// let mut input_channel = self.input_tx.clone(); -// let bar = self.address.clone(); -// rt.spawn(async move { -// loop { -// let foomp = Destination::new(bar, Default::default()); -// -// let test_message = b"foomp".to_vec(); -// let recipient = foomp; -// let input_message = InputMessage(recipient, test_message); -// input_channel.send(input_message).await.unwrap(); -// tokio::time::delay_for(Duration::from_secs(1)).await; -// } -// }); - let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( mix_tx.clone(), @@ -173,13 +159,12 @@ impl NymClient { )); let provider_polling_future = rt.spawn(NymClient::start_provider_polling()); - - // TODO: websocket handler future + let websocket_future = rt.spawn(ws::start_websocket(socket_address, self.input_tx)); rt.block_on(async { - let future_results = join4(mix_traffic_future, loop_cover_traffic_future, out_queue_control_future, provider_polling_future).await; + let future_results = join5(mix_traffic_future, loop_cover_traffic_future, out_queue_control_future, provider_polling_future, websocket_future).await; assert!( - future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() && future_results.3.is_ok() + future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() && future_results.3.is_ok() && future_results.4.is_ok() ); }); diff --git a/src/commands/run.rs b/src/commands/run.rs index 81afdad7aa..6999237eaf 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -17,14 +17,16 @@ use tokio::runtime::Runtime; use tokio::time::{interval_at, Instant}; pub fn execute(matches: &ArgMatches) { - let is_local = matches.is_present("local"); - println!("Starting client, local: {:?}", is_local); + unimplemented!() // currently the 'run' starts websocket! - // todo: to be taken from config or something - let my_address = [42u8; 32]; - let is_local = true; - let client = NymClient::new(my_address, is_local); - client.start().unwrap(); + // let is_local = matches.is_present("local"); + // println!("Starting client, local: {:?}", is_local); + // + // // todo: to be taken from config or something + // let my_address = [42u8; 32]; + // let is_local = true; + // let client = NymClient::new(my_address, is_local); + // client.start().unwrap(); // Grab the network topology from the remote directory server // let topology = get_topology(is_local); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 7d9889019c..59a2e7492b 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -1,5 +1,5 @@ use crate::banner; -use crate::sockets::ws; +use crate::clients::NymClient; use clap::ArgMatches; use std::net::ToSocketAddrs; @@ -19,5 +19,13 @@ pub fn execute(matches: &ArgMatches) { .next() .expect("Failed to extract the socket address from the iterator"); - ws::start(socket_address); + let is_local = matches.is_present("local"); + println!("Starting client, local: {:?}", is_local); + + // todo: to be taken from config or something + let my_address = [42u8; 32]; + let is_local = true; + let client = NymClient::new(my_address, is_local); + + client.start(socket_address).unwrap(); } diff --git a/src/lib.rs b/src/lib.rs index 0574ba4a4e..5f1dc2a7c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ pub mod clients; pub mod identity; pub mod persistence; +pub mod sockets; pub mod utils; diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index 832f5d5da9..b4778a15ae 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,98 +1,148 @@ use crate::clients::InputMessage; use futures::channel::mpsc; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; -use futures::stream::Stream; -use futures::Future; use futures::{SinkExt, StreamExt}; -use hex::FromHexError; use serde::{Deserialize, Serialize}; -use serde_json::Value; use sphinx::route::Destination; use std::net::SocketAddr; -use tokio::runtime::Runtime; -use tokio_tungstenite::accept_async; use tungstenite::protocol::Message; -use std::time::Duration; +use std::io; +use futures::io::Error; struct Connection { address: SocketAddr, rx: UnboundedReceiver, tx: UnboundedSender, + + msg_input: mpsc::UnboundedSender, } #[derive(Debug)] -enum WebSocketError { - InvalidDestinationEncoding, - InvalidDestinationLength, +pub enum WebSocketError { + FailedToStartSocketError, + UnknownSocketError, } -impl From for WebSocketError { - fn from(_: FromHexError) -> Self { +impl From for WebSocketError { + fn from(err: Error) -> Self { use WebSocketError::*; + match err.kind() { + io::ErrorKind::ConnectionRefused => FailedToStartSocketError, + io::ErrorKind::ConnectionReset => FailedToStartSocketError, + io::ErrorKind::ConnectionAborted => FailedToStartSocketError, + io::ErrorKind::NotConnected => FailedToStartSocketError, - InvalidDestinationEncoding + io::ErrorKind::AddrInUse => FailedToStartSocketError, + io::ErrorKind::AddrNotAvailable => FailedToStartSocketError, + _ => UnknownSocketError, + } } } + #[derive(Serialize, Deserialize, Debug)] -struct ClientMessageJSON { - message: String, - recipient_address: String, +#[serde(tag = "type", rename_all = "camelCase")] +enum ClientRequest { + Send { message: String, recipient_address: String }, + Fetch, + GetClients, + OwnDetails, +} + +impl From for ClientRequest { + fn from(msg: Message) -> Self { + let text_msg = match msg { + Message::Text(msg) => msg, + Message::Binary(_) => panic!("binary messages are not supported!"), + Message::Close(_) => panic!("todo: handle close!"), + _ => panic!("Other types of messages are also unsupported!"), + }; + serde_json::from_str(&text_msg).unwrap() + } +} + +impl ClientRequest { + async fn handle_send(msg: String, recipient_address: String, mut input_tx: mpsc::UnboundedSender) -> ServerResponse { + let address_vec = match hex::decode(recipient_address) { + Err(e) => return ServerResponse::Error { message: e.to_string() }, + Ok(hex) => hex, + }; + + if address_vec.len() != 32 { + return ServerResponse::Error { message: "InvalidDestinationLength".to_string() }; + } + + let mut address = [0; 32]; + address.copy_from_slice(&address_vec); + + let dummy_surb = [0; 16]; + + let input_msg = InputMessage( + Destination::new(address, dummy_surb), + msg.into_bytes(), + ); + + input_tx.send(input_msg).await.unwrap(); + + ServerResponse::Send + } + + async fn handle_fetch() -> ServerResponse { + ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + } + + async fn handle_get_clients() -> ServerResponse { + ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + } + + async fn handle_own_details() -> ServerResponse { + ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + } +} + +#[derive(Serialize, Deserialize, Debug)] +#[serde(tag = "type", rename_all = "camelCase")] +enum ServerResponse { + Send, + Fetch { messages: Vec> }, + GetClients { clients: Vec }, + OwnDetails { address: String }, + Error { message: String }, } fn dummy_response() -> Message { Message::Text("foomp".to_string()) } +impl Into for ServerResponse { + fn into(self) -> Message { + dummy_response() + } +} + + async fn handle_connection(conn: Connection) { let mut conn = conn; while let Some(msg) = conn.rx.next().await { println!("Received a message from {}: {}", conn.address, msg); - // TODO: currently only hardcoded sends are supported - let parsed_message = parse_message(msg); - println!("parsed: {:?}", parsed_message); - println!("test async pre wait"); + let request: ClientRequest = msg.into(); - tokio::time::delay_for(Duration::from_secs(2)).await; + let response = match request { + ClientRequest::Send { message, recipient_address } => ClientRequest::handle_send(message, recipient_address, conn.msg_input.clone()).await, + ClientRequest::Fetch => ClientRequest::handle_fetch().await, + ClientRequest::GetClients => ClientRequest::handle_get_clients().await, + ClientRequest::OwnDetails => ClientRequest::handle_own_details().await, + }; - println!("test async post wait"); conn .tx - .unbounded_send(dummy_response()) + .unbounded_send(response.into()) .expect("Failed to forward message"); } } -// Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts -// the `send_message` functionality. -fn parse_message(msg: Message) -> Result { - let text_msg = match msg { - Message::Text(msg) => msg, - Message::Binary(_) => panic!("binary messages are not supported!"), - Message::Close(_) => panic!("todo: handle close!"), - _ => panic!("Other types of messages are also unsupported!"), - }; - - let raw_msg: ClientMessageJSON = serde_json::from_str(&text_msg).unwrap(); - let address_vec = hex::decode(raw_msg.recipient_address)?; - - if address_vec.len() != 32 { - return Err(WebSocketError::InvalidDestinationLength); - } - - let mut address = [0; 32]; - address.copy_from_slice(&address_vec); - - let dummy_surb = [0; 16]; - - Ok(InputMessage( - Destination::new(address, dummy_surb), - raw_msg.message.into_bytes(), - )) -} - -async fn accept_connection(stream: tokio::net::TcpStream) { +async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::UnboundedSender) { let address = stream .peer_addr() .expect("connected streams should have a peer address"); @@ -113,6 +163,8 @@ async fn accept_connection(stream: tokio::net::TcpStream) { address, rx: msg_rx, tx: response_tx, + + msg_input, }; tokio::spawn(handle_connection(conn)); @@ -127,21 +179,16 @@ async fn accept_connection(stream: tokio::net::TcpStream) { } } +pub async fn start_websocket(address: SocketAddr, message_tx: mpsc::UnboundedSender) -> Result<(), WebSocketError> { + let mut listener = tokio::net::TcpListener::bind(address).await?; + while let Ok((stream, _)) = listener.accept().await { + // it's fine to be cloning the channel on all new connection, because in principle + // this server should only EVER have a single client connected + tokio::spawn(accept_connection(stream, message_tx.clone())); + } -pub fn start(address: SocketAddr) -> Result<(), Box> { - let mut rt = Runtime::new()?; - - rt.block_on(async { - let mut listener = tokio::net::TcpListener::bind(address).await?; - - while let Ok((stream, _)) = listener.accept().await { - // TODO: should it rather be rt.spawn? - tokio::spawn(accept_connection(stream)); - } - - eprintln!("The websocket went kaput..."); - Ok(()) - }) + eprintln!("The websocket went kaput..."); + Ok(()) } From 4918ed50f1edb99267182a57e7dd5f15bd9bd36c Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 16:00:15 +0000 Subject: [PATCH 132/167] Most-merge conflicts --- src/commands/run.rs | 2 +- src/commands/websocket.rs | 6 +----- src/main.rs | 8 ++------ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index dc19422b96..552a6469a6 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -12,5 +12,5 @@ pub fn execute(matches: &ArgMatches) { let keypair = pemstore::read_keypair_from_disk(id); let client = NymClient::new(keypair.public_bytes(), is_local); - client.start().unwrap(); + client.start("127.0.0.1:9000".parse().unwrap()).unwrap(); } diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 6c121b6e19..97fb915afc 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -25,12 +25,8 @@ pub fn execute(matches: &ArgMatches) { .next() .expect("Failed to extract the socket address from the iterator"); - - let is_local = matches.is_present("local"); - println!("Starting client, local: {:?}", is_local); - let keypair = pemstore::read_keypair_from_disk(id); let client = NymClient::new(keypair.public_bytes(), is_local); client.start(socket_address).unwrap(); - +} diff --git a/src/main.rs b/src/main.rs index 152cb00167..8167f91339 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,7 +53,8 @@ fn main() { .help("Port for TCP socket to listen on") .takes_value(true) .required(true), - ).arg(Arg::with_name("local") + ) + .arg(Arg::with_name("local") .long("local") .help("Flag to indicate whether the client is expected to run on the local deployment.") .takes_value(false) @@ -64,11 +65,6 @@ fn main() { .takes_value(true) .required(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) - ) ) .subcommand( SubCommand::with_name("websocket") From 3fb8ebbfeedc66f090dece18b96e69466d5fde53 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 17 Dec 2019 16:05:25 +0000 Subject: [PATCH 133/167] Changed tokio tungstenite to use specific commit --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb8d66ab7c..ffc598306d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1038,7 +1038,7 @@ dependencies = [ "sfw-provider-requests 0.1.0", "sphinx 0.1.0", "tokio 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2)", + "tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?rev=6dc2018cbfe8fe7ddd75ff977343086503135b38)", "tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1871,7 +1871,7 @@ dependencies = [ [[package]] name = "tokio-tungstenite" version = "0.10.0" -source = "git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2#6dc2018cbfe8fe7ddd75ff977343086503135b38" +source = "git+https://github.com/dbcfd/tokio-tungstenite?rev=6dc2018cbfe8fe7ddd75ff977343086503135b38#6dc2018cbfe8fe7ddd75ff977343086503135b38" dependencies = [ "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2270,7 +2270,7 @@ dependencies = [ "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c32ffea4827978e9aa392d2f743d973c1dfa3730a2ed3f22ce1e6984da848c" "checksum tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1739638e364e558128461fc1ad84d997702c8e31c2e6b18fb99842268199e827" -"checksum tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?branch=tokio2)" = "" +"checksum tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?rev=6dc2018cbfe8fe7ddd75ff977343086503135b38)" = "" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8a0c2bd5aeb7dcd2bb32e472c8872759308495e5eccc942e929a513cd8d36110" diff --git a/Cargo.toml b/Cargo.toml index 0ca4ee4fd7..73ad293fb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ tokio = { version = "0.2", features = ["full"] } tungstenite = "0.9.2" # putting this explicitly below everything and most likely, the next time we look into it, it will already have a proper release -tokio-tungstenite = { git = "https://github.com/dbcfd/tokio-tungstenite", branch = "tokio2" } +tokio-tungstenite = { git = "https://github.com/dbcfd/tokio-tungstenite", rev="6dc2018cbfe8fe7ddd75ff977343086503135b38" } [dev-dependencies] mockito = "0.22.0" From 4c3a5ac9d3c0d159df4f66e1964595159192815b Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 17:26:24 +0000 Subject: [PATCH 134/167] client: generating a random route. --- src/utils/sphinx.rs | 2 +- src/utils/topology.rs | 44 ++++++++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 3114dbea8f..fffb3a2efe 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -21,7 +21,7 @@ pub fn encapsulate_message( message: Vec, topology: &Topology, ) -> (NodeAddressBytes, SphinxPacket) { - let mixes_route = topology::route_from(&topology, 1); + let mixes_route = topology::route_from(&topology); let first_provider = topology.mix_provider_nodes.first().unwrap(); let decoded_key_bytes = base64::decode_config(&first_provider.pub_key, base64::URL_SAFE).unwrap(); diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 6bc8e59169..1580ef8f91 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -1,10 +1,13 @@ use crate::clients::directory; +use crate::clients::directory::presence::MixNodePresence; use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; use crate::utils::bytes; use curve25519_dalek::montgomery::MontgomeryPoint; +use rand::seq::SliceRandom; use sphinx::route::Node as SphinxNode; +use std::collections::HashMap; use std::net::SocketAddrV4; use std::string::ToString; @@ -25,21 +28,36 @@ pub(crate) fn get_topology(is_local: bool) -> Topology { topology } -pub(crate) fn route_from(topology: &Topology, route_len: usize) -> Vec { - let mut route = vec![]; - let nodes = topology.mix_nodes.iter(); - for mix in nodes.take(route_len) { - let address_bytes = socket_bytes_from_string(mix.host.clone()); - let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); - let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); - let key = MontgomeryPoint(key_bytes); - let sphinx_node = SphinxNode { - address: address_bytes, - pub_key: key, - }; - route.push(sphinx_node); +pub(crate) fn route_from(topology: &Topology) -> Vec { + let mut layered_topology: HashMap> = HashMap::new(); + let mixes = topology.mix_nodes.iter(); + for mix in mixes { + let layer_nodes = layered_topology.entry(mix.layer).or_insert(Vec::new()); + layer_nodes.push(mix.clone()); } + + let num_layers = layered_topology.len() as u64; + let mut route = vec![]; + + for x in 1..=num_layers { + let nodes = &layered_topology[&x]; + let the_node = nodes.choose(&mut rand::thread_rng()).unwrap(); + route.push(the_node); + } + route + .iter() + .map(|mix| { + let address_bytes = socket_bytes_from_string(mix.host.clone()); + let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); + let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); + let key = MontgomeryPoint(key_bytes); + SphinxNode { + address: address_bytes, + pub_key: key, + } + }) + .collect() } pub(crate) fn socket_bytes_from_string(address: String) -> [u8; 32] { From c81f2e860c6671bbf66289316abee7a8431d90d8 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Tue, 17 Dec 2019 17:26:42 +0000 Subject: [PATCH 135/167] commands: removing unused import --- src/commands/websocket.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 97fb915afc..d26ba5c988 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -1,7 +1,6 @@ use crate::banner; use crate::clients::NymClient; use crate::persistence::pemstore; -use crate::sockets::ws; use clap::ArgMatches; use std::net::ToSocketAddrs; From 5915e459611bf2b60b034c63489916baa6d403f7 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 10:22:24 +0000 Subject: [PATCH 136/167] Made code compile + moved address to provider client constructor --- src/clients/mod.rs | 10 ++++++++-- src/clients/provider.rs | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 39975b339b..dd818526df 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -130,14 +130,14 @@ impl NymClient { } async fn start_provider_polling(provider_address: SocketAddrV4) { - let provider_client = ProviderClient::new(); + let provider_client = ProviderClient::new(provider_address); loop { println!("[FETCH MSG] - Polling provider..."); let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; provider_client - .retrieve_messages(provider_address) + .retrieve_messages() .await .unwrap(); } @@ -146,6 +146,12 @@ impl NymClient { pub fn start(self, socket_address: SocketAddr) -> Result<(), Box> { println!("starting nym client"); + + // TODO: registration here + + return Ok(()); + // don't start anything, just register + let (mix_tx, mix_rx) = mpsc::unbounded(); let mut rt = Runtime::new()?; let topology = get_topology(self.is_local); diff --git a/src/clients/provider.rs b/src/clients/provider.rs index ff2fdb6bac..5991b42288 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,29 +1,33 @@ use sfw_provider_requests::requests::{ProviderRequest, PullRequest}; use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; -use std::net::Shutdown; +use std::net::{Shutdown, SocketAddr}; use std::net::SocketAddrV4; use tokio::prelude::*; -use tokio::time::Duration; +use std::time::Duration; -pub struct ProviderClient {} +pub struct ProviderClient { + address: SocketAddrV4, +} impl ProviderClient { - pub fn new() -> Self { - ProviderClient {} + pub fn new(address: SocketAddrV4) -> Self { + ProviderClient { + address + } } pub async fn retrieve_messages( &self, - provider: SocketAddrV4, ) -> Result<(), Box> { - let address = [42; 32]; - let pull_request = PullRequest::new(address); + let destination_address = [42u8; 32]; + let dummy_auth_token_to_make_it_compile = [0u8; 32]; + let pull_request = PullRequest::new(destination_address, dummy_auth_token_to_make_it_compile); let bytes = pull_request.to_bytes(); // DH temporary: the provider's client port is not in the topology, but we can't change that // right now without messing up the existing Go mixnet. So I'm going to hardcode this // for the moment until the Go mixnet goes away. - let provider_socket = SocketAddrV4::new(*provider.ip(), 9000); + let provider_socket = SocketAddrV4::new(*self.address.ip(), 9000); println!("Provider: {:?}", provider_socket); let mut socket = tokio::net::TcpStream::connect(provider_socket).await?; From 812a0fe1446023d989898e6f3a86f91d3a29a421 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 10:25:32 +0000 Subject: [PATCH 137/167] Deprecated run command --- src/commands/run.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/commands/run.rs b/src/commands/run.rs index 552a6469a6..e239986209 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -5,12 +5,13 @@ use clap::ArgMatches; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - - let is_local = matches.is_present("local"); - let id = matches.value_of("id").unwrap().to_string(); - println!("Starting client..."); - - let keypair = pemstore::read_keypair_from_disk(id); - let client = NymClient::new(keypair.public_bytes(), is_local); - client.start("127.0.0.1:9000".parse().unwrap()).unwrap(); + panic!("For time being this command is deprecated! Please use 'websocket' instead"); + // + // let is_local = matches.is_present("local"); + // let id = matches.value_of("id").unwrap().to_string(); + // println!("Starting client..."); + // + // let keypair = pemstore::read_keypair_from_disk(id); + // let client = NymClient::new(keypair.public_bytes(), is_local); + // client.start("127.0.0.1:9000".parse().unwrap()).unwrap(); } From 6726329e2c0af1ba7743addfaacb227ff0e2033f Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 10:26:53 +0000 Subject: [PATCH 138/167] Optional auth token for client constructor --- src/clients/mod.rs | 9 ++++++++- src/commands/tcpsocket.rs | 2 +- src/commands/websocket.rs | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index dd818526df..a9b08bf7e3 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -14,6 +14,7 @@ use std::net::SocketAddr; use std::net::SocketAddrV4; use std::time::Duration; use tokio::runtime::Runtime; +use sfw_provider_requests::requests::AuthToken; pub mod directory; pub mod mix; @@ -65,13 +66,14 @@ pub struct NymClient { input_rx: mpsc::UnboundedReceiver, is_local: bool, + auth_token: Option } #[derive(Debug)] pub struct InputMessage(pub Destination, pub Vec); impl NymClient { - pub fn new(address: DestinationAddressBytes, is_local: bool) -> Self { + pub fn new(address: DestinationAddressBytes, is_local: bool, auth_token: Option) -> Self { let (input_tx, input_rx) = mpsc::unbounded::(); NymClient { @@ -79,6 +81,7 @@ impl NymClient { input_tx, input_rx, is_local, + auth_token, } } @@ -147,6 +150,10 @@ impl NymClient { println!("starting nym client"); + match self.auth_token { + None => println!("Need to register!"), + Some(token) => println!("Already got the token! - {:?}", token), + } // TODO: registration here return Ok(()); diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index 1e3a21f1d1..c6163a37ac 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -26,7 +26,7 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to extract the socket address from the iterator"); let keypair = pemstore::read_keypair_from_disk(id); - let _client = NymClient::new(keypair.public_bytes(), is_local); + let _client = NymClient::new(keypair.public_bytes(), is_local, None); // Question: should we be passing the client into the TCP socket somehow next? tcp::start(socket_address); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index d26ba5c988..9150a69baa 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -25,7 +25,9 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to extract the socket address from the iterator"); let keypair = pemstore::read_keypair_from_disk(id); - let client = NymClient::new(keypair.public_bytes(), is_local); + // TODO: reading auth_token from disk (if exists); + let auth_token = None; + let client = NymClient::new(keypair.public_bytes(), is_local, auth_token); client.start(socket_address).unwrap(); } From 7a57078c65ff9c4f923e31b3bef948c2fecb9646 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 10:30:27 +0000 Subject: [PATCH 139/167] Moved socket address from start method to new --- src/clients/mod.rs | 9 +++++---- src/commands/tcpsocket.rs | 7 ++++++- src/commands/websocket.rs | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index a9b08bf7e3..d5734f9b5f 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -64,7 +64,7 @@ pub struct NymClient { pub input_tx: mpsc::UnboundedSender, // to be used by "send" function or socket, etc input_rx: mpsc::UnboundedReceiver, - + socket_listening_address: SocketAddr, is_local: bool, auth_token: Option } @@ -73,13 +73,14 @@ pub struct NymClient { pub struct InputMessage(pub Destination, pub Vec); impl NymClient { - pub fn new(address: DestinationAddressBytes, is_local: bool, auth_token: Option) -> Self { + pub fn new(address: DestinationAddressBytes, socket_listening_address: SocketAddr, is_local: bool, auth_token: Option) -> Self { let (input_tx, input_rx) = mpsc::unbounded::(); NymClient { address, input_tx, input_rx, + socket_listening_address, is_local, auth_token, } @@ -146,7 +147,7 @@ impl NymClient { } } - pub fn start(self, socket_address: SocketAddr) -> Result<(), Box> { + pub fn start(self) -> Result<(), Box> { println!("starting nym client"); @@ -185,7 +186,7 @@ impl NymClient { )); let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_address)); - let websocket_future = rt.spawn(ws::start_websocket(socket_address, self.input_tx)); + let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx)); rt.block_on(async { let future_results = join5( diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index c6163a37ac..4ba652bcd6 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -26,7 +26,12 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to extract the socket address from the iterator"); let keypair = pemstore::read_keypair_from_disk(id); - let _client = NymClient::new(keypair.public_bytes(), is_local, None); + let _client = NymClient::new( + keypair.public_bytes(), + socket_address.clone(), + is_local, + None, + ); // Question: should we be passing the client into the TCP socket somehow next? tcp::start(socket_address); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 9150a69baa..36a88ea9ed 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -27,7 +27,7 @@ pub fn execute(matches: &ArgMatches) { let keypair = pemstore::read_keypair_from_disk(id); // TODO: reading auth_token from disk (if exists); let auth_token = None; - let client = NymClient::new(keypair.public_bytes(), is_local, auth_token); + let client = NymClient::new(keypair.public_bytes(), socket_address, is_local, auth_token); - client.start(socket_address).unwrap(); + client.start().unwrap(); } From ef0e1d081d5cc160ffb746ff5d031579c170907b Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 10:58:47 +0000 Subject: [PATCH 140/167] Included address and auth token to provider client --- src/clients/mod.rs | 26 +++++++++++++---------- src/clients/provider.rs | 47 +++++++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index d5734f9b5f..0b18df060d 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -133,8 +133,8 @@ impl NymClient { } } - async fn start_provider_polling(provider_address: SocketAddrV4) { - let provider_client = ProviderClient::new(provider_address); + async fn start_provider_polling(provider_client: ProviderClient) { +// let provider_client = ProviderClient::new(provider_address); loop { println!("[FETCH MSG] - Polling provider..."); @@ -150,6 +150,18 @@ impl NymClient { pub fn start(self) -> Result<(), Box> { println!("starting nym client"); + let topology = get_topology(self.is_local); + let provider_address: SocketAddrV4 = topology + .mix_provider_nodes + .first() + .unwrap() + .host + .parse() + .unwrap(); + + + + let provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); match self.auth_token { None => println!("Need to register!"), @@ -162,14 +174,6 @@ impl NymClient { let (mix_tx, mix_rx) = mpsc::unbounded(); let mut rt = Runtime::new()?; - let topology = get_topology(self.is_local); - let provider_address: SocketAddrV4 = topology - .mix_provider_nodes - .first() - .unwrap() - .host - .parse() - .unwrap(); let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( @@ -185,7 +189,7 @@ impl NymClient { topology.clone(), )); - let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_address)); + let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_client)); let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx)); rt.block_on(async { diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 5991b42288..1e0f978077 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,33 +1,56 @@ -use sfw_provider_requests::requests::{ProviderRequest, PullRequest}; +use sfw_provider_requests::requests::{ProviderRequest, PullRequest, AuthToken, RegisterRequest}; use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; use std::net::{Shutdown, SocketAddr}; use std::net::SocketAddrV4; use tokio::prelude::*; use std::time::Duration; +use sphinx::route::DestinationAddressBytes; +use futures::io::Error; + +#[derive(Debug)] +pub enum ProviderClientError { + EmptyAuthTokenError, + NetworkError, +} + +impl From for ProviderClientError { + fn from(_: Error) -> Self { + use ProviderClientError::*; + + NetworkError + } +} + pub struct ProviderClient { - address: SocketAddrV4, + provider_network_address: SocketAddrV4, + our_address: DestinationAddressBytes, + auth_token: Option, } impl ProviderClient { - pub fn new(address: SocketAddrV4) -> Self { + pub fn new(provider_network_address: SocketAddrV4, our_address: DestinationAddressBytes, auth_token: Option) -> Self { ProviderClient { - address + provider_network_address, + our_address, + auth_token, } } pub async fn retrieve_messages( &self, - ) -> Result<(), Box> { - let destination_address = [42u8; 32]; - let dummy_auth_token_to_make_it_compile = [0u8; 32]; - let pull_request = PullRequest::new(destination_address, dummy_auth_token_to_make_it_compile); + ) -> Result<(), ProviderClientError> { + if self.auth_token.is_none() { + return Err(ProviderClientError::EmptyAuthTokenError) + } + + let pull_request = PullRequest::new(self.our_address, self.auth_token.unwrap()); let bytes = pull_request.to_bytes(); // DH temporary: the provider's client port is not in the topology, but we can't change that // right now without messing up the existing Go mixnet. So I'm going to hardcode this // for the moment until the Go mixnet goes away. - let provider_socket = SocketAddrV4::new(*self.address.ip(), 9000); + let provider_socket = SocketAddrV4::new(*self.provider_network_address.ip(), 9000); println!("Provider: {:?}", provider_socket); let mut socket = tokio::net::TcpStream::connect(provider_socket).await?; @@ -51,4 +74,10 @@ impl ProviderClient { } Ok(()) } + + pub async fn register(&mut self) -> Result> { + let register_request = RegisterRequest::new(self.our_address); + + Ok([0;32]) + } } From d08e51461b0ba98e1c81465e5ecb10073691b9a0 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 11:04:13 +0000 Subject: [PATCH 141/167] Overwriting provider address at 'new' --- src/clients/provider.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 1e0f978077..6802669772 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -30,8 +30,13 @@ pub struct ProviderClient { impl ProviderClient { pub fn new(provider_network_address: SocketAddrV4, our_address: DestinationAddressBytes, auth_token: Option) -> Self { + // DH temporary: the provider's client port is not in the topology, but we can't change that + // right now without messing up the existing Go mixnet. So I'm going to hardcode this + // for the moment until the Go mixnet goes away. + let provider_socket = SocketAddrV4::new(*provider_network_address.ip(), 9000); + ProviderClient { - provider_network_address, + provider_network_address: provider_socket, our_address, auth_token, } @@ -47,13 +52,7 @@ impl ProviderClient { let pull_request = PullRequest::new(self.our_address, self.auth_token.unwrap()); let bytes = pull_request.to_bytes(); - // DH temporary: the provider's client port is not in the topology, but we can't change that - // right now without messing up the existing Go mixnet. So I'm going to hardcode this - // for the moment until the Go mixnet goes away. - let provider_socket = SocketAddrV4::new(*self.provider_network_address.ip(), 9000); - println!("Provider: {:?}", provider_socket); - - let mut socket = tokio::net::TcpStream::connect(provider_socket).await?; + let mut socket = tokio::net::TcpStream::connect(self.provider_network_address).await?; println!("keep alive: {:?}", socket.keepalive()); socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); socket.write_all(&bytes[..]).await?; From bc143c16c0014e7cab622a5a87de502bb39d2564 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 11:11:07 +0000 Subject: [PATCH 142/167] Moved sending bytes to provider to separate method --- src/clients/provider.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 6802669772..9836d7f242 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -42,6 +42,26 @@ impl ProviderClient { } } + pub async fn send_request(&self, bytes: Vec) -> Result, ProviderClientError> { + let mut socket = tokio::net::TcpStream::connect(self.provider_network_address).await?; + println!("keep alive: {:?}", socket.keepalive()); + socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); + socket.write_all(&bytes[..]).await?; + if let Err(e) = socket.shutdown(Shutdown::Write) { + // TODO: make it a silent log once we have a proper logging library +// eprintln!("failed to close write part of the socket; err = {:?}", e) + } + + let mut response = Vec::new(); + socket.read_to_end(&mut response).await?; + if let Err(e) = socket.shutdown(Shutdown::Read) { + // TODO: make it a silent log once we have a proper logging library +// eprintln!("failed to close read part of the socket; err = {:?}", e) + } + + Ok(response) + } + pub async fn retrieve_messages( &self, ) -> Result<(), ProviderClientError> { @@ -52,21 +72,9 @@ impl ProviderClient { let pull_request = PullRequest::new(self.our_address, self.auth_token.unwrap()); let bytes = pull_request.to_bytes(); - let mut socket = tokio::net::TcpStream::connect(self.provider_network_address).await?; - println!("keep alive: {:?}", socket.keepalive()); - socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); - socket.write_all(&bytes[..]).await?; - if let Err(e) = socket.shutdown(Shutdown::Write) { - eprintln!("failed to close write part of the socket; err = {:?}", e) - } - - let mut response = Vec::new(); - socket.read_to_end(&mut response).await?; - if let Err(e) = socket.shutdown(Shutdown::Read) { - eprintln!("failed to close read part of the socket; err = {:?}", e) - } - + let response = self.send_request(bytes).await?; println!("Received the following response: {:?}", response); + let parsed_response = PullResponse::from_bytes(&response).unwrap(); for message in parsed_response.messages { println!("Received: {:?}", String::from_utf8(message).unwrap()) From 2b89be303137d7be399b4456f2c06d4d3f1ca0e8 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 11:20:52 +0000 Subject: [PATCH 143/167] Basic structure for client registration message send --- src/clients/provider.rs | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 9836d7f242..6b951dd0f4 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,5 +1,5 @@ use sfw_provider_requests::requests::{ProviderRequest, PullRequest, AuthToken, RegisterRequest}; -use sfw_provider_requests::responses::{ProviderResponse, PullResponse}; +use sfw_provider_requests::responses::{ProviderResponse, PullResponse, RegisterResponse, ProviderResponseError}; use std::net::{Shutdown, SocketAddr}; use std::net::SocketAddrV4; use tokio::prelude::*; @@ -9,8 +9,13 @@ use futures::io::Error; #[derive(Debug)] pub enum ProviderClientError { + ClientAlreadyRegisteredError, EmptyAuthTokenError, NetworkError, + + InvalidRequestError, + InvalidResponseError, + InvalidResponseLengthError, } impl From for ProviderClientError { @@ -21,6 +26,16 @@ impl From for ProviderClientError { } } +impl From for ProviderClientError { + fn from(err: ProviderResponseError) -> Self { + use ProviderClientError::*; + match err { + ProviderResponseError::MarshalError => InvalidRequestError, + ProviderResponseError::UnmarshalError => InvalidResponseError, + ProviderResponseError::UnmarshalErrorInvalidLength => InvalidResponseLengthError, + } + } +} pub struct ProviderClient { provider_network_address: SocketAddrV4, @@ -74,16 +89,29 @@ impl ProviderClient { let response = self.send_request(bytes).await?; println!("Received the following response: {:?}", response); - - let parsed_response = PullResponse::from_bytes(&response).unwrap(); + + let parsed_response = PullResponse::from_bytes(&response)?; for message in parsed_response.messages { println!("Received: {:?}", String::from_utf8(message).unwrap()) } + + // TODO: make it return the actual messages instead Ok(()) } - pub async fn register(&mut self) -> Result> { + pub async fn register(&mut self) -> Result { + if self.auth_token.is_some() { + return Err(ProviderClientError::ClientAlreadyRegisteredError); + } + let register_request = RegisterRequest::new(self.our_address); + let bytes = register_request.to_bytes(); + + let response = self.send_request(bytes).await?; + println!("Received the following response: {:?}", response); + + let parsed_response = RegisterResponse::from_bytes(&response)?; + println!("parsed register: {:?}", parsed_response); Ok([0;32]) } From 0fe7276d447ef33f5885c465235aa3fccd111cd0 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 11:22:46 +0000 Subject: [PATCH 144/167] Method to update auth token of provider client + removed mut from register --- src/clients/provider.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 6b951dd0f4..cf986041ed 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -57,6 +57,10 @@ impl ProviderClient { } } + pub fn update_token(&mut self, auth_token: AuthToken) { + self.auth_token = Some(auth_token) + } + pub async fn send_request(&self, bytes: Vec) -> Result, ProviderClientError> { let mut socket = tokio::net::TcpStream::connect(self.provider_network_address).await?; println!("keep alive: {:?}", socket.keepalive()); @@ -99,7 +103,7 @@ impl ProviderClient { Ok(()) } - pub async fn register(&mut self) -> Result { + pub async fn register(&self) -> Result { if self.auth_token.is_some() { return Err(ProviderClientError::ClientAlreadyRegisteredError); } From 441a6c3e1b7ed9c2554f78b7cbe765c5dbe1d5ca Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 14:25:29 +0000 Subject: [PATCH 145/167] Client sending registration request on startup --- src/clients/mod.rs | 25 +++++++++++++++++-------- src/clients/provider.rs | 14 +++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 0b18df060d..ff58ece3cf 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -140,15 +140,19 @@ impl NymClient { println!("[FETCH MSG] - Polling provider..."); let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; - provider_client + let messages = provider_client .retrieve_messages() .await .unwrap(); + for message in messages { + println!("Retrieved: {:?}", String::from_utf8(message).unwrap()) + } } } pub fn start(self) -> Result<(), Box> { println!("starting nym client"); + let mut rt = Runtime::new()?; let topology = get_topology(self.is_local); let provider_address: SocketAddrV4 = topology @@ -161,19 +165,24 @@ impl NymClient { - let provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); + let mut provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); + + rt.block_on(async { + match self.auth_token { + None => { + let auth_token = provider_client.register().await.unwrap(); + provider_client.update_token(auth_token); + println!("Obtained new token! - {:?}", auth_token); + }, + Some(token) => println!("Already got the token! - {:?}", token), + } + }); - match self.auth_token { - None => println!("Need to register!"), - Some(token) => println!("Already got the token! - {:?}", token), - } - // TODO: registration here return Ok(()); // don't start anything, just register let (mix_tx, mix_rx) = mpsc::unbounded(); - let mut rt = Runtime::new()?; let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( diff --git a/src/clients/provider.rs b/src/clients/provider.rs index cf986041ed..28c028596d 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -83,7 +83,7 @@ impl ProviderClient { pub async fn retrieve_messages( &self, - ) -> Result<(), ProviderClientError> { + ) -> Result>, ProviderClientError> { if self.auth_token.is_none() { return Err(ProviderClientError::EmptyAuthTokenError) } @@ -95,12 +95,7 @@ impl ProviderClient { println!("Received the following response: {:?}", response); let parsed_response = PullResponse::from_bytes(&response)?; - for message in parsed_response.messages { - println!("Received: {:?}", String::from_utf8(message).unwrap()) - } - - // TODO: make it return the actual messages instead - Ok(()) + Ok(parsed_response.messages) } pub async fn register(&self) -> Result { @@ -112,11 +107,8 @@ impl ProviderClient { let bytes = register_request.to_bytes(); let response = self.send_request(bytes).await?; - println!("Received the following response: {:?}", response); - let parsed_response = RegisterResponse::from_bytes(&response)?; - println!("parsed register: {:?}", parsed_response); - Ok([0;32]) + Ok(parsed_response.auth_token) } } From a9584453097a97d005d0890d931db1ef1e074f1f Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 14:44:07 +0000 Subject: [PATCH 146/167] Got rid of compiler warnings --- src/clients/mod.rs | 8 ++------ src/clients/provider.rs | 11 ++++++----- src/commands/run.rs | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index ff58ece3cf..fd5de14d11 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -14,7 +14,7 @@ use std::net::SocketAddr; use std::net::SocketAddrV4; use std::time::Duration; use tokio::runtime::Runtime; -use sfw_provider_requests::requests::AuthToken; +use sfw_provider_requests::AuthToken; pub mod directory; pub mod mix; @@ -155,6 +155,7 @@ impl NymClient { let mut rt = Runtime::new()?; let topology = get_topology(self.is_local); + // this is temporary and assumes there exists only a single provider. let provider_address: SocketAddrV4 = topology .mix_provider_nodes .first() @@ -163,8 +164,6 @@ impl NymClient { .parse() .unwrap(); - - let mut provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); rt.block_on(async { @@ -179,9 +178,6 @@ impl NymClient { }); - return Ok(()); - // don't start anything, just register - let (mix_tx, mix_rx) = mpsc::unbounded(); let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 28c028596d..eabed21ef4 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,11 +1,12 @@ -use sfw_provider_requests::requests::{ProviderRequest, PullRequest, AuthToken, RegisterRequest}; +use sfw_provider_requests::requests::{ProviderRequest, PullRequest, RegisterRequest}; use sfw_provider_requests::responses::{ProviderResponse, PullResponse, RegisterResponse, ProviderResponseError}; -use std::net::{Shutdown, SocketAddr}; +use std::net::Shutdown; use std::net::SocketAddrV4; use tokio::prelude::*; use std::time::Duration; use sphinx::route::DestinationAddressBytes; use futures::io::Error; +use sfw_provider_requests::AuthToken; #[derive(Debug)] pub enum ProviderClientError { @@ -66,14 +67,14 @@ impl ProviderClient { println!("keep alive: {:?}", socket.keepalive()); socket.set_keepalive(Some(Duration::from_secs(2))).unwrap(); socket.write_all(&bytes[..]).await?; - if let Err(e) = socket.shutdown(Shutdown::Write) { + if let Err(_e) = socket.shutdown(Shutdown::Write) { // TODO: make it a silent log once we have a proper logging library // eprintln!("failed to close write part of the socket; err = {:?}", e) } let mut response = Vec::new(); socket.read_to_end(&mut response).await?; - if let Err(e) = socket.shutdown(Shutdown::Read) { + if let Err(_e) = socket.shutdown(Shutdown::Read) { // TODO: make it a silent log once we have a proper logging library // eprintln!("failed to close read part of the socket; err = {:?}", e) } @@ -85,7 +86,7 @@ impl ProviderClient { &self, ) -> Result>, ProviderClientError> { if self.auth_token.is_none() { - return Err(ProviderClientError::EmptyAuthTokenError) + return Err(ProviderClientError::EmptyAuthTokenError); } let pull_request = PullRequest::new(self.our_address, self.auth_token.unwrap()); diff --git a/src/commands/run.rs b/src/commands/run.rs index e239986209..932da4a190 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -1,9 +1,9 @@ use crate::banner; -use crate::clients::NymClient; -use crate::persistence::pemstore; +//use crate::clients::NymClient; +//use crate::persistence::pemstore; use clap::ArgMatches; -pub fn execute(matches: &ArgMatches) { +pub fn execute(_matches: &ArgMatches) { println!("{}", banner()); panic!("For time being this command is deprecated! Please use 'websocket' instead"); // From 5d5d43eab23365a5f815f7bdb70bbcb40cbb37e4 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 16:04:10 +0000 Subject: [PATCH 147/167] Basic operations for the received messages buffer --- src/clients/mod.rs | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index fd5de14d11..82a3844a4b 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -4,7 +4,7 @@ use crate::clients::provider::ProviderClient; use crate::sockets::ws; use crate::utils; use crate::utils::topology::get_topology; -use futures::channel::mpsc; +use futures::channel::{mpsc, oneshot}; use futures::future::join5; use futures::select; use futures::{SinkExt, StreamExt}; @@ -15,6 +15,8 @@ use std::net::SocketAddrV4; use std::time::Duration; use tokio::runtime::Runtime; use sfw_provider_requests::AuthToken; +use futures::lock::Mutex as FMutex; +use std::sync::Arc; pub mod directory; pub mod mix; @@ -58,6 +60,42 @@ impl MixTrafficController { } } +type BufferResponse = oneshot::Sender>>; + +struct ReceivedMessagesBuffer{ + messages: Vec> +} + +impl ReceivedMessagesBuffer{ + fn add_arc_futures_mutex(self) -> Arc> { + Arc::new(FMutex::new(self)) + } + + fn new() -> Self { + ReceivedMessagesBuffer{ + messages: Vec::new() + } + } + + async fn add_new_messages(buf: Arc>, msgs: Vec>) { + let mut unlocked = buf.lock().await; + unlocked.messages.extend(msgs); + } + + async fn run_poller_input_controller(buf: Arc>, poller_rx: mpsc::UnboundedReceiver>>) { + + } + + async fn acquire_and_empty(buf: Arc>) -> Vec> { + let mut unlocked = buf.lock().await; + std::mem::replace(&mut unlocked.messages, Vec::new()) + } + + async fn run_query_output_controller(buf: Arc>, query_receiver: mpsc::UnboundedReceiver) { + + } +} + pub struct NymClient { // to be replaced by something else I guess address: DestinationAddressBytes, @@ -134,12 +172,10 @@ impl NymClient { } async fn start_provider_polling(provider_client: ProviderClient) { -// let provider_client = ProviderClient::new(provider_address); - loop { - println!("[FETCH MSG] - Polling provider..."); let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; + println!("[FETCH MSG] - Polling provider..."); let messages = provider_client .retrieve_messages() .await From a9222eff5b71602df86dfc8c841f87a5c50b844b Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 16:10:22 +0000 Subject: [PATCH 148/167] Tasks for message buffer --- src/clients/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 82a3844a4b..3ced1c7a3d 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -82,8 +82,10 @@ impl ReceivedMessagesBuffer{ unlocked.messages.extend(msgs); } - async fn run_poller_input_controller(buf: Arc>, poller_rx: mpsc::UnboundedReceiver>>) { - + async fn run_poller_input_controller(buf: Arc>, mut poller_rx: mpsc::UnboundedReceiver>>) { + while let Some(new_messages) = poller_rx.next().await { + ReceivedMessagesBuffer::add_new_messages(buf.clone(), new_messages).await; + } } async fn acquire_and_empty(buf: Arc>) -> Vec> { @@ -91,8 +93,13 @@ impl ReceivedMessagesBuffer{ std::mem::replace(&mut unlocked.messages, Vec::new()) } - async fn run_query_output_controller(buf: Arc>, query_receiver: mpsc::UnboundedReceiver) { - + async fn run_query_output_controller(buf: Arc>, mut query_receiver: mpsc::UnboundedReceiver) { + while let Some(request) = query_receiver.next().await { + let messages = ReceivedMessagesBuffer::acquire_and_empty(buf.clone()).await; + // if this fails, the whole application needs to blow + // because currently only this thread would fail + request.send(messages).unwrap(); + } } } From 04b065508e60a722c96e9847558bb486c098e32a Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 16:25:22 +0000 Subject: [PATCH 149/167] Working (kinda) received messages buffer --- src/clients/mod.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 3ced1c7a3d..3caaad2667 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -17,6 +17,7 @@ use tokio::runtime::Runtime; use sfw_provider_requests::AuthToken; use futures::lock::Mutex as FMutex; use std::sync::Arc; +use futures::join; pub mod directory; pub mod mix; @@ -78,6 +79,7 @@ impl ReceivedMessagesBuffer{ } async fn add_new_messages(buf: Arc>, msgs: Vec>) { + println!("Adding new messages to the buffer! {:?}", msgs); let mut unlocked = buf.lock().await; unlocked.messages.extend(msgs); } @@ -178,7 +180,7 @@ impl NymClient { } } - async fn start_provider_polling(provider_client: ProviderClient) { + async fn start_provider_polling(provider_client: ProviderClient, mut poller_tx: mpsc::UnboundedSender>>) { loop { let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; @@ -187,9 +189,8 @@ impl NymClient { .retrieve_messages() .await .unwrap(); - for message in messages { - println!("Retrieved: {:?}", String::from_utf8(message).unwrap()) - } + // if any of those fails, whole application should blow... + poller_tx.send(messages).await.unwrap(); } } @@ -209,6 +210,7 @@ impl NymClient { let mut provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); + // registration rt.block_on(async { match self.auth_token { None => { @@ -220,8 +222,15 @@ impl NymClient { } }); - + // channels for intercomponent communication let (mix_tx, mix_rx) = mpsc::unbounded(); + let (poller_input_tx, poller_input_rx) = mpsc::unbounded(); + let (received_messages_buffer_output_tx, received_messages_buffer_output_rx) = mpsc::unbounded(); + + let received_messages_buffer = ReceivedMessagesBuffer::new().add_arc_futures_mutex(); + + let received_messages_buffer_input_controller_future = rt.spawn(ReceivedMessagesBuffer::run_poller_input_controller(received_messages_buffer.clone(), poller_input_rx)); + let received_messages_buffer_output_controller_future = rt.spawn(ReceivedMessagesBuffer::run_query_output_controller(received_messages_buffer, received_messages_buffer_output_rx)); let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( @@ -237,24 +246,36 @@ impl NymClient { topology.clone(), )); - let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_client)); + let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_client, poller_input_tx)); let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx)); rt.block_on(async { - let future_results = join5( + let future_results = join!( + received_messages_buffer_input_controller_future, + received_messages_buffer_output_controller_future, mix_traffic_future, loop_cover_traffic_future, out_queue_control_future, provider_polling_future, websocket_future, - ) - .await; + ); + +// let future_results = join5( +// mix_traffic_future, +// loop_cover_traffic_future, +// out_queue_control_future, +// provider_polling_future, +// websocket_future, +// ) +// .await; assert!( future_results.0.is_ok() && future_results.1.is_ok() && future_results.2.is_ok() && future_results.3.is_ok() && future_results.4.is_ok() + && future_results.5.is_ok() + && future_results.6.is_ok() ); }); From b706d36e65cb0fa2b641c27ea5401153079a0e49 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 17:10:35 +0000 Subject: [PATCH 150/167] Ability for the websocket to retrieve stored messages --- src/clients/mod.rs | 12 ++---------- src/sockets/ws.rs | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 3caaad2667..58bdb1a02c 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -61,7 +61,7 @@ impl MixTrafficController { } } -type BufferResponse = oneshot::Sender>>; +pub type BufferResponse = oneshot::Sender>>; struct ReceivedMessagesBuffer{ messages: Vec> @@ -247,7 +247,7 @@ impl NymClient { )); let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_client, poller_input_tx)); - let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx)); + let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx, received_messages_buffer_output_tx)); rt.block_on(async { let future_results = join!( @@ -260,14 +260,6 @@ impl NymClient { websocket_future, ); -// let future_results = join5( -// mix_traffic_future, -// loop_cover_traffic_future, -// out_queue_control_future, -// provider_polling_future, -// websocket_future, -// ) -// .await; assert!( future_results.0.is_ok() && future_results.1.is_ok() diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index b4778a15ae..edd2ac13dc 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,13 +1,15 @@ use crate::clients::InputMessage; -use futures::channel::mpsc; +use futures::channel::{mpsc, oneshot}; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; -use futures::{SinkExt, StreamExt}; +use futures::{SinkExt, StreamExt, AsyncReadExt}; use serde::{Deserialize, Serialize}; use sphinx::route::Destination; use std::net::SocketAddr; use tungstenite::protocol::Message; use std::io; use futures::io::Error; +use crate::clients::BufferResponse; +use futures::future::FutureExt; struct Connection { address: SocketAddr, @@ -15,6 +17,7 @@ struct Connection { tx: UnboundedSender, msg_input: mpsc::UnboundedSender, + msg_query: mpsc::UnboundedSender, } #[derive(Debug)] @@ -40,7 +43,6 @@ impl From for WebSocketError { } - #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "type", rename_all = "camelCase")] enum ClientRequest { @@ -88,8 +90,23 @@ impl ClientRequest { ServerResponse::Send } - async fn handle_fetch() -> ServerResponse { - ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + async fn handle_fetch(mut msg_query: mpsc::UnboundedSender) -> ServerResponse { + let (res_tx, res_rx) = oneshot::channel(); + if msg_query.send(res_tx).await.is_err() { + return ServerResponse::Error { message: "Server failed to receive messages".to_string() }; + } + + let messages = res_rx.map(|msg| { + msg + }).await; + + if messages.is_err() { + return ServerResponse::Error { message: "Server failed to receive messages".to_string() }; + } + + let messages = messages.unwrap(); + + ServerResponse::Fetch {messages} } async fn handle_get_clients() -> ServerResponse { @@ -117,7 +134,8 @@ fn dummy_response() -> Message { impl Into for ServerResponse { fn into(self) -> Message { - dummy_response() + let str_res = serde_json::to_string(&self).unwrap(); + Message::Text(str_res) } } @@ -130,7 +148,7 @@ async fn handle_connection(conn: Connection) { let response = match request { ClientRequest::Send { message, recipient_address } => ClientRequest::handle_send(message, recipient_address, conn.msg_input.clone()).await, - ClientRequest::Fetch => ClientRequest::handle_fetch().await, + ClientRequest::Fetch => ClientRequest::handle_fetch(conn.msg_query.clone()).await, ClientRequest::GetClients => ClientRequest::handle_get_clients().await, ClientRequest::OwnDetails => ClientRequest::handle_own_details().await, }; @@ -142,7 +160,7 @@ async fn handle_connection(conn: Connection) { } } -async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::UnboundedSender) { +async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::UnboundedSender, msg_query: mpsc::UnboundedSender) { let address = stream .peer_addr() .expect("connected streams should have a peer address"); @@ -165,6 +183,7 @@ async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::Unbou tx: response_tx, msg_input, + msg_query, }; tokio::spawn(handle_connection(conn)); @@ -179,13 +198,13 @@ async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::Unbou } } -pub async fn start_websocket(address: SocketAddr, message_tx: mpsc::UnboundedSender) -> Result<(), WebSocketError> { +pub async fn start_websocket(address: SocketAddr, message_tx: mpsc::UnboundedSender, received_messages_query_tx: mpsc::UnboundedSender) -> Result<(), WebSocketError> { let mut listener = tokio::net::TcpListener::bind(address).await?; while let Ok((stream, _)) = listener.accept().await { // it's fine to be cloning the channel on all new connection, because in principle // this server should only EVER have a single client connected - tokio::spawn(accept_connection(stream, message_tx.clone())); + tokio::spawn(accept_connection(stream, message_tx.clone(), received_messages_query_tx.clone())); } eprintln!("The websocket went kaput..."); From eba2b1f4eaeb6fc30fc451708cc8c82ea766b098 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 17:15:13 +0000 Subject: [PATCH 151/167] Removed dummy response --- src/sockets/ws.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index edd2ac13dc..a294751778 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -128,9 +128,6 @@ enum ServerResponse { Error { message: String }, } -fn dummy_response() -> Message { - Message::Text("foomp".to_string()) -} impl Into for ServerResponse { fn into(self) -> Message { From 39a2b919ae0d3fe3e5a5aa4758edd0f2b4d57a3f Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 18 Dec 2019 17:15:55 +0000 Subject: [PATCH 152/167] Fixed compiler warnings --- src/clients/mod.rs | 1 - src/sockets/ws.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 58bdb1a02c..fd0e849fa2 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -5,7 +5,6 @@ use crate::sockets::ws; use crate::utils; use crate::utils::topology::get_topology; use futures::channel::{mpsc, oneshot}; -use futures::future::join5; use futures::select; use futures::{SinkExt, StreamExt}; use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index a294751778..6c23353a8c 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,7 +1,7 @@ use crate::clients::InputMessage; use futures::channel::{mpsc, oneshot}; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; -use futures::{SinkExt, StreamExt, AsyncReadExt}; +use futures::{SinkExt, StreamExt}; use serde::{Deserialize, Serialize}; use sphinx::route::Destination; use std::net::SocketAddr; From d5646515e14fc9ffa5f5e1897978f7011625c8c3 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 11:50:17 +0000 Subject: [PATCH 153/167] cargo fmt run --- .../directory/requests/health_check_get.rs | 1 - src/clients/directory/requests/mod.rs | 2 +- src/clients/mod.rs | 78 ++++++++++------ src/clients/provider.rs | 26 +++--- src/clients/validator.rs | 1 + src/sockets/ws.rs | 90 ++++++++++++------- 6 files changed, 129 insertions(+), 69 deletions(-) diff --git a/src/clients/directory/requests/health_check_get.rs b/src/clients/directory/requests/health_check_get.rs index a6e4174e87..d5eb73644e 100644 --- a/src/clients/directory/requests/health_check_get.rs +++ b/src/clients/directory/requests/health_check_get.rs @@ -42,7 +42,6 @@ mod healthcheck_requests { let req = Request::new(mockito::server_url()); assert!(req.get().is_err()); _m.assert(); - } } diff --git a/src/clients/directory/requests/mod.rs b/src/clients/directory/requests/mod.rs index 5205f4c9b0..f10a4a415f 100644 --- a/src/clients/directory/requests/mod.rs +++ b/src/clients/directory/requests/mod.rs @@ -4,4 +4,4 @@ pub mod metrics_mixes_post; pub mod presence_coconodes_post; pub mod presence_mixnodes_post; pub mod presence_providers_post; -pub mod presence_topology_get; \ No newline at end of file +pub mod presence_topology_get; diff --git a/src/clients/mod.rs b/src/clients/mod.rs index fd0e849fa2..63c8672ec0 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -5,18 +5,18 @@ use crate::sockets::ws; use crate::utils; use crate::utils::topology::get_topology; use futures::channel::{mpsc, oneshot}; +use futures::join; +use futures::lock::Mutex as FMutex; use futures::select; use futures::{SinkExt, StreamExt}; +use sfw_provider_requests::AuthToken; use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; use sphinx::SphinxPacket; use std::net::SocketAddr; use std::net::SocketAddrV4; +use std::sync::Arc; use std::time::Duration; use tokio::runtime::Runtime; -use sfw_provider_requests::AuthToken; -use futures::lock::Mutex as FMutex; -use std::sync::Arc; -use futures::join; pub mod directory; pub mod mix; @@ -62,18 +62,18 @@ impl MixTrafficController { pub type BufferResponse = oneshot::Sender>>; -struct ReceivedMessagesBuffer{ - messages: Vec> +struct ReceivedMessagesBuffer { + messages: Vec>, } -impl ReceivedMessagesBuffer{ +impl ReceivedMessagesBuffer { fn add_arc_futures_mutex(self) -> Arc> { Arc::new(FMutex::new(self)) } fn new() -> Self { - ReceivedMessagesBuffer{ - messages: Vec::new() + ReceivedMessagesBuffer { + messages: Vec::new(), } } @@ -83,7 +83,10 @@ impl ReceivedMessagesBuffer{ unlocked.messages.extend(msgs); } - async fn run_poller_input_controller(buf: Arc>, mut poller_rx: mpsc::UnboundedReceiver>>) { + async fn run_poller_input_controller( + buf: Arc>, + mut poller_rx: mpsc::UnboundedReceiver>>, + ) { while let Some(new_messages) = poller_rx.next().await { ReceivedMessagesBuffer::add_new_messages(buf.clone(), new_messages).await; } @@ -94,7 +97,10 @@ impl ReceivedMessagesBuffer{ std::mem::replace(&mut unlocked.messages, Vec::new()) } - async fn run_query_output_controller(buf: Arc>, mut query_receiver: mpsc::UnboundedReceiver) { + async fn run_query_output_controller( + buf: Arc>, + mut query_receiver: mpsc::UnboundedReceiver, + ) { while let Some(request) = query_receiver.next().await { let messages = ReceivedMessagesBuffer::acquire_and_empty(buf.clone()).await; // if this fails, the whole application needs to blow @@ -112,14 +118,19 @@ pub struct NymClient { input_rx: mpsc::UnboundedReceiver, socket_listening_address: SocketAddr, is_local: bool, - auth_token: Option + auth_token: Option, } #[derive(Debug)] pub struct InputMessage(pub Destination, pub Vec); impl NymClient { - pub fn new(address: DestinationAddressBytes, socket_listening_address: SocketAddr, is_local: bool, auth_token: Option) -> Self { + pub fn new( + address: DestinationAddressBytes, + socket_listening_address: SocketAddr, + is_local: bool, + auth_token: Option, + ) -> Self { let (input_tx, input_rx) = mpsc::unbounded::(); NymClient { @@ -179,15 +190,15 @@ impl NymClient { } } - async fn start_provider_polling(provider_client: ProviderClient, mut poller_tx: mpsc::UnboundedSender>>) { + async fn start_provider_polling( + provider_client: ProviderClient, + mut poller_tx: mpsc::UnboundedSender>>, + ) { loop { let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; println!("[FETCH MSG] - Polling provider..."); - let messages = provider_client - .retrieve_messages() - .await - .unwrap(); + let messages = provider_client.retrieve_messages().await.unwrap(); // if any of those fails, whole application should blow... poller_tx.send(messages).await.unwrap(); } @@ -207,7 +218,8 @@ impl NymClient { .parse() .unwrap(); - let mut provider_client = ProviderClient::new(provider_address, self.address, self.auth_token); + let mut provider_client = + ProviderClient::new(provider_address, self.address, self.auth_token); // registration rt.block_on(async { @@ -216,7 +228,7 @@ impl NymClient { let auth_token = provider_client.register().await.unwrap(); provider_client.update_token(auth_token); println!("Obtained new token! - {:?}", auth_token); - }, + } Some(token) => println!("Already got the token! - {:?}", token), } }); @@ -224,12 +236,21 @@ impl NymClient { // channels for intercomponent communication let (mix_tx, mix_rx) = mpsc::unbounded(); let (poller_input_tx, poller_input_rx) = mpsc::unbounded(); - let (received_messages_buffer_output_tx, received_messages_buffer_output_rx) = mpsc::unbounded(); + let (received_messages_buffer_output_tx, received_messages_buffer_output_rx) = + mpsc::unbounded(); let received_messages_buffer = ReceivedMessagesBuffer::new().add_arc_futures_mutex(); - let received_messages_buffer_input_controller_future = rt.spawn(ReceivedMessagesBuffer::run_poller_input_controller(received_messages_buffer.clone(), poller_input_rx)); - let received_messages_buffer_output_controller_future = rt.spawn(ReceivedMessagesBuffer::run_query_output_controller(received_messages_buffer, received_messages_buffer_output_rx)); + let received_messages_buffer_input_controller_future = + rt.spawn(ReceivedMessagesBuffer::run_poller_input_controller( + received_messages_buffer.clone(), + poller_input_rx, + )); + let received_messages_buffer_output_controller_future = + rt.spawn(ReceivedMessagesBuffer::run_query_output_controller( + received_messages_buffer, + received_messages_buffer_output_rx, + )); let mix_traffic_future = rt.spawn(MixTrafficController::run(mix_rx)); let loop_cover_traffic_future = rt.spawn(NymClient::start_loop_cover_traffic_stream( @@ -245,8 +266,15 @@ impl NymClient { topology.clone(), )); - let provider_polling_future = rt.spawn(NymClient::start_provider_polling(provider_client, poller_input_tx)); - let websocket_future = rt.spawn(ws::start_websocket(self.socket_listening_address, self.input_tx, received_messages_buffer_output_tx)); + let provider_polling_future = rt.spawn(NymClient::start_provider_polling( + provider_client, + poller_input_tx, + )); + let websocket_future = rt.spawn(ws::start_websocket( + self.socket_listening_address, + self.input_tx, + received_messages_buffer_output_tx, + )); rt.block_on(async { let future_results = join!( diff --git a/src/clients/provider.rs b/src/clients/provider.rs index eabed21ef4..43875689cf 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -1,12 +1,14 @@ +use futures::io::Error; use sfw_provider_requests::requests::{ProviderRequest, PullRequest, RegisterRequest}; -use sfw_provider_requests::responses::{ProviderResponse, PullResponse, RegisterResponse, ProviderResponseError}; +use sfw_provider_requests::responses::{ + ProviderResponse, ProviderResponseError, PullResponse, RegisterResponse, +}; +use sfw_provider_requests::AuthToken; +use sphinx::route::DestinationAddressBytes; use std::net::Shutdown; use std::net::SocketAddrV4; -use tokio::prelude::*; use std::time::Duration; -use sphinx::route::DestinationAddressBytes; -use futures::io::Error; -use sfw_provider_requests::AuthToken; +use tokio::prelude::*; #[derive(Debug)] pub enum ProviderClientError { @@ -45,7 +47,11 @@ pub struct ProviderClient { } impl ProviderClient { - pub fn new(provider_network_address: SocketAddrV4, our_address: DestinationAddressBytes, auth_token: Option) -> Self { + pub fn new( + provider_network_address: SocketAddrV4, + our_address: DestinationAddressBytes, + auth_token: Option, + ) -> Self { // DH temporary: the provider's client port is not in the topology, but we can't change that // right now without messing up the existing Go mixnet. So I'm going to hardcode this // for the moment until the Go mixnet goes away. @@ -69,22 +75,20 @@ impl ProviderClient { socket.write_all(&bytes[..]).await?; if let Err(_e) = socket.shutdown(Shutdown::Write) { // TODO: make it a silent log once we have a proper logging library -// eprintln!("failed to close write part of the socket; err = {:?}", e) + // eprintln!("failed to close write part of the socket; err = {:?}", e) } let mut response = Vec::new(); socket.read_to_end(&mut response).await?; if let Err(_e) = socket.shutdown(Shutdown::Read) { // TODO: make it a silent log once we have a proper logging library -// eprintln!("failed to close read part of the socket; err = {:?}", e) + // eprintln!("failed to close read part of the socket; err = {:?}", e) } Ok(response) } - pub async fn retrieve_messages( - &self, - ) -> Result>, ProviderClientError> { + pub async fn retrieve_messages(&self) -> Result>, ProviderClientError> { if self.auth_token.is_none() { return Err(ProviderClientError::EmptyAuthTokenError); } diff --git a/src/clients/validator.rs b/src/clients/validator.rs index e69de29bb2..8b13789179 100644 --- a/src/clients/validator.rs +++ b/src/clients/validator.rs @@ -0,0 +1 @@ + diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index 6c23353a8c..6afe2f9f90 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,15 +1,15 @@ +use crate::clients::BufferResponse; use crate::clients::InputMessage; -use futures::channel::{mpsc, oneshot}; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; +use futures::channel::{mpsc, oneshot}; +use futures::future::FutureExt; +use futures::io::Error; use futures::{SinkExt, StreamExt}; use serde::{Deserialize, Serialize}; use sphinx::route::Destination; +use std::io; use std::net::SocketAddr; use tungstenite::protocol::Message; -use std::io; -use futures::io::Error; -use crate::clients::BufferResponse; -use futures::future::FutureExt; struct Connection { address: SocketAddr, @@ -42,11 +42,13 @@ impl From for WebSocketError { } } - #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "type", rename_all = "camelCase")] enum ClientRequest { - Send { message: String, recipient_address: String }, + Send { + message: String, + recipient_address: String, + }, Fetch, GetClients, OwnDetails, @@ -65,14 +67,24 @@ impl From for ClientRequest { } impl ClientRequest { - async fn handle_send(msg: String, recipient_address: String, mut input_tx: mpsc::UnboundedSender) -> ServerResponse { + async fn handle_send( + msg: String, + recipient_address: String, + mut input_tx: mpsc::UnboundedSender, + ) -> ServerResponse { let address_vec = match hex::decode(recipient_address) { - Err(e) => return ServerResponse::Error { message: e.to_string() }, + Err(e) => { + return ServerResponse::Error { + message: e.to_string(), + } + } Ok(hex) => hex, }; if address_vec.len() != 32 { - return ServerResponse::Error { message: "InvalidDestinationLength".to_string() }; + return ServerResponse::Error { + message: "InvalidDestinationLength".to_string(), + }; } let mut address = [0; 32]; @@ -80,10 +92,7 @@ impl ClientRequest { let dummy_surb = [0; 16]; - let input_msg = InputMessage( - Destination::new(address, dummy_surb), - msg.into_bytes(), - ); + let input_msg = InputMessage(Destination::new(address, dummy_surb), msg.into_bytes()); input_tx.send(input_msg).await.unwrap(); @@ -93,28 +102,34 @@ impl ClientRequest { async fn handle_fetch(mut msg_query: mpsc::UnboundedSender) -> ServerResponse { let (res_tx, res_rx) = oneshot::channel(); if msg_query.send(res_tx).await.is_err() { - return ServerResponse::Error { message: "Server failed to receive messages".to_string() }; + return ServerResponse::Error { + message: "Server failed to receive messages".to_string(), + }; } - let messages = res_rx.map(|msg| { - msg - }).await; + let messages = res_rx.map(|msg| msg).await; if messages.is_err() { - return ServerResponse::Error { message: "Server failed to receive messages".to_string() }; + return ServerResponse::Error { + message: "Server failed to receive messages".to_string(), + }; } let messages = messages.unwrap(); - ServerResponse::Fetch {messages} + ServerResponse::Fetch { messages } } async fn handle_get_clients() -> ServerResponse { - ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + ServerResponse::Error { + message: "NOT IMPLEMENTED".to_string(), + } } async fn handle_own_details() -> ServerResponse { - ServerResponse::Error { message: "NOT IMPLEMENTED".to_string() } + ServerResponse::Error { + message: "NOT IMPLEMENTED".to_string(), + } } } @@ -128,7 +143,6 @@ enum ServerResponse { Error { message: String }, } - impl Into for ServerResponse { fn into(self) -> Message { let str_res = serde_json::to_string(&self).unwrap(); @@ -136,7 +150,6 @@ impl Into for ServerResponse { } } - async fn handle_connection(conn: Connection) { let mut conn = conn; while let Some(msg) = conn.rx.next().await { @@ -144,20 +157,28 @@ async fn handle_connection(conn: Connection) { let request: ClientRequest = msg.into(); let response = match request { - ClientRequest::Send { message, recipient_address } => ClientRequest::handle_send(message, recipient_address, conn.msg_input.clone()).await, + ClientRequest::Send { + message, + recipient_address, + } => { + ClientRequest::handle_send(message, recipient_address, conn.msg_input.clone()).await + } ClientRequest::Fetch => ClientRequest::handle_fetch(conn.msg_query.clone()).await, ClientRequest::GetClients => ClientRequest::handle_get_clients().await, ClientRequest::OwnDetails => ClientRequest::handle_own_details().await, }; - conn - .tx + conn.tx .unbounded_send(response.into()) .expect("Failed to forward message"); } } -async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::UnboundedSender, msg_query: mpsc::UnboundedSender) { +async fn accept_connection( + stream: tokio::net::TcpStream, + msg_input: mpsc::UnboundedSender, + msg_query: mpsc::UnboundedSender, +) { let address = stream .peer_addr() .expect("connected streams should have a peer address"); @@ -195,16 +216,23 @@ async fn accept_connection(stream: tokio::net::TcpStream, msg_input: mpsc::Unbou } } -pub async fn start_websocket(address: SocketAddr, message_tx: mpsc::UnboundedSender, received_messages_query_tx: mpsc::UnboundedSender) -> Result<(), WebSocketError> { +pub async fn start_websocket( + address: SocketAddr, + message_tx: mpsc::UnboundedSender, + received_messages_query_tx: mpsc::UnboundedSender, +) -> Result<(), WebSocketError> { let mut listener = tokio::net::TcpListener::bind(address).await?; while let Ok((stream, _)) = listener.accept().await { // it's fine to be cloning the channel on all new connection, because in principle // this server should only EVER have a single client connected - tokio::spawn(accept_connection(stream, message_tx.clone(), received_messages_query_tx.clone())); + tokio::spawn(accept_connection( + stream, + message_tx.clone(), + received_messages_query_tx.clone(), + )); } eprintln!("The websocket went kaput..."); Ok(()) } - From 3a8ce3d3d91617c8208b588bcb0b91f1c3c46361 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 15:47:44 +0000 Subject: [PATCH 154/167] capitalization --- src/clients/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 63c8672ec0..a68b1d6728 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -205,7 +205,7 @@ impl NymClient { } pub fn start(self) -> Result<(), Box> { - println!("starting nym client"); + println!("Starting nym client"); let mut rt = Runtime::new()?; let topology = get_topology(self.is_local); From c001fe5908bf55e926957f91dc146c805ecb7db2 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 15:48:38 +0000 Subject: [PATCH 155/167] websockets: starting to implement own_details and get_clients messages --- src/clients/mod.rs | 2 ++ src/sockets/ws.rs | 60 +++++++++++++++++++++++++++++++--------------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index a68b1d6728..2b92200057 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -274,6 +274,8 @@ impl NymClient { self.socket_listening_address, self.input_tx, received_messages_buffer_output_tx, + self.address, + topology, )); rt.block_on(async { diff --git a/src/sockets/ws.rs b/src/sockets/ws.rs index 6afe2f9f90..4b211feb0e 100644 --- a/src/sockets/ws.rs +++ b/src/sockets/ws.rs @@ -1,3 +1,4 @@ +use crate::clients::directory::presence::Topology; use crate::clients::BufferResponse; use crate::clients::InputMessage; use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender}; @@ -6,18 +7,19 @@ use futures::future::FutureExt; use futures::io::Error; use futures::{SinkExt, StreamExt}; use serde::{Deserialize, Serialize}; -use sphinx::route::Destination; +use sphinx::route::{Destination, DestinationAddressBytes}; use std::io; use std::net::SocketAddr; use tungstenite::protocol::Message; struct Connection { address: SocketAddr, - rx: UnboundedReceiver, - tx: UnboundedSender, - msg_input: mpsc::UnboundedSender, msg_query: mpsc::UnboundedSender, + rx: UnboundedReceiver, + self_address: DestinationAddressBytes, + topology: Topology, + tx: UnboundedSender, } #[derive(Debug)] @@ -72,7 +74,7 @@ impl ClientRequest { recipient_address: String, mut input_tx: mpsc::UnboundedSender, ) -> ServerResponse { - let address_vec = match hex::decode(recipient_address) { + let address_vec = match base64::decode_config(&recipient_address, base64::URL_SAFE) { Err(e) => { return ServerResponse::Error { message: e.to_string(), @@ -94,6 +96,7 @@ impl ClientRequest { let input_msg = InputMessage(Destination::new(address, dummy_surb), msg.into_bytes()); + println!("ALMOST ABOUT TO SOMEDAY SEND {:?}", input_msg); input_tx.send(input_msg).await.unwrap(); ServerResponse::Send @@ -116,19 +119,29 @@ impl ClientRequest { } let messages = messages.unwrap(); - - ServerResponse::Fetch { messages } - } - - async fn handle_get_clients() -> ServerResponse { - ServerResponse::Error { - message: "NOT IMPLEMENTED".to_string(), + let messages_as_b64 = messages + .iter() + .map(|message| base64::encode_config(message, base64::URL_SAFE)) + .collect(); + ServerResponse::Fetch { + messages: messages_as_b64, } } - async fn handle_own_details() -> ServerResponse { - ServerResponse::Error { - message: "NOT IMPLEMENTED".to_string(), + async fn handle_get_clients(topology: Topology) -> ServerResponse { + let clients = topology + .mix_provider_nodes + .into_iter() + .flat_map(|provider| provider.registered_clients.into_iter()) + .map(|client| client.pub_key) + .collect(); + ServerResponse::GetClients { clients } + } + + async fn handle_own_details(self_address_bytes: DestinationAddressBytes) -> ServerResponse { + let self_address = base64::encode_config(&self_address_bytes, base64::URL_SAFE); + ServerResponse::OwnDetails { + address: self_address, } } } @@ -137,7 +150,7 @@ impl ClientRequest { #[serde(tag = "type", rename_all = "camelCase")] enum ServerResponse { Send, - Fetch { messages: Vec> }, + Fetch { messages: Vec }, GetClients { clients: Vec }, OwnDetails { address: String }, Error { message: String }, @@ -164,8 +177,10 @@ async fn handle_connection(conn: Connection) { ClientRequest::handle_send(message, recipient_address, conn.msg_input.clone()).await } ClientRequest::Fetch => ClientRequest::handle_fetch(conn.msg_query.clone()).await, - ClientRequest::GetClients => ClientRequest::handle_get_clients().await, - ClientRequest::OwnDetails => ClientRequest::handle_own_details().await, + ClientRequest::GetClients => { + ClientRequest::handle_get_clients(conn.topology.clone()).await + } + ClientRequest::OwnDetails => ClientRequest::handle_own_details(conn.self_address).await, }; conn.tx @@ -178,6 +193,8 @@ async fn accept_connection( stream: tokio::net::TcpStream, msg_input: mpsc::UnboundedSender, msg_query: mpsc::UnboundedSender, + self_address: DestinationAddressBytes, + topology: Topology, ) { let address = stream .peer_addr() @@ -199,9 +216,10 @@ async fn accept_connection( address, rx: msg_rx, tx: response_tx, - + topology, msg_input, msg_query, + self_address, }; tokio::spawn(handle_connection(conn)); @@ -220,6 +238,8 @@ pub async fn start_websocket( address: SocketAddr, message_tx: mpsc::UnboundedSender, received_messages_query_tx: mpsc::UnboundedSender, + self_address: DestinationAddressBytes, + topology: Topology, ) -> Result<(), WebSocketError> { let mut listener = tokio::net::TcpListener::bind(address).await?; @@ -230,6 +250,8 @@ pub async fn start_websocket( stream, message_tx.clone(), received_messages_query_tx.clone(), + self_address, + topology.clone(), )); } From 2e7c4214e1652496d9f0157f7c4b317e8f4f93f1 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 15:48:58 +0000 Subject: [PATCH 156/167] main: removing required on websocket port (default is 9001) --- src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8167f91339..4065dedd16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,6 @@ fn main() { .long("port") .help("Port for websocket to listen on") .takes_value(true) - .required(true), ) .arg(Arg::with_name("local") .long("local") From 49ae6d9c56aa4b7fa2f13934153cc693fb53712b Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 16:33:45 +0000 Subject: [PATCH 157/167] speeding up message rates --- src/clients/mod.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 2b92200057..0ce1211687 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -23,12 +23,9 @@ pub mod mix; pub mod provider; pub mod validator; -// TODO: put that in config once it exists -const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; -// assume seconds -const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; -// assume seconds; -const FETCH_MESSAGES_DELAY: f64 = 10.0; // assume seconds; +const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; // seconds +const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 1.0; // seconds; +const FETCH_MESSAGES_DELAY: f64 = 1.0; // seconds; // provider-poller sends polls service provider; receives messages // provider-poller sends (TX) to ReceivedBufferController (RX) From 019c9d6f96d1effbd4a2f2f8c444921f13a07a8f Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Thu, 19 Dec 2019 16:34:19 +0000 Subject: [PATCH 158/167] websocket: filtering so that dummy/loop messages aren't pumped up to the websocket --- src/clients/mod.rs | 8 +++++++- src/utils/sphinx.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 0ce1211687..b9595974fa 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -191,13 +191,19 @@ impl NymClient { provider_client: ProviderClient, mut poller_tx: mpsc::UnboundedSender>>, ) { + let loop_message = &utils::sphinx::LOOP_COVER_MESSAGE_PAYLOAD.to_vec(); + let dummy_message = &sfw_provider_requests::DUMMY_MESSAGE_CONTENT.to_vec(); loop { let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY); tokio::time::delay_for(delay_duration).await; println!("[FETCH MSG] - Polling provider..."); let messages = provider_client.retrieve_messages().await.unwrap(); + let good_messages = messages + .into_iter() + .filter(|message| message != loop_message && message != dummy_message) + .collect(); // if any of those fails, whole application should blow... - poller_tx.send(messages).await.unwrap(); + poller_tx.send(good_messages).await.unwrap(); } } diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index fffb3a2efe..57710f2f15 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -4,7 +4,7 @@ use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; -const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; +pub const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; pub fn loop_cover_message( our_address: DestinationAddressBytes, From 386a877f131364f833f92da3ffeefac12fa4dfcc Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 20 Dec 2019 16:34:58 +0000 Subject: [PATCH 159/167] TCP socket for nym client --- src/clients/mod.rs | 52 +++++-- src/commands/tcpsocket.rs | 12 +- src/commands/websocket.rs | 10 +- src/sockets/tcp.rs | 304 +++++++++++++++++++++++++++++++++++++- 4 files changed, 356 insertions(+), 22 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index b9595974fa..b521d86080 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -1,6 +1,7 @@ use crate::clients::directory::presence::Topology; use crate::clients::mix::MixClient; use crate::clients::provider::ProviderClient; +use crate::sockets::tcp; use crate::sockets::ws; use crate::utils; use crate::utils::topology::get_topology; @@ -23,9 +24,11 @@ pub mod mix; pub mod provider; pub mod validator; -const LOOP_COVER_AVERAGE_DELAY: f64 = 10.0; // seconds -const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 1.0; // seconds; -const FETCH_MESSAGES_DELAY: f64 = 1.0; // seconds; +const LOOP_COVER_AVERAGE_DELAY: f64 = 100.0; +// seconds +const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; +// seconds; +const FETCH_MESSAGES_DELAY: f64 = 10.0; // seconds; // provider-poller sends polls service provider; receives messages // provider-poller sends (TX) to ReceivedBufferController (RX) @@ -107,6 +110,12 @@ impl ReceivedMessagesBuffer { } } +pub enum SocketType { + TCP, + WebSocket, + None, +} + pub struct NymClient { // to be replaced by something else I guess address: DestinationAddressBytes, @@ -116,6 +125,7 @@ pub struct NymClient { socket_listening_address: SocketAddr, is_local: bool, auth_token: Option, + socket_type: SocketType, } #[derive(Debug)] @@ -127,6 +137,7 @@ impl NymClient { socket_listening_address: SocketAddr, is_local: bool, auth_token: Option, + socket_type: SocketType, ) -> Self { let (input_tx, input_rx) = mpsc::unbounded::(); @@ -137,6 +148,7 @@ impl NymClient { socket_listening_address, is_local, auth_token, + socket_type, } } @@ -180,7 +192,8 @@ impl NymClient { let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, &topology); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await.unwrap(); } - }; + } + ; let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; @@ -273,13 +286,28 @@ impl NymClient { provider_client, poller_input_tx, )); - let websocket_future = rt.spawn(ws::start_websocket( - self.socket_listening_address, - self.input_tx, - received_messages_buffer_output_tx, - self.address, - topology, - )); + + match self.socket_type { + SocketType::WebSocket => { + rt.spawn(ws::start_websocket( + self.socket_listening_address, + self.input_tx, + received_messages_buffer_output_tx, + self.address, + topology, + )); + } + SocketType::TCP => { + rt.spawn(tcp::start_tcpsocket( + self.socket_listening_address, + self.input_tx, + received_messages_buffer_output_tx, + self.address, + topology + )); + } + SocketType::None => (), + } rt.block_on(async { let future_results = join!( @@ -289,7 +317,6 @@ impl NymClient { loop_cover_traffic_future, out_queue_control_future, provider_polling_future, - websocket_future, ); assert!( @@ -299,7 +326,6 @@ impl NymClient { && future_results.3.is_ok() && future_results.4.is_ok() && future_results.5.is_ok() - && future_results.6.is_ok() ); }); diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index 4ba652bcd6..8c160a5ee0 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -1,5 +1,5 @@ use crate::banner; -use crate::clients::NymClient; +use crate::clients::{NymClient, SocketType}; use crate::persistence::pemstore; use crate::sockets::tcp; @@ -26,13 +26,15 @@ pub fn execute(matches: &ArgMatches) { .expect("Failed to extract the socket address from the iterator"); let keypair = pemstore::read_keypair_from_disk(id); - let _client = NymClient::new( + let auth_token = None; + + let client = NymClient::new( keypair.public_bytes(), socket_address.clone(), is_local, - None, + auth_token, + SocketType::TCP, ); - // Question: should we be passing the client into the TCP socket somehow next? - tcp::start(socket_address); + client.start().unwrap(); } diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 36a88ea9ed..913417c31e 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -1,5 +1,5 @@ use crate::banner; -use crate::clients::NymClient; +use crate::clients::{NymClient, SocketType}; use crate::persistence::pemstore; use clap::ArgMatches; @@ -27,7 +27,13 @@ pub fn execute(matches: &ArgMatches) { let keypair = pemstore::read_keypair_from_disk(id); // TODO: reading auth_token from disk (if exists); let auth_token = None; - let client = NymClient::new(keypair.public_bytes(), socket_address, is_local, auth_token); + let client = NymClient::new( + keypair.public_bytes(), + socket_address, + is_local, + auth_token, + SocketType::WebSocket, + ); client.start().unwrap(); } diff --git a/src/sockets/tcp.rs b/src/sockets/tcp.rs index a9475ab1cb..5262475092 100644 --- a/src/sockets/tcp.rs +++ b/src/sockets/tcp.rs @@ -1,5 +1,305 @@ +use crate::clients::directory::presence::Topology; +use crate::clients::BufferResponse; +use crate::clients::InputMessage; +use futures::channel::{mpsc, oneshot}; +use futures::future::FutureExt; +use futures::io::Error; +use futures::SinkExt; +use sphinx::route::{Destination, DestinationAddressBytes}; +use std::io; use std::net::SocketAddr; +use tokio::prelude::*; +use std::convert::TryFrom; +use std::sync::Arc; +use std::borrow::Borrow; -pub fn start(_socket_address: SocketAddr) { - println!("TCP server time!!!"); +const SEND_REQUEST_PREFIX: u8 = 1; +const FETCH_REQUEST_PREFIX: u8 = 2; +const GET_CLIENTS_REQUEST_PREFIX: u8 = 3; +const OWN_DETAILS_REQUEST_PREFIX: u8 = 4; + +#[derive(Debug)] +pub enum TCPSocketError { + FailedToStartSocketError, + UnknownSocketError, + IncompleteDataError, + UnknownRequestError, } + +impl From for TCPSocketError { + fn from(err: Error) -> Self { + use TCPSocketError::*; + match err.kind() { + io::ErrorKind::ConnectionRefused => FailedToStartSocketError, + io::ErrorKind::ConnectionReset => FailedToStartSocketError, + io::ErrorKind::ConnectionAborted => FailedToStartSocketError, + io::ErrorKind::NotConnected => FailedToStartSocketError, + + io::ErrorKind::AddrInUse => FailedToStartSocketError, + io::ErrorKind::AddrNotAvailable => FailedToStartSocketError, + _ => UnknownSocketError, + } + } +} + + +enum ClientRequest { + Send { + message: Vec, + recipient_address: DestinationAddressBytes, + }, + Fetch, + GetClients, + OwnDetails, +} + +impl TryFrom<&[u8]> for ClientRequest { + type Error = TCPSocketError; + + fn try_from(data: &[u8]) -> Result { + use TCPSocketError::*; + if data.is_empty() { + return Err(IncompleteDataError); + } + + match data[0] { + SEND_REQUEST_PREFIX => parse_send_request(data), + FETCH_REQUEST_PREFIX => Ok(ClientRequest::Fetch), + GET_CLIENTS_REQUEST_PREFIX => Ok(ClientRequest::GetClients), + OWN_DETAILS_REQUEST_PREFIX => Ok(ClientRequest::OwnDetails), + _ => Err(UnknownRequestError) + } + } +} + +fn parse_send_request(data: &[u8]) -> Result { + if data.len() < 1 + 32 + 1 { + // make sure it has the prefix, destination and at least single byte of data + return Err(TCPSocketError::IncompleteDataError); + } + + let mut recipient_address = [0u8; 32]; + recipient_address.copy_from_slice(&data[1..33]); + + let message = data[33..].to_vec(); + + Ok(ClientRequest::Send { + message, + recipient_address, + }) +} + +impl ClientRequest { + async fn handle_send( + msg: Vec, + recipient_address: DestinationAddressBytes, + mut input_tx: mpsc::UnboundedSender, + ) -> ServerResponse { + println!("send handle. sending to: {:?}, msg: {:?}", recipient_address, msg); + let dummy_surb = [0; 16]; + let input_msg = InputMessage(Destination::new(recipient_address, dummy_surb), msg); + + println!("ALMOST ABOUT TO SOMEDAY SEND {:?}", input_msg); + input_tx.send(input_msg).await.unwrap(); + + ServerResponse::Send + } + + async fn handle_fetch(mut msg_query: mpsc::UnboundedSender) -> ServerResponse { + println!("fetch handle"); + let (res_tx, res_rx) = oneshot::channel(); + if msg_query.send(res_tx).await.is_err() { + return ServerResponse::Error { + message: "Server failed to receive messages".to_string(), + }; + } + + let messages = res_rx.map(|msg| msg).await; + + if messages.is_err() { + return ServerResponse::Error { + message: "Server failed to receive messages".to_string(), + }; + } + + let messages = messages.unwrap(); + println!("fetched {} messages", messages.len()); + ServerResponse::Fetch { + messages, + } + } + + async fn handle_get_clients(topology: &Topology) -> ServerResponse { + println!("get clients handle"); + let clients = topology + .mix_provider_nodes + .iter() + .flat_map(|provider| provider.registered_clients.iter()) + .map(|client| base64::decode_config(&client.pub_key, base64::URL_SAFE).unwrap()) // TODO: this can potentially throw an error + .collect(); + ServerResponse::GetClients { clients } + } + + async fn handle_own_details(self_address_bytes: DestinationAddressBytes) -> ServerResponse { + println!("own details handle"); + ServerResponse::OwnDetails { + address: self_address_bytes.to_vec(), + } + } +} + + +enum ServerResponse { + Send, + Fetch { messages: Vec> }, + GetClients { clients: Vec> }, + OwnDetails { address: Vec }, + Error { message: String }, +} + +impl Into> for ServerResponse { + fn into(self) -> Vec { + match self { + ServerResponse::Send => b"ok".to_vec(), + ServerResponse::Fetch {messages} =>encode_fetched_messages(messages), + ServerResponse::GetClients {clients} => encode_list_of_clients(clients), + ServerResponse::OwnDetails {address} => address, + ServerResponse::Error { message } => message.as_bytes().to_vec() + } + } +} + +// num_msgs || len1 || len2 || ... || msg1 || msg2 || ... +fn encode_fetched_messages(messages: Vec>) -> Vec { + // for reciprocal of this look into sfw-provider-requests::responses::PullResponse::from_bytes() + + let num_msgs = messages.len() as u16; + let msgs_lens: Vec = messages.iter().map(|msg| msg.len() as u16).collect(); + + num_msgs + .to_be_bytes() + .to_vec() + .into_iter() + .chain( + msgs_lens + .into_iter() + .flat_map(|len| len.to_be_bytes().to_vec().into_iter()), + ) + .chain(messages.iter().flat_map(|msg| msg.clone().into_iter())) + .collect() +} + +fn encode_list_of_clients(clients: Vec>) -> Vec { + println!("clients: {:?}", clients); + // we can just concat all clients since all of them got to be 32 bytes long + // (if not, then we have bigger problem somewhere up the line) + + // converts [[1,2,3],[4,5,6],...] into [1,2,3,4,5,6,...] + clients.into_iter().flatten().collect() +} + +impl ServerResponse { + fn new_error(message: String) -> ServerResponse { + ServerResponse::Error { message } + } +} + + +async fn handle_connection(data: &[u8], request_handling_data: RequestHandlingData) -> Result { + let request = ClientRequest::try_from(data)?; + let response = match request { + ClientRequest::Send { + message, + recipient_address + } => ClientRequest::handle_send(message, recipient_address, request_handling_data.msg_input).await, + ClientRequest::Fetch => ClientRequest::handle_fetch(request_handling_data.msg_query).await, + ClientRequest::GetClients => ClientRequest::handle_get_clients(request_handling_data.topology.borrow()).await, + ClientRequest::OwnDetails => ClientRequest::handle_own_details(request_handling_data.self_address).await, + }; + + Ok(response) +} + +struct RequestHandlingData { + msg_input: mpsc::UnboundedSender, + msg_query: mpsc::UnboundedSender, + self_address: DestinationAddressBytes, + topology: Arc, +} + +async fn accept_connection( + mut socket: tokio::net::TcpStream, + msg_input: mpsc::UnboundedSender, + msg_query: mpsc::UnboundedSender, + self_address: DestinationAddressBytes, + topology: Topology, +) { + let address = socket + .peer_addr() + .expect("connected streams should have a peer address"); + println!("Peer address: {}", address); + + let topology = Arc::new(topology); + + let mut buf = [0u8; 2048]; + + // In a loop, read data from the socket and write the data back. + loop { + // TODO: shutdowns? + + let response = match socket.read(&mut buf).await { + // socket closed + Ok(n) if n == 0 => { + println!("Remote connection closed."); + return; + } + Ok(n) => { + let request_handling_data = RequestHandlingData { + topology: topology.clone(), + msg_input: msg_input.clone(), + msg_query: msg_query.clone(), + self_address: self_address.clone(), + }; + match handle_connection(&buf[..n], request_handling_data).await { + Ok(res) => res, + Err(e) => ServerResponse::new_error(format!("{:?}", e)) + } + } + Err(e) => { + eprintln!("failed to read from socket; err = {:?}", e); + return; + } + }; + + let response_vec: Vec = response.into(); + if let Err(e) = socket.write_all(&response_vec).await { + eprintln!("failed to write reply to socket; err = {:?}", e); + return; + } + } +} + +pub async fn start_tcpsocket( + address: SocketAddr, + message_tx: mpsc::UnboundedSender, + received_messages_query_tx: mpsc::UnboundedSender, + self_address: DestinationAddressBytes, + topology: Topology, +) -> Result<(), TCPSocketError> { + let mut listener = tokio::net::TcpListener::bind(address).await?; + + while let Ok((stream, _)) = listener.accept().await { + // it's fine to be cloning the channel on all new connection, because in principle + // this server should only EVER have a single client connected + tokio::spawn(accept_connection( + stream, + message_tx.clone(), + received_messages_query_tx.clone(), + self_address, + topology.clone(), + )); + } + + eprintln!("The tcpsocket went kaput..."); + Ok(()) +} \ No newline at end of file From ea779ea1e80d6eb291af11f15c80d0b5d1842443 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 6 Jan 2020 12:27:57 +0000 Subject: [PATCH 160/167] using built to print version on startup --- Cargo.lock | 104 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++ build.rs | 5 +++ src/clients/mod.rs | 11 +++-- src/main.rs | 15 +++++-- 5 files changed, 129 insertions(+), 10 deletions(-) create mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index ffc598306d..bc74799774 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -176,6 +176,17 @@ dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "built" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "byte-tools" version = "0.3.1" @@ -213,6 +224,10 @@ dependencies = [ name = "cc" version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "cfg-if" @@ -228,6 +243,16 @@ dependencies = [ "keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "chrono" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "clap" version = "2.33.0" @@ -646,6 +671,18 @@ dependencies = [ "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "git2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "h2" version = "0.1.26" @@ -810,6 +847,16 @@ name = "itoa" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "jobserver" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -834,6 +881,28 @@ name = "libc" version = "0.2.66" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libgit2-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libz-sys" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lioness" version = "0.1.2" @@ -1009,6 +1078,23 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num-integer" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num_cpus" version = "1.11.1" @@ -1023,6 +1109,7 @@ name = "nym-client" version = "0.1.0" dependencies = [ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "built 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1880,6 +1967,14 @@ dependencies = [ "tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "toml" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "try-lock" version = "0.2.2" @@ -2088,6 +2183,7 @@ dependencies = [ "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" "checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +"checksum built 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3d2315cfb416f86e05360edc950b1d7d25ecfb00f7f8eba60dbd7882a0f2e944" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" @@ -2096,6 +2192,7 @@ dependencies = [ "checksum cc 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chacha 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddf3c081b5fba1e5615640aae998e0fbd10c24cbd897ee39ed754a77601a4862" +"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" @@ -2145,6 +2242,7 @@ dependencies = [ "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +"checksum git2 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c1af51ea8a906616af45a4ce78eacf25860f7a13ae7bf8a814693f0f4037a26" "checksum h2 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b34c246847f938a410a03c5458c7fee2274436675e76d8b903c08efc29c462" "checksum hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "307c3c9f937f38e3534b1d6447ecf090cafcc9744e4a6360e8b037b2cf5af120" "checksum hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "023b39be39e3a2da62a94feb433e91e8bcd37676fbc8bea371daf52b7a769a3e" @@ -2161,10 +2259,13 @@ dependencies = [ "checksum input_buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e1b822cc844905551931d6f81608ed5f50a79c1078a4e2b4d42dbc7c1eedfbf" "checksum iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum jobserver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum keystream 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c33070833c9ee02266356de0c43f723152bd38bd96ddf52c82b3af10c9138b28" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum libgit2-sys 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4870c781f6063efb83150cd22c1ddf6ecf58531419e7570cdcced46970f64a16" +"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum lioness 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ae926706ba42c425c9457121178330d75e273df2e82e28b758faf3de3a9acb9" "checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" @@ -2183,6 +2284,8 @@ dependencies = [ "checksum mockito 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e524e85ea7c80559354217a6470c14abc2411802a9996aed1821559b9e28e3c" "checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c81ffc11c212fa327657cb19dd85eb7419e163b5b076bede2bdb5c974c07e4" "checksum num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76dac5ed2a876980778b8b85f75a71b6cbf0db0b1232ee12f826bccb00d09d72" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3a3cc5799d98e1088141b8e01ff760112bbd9f19d850c124500566ca6901a585" @@ -2271,6 +2374,7 @@ dependencies = [ "checksum tokio-threadpool 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c32ffea4827978e9aa392d2f743d973c1dfa3730a2ed3f22ce1e6984da848c" "checksum tokio-timer 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1739638e364e558128461fc1ad84d997702c8e31c2e6b18fb99842268199e827" "checksum tokio-tungstenite 0.10.0 (git+https://github.com/dbcfd/tokio-tungstenite?rev=6dc2018cbfe8fe7ddd75ff977343086503135b38)" = "" +"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum tungstenite 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8a0c2bd5aeb7dcd2bb32e472c8872759308495e5eccc942e929a513cd8d36110" diff --git a/Cargo.toml b/Cargo.toml index 73ad293fb1..09541fdefd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [package] +build = "build.rs" name = "nym-client" version = "0.1.0" authors = ["Dave Hrycyszyn "] @@ -31,5 +32,8 @@ tungstenite = "0.9.2" # putting this explicitly below everything and most likely, the next time we look into it, it will already have a proper release tokio-tungstenite = { git = "https://github.com/dbcfd/tokio-tungstenite", rev="6dc2018cbfe8fe7ddd75ff977343086503135b38" } +[build-dependencies] +built = "0.3.2" + [dev-dependencies] mockito = "0.22.0" diff --git a/build.rs b/build.rs new file mode 100644 index 0000000000..71d5c82762 --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +use built; + +fn main() { + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/src/clients/mod.rs b/src/clients/mod.rs index b521d86080..b27c2c164f 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -24,11 +24,11 @@ pub mod mix; pub mod provider; pub mod validator; -const LOOP_COVER_AVERAGE_DELAY: f64 = 100.0; +const LOOP_COVER_AVERAGE_DELAY: f64 = 0.5; // seconds -const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 10.0; +const MESSAGE_SENDING_AVERAGE_DELAY: f64 = 0.5; // seconds; -const FETCH_MESSAGES_DELAY: f64 = 10.0; // seconds; +const FETCH_MESSAGES_DELAY: f64 = 1.0; // seconds; // provider-poller sends polls service provider; receives messages // provider-poller sends (TX) to ReceivedBufferController (RX) @@ -192,8 +192,7 @@ impl NymClient { let cover_message = utils::sphinx::loop_cover_message(our_info.address, our_info.identifier, &topology); mix_tx.send(MixMessage(cover_message.0, cover_message.1)).await.unwrap(); } - } - ; + }; let delay_duration = Duration::from_secs_f64(MESSAGE_SENDING_AVERAGE_DELAY); tokio::time::delay_for(delay_duration).await; @@ -303,7 +302,7 @@ impl NymClient { self.input_tx, received_messages_buffer_output_tx, self.address, - topology + topology, )); } SocketType::None => (), diff --git a/src/main.rs b/src/main.rs index 4065dedd16..a753b97a82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,11 @@ fn main() { } } +pub mod built_info { + // The file has been placed there by the build script. + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + fn execute(matches: ArgMatches) -> Result<(), String> { match matches.subcommand() { ("init", Some(m)) => Ok(commands::init::execute(m)), @@ -111,7 +116,8 @@ fn usage() -> String { } fn banner() -> String { - return r#" + format!( + r#" _ __ _ _ _ __ ___ | '_ \| | | | '_ \ _ \ @@ -119,8 +125,9 @@ fn banner() -> String { |_| |_|\__, |_| |_| |_| |___/ - (client) + (client - version {:}) - "# - .to_string(); + "#, + built_info::PKG_VERSION + ) } From d1eedec21001f689692a56aec92d44ca3947a0c5 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 6 Jan 2020 14:31:35 +0000 Subject: [PATCH 161/167] conversion from address bytes to socket address and vice versa --- src/utils/addressing.rs | 80 +++++++++++++++++++++++++++++++++++++++++ src/utils/mod.rs | 1 + src/utils/sphinx.rs | 4 +-- src/utils/topology.rs | 23 +++--------- 4 files changed, 88 insertions(+), 20 deletions(-) create mode 100644 src/utils/addressing.rs diff --git a/src/utils/addressing.rs b/src/utils/addressing.rs new file mode 100644 index 0000000000..5688329a2b --- /dev/null +++ b/src/utils/addressing.rs @@ -0,0 +1,80 @@ +use std::convert::{TryFrom, TryInto}; +use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; + +pub enum AddressType { + V4, + V6, +} + +impl Into for AddressType { + fn into(self) -> u8 { + use AddressType::*; + + match self { + V4 => 4, + V6 => 6, + } + } +} + +#[derive(Debug)] +pub enum AddressTypeError { + InvalidPrefixError, +} + +impl TryFrom for AddressType { + type Error = AddressTypeError; + + fn try_from(value: u8) -> Result { + use AddressType::*; + use AddressTypeError::*; + + match value { + 4 => Ok(V4), + 6 => Ok(V6), + _ => Err(InvalidPrefixError), + } + } +} + +/// FLAG || port || octets || zeropad +pub(crate) fn encoded_bytes_from_socket_address(address: SocketAddr) -> [u8; 32] { + let port_bytes = address.port().to_be_bytes(); + + let encoded_host: Vec = match address.ip() { + IpAddr::V4(ip) => std::iter::once(AddressType::V4.into()) + .chain(port_bytes.iter().cloned()) + .chain(ip.octets().iter().cloned()) + .chain(std::iter::repeat(0)) + .take(32) + .collect(), + IpAddr::V6(ip) => std::iter::once(AddressType::V6.into()) + .chain(port_bytes.iter().cloned()) + .chain(ip.octets().iter().cloned()) + .chain(std::iter::repeat(0)) + .take(32) + .collect(), + }; + + let mut address_bytes = [0u8; 32]; + address_bytes.copy_from_slice(&encoded_host[..32]); + + address_bytes +} + +pub(crate) fn socket_address_from_encoded_bytes(b: [u8; 32]) -> SocketAddr { + let address_type: AddressType = b[0].try_into().unwrap(); + + let port: u16 = u16::from_be_bytes([b[1], b[2]]); + + let ip = match address_type { + AddressType::V4 => IpAddr::V4(Ipv4Addr::new(b[3], b[4], b[5], b[6])), + AddressType::V6 => { + let mut address_octets = [0u8; 16]; + address_octets.copy_from_slice(&b[3..19]); + IpAddr::V6(Ipv6Addr::from(address_octets)) + } + }; + + SocketAddr::new(ip, port) +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index ee03437270..5e6fb07681 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ +pub mod addressing; pub mod bytes; pub mod poisson; pub mod sphinx; diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index 57710f2f15..e0e1d0924f 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -1,5 +1,5 @@ use crate::clients::directory::presence::Topology; -use crate::utils::{bytes, topology}; +use crate::utils::{addressing, bytes, topology}; use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; @@ -29,7 +29,7 @@ pub fn encapsulate_message( let key = MontgomeryPoint(key_bytes); let provider = Node::new( - topology::socket_bytes_from_string(first_provider.host.clone()), + addressing::encoded_bytes_from_socket_address(first_provider.host.clone().parse().unwrap()), key, ); diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 1580ef8f91..2a552e7608 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -3,12 +3,13 @@ use crate::clients::directory::presence::MixNodePresence; use crate::clients::directory::presence::Topology; use crate::clients::directory::requests::presence_topology_get::PresenceTopologyGetRequester; use crate::clients::directory::DirectoryClient; -use crate::utils::bytes; +use crate::utils::{addressing, bytes}; use curve25519_dalek::montgomery::MontgomeryPoint; use rand::seq::SliceRandom; use sphinx::route::Node as SphinxNode; use std::collections::HashMap; -use std::net::SocketAddrV4; +use std::convert::TryFrom; +use std::net::{IpAddr, SocketAddr}; use std::string::ToString; pub(crate) fn get_topology(is_local: bool) -> Topology { @@ -48,7 +49,8 @@ pub(crate) fn route_from(topology: &Topology) -> Vec { route .iter() .map(|mix| { - let address_bytes = socket_bytes_from_string(mix.host.clone()); + let address_bytes = + addressing::encoded_bytes_from_socket_address(mix.host.clone().parse().unwrap()); let decoded_key_bytes = base64::decode_config(&mix.pub_key, base64::URL_SAFE).unwrap(); let key_bytes = bytes::zero_pad_to_32(decoded_key_bytes); let key = MontgomeryPoint(key_bytes); @@ -60,18 +62,3 @@ pub(crate) fn route_from(topology: &Topology) -> Vec { .collect() } -pub(crate) fn socket_bytes_from_string(address: String) -> [u8; 32] { - let socket: SocketAddrV4 = address.parse().unwrap(); - let host_bytes = socket.ip().octets(); - let port_bytes = socket.port().to_be_bytes(); - let mut address_bytes = [0u8; 32]; - - address_bytes[0] = host_bytes[0]; - address_bytes[1] = host_bytes[1]; - address_bytes[2] = host_bytes[2]; - address_bytes[3] = host_bytes[3]; - - address_bytes[4] = port_bytes[0]; - address_bytes[5] = port_bytes[1]; - address_bytes -} From 85de3d1a326c840d588fdc087092666702c5c5cd Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 6 Jan 2020 14:42:17 +0000 Subject: [PATCH 162/167] IpV6 compatible nym-client --- src/clients/mix.rs | 12 ++++-------- src/clients/mod.rs | 7 +++---- src/clients/provider.rs | 9 ++++----- src/utils/addressing.rs | 4 ++-- src/utils/sphinx.rs | 8 +++++--- src/utils/topology.rs | 2 +- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/clients/mix.rs b/src/clients/mix.rs index 2dcc178182..b8bcb77883 100644 --- a/src/clients/mix.rs +++ b/src/clients/mix.rs @@ -1,6 +1,6 @@ use sphinx::route::NodeAddressBytes; use sphinx::SphinxPacket; -use std::net::{Ipv4Addr, SocketAddrV4}; +use std::net::SocketAddr; use tokio::prelude::*; pub struct MixClient {} @@ -14,17 +14,13 @@ impl MixClient { pub async fn send( &self, packet: SphinxPacket, - mix_addr: NodeAddressBytes, + mix_addr: SocketAddr, ) -> Result<(), Box> { let bytes = packet.to_bytes(); - let b = mix_addr; - let host = Ipv4Addr::new(b[0], b[1], b[2], b[3]); - let port: u16 = u16::from_be_bytes([b[4], b[5]]); - let socket_address = SocketAddrV4::new(host, port); - println!("socket addr: {:?}", socket_address); + println!("socket addr: {:?}", mix_addr); - let mut stream = tokio::net::TcpStream::connect(socket_address).await?; + let mut stream = tokio::net::TcpStream::connect(mix_addr).await?; stream.write_all(&bytes[..]).await?; Ok(()) } diff --git a/src/clients/mod.rs b/src/clients/mod.rs index b27c2c164f..08be8de478 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -11,10 +11,9 @@ use futures::lock::Mutex as FMutex; use futures::select; use futures::{SinkExt, StreamExt}; use sfw_provider_requests::AuthToken; -use sphinx::route::{Destination, DestinationAddressBytes, NodeAddressBytes}; +use sphinx::route::{Destination, DestinationAddressBytes}; use sphinx::SphinxPacket; use std::net::SocketAddr; -use std::net::SocketAddrV4; use std::sync::Arc; use std::time::Duration; use tokio::runtime::Runtime; @@ -38,7 +37,7 @@ const FETCH_MESSAGES_DELAY: f64 = 1.0; // seconds; // ... ??Client?? sends (TX) to outQueueController (RX) // Loop cover traffic stream just sends messages to mixnet without any channel communication -struct MixMessage(NodeAddressBytes, SphinxPacket); +struct MixMessage(SocketAddr, SphinxPacket); struct MixTrafficController; @@ -225,7 +224,7 @@ impl NymClient { let topology = get_topology(self.is_local); // this is temporary and assumes there exists only a single provider. - let provider_address: SocketAddrV4 = topology + let provider_address: SocketAddr = topology .mix_provider_nodes .first() .unwrap() diff --git a/src/clients/provider.rs b/src/clients/provider.rs index 43875689cf..e95c318e22 100644 --- a/src/clients/provider.rs +++ b/src/clients/provider.rs @@ -5,8 +5,7 @@ use sfw_provider_requests::responses::{ }; use sfw_provider_requests::AuthToken; use sphinx::route::DestinationAddressBytes; -use std::net::Shutdown; -use std::net::SocketAddrV4; +use std::net::{Shutdown, SocketAddr}; use std::time::Duration; use tokio::prelude::*; @@ -41,21 +40,21 @@ impl From for ProviderClientError { } pub struct ProviderClient { - provider_network_address: SocketAddrV4, + provider_network_address: SocketAddr, our_address: DestinationAddressBytes, auth_token: Option, } impl ProviderClient { pub fn new( - provider_network_address: SocketAddrV4, + provider_network_address: SocketAddr, our_address: DestinationAddressBytes, auth_token: Option, ) -> Self { // DH temporary: the provider's client port is not in the topology, but we can't change that // right now without messing up the existing Go mixnet. So I'm going to hardcode this // for the moment until the Go mixnet goes away. - let provider_socket = SocketAddrV4::new(*provider_network_address.ip(), 9000); + let provider_socket = SocketAddr::new(provider_network_address.ip(), 9000); ProviderClient { provider_network_address: provider_socket, diff --git a/src/utils/addressing.rs b/src/utils/addressing.rs index 5688329a2b..a2660471f4 100644 --- a/src/utils/addressing.rs +++ b/src/utils/addressing.rs @@ -38,7 +38,7 @@ impl TryFrom for AddressType { } /// FLAG || port || octets || zeropad -pub(crate) fn encoded_bytes_from_socket_address(address: SocketAddr) -> [u8; 32] { +pub fn encoded_bytes_from_socket_address(address: SocketAddr) -> [u8; 32] { let port_bytes = address.port().to_be_bytes(); let encoded_host: Vec = match address.ip() { @@ -62,7 +62,7 @@ pub(crate) fn encoded_bytes_from_socket_address(address: SocketAddr) -> [u8; 32] address_bytes } -pub(crate) fn socket_address_from_encoded_bytes(b: [u8; 32]) -> SocketAddr { +pub fn socket_address_from_encoded_bytes(b: [u8; 32]) -> SocketAddr { let address_type: AddressType = b[0].try_into().unwrap(); let port: u16 = u16::from_be_bytes([b[1], b[2]]); diff --git a/src/utils/sphinx.rs b/src/utils/sphinx.rs index e0e1d0924f..234df40448 100644 --- a/src/utils/sphinx.rs +++ b/src/utils/sphinx.rs @@ -3,6 +3,7 @@ use crate::utils::{addressing, bytes, topology}; use curve25519_dalek::montgomery::MontgomeryPoint; use sphinx::route::{Destination, DestinationAddressBytes, Node, NodeAddressBytes, SURBIdentifier}; use sphinx::SphinxPacket; +use std::net::SocketAddr; pub const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!"; @@ -10,7 +11,7 @@ pub fn loop_cover_message( our_address: DestinationAddressBytes, surb_id: SURBIdentifier, topology: &Topology, -) -> (NodeAddressBytes, SphinxPacket) { +) -> (SocketAddr, SphinxPacket) { let destination = Destination::new(our_address, surb_id); encapsulate_message(destination, LOOP_COVER_MESSAGE_PAYLOAD.to_vec(), topology) @@ -20,7 +21,7 @@ pub fn encapsulate_message( recipient: Destination, message: Vec, topology: &Topology, -) -> (NodeAddressBytes, SphinxPacket) { +) -> (SocketAddr, SphinxPacket) { let mixes_route = topology::route_from(&topology); let first_provider = topology.mix_provider_nodes.first().unwrap(); let decoded_key_bytes = @@ -40,7 +41,8 @@ pub fn encapsulate_message( // build the packet let packet = sphinx::SphinxPacket::new(message, &route[..], &recipient, &delays).unwrap(); - let first_node_address = route.first().unwrap().address; + let first_node_address = + addressing::socket_address_from_encoded_bytes(route.first().unwrap().address); (first_node_address, packet) } diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 2a552e7608..08eb1ab5e1 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -5,6 +5,7 @@ use crate::clients::directory::requests::presence_topology_get::PresenceTopology use crate::clients::directory::DirectoryClient; use crate::utils::{addressing, bytes}; use curve25519_dalek::montgomery::MontgomeryPoint; +use futures::AsyncReadExt; use rand::seq::SliceRandom; use sphinx::route::Node as SphinxNode; use std::collections::HashMap; @@ -61,4 +62,3 @@ pub(crate) fn route_from(topology: &Topology) -> Vec { }) .collect() } - From 50a68e44e55adfdd5d3d3a627d0e7ec5f30018d9 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 6 Jan 2020 14:52:57 +0000 Subject: [PATCH 163/167] Removed local flag and replaced it with explicit directory server --- src/clients/mod.rs | 8 ++++---- src/commands/tcpsocket.rs | 8 ++++++-- src/commands/websocket.rs | 8 ++++++-- src/main.rs | 27 +++++++++++++++------------ src/utils/topology.rs | 16 +++++----------- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/clients/mod.rs b/src/clients/mod.rs index 08be8de478..d2da563ec0 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -122,7 +122,7 @@ pub struct NymClient { // to be used by "send" function or socket, etc input_rx: mpsc::UnboundedReceiver, socket_listening_address: SocketAddr, - is_local: bool, + directory: String, auth_token: Option, socket_type: SocketType, } @@ -134,7 +134,7 @@ impl NymClient { pub fn new( address: DestinationAddressBytes, socket_listening_address: SocketAddr, - is_local: bool, + directory: String, auth_token: Option, socket_type: SocketType, ) -> Self { @@ -145,7 +145,7 @@ impl NymClient { input_tx, input_rx, socket_listening_address, - is_local, + directory, auth_token, socket_type, } @@ -222,7 +222,7 @@ impl NymClient { println!("Starting nym client"); let mut rt = Runtime::new()?; - let topology = get_topology(self.is_local); + let topology = get_topology(self.directory.clone()); // this is temporary and assumes there exists only a single provider. let provider_address: SocketAddr = topology .mix_provider_nodes diff --git a/src/commands/tcpsocket.rs b/src/commands/tcpsocket.rs index 8c160a5ee0..d609f00d1b 100644 --- a/src/commands/tcpsocket.rs +++ b/src/commands/tcpsocket.rs @@ -9,13 +9,17 @@ use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - let is_local = matches.is_present("local"); let id = matches.value_of("id").unwrap().to_string(); let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; + let directory_server = matches + .value_of("directory") + .unwrap_or("https://directory.nymtech.net") + .to_string(); + println!("Starting TCP socket on port: {:?}", port); println!("Listening for messages..."); @@ -31,7 +35,7 @@ pub fn execute(matches: &ArgMatches) { let client = NymClient::new( keypair.public_bytes(), socket_address.clone(), - is_local, + directory_server, auth_token, SocketType::TCP, ); diff --git a/src/commands/websocket.rs b/src/commands/websocket.rs index 913417c31e..1b8ccd69b2 100644 --- a/src/commands/websocket.rs +++ b/src/commands/websocket.rs @@ -8,13 +8,17 @@ use std::net::ToSocketAddrs; pub fn execute(matches: &ArgMatches) { println!("{}", banner()); - let is_local = matches.is_present("local"); let id = matches.value_of("id").unwrap().to_string(); let port = match matches.value_of("port").unwrap_or("9001").parse::() { Ok(n) => n, Err(err) => panic!("Invalid port value provided - {:?}", err), }; + let directory_server = matches + .value_of("directory") + .unwrap_or("https://directory.nymtech.net") + .to_string(); + println!("Starting websocket on port: {:?}", port); println!("Listening for messages..."); @@ -30,7 +34,7 @@ pub fn execute(matches: &ArgMatches) { let client = NymClient::new( keypair.public_bytes(), socket_address, - is_local, + directory_server, auth_token, SocketType::WebSocket, ); diff --git a/src/main.rs b/src/main.rs index a753b97a82..6d73a64713 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,10 +37,11 @@ fn main() { .takes_value(true) .required(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) ) .subcommand( @@ -54,10 +55,11 @@ fn main() { .takes_value(true) .required(true), ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) .arg(Arg::with_name("id") .long("id") @@ -76,10 +78,11 @@ fn main() { .help("Port for websocket to listen on") .takes_value(true) ) - .arg(Arg::with_name("local") - .long("local") - .help("Flag to indicate whether the client is expected to run on the local deployment.") - .takes_value(false) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the client is getting topology from") + .takes_value(true), ) .arg(Arg::with_name("id") .long("id") diff --git a/src/utils/topology.rs b/src/utils/topology.rs index 08eb1ab5e1..5e11de7aa7 100644 --- a/src/utils/topology.rs +++ b/src/utils/topology.rs @@ -5,22 +5,16 @@ use crate::clients::directory::requests::presence_topology_get::PresenceTopology use crate::clients::directory::DirectoryClient; use crate::utils::{addressing, bytes}; use curve25519_dalek::montgomery::MontgomeryPoint; -use futures::AsyncReadExt; use rand::seq::SliceRandom; use sphinx::route::Node as SphinxNode; use std::collections::HashMap; -use std::convert::TryFrom; -use std::net::{IpAddr, SocketAddr}; -use std::string::ToString; +use std::net::SocketAddr; -pub(crate) fn get_topology(is_local: bool) -> Topology { - let url = if is_local { - "http://localhost:8080".to_string() - } else { - "https://directory.nymtech.net".to_string() +pub(crate) fn get_topology(directory_server: String) -> Topology { + println!("Using directory server: {:?}", directory_server); + let directory_config = directory::Config { + base_url: directory_server, }; - println!("Using directory server: {:?}", url); - let directory_config = directory::Config { base_url: url }; let directory = directory::Client::new(directory_config); let topology = directory From b146dd4c2206fcca29c8a3a55b70c2327dd55ccd Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 6 Jan 2020 15:26:38 +0000 Subject: [PATCH 164/167] Changelog file --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000000..3ae5b3acc6 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# nym-client Changelog + +## 0.1.0 - Initial Release + +* The bare minimum set of features required by a Nym Client \ No newline at end of file From 9176524e9219cf47972c640a12c1b263005e3d92 Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 6 Jan 2020 17:50:10 +0000 Subject: [PATCH 165/167] changelog for 0.2.0 --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae5b3acc6..0c4f7337ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # nym-client Changelog +* removed the `--local` flag +* introduced `--directory` argument to support arbitrary directory servers. Leaving it out will point the node at the "https://directory.nymtech.net" alpha testnet server +* IPv6 support +* client version number is now shown at node start +* directory server location is now shown at node start +* decrease default delays + ## 0.1.0 - Initial Release -* The bare minimum set of features required by a Nym Client \ No newline at end of file +* The bare minimum set of features required by a Nym Client From f1500fd82c1e6978fabc592bab81556b49a9fc9f Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 6 Jan 2020 17:50:24 +0000 Subject: [PATCH 166/167] version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc74799774..843b1a0f44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1106,7 +1106,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "0.1.0" +version = "0.2.0" dependencies = [ "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "built 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 09541fdefd..8e2416127c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] build = "build.rs" name = "nym-client" -version = "0.1.0" authors = ["Dave Hrycyszyn "] +version = "0.2.0" edition = "2018" [lib] From 32487b48e8f3b4069a3590528c9d1ced427d377b Mon Sep 17 00:00:00 2001 From: Dave Hrycyszyn Date: Mon, 6 Jan 2020 17:51:25 +0000 Subject: [PATCH 167/167] =?UTF-8?q?Added=20the=20glorious=20and=20talented?= =?UTF-8?q?=20J=E2=96=A1drzej=20Stuczy=E2=96=A1ski=20as=20author.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8e2416127c..3ee49b2004 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] build = "build.rs" name = "nym-client" -authors = ["Dave Hrycyszyn "] version = "0.2.0" +authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2018" [lib]