diff --git a/.env.sample-dev b/.env.sample-dev index d77245ab12..3a48d8ebb0 100644 --- a/.env.sample-dev +++ b/.env.sample-dev @@ -14,7 +14,7 @@ GEOIPUPDATE_LICENSE_KEY=xxx # List of space-separated database edition IDs. Edition IDs may # consist of letters, digits, and dashes. For example, GeoIP2-City # would download the GeoIP2 City database (GeoIP2-City). -GEOIPUPDATE_EDITION_IDS=GeoLite2-Country +GEOIPUPDATE_EDITION_IDS=GeoLite2-City # The number of hours between geoipupdate runs. If this is not set # or is set to 0, geoipupdate will run once and exit. GEOIPUPDATE_FREQUENCY=72 diff --git a/explorer-api/.env.sample b/explorer-api/.env.sample index 1efd2de597..e5922f9cf0 100644 --- a/explorer-api/.env.sample +++ b/explorer-api/.env.sample @@ -1,2 +1,2 @@ # The path to the geoip database file -GEOIP_DB_PATH=./geo_ip/GeoLite2-Country.mmdb +GEOIP_DB_PATH=./geo_ip/GeoLite2-City.mmdb diff --git a/explorer-api/README.md b/explorer-api/README.md index d4e193dbb0..86e64e4c12 100644 --- a/explorer-api/README.md +++ b/explorer-api/README.md @@ -40,7 +40,7 @@ It should be previously installed thanks to `geoipupdate` service. For example: ```shell -GEOIP_DB_PATH=./geo_ip/GeoLite2-Country.mmdb cargo run +GEOIP_DB_PATH=./geo_ip/GeoLite2-City.mmdb cargo run ``` Note: explorer-api binary reads the provided `.env` file. diff --git a/explorer-api/src/buy_terms/http.rs b/explorer-api/src/buy_terms/http.rs deleted file mode 100644 index 5594a1a3be..0000000000 --- a/explorer-api/src/buy_terms/http.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2022 - Nym Technologies SA -// SPDX-License-Identifier: Apache-2.0 - -use crate::geo_ip::location::Location; -use crate::state::ExplorerApiStateContext; -use rocket::response::status; -use rocket::serde::json::Json; -use rocket::{Route, State}; -use rocket_okapi::okapi::openapi3::OpenApi; -use rocket_okapi::settings::OpenApiSettings; - -pub fn nym_terms_make_default_routes(settings: &OpenApiSettings) -> (Vec, OpenApi) { - openapi_get_routes_spec![settings: terms] -} - -#[openapi(tag = "terms")] -#[get("/")] -pub(crate) async fn terms( - _state: &State, - location: Location, -) -> Result, status::Forbidden> { - if location.iso_alpha2 == "US" { - return Err(status::Forbidden(Some("US government sucks".to_string()))); - } - Ok(Json("Nym Terms & Conditions: Welcome".to_string())) -} diff --git a/explorer-api/src/buy_terms/mod.rs b/explorer-api/src/buy_terms/mod.rs deleted file mode 100644 index d064c8bd6f..0000000000 --- a/explorer-api/src/buy_terms/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub(crate) mod http; diff --git a/explorer-api/src/geo_ip/location.rs b/explorer-api/src/geo_ip/location.rs index a1afec55d6..adbdb6cef3 100644 --- a/explorer-api/src/geo_ip/location.rs +++ b/explorer-api/src/geo_ip/location.rs @@ -3,14 +3,14 @@ use isocountry::CountryCode; use log::warn; -use maxminddb::{geoip2::Country, MaxMindDBError, Reader}; +use maxminddb::{geoip2::City, MaxMindDBError, Reader}; use std::{ net::{IpAddr, ToSocketAddrs}, str::FromStr, sync::Arc, }; -const DEFAULT_DATABASE_PATH: &str = "./geo_ip/GeoLite2-Country.mmdb"; +const DEFAULT_DATABASE_PATH: &str = "./geo_ip/GeoLite2-City.mmdb"; const FAKE_PORT: u16 = 1234; #[derive(Debug)] @@ -38,6 +38,8 @@ pub(crate) struct Location { pub(crate) iso_alpha3: String, /// English country short name (ISO 3166-1) pub(crate) name: String, + pub(crate) latitude: Option, + pub(crate) longitude: Option, } impl GeoIp { @@ -86,7 +88,7 @@ impl GeoIp { error!("No registered GeoIP database"); GeoIpError::InternalError })? - .lookup::(ip); + .lookup::(ip); match &result { Ok(v) => Ok(Some( Location::try_from(v).map_err(|_| GeoIpError::InternalError)?, @@ -99,11 +101,11 @@ impl GeoIp { } } -impl<'a> TryFrom<&Country<'a>> for Location { +impl<'a> TryFrom<&City<'a>> for Location { type Error = String; - fn try_from(country: &Country) -> Result { - let data = country.country.as_ref().ok_or_else(|| { + fn try_from(city: &City) -> Result { + let data = city.country.as_ref().ok_or_else(|| { warn!("No Country data found"); "No Country data found" })?; @@ -119,10 +121,13 @@ impl<'a> TryFrom<&Country<'a>> for Location { warn!("{}", &message); message })?; + Ok(Location { iso_alpha2, iso_alpha3: String::from(iso_codes.alpha3()), name: String::from(iso_codes.name()), + latitude: city.location.as_ref().and_then(|l| l.latitude), + longitude: city.location.as_ref().and_then(|l| l.longitude), }) } } diff --git a/explorer-api/src/http/mod.rs b/explorer-api/src/http/mod.rs index f5559124a5..31f638ee5f 100644 --- a/explorer-api/src/http/mod.rs +++ b/explorer-api/src/http/mod.rs @@ -5,7 +5,6 @@ use rocket::{Build, Request, Rocket}; use rocket_cors::{AllowedHeaders, AllowedOrigins}; use rocket_okapi::swagger_ui::make_swagger_ui; -use crate::buy_terms::http::nym_terms_make_default_routes; use crate::country_statistics::http::country_statistics_make_default_routes; use crate::gateways::http::gateways_make_default_routes; use crate::http::swagger::get_docs; @@ -57,7 +56,6 @@ fn configure_rocket(state: ExplorerApiStateContext) -> Rocket { "/overview" => overview_make_default_routes(&openapi_settings), "/ping" => ping_make_default_routes(&openapi_settings), "/validators" => validators_make_default_routes(&openapi_settings), - "/terms" => nym_terms_make_default_routes(&openapi_settings), }; building_rocket diff --git a/explorer-api/src/main.rs b/explorer-api/src/main.rs index e1a02c57ea..81478638d4 100644 --- a/explorer-api/src/main.rs +++ b/explorer-api/src/main.rs @@ -10,7 +10,6 @@ use logging::setup_logging; use network_defaults::setup_env; use task::TaskManager; -mod buy_terms; pub(crate) mod cache; mod client; pub(crate) mod commands; diff --git a/explorer-api/src/mix_nodes/location.rs b/explorer-api/src/mix_nodes/location.rs index d14eaf771e..51c46261c6 100644 --- a/explorer-api/src/mix_nodes/location.rs +++ b/explorer-api/src/mix_nodes/location.rs @@ -36,6 +36,8 @@ pub(crate) struct Location { pub(crate) two_letter_iso_country_code: String, pub(crate) three_letter_iso_country_code: String, pub(crate) country_name: String, + pub(crate) latitude: Option, + pub(crate) longitude: Option, } impl Location { @@ -44,6 +46,8 @@ impl Location { country_name: location.name, two_letter_iso_country_code: location.iso_alpha2, three_letter_iso_country_code: location.iso_alpha3, + latitude: location.latitude, + longitude: location.longitude, } } } diff --git a/explorer/src/pages/MixnodeDetail/index.tsx b/explorer/src/pages/MixnodeDetail/index.tsx index 1c38f69a53..95e18ea603 100644 --- a/explorer/src/pages/MixnodeDetail/index.tsx +++ b/explorer/src/pages/MixnodeDetail/index.tsx @@ -164,10 +164,10 @@ const PageMixnodeDetailWithState: React.FC = () => { {mixNode && ( {mixNode?.error && } - {mixNode.data && mixNode?.data?.location && ( + {mixNode?.data?.location?.latitude && mixNode?.data?.location?.longitude && ( )} diff --git a/explorer/src/typeDefs/explorer-api.ts b/explorer/src/typeDefs/explorer-api.ts index f8350775c4..188a0c3ac0 100644 --- a/explorer/src/typeDefs/explorer-api.ts +++ b/explorer/src/typeDefs/explorer-api.ts @@ -77,8 +77,8 @@ export interface MixNodeResponseItem { status: MixnodeStatus; location: { country_name: string; - lat: number; - lng: number; + latitude?: number; + longitude?: number; three_letter_iso_country_code: string; two_letter_iso_country_code: string; };