[Stats API] IP from nginx headers if available (#5830)
* proper IP handling * workflow doesn't like fancy versions
This commit is contained in:
Generated
+2
-1
@@ -7224,10 +7224,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nym-statistics-api"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum 0.7.9",
|
||||
"axum-client-ip",
|
||||
"axum-extra",
|
||||
"celes",
|
||||
"clap",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
[package]
|
||||
name = "nym-statistics-api"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
@@ -16,6 +16,7 @@ rust-version.workspace = true
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
axum = { workspace = true, features = ["tokio", "macros"] }
|
||||
axum-client-ip.workspace = true
|
||||
axum-extra = { workspace = true, features = ["typed-header"] }
|
||||
celes.workspace = true
|
||||
clap = { workspace = true, features = ["cargo", "derive", "env", "string"] }
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::{
|
||||
extract::{ConnectInfo, State},
|
||||
Json, Router,
|
||||
};
|
||||
use axum::{extract::State, Json, Router};
|
||||
use axum_client_ip::InsecureClientIp;
|
||||
use axum_extra::{headers::UserAgent, TypedHeader};
|
||||
use nym_statistics_common::report::vpn_client::VpnClientStatsReport;
|
||||
use tracing::debug;
|
||||
@@ -33,12 +29,16 @@ pub(crate) fn routes() -> Router<AppState> {
|
||||
#[tracing::instrument(level = "info", skip_all)]
|
||||
async fn submit_stats_report(
|
||||
State(mut state): State<AppState>,
|
||||
ConnectInfo(addr): ConnectInfo<SocketAddr>,
|
||||
TypedHeader(user_agent): TypedHeader<UserAgent>,
|
||||
insecure_ip_addr: InsecureClientIp,
|
||||
Json(report): Json<VpnClientStatsReport>,
|
||||
) -> HttpResult<Json<()>> {
|
||||
let now = time::OffsetDateTime::now_utc();
|
||||
let gateway_record = state.network_view().get_country_by_ip(&addr.ip()).await;
|
||||
|
||||
let gateway_record = state
|
||||
.network_view()
|
||||
.get_country_by_ip(&insecure_ip_addr.0)
|
||||
.await;
|
||||
|
||||
let from_mixnet = gateway_record.is_some();
|
||||
let maybe_location = gateway_record.unwrap_or_default();
|
||||
@@ -50,8 +50,13 @@ async fn submit_stats_report(
|
||||
}
|
||||
|
||||
let active_device = DailyActiveDeviceDto::new(now, &report, user_agent, from_mixnet);
|
||||
let maybe_connection_info =
|
||||
ConnectionInfoDto::maybe_new(now, &report, addr, maybe_location, from_mixnet);
|
||||
let maybe_connection_info = ConnectionInfoDto::maybe_new(
|
||||
now,
|
||||
&report,
|
||||
insecure_ip_addr.0,
|
||||
maybe_location,
|
||||
from_mixnet,
|
||||
);
|
||||
|
||||
state
|
||||
.storage()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::net::SocketAddr;
|
||||
use std::net::IpAddr;
|
||||
|
||||
use axum_extra::headers::UserAgent;
|
||||
use celes::Country;
|
||||
@@ -53,13 +53,13 @@ impl ConnectionInfoDto {
|
||||
pub(crate) fn maybe_new(
|
||||
received_at: OffsetDateTime,
|
||||
stats_report: &VpnClientStatsReport,
|
||||
received_from: SocketAddr,
|
||||
received_from: IpAddr,
|
||||
maybe_country: Option<Country>,
|
||||
from_mixnet: bool,
|
||||
) -> Option<Self> {
|
||||
stats_report.basic_usage.as_ref().map(|usage_report| Self {
|
||||
received_at,
|
||||
received_from: received_from.ip().to_string(),
|
||||
received_from: received_from.to_string(),
|
||||
connection_time_ms: usage_report.connection_time_ms,
|
||||
two_hop: usage_report.two_hop,
|
||||
country_code: maybe_country.map(|c| c.alpha2.into()),
|
||||
|
||||
Reference in New Issue
Block a user