mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-12-23 20:20:01 +00:00
4b93dbec4c
Some checks failed
Audit / audit (push) Has been cancelled
Deny / audit (push) Has been cancelled
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
* rename all directories and crates * fix all `use` * fix doc link * `dandelion/` -> `dandelion-tower/` * fix epee-encoding test * fix `json-rpc` * fix pruning * crate import fixes * fix leftover merge conflicts * fix `epee-encoding`
110 lines
3.1 KiB
Rust
110 lines
3.1 KiB
Rust
use std::{
|
|
future::Future,
|
|
pin::Pin,
|
|
task::{Context, Poll},
|
|
};
|
|
|
|
use futures::FutureExt;
|
|
use tower::Service;
|
|
|
|
use cuprate_p2p_core::{
|
|
services::{
|
|
AddressBookRequest, AddressBookResponse, CoreSyncDataRequest, CoreSyncDataResponse,
|
|
PeerSyncRequest, PeerSyncResponse,
|
|
},
|
|
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 {
|
|
AddressBookRequest::GetWhitePeers(_) => AddressBookResponse::Peers(vec![]),
|
|
_ => 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(()))
|
|
}
|
|
|
|
fn call(&mut self, _: CoreSyncDataRequest) -> Self::Future {
|
|
async move {
|
|
Ok(CoreSyncDataResponse(cuprate_wire::CoreSyncData {
|
|
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,
|
|
}))
|
|
}
|
|
.boxed()
|
|
}
|
|
}
|
|
|
|
#[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()
|
|
}
|
|
}
|
|
|
|
#[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>>;
|
|
|
|
fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
Poll::Ready(Ok(()))
|
|
}
|
|
|
|
fn call(&mut self, _: PeerRequest) -> Self::Future {
|
|
async move { Ok(PeerResponse::NA) }.boxed()
|
|
}
|
|
}
|