mirror of
https://github.com/logos-co/nomos-node.git
synced 2026-08-31 03:21:15 +00:00
chore(api): Add testing connect endpoint (#2574)
This commit is contained in:
@@ -6,11 +6,11 @@ use axum::{
|
||||
HeaderValue,
|
||||
header::{CONTENT_TYPE, USER_AGENT},
|
||||
},
|
||||
routing::get,
|
||||
routing::{get, post},
|
||||
};
|
||||
use lb_api_service::Backend;
|
||||
use lb_http_api_common::paths::MANTLE_SDP_DECLARATIONS;
|
||||
pub use lb_network_service::backends::libp2p::Libp2p as NetworkBackend;
|
||||
use lb_http_api_common::paths::{DIAL_PEER, MANTLE_SDP_DECLARATIONS};
|
||||
use lb_network_service::{NetworkService, backends::libp2p::Libp2p as NetworkBackend};
|
||||
use overwatch::{overwatch::handle::OverwatchHandle, services::AsServiceId};
|
||||
use tokio::net::TcpListener;
|
||||
use tower::limit::ConcurrencyLimitLayer;
|
||||
@@ -23,7 +23,10 @@ use tower_http::{
|
||||
use tracing::Level as TracingLevel;
|
||||
|
||||
use crate::{
|
||||
api::{backend::AxumBackendSettings, testing::handlers::get_sdp_declarations},
|
||||
api::{
|
||||
backend::AxumBackendSettings,
|
||||
testing::handlers::{dial_peer, get_sdp_declarations},
|
||||
},
|
||||
generic_services::{self, SdpService},
|
||||
};
|
||||
pub struct TestAxumBackend {
|
||||
@@ -45,6 +48,7 @@ where
|
||||
+ Debug
|
||||
+ Clone
|
||||
+ 'static
|
||||
+ AsServiceId<NetworkService<NetworkBackend, RuntimeServiceId>>
|
||||
+ AsServiceId<TestCryptarchiaService<RuntimeServiceId>>
|
||||
+ AsServiceId<TestHttpCryptarchiaService<RuntimeServiceId>>
|
||||
+ AsServiceId<SdpService<RuntimeServiceId>>
|
||||
@@ -81,6 +85,7 @@ where
|
||||
MANTLE_SDP_DECLARATIONS,
|
||||
get(get_sdp_declarations::<RuntimeServiceId>),
|
||||
)
|
||||
.route(DIAL_PEER, post(dial_peer::<RuntimeServiceId>))
|
||||
.with_state(handle)
|
||||
.layer(axum::extract::DefaultBodyLimit::max(
|
||||
self.settings.max_body_size,
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
use axum::{extract::State, response::Response};
|
||||
use lb_api_service::http::mantle;
|
||||
use axum::{Json, extract::State, response::Response};
|
||||
use lb_api_service::http::{libp2p, mantle};
|
||||
use lb_libp2p::{Multiaddr, PeerId};
|
||||
use lb_network_service::{NetworkService, backends::libp2p::Libp2p as NetworkBackend};
|
||||
use overwatch::{overwatch::OverwatchHandle, services::AsServiceId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::backend::TestHttpCryptarchiaService;
|
||||
use crate::{
|
||||
@@ -10,6 +13,11 @@ use crate::{
|
||||
make_request_and_return_response,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DialPeerRequestBody {
|
||||
pub addr: Multiaddr,
|
||||
}
|
||||
|
||||
pub async fn get_sdp_declarations<RuntimeServiceId>(
|
||||
State(handle): State<OverwatchHandle<RuntimeServiceId>>,
|
||||
) -> Response
|
||||
@@ -25,3 +33,24 @@ where
|
||||
{
|
||||
make_request_and_return_response!(mantle::get_sdp_declarations::<RuntimeServiceId>(&handle))
|
||||
}
|
||||
|
||||
pub async fn dial_peer<RuntimeServiceId>(
|
||||
State(handle): State<OverwatchHandle<RuntimeServiceId>>,
|
||||
Json(req): Json<DialPeerRequestBody>,
|
||||
) -> Response
|
||||
where
|
||||
RuntimeServiceId: Debug
|
||||
+ Send
|
||||
+ Sync
|
||||
+ Display
|
||||
+ 'static
|
||||
+ AsServiceId<NetworkService<NetworkBackend, RuntimeServiceId>>
|
||||
+ AsServiceId<TestHttpCryptarchiaService<RuntimeServiceId>>
|
||||
+ AsServiceId<SdpService<RuntimeServiceId>>
|
||||
+ AsServiceId<TxMempoolService<RuntimeServiceId>>,
|
||||
{
|
||||
make_request_and_return_response!(async move {
|
||||
let peer_id: PeerId = libp2p::connect_peer::<RuntimeServiceId>(&handle, req.addr).await?;
|
||||
Ok::<PeerId, overwatch::DynError>(peer_id)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user