Skip to content

Commit

Permalink
move events into a common crate for future use elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwicky committed Oct 14, 2024
1 parent 87bbd1c commit 1d2d8e0
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ members = [
"common/socks5-client-core",
"common/socks5/proxy-helpers",
"common/socks5/requests",
"common/statistics",
"common/store-cipher",
"common/task",
"common/topology",
Expand Down
16 changes: 16 additions & 0 deletions common/statistics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 - Nym Technologies SA <[email protected]>
# SPDX-License-Identifier: Apache-2.0

[package]
name = "nym-statistics-common"
version = "1.1.1"
edition = "2021"
license.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
futures = { workspace = true }
time = { workspace = true }

nym-sphinx = { path = "../nymsphinx" }
File renamed without changes.
4 changes: 4 additions & 0 deletions common/statistics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2024 - Nym Technologies SA <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only

pub mod events;
1 change: 1 addition & 0 deletions gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ nym-network-requester = { path = "../service-providers/network-requester" }
nym-node-http-api = { path = "../nym-node/nym-node-http-api" }
nym-pemstore = { path = "../common/pemstore" }
nym-sphinx = { path = "../common/nymsphinx" }
nym-statistics-common = { path = "../common/statistics" }
nym-task = { path = "../common/task" }
nym-types = { path = "../common/types" }
nym-validator-client = { path = "../common/client-libs/validator-client" }
Expand Down
12 changes: 7 additions & 5 deletions gateway/src/node/client_handling/active_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// SPDX-License-Identifier: GPL-3.0-only

use super::websocket::message_receiver::{IsActiveRequestSender, MixMessageSender};
use crate::node::{client_handling::embedded_clients::LocalEmbeddedClientHandle, statistics};
use crate::node::client_handling::embedded_clients::LocalEmbeddedClientHandle;
use dashmap::DashMap;
use nym_sphinx::DestinationAddressBytes;
use nym_statistics_common::events;
use nym_statistics_common::events::StatsEventSender;
use std::sync::Arc;
use tracing::warn;

Expand Down Expand Up @@ -35,7 +37,7 @@ impl ActiveClient {
#[derive(Clone)]
pub(crate) struct ActiveClientsStore {
inner: Arc<DashMap<DestinationAddressBytes, ActiveClient>>,
stats_event_sender: statistics::StatsEventSender,
stats_event_sender: StatsEventSender,
}

#[derive(Clone)]
Expand All @@ -49,7 +51,7 @@ pub(crate) struct ClientIncomingChannels {

impl ActiveClientsStore {
/// Creates new instance of `ActiveClientsStore` to store in-memory handles to all currently connected clients.
pub(crate) fn new(stats_event_sender: statistics::StatsEventSender) -> Self {
pub(crate) fn new(stats_event_sender: StatsEventSender) -> Self {
ActiveClientsStore {
inner: Arc::new(DashMap::new()),
stats_event_sender,
Expand Down Expand Up @@ -130,7 +132,7 @@ impl ActiveClientsStore {
self.inner.remove(&client);
let _ = self
.stats_event_sender
.unbounded_send(statistics::events::new_session_stop_event(client));
.unbounded_send(events::new_session_stop_event(client));
}

/// Insert new client handle into the store.
Expand All @@ -154,7 +156,7 @@ impl ActiveClientsStore {
}
let _ = self
.stats_event_sender
.unbounded_send(statistics::events::new_session_start_event(client));
.unbounded_send(events::new_session_start_event(client));
}

/// Inserts a handle to the embedded client
Expand Down
3 changes: 2 additions & 1 deletion gateway/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use nym_mixnet_client::forwarder::{MixForwardingSender, PacketForwarder};
use nym_network_defaults::NymNetworkDetails;
use nym_network_requester::{LocalGateway, NRServiceProviderBuilder, RequestFilter};
use nym_node_http_api::state::metrics::SharedSessionStats;
use nym_statistics_common::events;
use nym_task::{TaskClient, TaskHandle, TaskManager};
use nym_types::gateway::GatewayNodeDetailsResponse;
use nym_validator_client::nyxd::{Coin, CosmWasmClient};
Expand Down Expand Up @@ -408,7 +409,7 @@ impl<St> Gateway<St> {
&self,
shared_session_stats: SharedSessionStats,
shutdown: TaskClient,
) -> statistics::StatsEventSender {
) -> events::StatsEventSender {
info!("Starting gateway stats collector...");

let (mut stats_collector, stats_event_sender) =
Expand Down
7 changes: 2 additions & 5 deletions gateway/src/node/statistics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@

use futures::{channel::mpsc, StreamExt};
use nym_node_http_api::state::metrics::SharedSessionStats;
use nym_statistics_common::events::{StatsEvent, StatsEventReceiver, StatsEventSender};
use nym_task::TaskClient;
use sessions::SessionStatsHandler;
use std::time::Duration;
use time::OffsetDateTime;
use tracing::trace;

use sessions::SessionStatsHandler;

pub use events::{StatsEvent, StatsEventReceiver, StatsEventSender};

pub mod events;
pub mod sessions;

const STATISTICS_UPDATE_TIMER_INTERVAL: Duration = Duration::from_secs(3600); //update timer, no need to check everytime
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/node/statistics/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use nym_sphinx::DestinationAddressBytes;
use std::collections::{HashMap, HashSet};
use time::{Date, OffsetDateTime};

use crate::node::statistics::events::SessionEvent;
use nym_statistics_common::events::SessionEvent;

type SessionDuration = u64; //in miliseconds

Expand Down

0 comments on commit 1d2d8e0

Please sign in to comment.