Files
nym/explorer-api/src/main.rs
T
Bogdan-Ștefan Neacşu 852d12b440 Make develop branch agnostic of the network (#976)
* Make develop branch agnostic of the network

* Update network defaults

* Short node identity signature check

Fix tests

* Do not set proxy only for this time

* Update contract addresses

* Network Explorer: configure URLs with `.env` file

* Network Explorer API improvements:
- upgrade `okapi` for swagger generation across multiple resources
- switched `GET mix-node` to `GET mix-nodes`
- added error message when no geolocation env var is set and process continues

* Network Explorer improvements:
- fix up API urls after Network Explorer API changes
- set currency denominations in `.env` file
- set API endpoints in `.env` file

* Network Explorer: change prod env to round robin DNS

* Update test

Co-authored-by: Mark Sinclair <mmsinclair@gmail.com>
2021-12-17 15:36:35 +02:00

83 lines
2.1 KiB
Rust

#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_okapi;
use log::info;
mod country_statistics;
mod http;
mod mix_node;
mod mix_nodes;
mod ping;
mod state;
const GEO_IP_SERVICE: &str = "https://api.freegeoip.app/json";
#[tokio::main]
async fn main() {
setup_logging();
let mut explorer_api = ExplorerApi::new();
explorer_api.run().await;
}
pub struct ExplorerApi {
state: state::ExplorerApiStateContext,
}
impl ExplorerApi {
fn new() -> ExplorerApi {
ExplorerApi {
state: state::ExplorerApiStateContext::new(),
}
}
async fn run(&mut self) {
info!("Explorer API starting up...");
info!(
"Using validator API - {}",
network_defaults::default_api_endpoints()[0].clone()
);
// spawn concurrent tasks
mix_nodes::tasks::MixNodesTasks::new(self.state.clone()).start();
country_statistics::distribution::CountryStatisticsDistributionTask::new(
self.state.clone(),
)
.start();
country_statistics::geolocate::GeoLocateTask::new(self.state.clone()).start();
http::start(self.state.clone());
// wait for user to press ctrl+C
self.wait_for_interrupt().await
}
async fn wait_for_interrupt(&self) {
if let Err(e) = tokio::signal::ctrl_c().await {
error!(
"There was an error while capturing SIGINT - {:?}. We will terminate regardless",
e
);
}
info!(
"Received SIGINT - the mixnode will terminate now (threads are not yet nicely stopped, if you see stack traces that's alright)."
);
}
}
fn setup_logging() {
let mut log_builder = pretty_env_logger::formatted_timed_builder();
if let Ok(s) = ::std::env::var("RUST_LOG") {
log_builder.parse_filters(&s);
} else {
// default to 'Info'
log_builder.filter(None, log::LevelFilter::Info);
}
log_builder
.filter_module("tokio_reactor", log::LevelFilter::Warn)
.filter_module("reqwest", log::LevelFilter::Warn)
.init();
}