Feature/add rocket (#600)

* Added rocket at a git tag

* Adding Rocket to the mixnode

* Verloc route now in place

* Adding an http api startup notification

* Updated version number to 0.10.1-dev

* Fixing clippy warnings

* Compressing split a bit

* Adjusted used version of js-sys

Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com>
This commit is contained in:
Dave Hrycyszyn
2021-05-11 12:40:29 -04:00
committed by GitHub
parent 2f9e67e8b2
commit 7dc4d653c2
21 changed files with 644 additions and 60 deletions
+1
View File
@@ -0,0 +1 @@
pub(crate) mod verloc;
+28
View File
@@ -0,0 +1,28 @@
use rocket_contrib::json::Json;
use serde::Serialize;
/// Provides verifiable location (verloc) measurements for this mixnode - a list of the
/// round-trip times, in milliseconds, for all other mixnodes that this node knows about.
#[get("/verloc")]
pub(crate) fn verloc() -> Json<Vec<Foomp>> {
// replace the foomps with a reference to the measurements vec :)
let foomp1 = Foomp {
ip: "1.2.3.4".to_string(),
port: "1789".to_string(),
identity_key: "abc".to_string(),
};
let foomp2 = Foomp {
ip: "2.3.4.5".to_string(),
port: "1789".to_string(),
identity_key: "def".to_string(),
};
let foomps = vec![foomp1, foomp2];
Json(foomps)
}
#[derive(Serialize)]
pub(crate) struct Foomp {
ip: String,
port: String,
identity_key: String,
}
@@ -6,7 +6,7 @@ use crate::node::listener::connection_handler::packet_processing::{
};
use crate::node::packet_delayforwarder::PacketDelayForwardSender;
use futures::StreamExt;
use log::*;
use log::{error, info};
use nymsphinx::forwarding::packet::MixPacket;
use nymsphinx::framing::codec::SphinxCodec;
use nymsphinx::framing::packet::FramedSphinxPacket;
+1 -1
View File
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::node::listener::connection_handler::ConnectionHandler;
use log::*;
use log::error;
use std::net::SocketAddr;
use std::process;
use tokio::net::TcpListener;
+1 -1
View File
@@ -4,7 +4,7 @@
use futures::channel::mpsc;
use futures::lock::Mutex;
use futures::StreamExt;
use log::*;
use log::trace;
use metrics_client::models::metrics::MixMetric;
use std::collections::HashMap;
use std::ops::DerefMut;
+11 -4
View File
@@ -2,16 +2,18 @@
// SPDX-License-Identifier: Apache-2.0
use crate::config::Config;
use crate::node::http::verloc::verloc;
use crate::node::listener::connection_handler::packet_processing::PacketProcessor;
use crate::node::listener::connection_handler::ConnectionHandler;
use crate::node::listener::Listener;
use crate::node::packet_delayforwarder::{DelayForwarder, PacketDelayForwardSender};
use crypto::asymmetric::{encryption, identity};
use log::*;
use log::{error, info, warn};
use std::process;
use std::sync::Arc;
use tokio::runtime::Runtime;
pub(crate) mod http;
mod listener;
mod metrics;
pub(crate) mod packet_delayforwarder;
@@ -36,6 +38,11 @@ impl MixNode {
}
}
fn start_http_api(&self) {
info!("Starting HTTP API on port 8000...");
tokio::spawn(async move { rocket::build().mount("/", routes![verloc]).launch().await });
}
fn start_metrics_reporter(&self) -> metrics::MetricsReporter {
info!("Starting metrics reporter...");
metrics::MetricsController::new(
@@ -130,7 +137,7 @@ impl MixNode {
if duplicate_node_key == self.identity_keypair.public_key().to_base58_string() {
warn!("You seem to have bonded your mixnode before starting it - that's highly unrecommended as in the future it will result in slashing");
} else {
error!(
log::error!(
"Our announce-host is identical to an existing node's announce-host! (its key is {:?})",
duplicate_node_key
);
@@ -141,10 +148,10 @@ impl MixNode {
let metrics_reporter = self.start_metrics_reporter();
let delay_forwarding_channel = self.start_packet_delay_forwarder(metrics_reporter.clone());
self.start_socket_listener(metrics_reporter, delay_forwarding_channel);
self.start_http_api();
info!("Finished nym mixnode startup procedure - it should now be able to receive mix traffic!");
self.wait_for_interrupt().await
})
});
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
use crate::node::metrics::MetricsReporter;
use futures::channel::mpsc;
use futures::StreamExt;
use log::*;
use log::debug;
use nonexhaustive_delayqueue::{Expired, NonExhaustiveDelayQueue, TimerError};
use nymsphinx::forwarding::packet::MixPacket;
use tokio::time::{Duration, Instant};