mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-02-02 03:06:36 +00:00
check if incoming peers are banned
This commit is contained in:
parent
a4ca123589
commit
fd7225e673
4 changed files with 34 additions and 8 deletions
|
@ -409,6 +409,9 @@ impl<Z: NetworkZone> Service<AddressBookRequest<Z>> for AddressBook<Z> {
|
|||
AddressBookRequest::GetWhitePeers(len) => {
|
||||
Ok(AddressBookResponse::Peers(self.get_white_peers(len)))
|
||||
}
|
||||
AddressBookRequest::IsPeerBanned(addr) => Ok(AddressBookResponse::IsPeerBanned(
|
||||
self.is_peer_banned(&addr),
|
||||
)),
|
||||
};
|
||||
|
||||
ready(response)
|
||||
|
|
|
@ -12,9 +12,10 @@ use tokio::{
|
|||
use tower::{Service, ServiceExt};
|
||||
use tracing::{instrument, Instrument, Span};
|
||||
|
||||
use monero_p2p::services::{AddressBookRequest, AddressBookResponse};
|
||||
use monero_p2p::{
|
||||
client::{Client, DoHandshakeRequest, HandshakeError, InternalPeerID},
|
||||
ConnectionDirection, NetworkZone,
|
||||
AddressBook, ConnectionDirection, NetworkZone,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -25,9 +26,10 @@ use crate::{
|
|||
|
||||
/// The inbound server.
|
||||
#[instrument(level = "warn", skip_all)]
|
||||
pub async fn inbound_server<N, HS>(
|
||||
pub async fn inbound_server<N, HS, A>(
|
||||
client_pool: Arc<ClientPool<N>>,
|
||||
mut handshaker: HS,
|
||||
mut address_book: A,
|
||||
config: P2PConfig<N>,
|
||||
) -> Result<(), tower::BoxError>
|
||||
where
|
||||
|
@ -36,15 +38,13 @@ where
|
|||
+ Send
|
||||
+ 'static,
|
||||
HS::Future: Send + 'static,
|
||||
A: AddressBook<N>,
|
||||
{
|
||||
let Some(server_config) = config.server_config else {
|
||||
tracing::warn!("No inbound server config provided, not listening for inbound connections.");
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
// TODO: take in the address book and check if incoming peers are banned before adding them to our
|
||||
// connections.
|
||||
|
||||
tracing::info!("Starting inbound connection server");
|
||||
|
||||
let listener = N::incoming_connection_listener(server_config, config.p2p_port)
|
||||
|
@ -60,6 +60,21 @@ where
|
|||
continue;
|
||||
};
|
||||
|
||||
if let Some(addr) = &addr {
|
||||
let AddressBookResponse::IsPeerBanned(banned) = address_book
|
||||
.ready()
|
||||
.await?
|
||||
.call(AddressBookRequest::IsPeerBanned(*addr))
|
||||
.await?
|
||||
else {
|
||||
panic!("Address book returned incorrect response!");
|
||||
};
|
||||
|
||||
if banned {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
let addr = match addr {
|
||||
Some(addr) => InternalPeerID::KnownAddr(addr),
|
||||
None => InternalPeerID::Unknown(rand::random()),
|
||||
|
|
|
@ -56,7 +56,7 @@ where
|
|||
config.max_inbound_connections + config.outbound_connections,
|
||||
);
|
||||
|
||||
// Use the default config. Changing the defaults affects tx fluff times, which could effect D++ so for now don't allow changing
|
||||
// Use the default config. Changing the defaults affects tx fluff times, which could affect D++ so for now don't allow changing
|
||||
// this.
|
||||
let (broadcast_svc, outbound_mkr, inbound_mkr) =
|
||||
broadcast::init_broadcast_channels(broadcast::BroadcastConfig::default());
|
||||
|
@ -105,8 +105,13 @@ where
|
|||
.instrument(Span::current()),
|
||||
);
|
||||
tokio::spawn(
|
||||
inbound_server::inbound_server(client_pool.clone(), inbound_handshaker, config)
|
||||
.instrument(Span::current()),
|
||||
inbound_server::inbound_server(
|
||||
client_pool.clone(),
|
||||
inbound_handshaker,
|
||||
address_book,
|
||||
config,
|
||||
)
|
||||
.instrument(Span::current()),
|
||||
);
|
||||
|
||||
Ok(NetworkInterface {
|
||||
|
|
|
@ -119,10 +119,13 @@ pub enum AddressBookRequest<Z: NetworkZone> {
|
|||
TakeRandomPeer { height: Option<u64> },
|
||||
/// Gets the specified number of white peers, or less if we don't have enough.
|
||||
GetWhitePeers(usize),
|
||||
/// Checks if the given peer is banned.
|
||||
IsPeerBanned(Z::Addr),
|
||||
}
|
||||
|
||||
pub enum AddressBookResponse<Z: NetworkZone> {
|
||||
Ok,
|
||||
Peer(ZoneSpecificPeerListEntryBase<Z::Addr>),
|
||||
Peers(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>),
|
||||
IsPeerBanned(bool),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue