d126d8e5a0
* placeholder handling of wg registration with upgrade mode token * include upgrade mode credentials as part of credential storage * introduce helper for decoding JWT payload * expose methods for removing emergency credentials from the storage * don't allow duplicate emergency credentials with the same content * added authenticator ClientMessage for upgrade mode check * retrieve credentials with longest expiration first * post rebasing fixes * fixed gateway config * feat: allow specifying minimum node performance for client init * nym-node UM improvements * fixed upgrade mode bandwidth on initial authentication * fix: logs and thresholds * expose attestation information from nym-node http api * additional logs * post rebasing fixes * make @simonwicky happy by removing empty lines in emergency_credential table definition * chore: remove '_' prefix for internal counters within in-mem ecash storage * improved import of 'UpgradeModeState' within the nym-node * use explicit time dependency within credential-storage * re-order imports within the gateway-client * moved 'AvailableBandwidth' definition to the monorepo
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use nym_credentials_interface::{
|
|
BandwidthCredential, CredentialSpendingData, TicketType, UnknownTicketType,
|
|
};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
|
|
pub enum CurrentUpgradeModeStatus {
|
|
Enabled,
|
|
Disabled,
|
|
// everything pre-v6
|
|
Unknown,
|
|
}
|
|
|
|
impl CurrentUpgradeModeStatus {
|
|
pub fn is_enabled(&self) -> bool {
|
|
matches!(self, CurrentUpgradeModeStatus::Enabled)
|
|
}
|
|
}
|
|
|
|
impl From<bool> for CurrentUpgradeModeStatus {
|
|
fn from(value: bool) -> Self {
|
|
if value {
|
|
CurrentUpgradeModeStatus::Enabled
|
|
} else {
|
|
CurrentUpgradeModeStatus::Disabled
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<CurrentUpgradeModeStatus> for Option<bool> {
|
|
fn from(value: CurrentUpgradeModeStatus) -> Self {
|
|
match value {
|
|
CurrentUpgradeModeStatus::Enabled => Some(true),
|
|
CurrentUpgradeModeStatus::Disabled => Some(false),
|
|
CurrentUpgradeModeStatus::Unknown => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
|
pub struct BandwidthClaim {
|
|
pub credential: BandwidthCredential,
|
|
pub kind: TicketType,
|
|
}
|
|
|
|
impl TryFrom<CredentialSpendingData> for BandwidthClaim {
|
|
type Error = UnknownTicketType;
|
|
|
|
fn try_from(credential: CredentialSpendingData) -> Result<Self, Self::Error> {
|
|
Ok(BandwidthClaim {
|
|
kind: TicketType::try_from_encoded(credential.payment.t_type)?,
|
|
credential: BandwidthCredential::from(credential),
|
|
})
|
|
}
|
|
}
|