pub struct IPDiversityConfig {
pub max_per_ip: Option<usize>,
pub max_per_subnet: Option<usize>,
}Expand description
Configuration for IP diversity enforcement at two tiers: exact IP and subnet.
Limits are applied per-bucket and per-close-group (the K closest nodes to self), matching how geographic diversity is enforced. When a candidate would exceed a limit, it may still be admitted via swap-closer logic: if the candidate is closer (XOR distance) to self than the farthest same-subnet peer in the scope, that farther peer is evicted.
By default every limit is None, meaning the K-based defaults from
DhtCoreEngine apply (fractions of the bucket size K). Setting an
explicit Some(n) overrides the K-based default for that tier.
Fields§
§max_per_ip: Option<usize>Override for max nodes sharing an exact IP address per bucket/close-group.
When None, uses the default of 2.
max_per_subnet: Option<usize>Override for max nodes in the same subnet (/24 IPv4, /48 IPv6).
When None, uses the K-based default (~25% of bucket size).
Implementations§
Source§impl IPDiversityConfig
impl IPDiversityConfig
Sourcepub fn testnet() -> IPDiversityConfig
pub fn testnet() -> IPDiversityConfig
Create a testnet configuration with relaxed diversity requirements.
This is useful for testing environments like Digital Ocean where all nodes share the same ASN (AS14061). The relaxed limits allow many nodes from the same provider while still maintaining some diversity tracking.
Currently identical to permissive but kept as a
separate constructor so testnet limits can diverge independently (e.g.
allowing same-subnet but limiting per-IP) without changing local-dev
callers.
§Warning
This configuration should NEVER be used in production as it significantly weakens Sybil attack protection.
Sourcepub fn permissive() -> IPDiversityConfig
pub fn permissive() -> IPDiversityConfig
Create a permissive configuration that effectively disables diversity checks.
This is useful for local development and unit testing where all nodes run on localhost or the same machine.
Trait Implementations§
Source§impl Clone for IPDiversityConfig
impl Clone for IPDiversityConfig
Source§fn clone(&self) -> IPDiversityConfig
fn clone(&self) -> IPDiversityConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IPDiversityConfig
impl Debug for IPDiversityConfig
Source§impl Default for IPDiversityConfig
impl Default for IPDiversityConfig
Source§fn default() -> IPDiversityConfig
fn default() -> IPDiversityConfig
Source§impl<'de> Deserialize<'de> for IPDiversityConfig
impl<'de> Deserialize<'de> for IPDiversityConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<IPDiversityConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<IPDiversityConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for IPDiversityConfig
impl Serialize for IPDiversityConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for IPDiversityConfig
impl RefUnwindSafe for IPDiversityConfig
impl Send for IPDiversityConfig
impl Sync for IPDiversityConfig
impl Unpin for IPDiversityConfig
impl UnsafeUnpin for IPDiversityConfig
impl UnwindSafe for IPDiversityConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more