-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26f55a3
commit b7463e5
Showing
9 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 - Nym Technologies SA <[email protected]> | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::ClientStatsEvents; | ||
|
||
use nym_credentials_interface::TicketType; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize)] | ||
pub(crate) struct CredentialStats { | ||
mixnet_entry_spent: u32, | ||
vpn_entry_spent: u32, | ||
mixnet_exit_spent: u32, | ||
vpn_exit_spent: u32, | ||
} | ||
|
||
/// Event space for Nym API statistics tracking | ||
#[derive(Debug)] | ||
pub enum CredentialStatsEvent { | ||
/// ecash ticket was spend | ||
TicketSpent { typ: TicketType, amount: u32 }, | ||
} | ||
|
||
impl From<CredentialStatsEvent> for ClientStatsEvents { | ||
fn from(event: CredentialStatsEvent) -> ClientStatsEvents { | ||
ClientStatsEvents::Credential(event) | ||
} | ||
} | ||
|
||
/// Nym API statistics tracking object | ||
#[derive(Default)] | ||
pub struct CredentialStatsControl { | ||
// Keep track of packet statistics over time | ||
stats: CredentialStats, | ||
} | ||
|
||
impl CredentialStatsControl { | ||
pub(crate) fn handle_event(&mut self, event: CredentialStatsEvent) { | ||
match event { | ||
CredentialStatsEvent::TicketSpent { typ, amount } => match typ { | ||
TicketType::V1MixnetEntry => self.stats.mixnet_entry_spent += amount, | ||
TicketType::V1MixnetExit => self.stats.mixnet_exit_spent += amount, | ||
TicketType::V1WireguardEntry => self.stats.vpn_entry_spent += amount, | ||
TicketType::V1WireguardExit => self.stats.vpn_exit_spent += amount, | ||
}, | ||
} | ||
} | ||
|
||
pub(crate) fn report(&self) -> CredentialStats { | ||
self.stats | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters