mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-16 15:58:14 +00:00
get_bans
This commit is contained in:
parent
f677b1ae2a
commit
37bcbb5ea0
2 changed files with 30 additions and 4 deletions
|
@ -38,7 +38,7 @@ use cuprate_rpc_types::{
|
|||
SetBansRequest, SetBansResponse, SubmitBlockRequest, SubmitBlockResponse, SyncInfoRequest,
|
||||
SyncInfoResponse,
|
||||
},
|
||||
misc::{BlockHeader, Status},
|
||||
misc::{BlockHeader, GetBan, Status},
|
||||
CORE_RPC_VERSION,
|
||||
};
|
||||
|
||||
|
@ -433,9 +433,34 @@ async fn get_bans(
|
|||
state: CupratedRpcHandler,
|
||||
request: GetBansRequest,
|
||||
) -> 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 {
|
||||
base: ResponseBase::ok(),
|
||||
bans: todo!(),
|
||||
bans,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use tower::ServiceExt;
|
|||
use cuprate_helper::cast::usize_to_u64;
|
||||
use cuprate_p2p_core::{
|
||||
services::{AddressBookRequest, AddressBookResponse},
|
||||
types::BanState,
|
||||
AddressBook, NetworkZone,
|
||||
};
|
||||
|
||||
|
@ -141,7 +142,7 @@ pub(crate) async fn get_ban<Z: NetworkZone>(
|
|||
/// [`AddressBookRequest::GetBans`]
|
||||
pub(crate) async fn get_bans<Z: NetworkZone>(
|
||||
address_book: &mut impl AddressBook<Z>,
|
||||
) -> Result<(), Error> {
|
||||
) -> Result<Vec<BanState<Z::Addr>>, Error> {
|
||||
let AddressBookResponse::GetBans(bans) = address_book
|
||||
.ready()
|
||||
.await
|
||||
|
@ -153,5 +154,5 @@ pub(crate) async fn get_bans<Z: NetworkZone>(
|
|||
unreachable!();
|
||||
};
|
||||
|
||||
Ok(todo!())
|
||||
Ok(bans)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue