Merge pull request #149 from nymtech/feature/add-topology-to-validator

Feature/add topology to validator
This commit is contained in:
Jędrzej Stuczyński
2020-03-17 11:02:51 +00:00
committed by GitHub
8 changed files with 92 additions and 6 deletions
Generated
+19
View File
@@ -1639,7 +1639,9 @@ dependencies = [
"iron",
"log 0.4.8",
"pretty_env_logger",
"router",
"serde",
"serde_json",
"tempfile",
"tokio 0.2.12",
"topology",
@@ -2249,6 +2251,23 @@ dependencies = [
"winreg",
]
[[package]]
name = "route-recognizer"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea509065eb0b3c446acdd0102f0d46567dc30902dc0be91d6552035d92b0f4f8"
[[package]]
name = "router"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc63b6f3b8895b0d04e816b2b1aa58fdba2d5acca3cbb8f0ab8e017347d57397"
dependencies = [
"iron",
"route-recognizer",
"url 1.7.2",
]
[[package]]
name = "rust-argon2"
version = "0.7.0"
+2
View File
@@ -18,7 +18,9 @@ futures = "0.3.1"
iron = "0.6.1"
log = "0.4"
pretty_env_logger = "0.3"
router = "0.6.0"
serde = "1.0.104"
serde_json = "1.0.48"
tokio = { version = "0.2", features = ["full"] }
## internal
+13 -2
View File
@@ -1,5 +1,8 @@
use iron::prelude::*;
use iron::status;
use router::Router;
mod models;
mod routes;
pub struct Api {}
@@ -11,8 +14,16 @@ impl Api {
pub async fn run(self) {
let port = 3000;
println!("* starting REST API on localhost:{}", port);
Iron::new(|_: &mut Request| Ok(Response::with((status::Ok, "Hello World!"))))
let router = self.setup_routes();
Iron::new(router)
.http(format!("localhost:{}", port))
.unwrap();
}
pub fn setup_routes(&self) -> Router {
let mut router = Router::new();
router.get("/topology", routes::topology::get, "topology_get");
router
}
}
+1
View File
@@ -0,0 +1 @@
pub mod presence;
@@ -0,0 +1,36 @@
use serde::{Deserialize, Serialize};
// Topology shows us the current state of the overall Nym network
#[derive(Serialize, Deserialize, Debug)]
pub struct Topology {
pub validators: Vec<Validator>,
pub mix_nodes: Vec<MixNode>,
pub service_providers: Vec<ServiceProvider>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Validator {
host: String,
public_key: String,
version: String,
last_seen: u64,
location: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MixNode {
host: String,
public_key: String,
version: String,
last_seen: u64,
location: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ServiceProvider {
host: String,
public_key: String,
version: String,
last_seen: u64,
location: String,
}
+4
View File
@@ -0,0 +1,4 @@
use iron::prelude::*;
use iron::status;
pub mod topology;
@@ -0,0 +1,12 @@
use super::*;
use crate::network::rest::models::presence::{MixNode, ServiceProvider, Topology, Validator};
pub fn get(_req: &mut Request) -> IronResult<Response> {
let topology = Topology {
mix_nodes: Vec::<MixNode>::new(),
service_providers: Vec::<ServiceProvider>::new(),
validators: Vec::<Validator>::new(),
};
let response = serde_json::to_string_pretty(&topology).unwrap();
Ok(Response::with((status::Ok, response)))
}
+5 -4
View File
@@ -6,7 +6,6 @@ use crypto::identity::MixIdentityKeyPair;
use healthcheck::HealthChecker;
use tokio::runtime::Runtime;
// allow for a generic validator
pub struct Validator {
// when you re-introduce keys, check which ones you want:
// MixIdentityKeyPair (like 'nym-client' ) <- probably that one (after maybe renaming to just identity::KeyPair)
@@ -16,7 +15,6 @@ pub struct Validator {
rest_api: rest::Api,
}
// but for time being, since it's a dummy one, have it use dummy keys
impl Validator {
pub fn new(config: Config) -> Self {
let dummy_healthcheck_keypair = MixIdentityKeyPair::new();
@@ -44,14 +42,17 @@ impl Validator {
}
}
// TODO: Fix Tendermint startup here, see https://github.com/nymtech/nym/issues/147
pub fn start(self) {
let mut rt = Runtime::new().unwrap();
rt.spawn(self.health_check_runner.run());
rt.spawn(self.rest_api.run());
rt.spawn(self.tendermint_abci.run());
println!("Validator startup complete."); // TODO: Not immensely important to me right now, but why doesn't this get hit?
// TODO: this message is going to come out of order (if at all), as spawns are async
println!("Validator startup complete.");
rt.block_on(blocker());
}
}
pub async fn blocker() {}
pub async fn blocker() {} // once Tendermint unblocks us, make this block forever.