Proper way to ban relays #1337
|
Thanks for building this project. My connection pool is very large; it may contain all existing relays with gossip flag enabled. I want to permanently disallow connections to some relays and waste as little RAM on the unused relays as possible. Is it currently possible only by implementing
|
Replies: 2 comments 1 reply
|
The function @yukibtc I think we should make it public. Until the next release, you need to mark the relay as banned and refuse to connect to it in I think you should enable |
|
Hey @alopatindev, at the moment I think something like this could be used: #[derive(Debug)]
struct BanSystem {
database: YourDatabase,
}
impl AdmitPolicy for BanSystem {
fn admit_connection<'a>(&'a self, relay_url: &'a RelayUrl) -> BoxedFuture<'a, Result<AdmitStatus, PolicyError>> {
Box::pin(async move {
if self.database.is_relay_banned(relay_url) {
return Ok(AdmitStatus::rejected("banned"));
}
Ok(AdmitStatus::Success)
})
}
}
async fn ban_relay(client: &Client, ban_system: &BanSystem, relay_url: &RelayUrl) -> Result<()> {
let relay = client.relay(relay_url).await?.unwrap();
// Marks the relay as banned (stored only in RAM, until the relay is in the pool)
relay.ban();
// Persist in the database to prevent future connection attempts, in case the client is dropped and the relay is re-added to the pool with a clean status.
ban_system.database.ban_relay(relay_url).await?;
Ok(())
}Maybe we can add an additional policy like CC @TheAwiteb |
The function
force_remove_relayonly disconnect the relay, but you can connect to it later, the client can actually ban relays, but it's not exposed, it do it internally when an event mismatch with the subscription.@yukibtc I think we should make it public.
Until the next release, you need to mark the relay as banned and refuse to connect to it in
AdmitPolicy::admit_connection. Later when the client can ban relays, you can setup a monitor and when you getRelayStatus::Bannedyou update your banned relays list so the client remember them on the next run.I think you should enable
ban_relay_on_mismatchand update your list when a relay is banned, you can also update the list when you disco…