d8c84cc4d6
* wip * wip: wrap node's sphinx key with a manager * wip: choosing correct key for packet processing * further propagation of key rotation information * attaching key rotation information to reply surbs * added basic key rotation information to mixnet contract * wip: introducing cached queries for key rotation info from nym api * unified nym-api contract cache refreshing * finish packet decoding * multi api client + retrieving rotation id * rotating sphinx key files * logic for migrating config file * wip: putting new sphinx keys to self described endpoints * processing loop of KeyRotationController * fixed sphinx key loading * rotating bloomfilters * wired up KeyRotationController * flushing bloomfilters to disk and loading * most of nym-node changes * post rebase fixes * fixes due to backwards compatible hostkeys * split http state.rs file * dont use deprecated fields * fixed backwards compatible deserialisation of host information * split up node describe cache * added a dedicated CacheRefresher listener to perform full refresh outside the set interval * controlling announced sphinx keys within nym-api * retrieving rotation id when pulling topology * split nym-nodes http handlers * v2 nym-api endpoints to retrieve nodes with additional metadata information * bug fixes... * additional bugfixes and guards against stuck epoch * testnet manager: set first nym-api as the rewarder * fixed host information deserialisation * fixed panic during first key rotation * post rebase fixes * clippy * more guards against stuck epochs * added helper method to reset node's sphinx key * instantiate mixnet contract with custom key rotation validity * additional bugfixes and debugging nym-api deadlock * passing shutdown to nym apis client * remove dead test * post rebasing fixes * missing MixnetQueryClient variants * remove usage of deprecated methods in sdk example * fix: incorrect method signature * post rebasing fixes * attempt to retrieve key rotation id before doing any config migration work * ignore tests relying on networking behaviour * allow networking failures in certain tests
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::response::{error_response, ResponseWrapper};
|
|
use axum::http::header::IntoHeaderName;
|
|
use axum::http::{header, HeaderValue};
|
|
use axum::response::{IntoResponse, Response};
|
|
use bytes::{BufMut, BytesMut};
|
|
use serde::Serialize;
|
|
use utoipa::gen::serde_json;
|
|
|
|
// don't use axum's Json directly as we need to be able to define custom headers
|
|
#[derive(Debug, Clone, Default)]
|
|
#[must_use]
|
|
pub struct Json<T>(pub(crate) ResponseWrapper<T>);
|
|
|
|
impl<T> From<T> for Json<T> {
|
|
fn from(response: T) -> Self {
|
|
Json(ResponseWrapper::new(response).with_header(
|
|
header::CONTENT_TYPE,
|
|
HeaderValue::from_static(mime::APPLICATION_JSON.as_ref()),
|
|
))
|
|
}
|
|
}
|
|
|
|
impl<T> Json<T> {
|
|
pub(crate) fn with_header(
|
|
mut self,
|
|
name: impl IntoHeaderName,
|
|
value: impl Into<HeaderValue>,
|
|
) -> Self {
|
|
self.0.headers.insert(name, value.into());
|
|
self
|
|
}
|
|
|
|
pub(crate) fn map<U, F: FnOnce(T) -> U>(self, op: F) -> Json<U> {
|
|
Json(self.0.map(op))
|
|
}
|
|
}
|
|
|
|
impl<T> IntoResponse for Json<T>
|
|
where
|
|
T: Serialize,
|
|
{
|
|
fn into_response(self) -> Response {
|
|
let mut buf = BytesMut::with_capacity(128).writer();
|
|
|
|
match serde_json::to_writer(&mut buf, &self.0.data) {
|
|
Ok(()) => (self.0.headers, buf.into_inner().freeze()).into_response(),
|
|
Err(err) => error_response(err),
|
|
}
|
|
}
|
|
}
|