2023-11-30 18:09:05 +00:00
|
|
|
use std::{
|
|
|
|
future::Future,
|
|
|
|
pin::Pin,
|
|
|
|
task::{Context, Poll},
|
|
|
|
};
|
|
|
|
|
|
|
|
use futures::FutureExt;
|
|
|
|
use tower::Service;
|
|
|
|
|
2024-06-24 01:30:47 +00:00
|
|
|
use cuprate_p2p_core::{
|
2023-11-30 18:09:05 +00:00
|
|
|
services::{
|
|
|
|
AddressBookRequest, AddressBookResponse, CoreSyncDataRequest, CoreSyncDataResponse,
|
2024-05-02 22:58:22 +00:00
|
|
|
PeerSyncRequest, PeerSyncResponse,
|
2023-11-30 18:09:05 +00:00
|
|
|
},
|
|
|
|
NetworkZone, PeerRequest, PeerResponse,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DummyAddressBook;
|
|
|
|
|
|
|
|
impl<Z: NetworkZone> Service<AddressBookRequest<Z>> for DummyAddressBook {
|
|
|
|
type Response = AddressBookResponse<Z>;
|
|
|
|
type Error = tower::BoxError;
|
|
|
|
type Future =
|
|
|
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
|
|
|
|
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call(&mut self, req: AddressBookRequest<Z>) -> Self::Future {
|
|
|
|
async move {
|
|
|
|
Ok(match req {
|
2023-12-08 15:03:01 +00:00
|
|
|
AddressBookRequest::GetWhitePeers(_) => AddressBookResponse::Peers(vec![]),
|
2023-11-30 18:09:05 +00:00
|
|
|
_ => AddressBookResponse::Ok,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DummyCoreSyncSvc;
|
|
|
|
|
|
|
|
impl Service<CoreSyncDataRequest> for DummyCoreSyncSvc {
|
|
|
|
type Response = CoreSyncDataResponse;
|
|
|
|
type Error = tower::BoxError;
|
|
|
|
type Future =
|
|
|
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
|
|
|
|
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
}
|
|
|
|
|
2024-05-02 22:58:22 +00:00
|
|
|
fn call(&mut self, _: CoreSyncDataRequest) -> Self::Future {
|
2023-11-30 18:09:05 +00:00
|
|
|
async move {
|
2024-06-24 01:30:47 +00:00
|
|
|
Ok(CoreSyncDataResponse(cuprate_wire::CoreSyncData {
|
2024-05-02 22:58:22 +00:00
|
|
|
cumulative_difficulty: 1,
|
|
|
|
cumulative_difficulty_top64: 0,
|
|
|
|
current_height: 1,
|
|
|
|
pruning_seed: 0,
|
|
|
|
top_id: hex::decode(
|
|
|
|
"418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3",
|
|
|
|
)
|
|
|
|
.unwrap()
|
|
|
|
.try_into()
|
|
|
|
.unwrap(),
|
|
|
|
top_version: 1,
|
|
|
|
}))
|
2023-11-30 18:09:05 +00:00
|
|
|
}
|
|
|
|
.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 22:58:22 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DummyPeerSyncSvc;
|
|
|
|
|
|
|
|
impl<N: NetworkZone> Service<PeerSyncRequest<N>> for DummyPeerSyncSvc {
|
|
|
|
type Error = tower::BoxError;
|
|
|
|
type Future =
|
|
|
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
|
|
|
|
|
|
|
type Response = PeerSyncResponse<N>;
|
|
|
|
|
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn call(&mut self, _: PeerSyncRequest<N>) -> Self::Future {
|
|
|
|
async { Ok(PeerSyncResponse::Ok) }.boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-30 18:09:05 +00:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DummyPeerRequestHandlerSvc;
|
|
|
|
|
|
|
|
impl Service<PeerRequest> for DummyPeerRequestHandlerSvc {
|
|
|
|
type Response = PeerResponse;
|
|
|
|
type Error = tower::BoxError;
|
|
|
|
type Future =
|
|
|
|
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
|
|
|
|
2023-12-03 00:29:12 +00:00
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
2024-01-13 13:22:34 +00:00
|
|
|
Poll::Ready(Ok(()))
|
2023-11-30 18:09:05 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 00:29:12 +00:00
|
|
|
fn call(&mut self, _: PeerRequest) -> Self::Future {
|
2024-01-13 13:22:34 +00:00
|
|
|
async move { Ok(PeerResponse::NA) }.boxed()
|
2023-11-30 18:09:05 +00:00
|
|
|
}
|
|
|
|
}
|