This commit is contained in:
hinto.janai 2024-10-14 17:04:25 -04:00
parent 50bd576bb1
commit f677b1ae2a
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
2 changed files with 19 additions and 4 deletions

View file

@ -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(),

View file

@ -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 {