diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index fe2b597..1c82df1 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -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 { - 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::(&mut DummyAddressBook, set_ban).await?; + } Ok(SetBansResponse { base: ResponseBase::ok(), diff --git a/binaries/cuprated/src/rpc/request/address_book.rs b/binaries/cuprated/src/rpc/request/address_book.rs index 3fe4de3..5458c49 100644 --- a/binaries/cuprated/src/rpc/request/address_book.rs +++ b/binaries/cuprated/src/rpc/request/address_book.rs @@ -103,13 +103,13 @@ pub(crate) async fn connection_count( /// [`AddressBookRequest::SetBan`] pub(crate) async fn set_ban( address_book: &mut impl AddressBook, - peer: cuprate_p2p_core::types::SetBan, + set_ban: cuprate_p2p_core::types::SetBan, ) -> 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 {