5a07b73375
* removed mnemonic from gateway config struct scaffolding for common mixnet listener running verloc unconditionally in a nym-node remove filtering by mixnode extracted verloc to separate crate integrated nym-node-http-server more tightly with the binary most logic for handling forward packets running all mixnode-related tasks natively inside nymnode removed gateway storage trait in favour of the only concrete implementation most logic for handling final hop packets using nym-node owned socket listener for gateways utility for sending plain message through mixnet + gateway fix using common packet forwarding in both modes nifying nym-node metrics reproduce behaviour of the console logger cleaned up cli args redesigned gateway tasks startup procedure removing dead code scaffolding for old config v6 config migration implemented MixnetMetricsCleaner * clippy * require entry/exit for wireguard * removed dead code in migration code * updated config template * use custom user agent for verloc queries * fixed premature shutdown of gateway tasks * hidden nym-api flag to allow illegal node ips * experiment: final hop handing with wireguard * added additional startup logs * typo * fixed legacy stats endpoint data * additional logs * apply review comments * fixed local testnet manager
113 lines
2.7 KiB
Rust
113 lines
2.7 KiB
Rust
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use nym_statistics_common::hash_identifier;
|
|
use std::time::Duration;
|
|
use time::{Date, OffsetDateTime};
|
|
use tokio::sync::{RwLock, RwLockReadGuard};
|
|
|
|
#[derive(Default)]
|
|
pub struct EntryStats {
|
|
sessions: RwLock<ClientSessions>,
|
|
}
|
|
|
|
impl EntryStats {
|
|
pub async fn update_client_sessions(&self, new: ClientSessions) {
|
|
*self.sessions.write().await = new
|
|
}
|
|
|
|
pub async fn client_sessions(&self) -> RwLockReadGuard<ClientSessions> {
|
|
self.sessions.read().await
|
|
}
|
|
}
|
|
|
|
pub struct ClientSessions {
|
|
pub update_time: Date,
|
|
pub unique_users: Vec<String>,
|
|
pub sessions_started: u32,
|
|
pub finished_sessions: Vec<FinishedSession>,
|
|
}
|
|
|
|
impl Default for ClientSessions {
|
|
fn default() -> Self {
|
|
ClientSessions {
|
|
update_time: OffsetDateTime::UNIX_EPOCH.date(),
|
|
unique_users: vec![],
|
|
sessions_started: 0,
|
|
finished_sessions: vec![],
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ClientSessions {
|
|
pub fn new(
|
|
update_time: Date,
|
|
unique_users: Vec<String>,
|
|
sessions_started: u32,
|
|
sessions: Vec<FinishedSession>,
|
|
) -> Self {
|
|
ClientSessions {
|
|
update_time,
|
|
unique_users: unique_users.into_iter().map(hash_identifier).collect(),
|
|
sessions_started,
|
|
finished_sessions: sessions,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub struct FinishedSession {
|
|
pub duration: Duration,
|
|
pub typ: SessionType,
|
|
}
|
|
|
|
impl FinishedSession {
|
|
pub fn new(duration: Duration, typ: SessionType) -> Self {
|
|
FinishedSession { duration, typ }
|
|
}
|
|
}
|
|
|
|
#[derive(PartialEq, Copy, Clone, strum::Display, strum::EnumString)]
|
|
pub enum SessionType {
|
|
Vpn,
|
|
Mixnet,
|
|
Unknown,
|
|
}
|
|
|
|
impl SessionType {
|
|
pub fn from_string<S: AsRef<str>>(s: S) -> Self {
|
|
s.as_ref().parse().unwrap_or(Self::Unknown)
|
|
}
|
|
}
|
|
|
|
pub struct ActiveSession {
|
|
pub start: OffsetDateTime,
|
|
pub typ: SessionType,
|
|
}
|
|
|
|
impl ActiveSession {
|
|
pub fn new(start_time: OffsetDateTime) -> Self {
|
|
ActiveSession {
|
|
start: start_time,
|
|
typ: SessionType::Unknown,
|
|
}
|
|
}
|
|
|
|
pub fn set_type(&mut self, typ: SessionType) {
|
|
self.typ = typ;
|
|
}
|
|
|
|
pub fn end_at(self, stop_time: OffsetDateTime) -> Option<FinishedSession> {
|
|
let session_duration = stop_time - self.start;
|
|
//ensure duration is positive to fit in a u64
|
|
//u64::max milliseconds is 500k millenia so no overflow issue
|
|
if session_duration > Duration::ZERO {
|
|
Some(FinishedSession {
|
|
duration: session_duration.unsigned_abs(),
|
|
typ: self.typ,
|
|
})
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|