This commit is contained in:
Dave Hrycyszyn
2019-12-09 17:59:54 +00:00
parent 5baa822eeb
commit b1d650c76d
6 changed files with 1184 additions and 15 deletions
Generated
+1104
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -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"] }
tokio = { version = "0.2", features = ["full"] }
@@ -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<SphinxNode> {
@@ -22,6 +30,12 @@ impl DirectoryClient {
}
}
fn retrieve_topology() -> Result<Topology, reqwest::Error> {
let topology: Topology = reqwest::get("https://directory.nymtech.net/api/presence/topology")?
.json()?;
Ok(topology)
}
fn fake_directory_mixes() -> Vec<SphinxNode> {
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],
+51
View File
@@ -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<CocoPresence>,
mix_nodes: Vec<MixNodePresence>,
mix_provider_nodes: Vec<MixProviderPresence>
}
+2 -2
View File
@@ -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();
+3 -5
View File
@@ -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;
}
}
}