mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-03-11 08:56:26 +00:00
get_bans
This commit is contained in:
parent
f677b1ae2a
commit
37bcbb5ea0
2 changed files with 30 additions and 4 deletions
binaries/cuprated/src/rpc
|
@ -38,7 +38,7 @@ use cuprate_rpc_types::{
|
||||||
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
||||||
SyncInfoResponse,
|
SyncInfoResponse,
|
||||||
},
|
},
|
||||||
misc::{BlockHeader, Status},
|
misc::{BlockHeader, GetBan, Status},
|
||||||
CORE_RPC_VERSION,
|
CORE_RPC_VERSION,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -433,9 +433,34 @@ async fn get_bans(
|
||||||
state: CupratedRpcHandler,
|
state: CupratedRpcHandler,
|
||||||
request: GetBansRequest,
|
request: GetBansRequest,
|
||||||
) -> Result<GetBansResponse, Error> {
|
) -> Result<GetBansResponse, Error> {
|
||||||
|
let now = Instant::now();
|
||||||
|
|
||||||
|
let bans = address_book::get_bans::<ClearNet>(&mut DummyAddressBook)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|ban| {
|
||||||
|
let seconds = if let Some(instant) = ban.unban_instant {
|
||||||
|
instant
|
||||||
|
.checked_duration_since(now)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_secs()
|
||||||
|
.try_into()
|
||||||
|
.unwrap_or(0)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
GetBan {
|
||||||
|
host: ban.address.to_string(),
|
||||||
|
ip: todo!(),
|
||||||
|
seconds,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(GetBansResponse {
|
Ok(GetBansResponse {
|
||||||
base: ResponseBase::ok(),
|
base: ResponseBase::ok(),
|
||||||
bans: todo!(),
|
bans,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use tower::ServiceExt;
|
||||||
use cuprate_helper::cast::usize_to_u64;
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
use cuprate_p2p_core::{
|
use cuprate_p2p_core::{
|
||||||
services::{AddressBookRequest, AddressBookResponse},
|
services::{AddressBookRequest, AddressBookResponse},
|
||||||
|
types::BanState,
|
||||||
AddressBook, NetworkZone,
|
AddressBook, NetworkZone,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ pub(crate) async fn get_ban<Z: NetworkZone>(
|
||||||
/// [`AddressBookRequest::GetBans`]
|
/// [`AddressBookRequest::GetBans`]
|
||||||
pub(crate) async fn get_bans<Z: NetworkZone>(
|
pub(crate) async fn get_bans<Z: NetworkZone>(
|
||||||
address_book: &mut impl AddressBook<Z>,
|
address_book: &mut impl AddressBook<Z>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<Vec<BanState<Z::Addr>>, Error> {
|
||||||
let AddressBookResponse::GetBans(bans) = address_book
|
let AddressBookResponse::GetBans(bans) = address_book
|
||||||
.ready()
|
.ready()
|
||||||
.await
|
.await
|
||||||
|
@ -153,5 +154,5 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(todo!())
|
Ok(bans)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue