pub struct Discv5State {
pub counter: u32,
pub pending_by_nonce: FxHashMap<[u8; 12], (Node, Message, Instant)>,
pub pending_challenges: FxHashMap<H256, (Vec<u8>, Instant, Vec<u8>)>,
pub whoareyou_rate_limit: LruCache<(IpAddr, H256), Instant>,
pub whoareyou_global_count: u32,
pub whoareyou_global_window_start: Instant,
pub session_ips: FxHashMap<H256, IpAddr>,
pub ip_votes: FxHashMap<IpAddr, FxHashSet<H256>>,
pub ip_vote_period_start: Option<Instant>,
pub first_ip_vote_round_completed: bool,
pub active_lookups: Vec<IterativeLookup>,
}Expand description
Discv5-specific state held within the unified DiscoveryServer.
Fields§
§counter: u32Outgoing message count, used for nonce generation as per the spec.
pending_by_nonce: FxHashMap<[u8; 12], (Node, Message, Instant)>Pending outgoing messages awaiting WhoAreYou response, keyed by nonce.
pending_challenges: FxHashMap<H256, (Vec<u8>, Instant, Vec<u8>)>Pending WhoAreYou challenges awaiting Handshake response, keyed by src_id. Tuple: (challenge_data, timestamp, encoded_packet_bytes).
whoareyou_rate_limit: LruCache<(IpAddr, H256), Instant>Tracks last WHOAREYOU send time per (source IP, node ID) to prevent amplification attacks.
whoareyou_global_count: u32Global WHOAREYOU rate limit: count of packets sent in the current second.
whoareyou_global_window_start: InstantStart of the current global rate limit window.
session_ips: FxHashMap<H256, IpAddr>Tracks the source IP that each session was established from.
ip_votes: FxHashMap<IpAddr, FxHashSet<H256>>Collects recipient_addr IPs from PONGs for external IP detection via majority voting.
ip_vote_period_start: Option<Instant>When the current IP voting period started. None if no votes received yet.
first_ip_vote_round_completed: boolWhether the first (fast) voting round has completed.
active_lookups: Vec<IterativeLookup>Currently active iterative lookups.
Implementations§
Source§impl Discv5State
impl Discv5State
Sourcepub fn next_nonce<R: RngCore>(&mut self, rng: &mut R) -> [u8; 12]
pub fn next_nonce<R: RngCore>(&mut self, rng: &mut R) -> [u8; 12]
Generates a 96-bit AES-GCM nonce. Encodes the current outgoing message count into the first 32 bits and fills the remaining 64 bits with random data.
Sourcepub fn cleanup_stale_entries(&mut self) -> Option<IpAddr>
pub fn cleanup_stale_entries(&mut self) -> Option<IpAddr>
Remove stale entries from caches.
Returns Some(ip) if a timed-out IP voting round produced a winning IP to apply.
Sourcepub fn record_ip_vote(
&mut self,
reported_ip: IpAddr,
voter_id: H256,
) -> Option<IpAddr>
pub fn record_ip_vote( &mut self, reported_ip: IpAddr, voter_id: H256, ) -> Option<IpAddr>
Records an IP vote from a PONG recipient_addr.
Returns Some(ip) if the voting round ended with a winning IP to apply.
Sourcepub fn is_private_ip(ip: IpAddr) -> bool
pub fn is_private_ip(ip: IpAddr) -> bool
Returns true if the IP is private/local (not useful for external connectivity).
Trait Implementations§
Source§impl Debug for Discv5State
impl Debug for Discv5State
Auto Trait Implementations§
impl Freeze for Discv5State
impl RefUnwindSafe for Discv5State
impl Send for Discv5State
impl Sync for Discv5State
impl Unpin for Discv5State
impl UnsafeUnpin for Discv5State
impl UnwindSafe for Discv5State
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> 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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.