fixes
This commit is contained in:
+1
-42
@@ -33,14 +33,6 @@ struct ClientDiagnostics {
|
||||
timezone: Option<String>,
|
||||
#[serde(default)]
|
||||
platform: Option<String>,
|
||||
#[serde(default)]
|
||||
effective_type: Option<String>,
|
||||
#[serde(default)]
|
||||
downlink_mbps: Option<f64>,
|
||||
#[serde(default)]
|
||||
network_rtt_ms: Option<u64>,
|
||||
#[serde(default)]
|
||||
save_data: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -48,7 +40,6 @@ struct RequestClientContext {
|
||||
client_id: String,
|
||||
user_agent: Option<String>,
|
||||
accept_language: Option<String>,
|
||||
request_scheme: Option<String>,
|
||||
}
|
||||
|
||||
impl RequestClientContext {
|
||||
@@ -58,13 +49,6 @@ impl RequestClientContext {
|
||||
client_id: hex::encode(&digest[..8]),
|
||||
user_agent: diagnostic_header(headers, header::USER_AGENT.as_str(), 180),
|
||||
accept_language: diagnostic_header(headers, header::ACCEPT_LANGUAGE.as_str(), 100),
|
||||
request_scheme: diagnostic_header(headers, "x-forwarded-proto", 12).or_else(|| {
|
||||
headers
|
||||
.get(header::ORIGIN)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.and_then(|value| value.split_once("://").map(|(scheme, _)| scheme))
|
||||
.and_then(|value| clean_diagnostic_text(Some(value.to_owned()), 12))
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,23 +65,13 @@ struct DiagnosticClient {
|
||||
id: String,
|
||||
user_agent: Option<String>,
|
||||
accept_language: Option<String>,
|
||||
request_scheme: Option<String>,
|
||||
language: Option<String>,
|
||||
timezone: Option<String>,
|
||||
platform: Option<String>,
|
||||
effective_type: Option<String>,
|
||||
downlink_mbps: Option<f64>,
|
||||
network_rtt_ms: Option<u64>,
|
||||
save_data: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct ConnectionDiagnostics {
|
||||
connection_id: u64,
|
||||
connected_at: String,
|
||||
server_time: String,
|
||||
server_version: &'static str,
|
||||
transport: &'static str,
|
||||
heartbeat_interval_ms: u64,
|
||||
heartbeat_timeout_ms: u64,
|
||||
max_reconnect_delay_ms: u64,
|
||||
@@ -169,18 +143,11 @@ enum ServerMessage {
|
||||
}
|
||||
|
||||
fn connection_diagnostics(
|
||||
connection_id: u64,
|
||||
request: &RequestClientContext,
|
||||
client: Option<ClientDiagnostics>,
|
||||
) -> ConnectionDiagnostics {
|
||||
let client = client.unwrap_or_default();
|
||||
let now = chrono::Utc::now().to_rfc3339();
|
||||
ConnectionDiagnostics {
|
||||
connection_id,
|
||||
connected_at: now.clone(),
|
||||
server_time: now,
|
||||
server_version: env!("CARGO_PKG_VERSION"),
|
||||
transport: "websocket",
|
||||
heartbeat_interval_ms: HEARTBEAT_INTERVAL_MS,
|
||||
heartbeat_timeout_ms: HEARTBEAT_TIMEOUT_MS,
|
||||
max_reconnect_delay_ms: MAX_RECONNECT_DELAY_MS,
|
||||
@@ -194,17 +161,9 @@ fn connection_diagnostics(
|
||||
id: request.client_id.clone(),
|
||||
user_agent: request.user_agent.clone(),
|
||||
accept_language: request.accept_language.clone(),
|
||||
request_scheme: request.request_scheme.clone(),
|
||||
language: clean_diagnostic_text(client.language, 40),
|
||||
timezone: clean_diagnostic_text(client.timezone, 80),
|
||||
platform: clean_diagnostic_text(client.platform, 80),
|
||||
effective_type: clean_diagnostic_text(client.effective_type, 20),
|
||||
downlink_mbps: client
|
||||
.downlink_mbps
|
||||
.filter(|value| value.is_finite())
|
||||
.map(|value| value.clamp(0.0, 10_000.0)),
|
||||
network_rtt_ms: client.network_rtt_ms.map(|value| value.min(120_000)),
|
||||
save_data: client.save_data,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -488,7 +447,7 @@ async fn handle_socket(
|
||||
if send_split(
|
||||
&mut sender,
|
||||
&ServerMessage::Diagnostics {
|
||||
diagnostics: connection_diagnostics(connection_id, &client_context, client_diagnostics),
|
||||
diagnostics: connection_diagnostics(&client_context, client_diagnostics),
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -246,7 +246,7 @@ async fn handle_pad_socket(
|
||||
if send_pad_split(
|
||||
&mut sender,
|
||||
&PadServerMessage::Diagnostics {
|
||||
diagnostics: connection_diagnostics(connection_id, &client_context, client_diagnostics),
|
||||
diagnostics: connection_diagnostics(&client_context, client_diagnostics),
|
||||
},
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user