mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-18 16:54:32 +00:00
set_bans
This commit is contained in:
parent
50bd576bb1
commit
f677b1ae2a
2 changed files with 19 additions and 4 deletions
|
@ -1,4 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use std::{
|
||||
sync::Arc,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Error};
|
||||
use cuprate_p2p_core::{client::handshaker::builder::DummyAddressBook, ClearNet};
|
||||
|
@ -406,7 +409,19 @@ async fn set_bans(
|
|||
state: CupratedRpcHandler,
|
||||
request: SetBansRequest,
|
||||
) -> Result<SetBansResponse, Error> {
|
||||
todo!();
|
||||
for peer in request.bans {
|
||||
let address = todo!();
|
||||
|
||||
let ban = if peer.ban {
|
||||
Some(Duration::from_secs(peer.seconds.into()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let set_ban = cuprate_p2p_core::types::SetBan { address, ban };
|
||||
|
||||
address_book::set_ban::<ClearNet>(&mut DummyAddressBook, set_ban).await?;
|
||||
}
|
||||
|
||||
Ok(SetBansResponse {
|
||||
base: ResponseBase::ok(),
|
||||
|
|
|
@ -103,13 +103,13 @@ pub(crate) async fn connection_count<Z: NetworkZone>(
|
|||
/// [`AddressBookRequest::SetBan`]
|
||||
pub(crate) async fn set_ban<Z: NetworkZone>(
|
||||
address_book: &mut impl AddressBook<Z>,
|
||||
peer: cuprate_p2p_core::types::SetBan<Z::Addr>,
|
||||
set_ban: cuprate_p2p_core::types::SetBan<Z::Addr>,
|
||||
) -> Result<(), Error> {
|
||||
let AddressBookResponse::Ok = address_book
|
||||
.ready()
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
.call(AddressBookRequest::SetBan(peer))
|
||||
.call(AddressBookRequest::SetBan(set_ban))
|
||||
.await
|
||||
.map_err(|e| anyhow!(e))?
|
||||
else {
|
||||
|
|
Loading…
Reference in a new issue