6b2bb3029b
* squashing feat: merge intermediate upgrade mode changes #6174 to more easily resolve merge conflicts during rebasing added additional v2 query for metadata endpoint for requesting upgrade mode recheck added additional message to v6 authenticator to request explicit upgrade mode recheck clippy test fixes due to updated keys updated assertion for upgrading v1 top up request to v2 compare attester public key against the expected value within the credential proxy use pre-generated attestation public keys within nym-nodes remove version deprecation bugfix: default bandwidth response for authenticator expose upgrade mode information in authenticator responses adding tests for new v2 server passing upgrade mode information in metadata endpoint v2 wireguard private metadata bugfix: make sure to immediately poll for attestation after spawning task fix gateway probe and remove code duplication for finalizing registration squashing before rebasing post rebasing fixes AuthenticatorVersion helpers additional nits allow unwraps in mocks fixed linux build clippy integrating upgrade mode into authenticator fixed build after adding wrappers to response types conditionally updating peer handle bandwidth cleanup negotiate initial protocol during registration change auth to use highest protocol handler for JWT message dont meter client bandwidth in upgrade mode handling recheck requests sending information about upgrade_mode on client messages gateway watching for upgrade mode attestation wip: gateways to disable bandwidth metering on upgrade mode * fixed ServerResponse deserialisation * fixed incorrect swagger path for upgrade mode check endpoint * moved upgrade mode endpoint out of bandwidth routes * chore: remove unused error variant * removed re-export of UpgradeModeAttestation from credentials-interface * chore: define single source of truth for minimum bandwidth threshold value * moved type definitions out of traits.rs * updated v6 versioning to point to niolo release instead * fixed incorrect error mapping
133 lines
4.2 KiB
Rust
133 lines
4.2 KiB
Rust
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use super::registration::{RegisteredData, RegistrationData, RemainingBandwidthData};
|
|
use nym_service_provider_requests_common::{Protocol, ServiceProviderType};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::make_bincode_serializer;
|
|
|
|
use super::VERSION;
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct AuthenticatorResponse {
|
|
pub protocol: Protocol,
|
|
pub data: AuthenticatorResponseData,
|
|
}
|
|
|
|
impl AuthenticatorResponse {
|
|
pub fn new_pending_registration_success(
|
|
registration_data: RegistrationData,
|
|
request_id: u64,
|
|
) -> Self {
|
|
Self {
|
|
protocol: Protocol {
|
|
service_provider_type: ServiceProviderType::Authenticator,
|
|
version: VERSION,
|
|
},
|
|
data: AuthenticatorResponseData::PendingRegistration(PendingRegistrationResponse {
|
|
reply: registration_data,
|
|
request_id,
|
|
}),
|
|
}
|
|
}
|
|
|
|
pub fn new_registered(registred_data: RegisteredData, request_id: u64) -> Self {
|
|
Self {
|
|
protocol: Protocol {
|
|
service_provider_type: ServiceProviderType::Authenticator,
|
|
version: VERSION,
|
|
},
|
|
data: AuthenticatorResponseData::Registered(RegisteredResponse {
|
|
reply: registred_data,
|
|
request_id,
|
|
}),
|
|
}
|
|
}
|
|
|
|
pub fn new_remaining_bandwidth(
|
|
remaining_bandwidth_data: Option<RemainingBandwidthData>,
|
|
request_id: u64,
|
|
) -> Self {
|
|
Self {
|
|
protocol: Protocol {
|
|
service_provider_type: ServiceProviderType::Authenticator,
|
|
version: VERSION,
|
|
},
|
|
data: AuthenticatorResponseData::RemainingBandwidth(RemainingBandwidthResponse {
|
|
reply: remaining_bandwidth_data,
|
|
request_id,
|
|
}),
|
|
}
|
|
}
|
|
|
|
pub fn new_topup_bandwidth(
|
|
remaining_bandwidth_data: RemainingBandwidthData,
|
|
request_id: u64,
|
|
) -> Self {
|
|
Self {
|
|
protocol: Protocol {
|
|
service_provider_type: ServiceProviderType::Authenticator,
|
|
version: VERSION,
|
|
},
|
|
data: AuthenticatorResponseData::TopUpBandwidth(TopUpBandwidthResponse {
|
|
reply: remaining_bandwidth_data,
|
|
request_id,
|
|
}),
|
|
}
|
|
}
|
|
|
|
pub fn to_bytes(&self) -> Result<Vec<u8>, bincode::Error> {
|
|
use bincode::Options;
|
|
make_bincode_serializer().serialize(self)
|
|
}
|
|
|
|
pub fn from_reconstructed_message(
|
|
message: &nym_sphinx::receiver::ReconstructedMessage,
|
|
) -> Result<Self, bincode::Error> {
|
|
use bincode::Options;
|
|
make_bincode_serializer().deserialize(&message.message)
|
|
}
|
|
|
|
pub fn id(&self) -> Option<u64> {
|
|
match &self.data {
|
|
AuthenticatorResponseData::PendingRegistration(response) => Some(response.request_id),
|
|
AuthenticatorResponseData::Registered(response) => Some(response.request_id),
|
|
AuthenticatorResponseData::RemainingBandwidth(response) => Some(response.request_id),
|
|
AuthenticatorResponseData::TopUpBandwidth(response) => Some(response.request_id),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub enum AuthenticatorResponseData {
|
|
PendingRegistration(PendingRegistrationResponse),
|
|
Registered(RegisteredResponse),
|
|
RemainingBandwidth(RemainingBandwidthResponse),
|
|
TopUpBandwidth(TopUpBandwidthResponse),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct PendingRegistrationResponse {
|
|
pub request_id: u64,
|
|
pub reply: RegistrationData,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct RegisteredResponse {
|
|
pub request_id: u64,
|
|
pub reply: RegisteredData,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct RemainingBandwidthResponse {
|
|
pub request_id: u64,
|
|
pub reply: Option<RemainingBandwidthData>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
pub struct TopUpBandwidthResponse {
|
|
pub request_id: u64,
|
|
pub reply: RemainingBandwidthData,
|
|
}
|