Struct NodeId

Source
#[repr(C)]
pub struct NodeId { pub high: u64, pub low: u64, }
Expand description

A 128-bit node identifier generated from XorShiftRng.

NodeIds uniquely identify clients and nodes in the network. They are formatted as UUID-style strings for human readability and protocol compatibility.

Fields§

§high: u64§low: u64

Implementations§

Source§

impl NodeId

Source

pub fn generate(rng: &mut XorShiftRng) -> Self

Generate a new random NodeId using XorShiftRng.

§Example
use bbx_core::random::XorShiftRng;
use bbx_net::address::NodeId;

let mut rng = XorShiftRng::new(12345);
let node_id = NodeId::generate(&mut rng);
Source

pub fn generate_with_entropy(clock_micros: u64) -> Self

Generate a NodeId with mixed entropy sources for improved unpredictability.

Combines multiple entropy sources: time, process ID, memory address (ASLR), and a monotonic counter to create a more unpredictable seed.

Source

pub fn generate_unique<F>(clock_micros: u64, exists: F) -> Self
where F: FnMut(&NodeId) -> bool,

Generate a unique NodeId that doesn’t collide with existing IDs.

Uses generate_with_entropy internally and loops until finding an ID that the exists predicate returns false for.

Source

pub const fn from_parts(high: u64, low: u64) -> Self

Create a NodeId from explicit high and low parts.

Source

pub fn to_uuid_string(&self) -> String

Format as hyphenated UUID string.

Returns a string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Source

pub fn from_uuid_string(s: &str) -> Result<Self>

Parse from UUID string.

Accepts the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

Trait Implementations§

Source§

impl Clone for NodeId

Source§

fn clone(&self) -> NodeId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NodeId

Source§

fn default() -> NodeId

Returns the “default value” for a type. Read more
Source§

impl Hash for NodeId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NodeId

Source§

fn eq(&self, other: &NodeId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for NodeId

Source§

impl Eq for NodeId

Source§

impl StructuralPartialEq for NodeId

Auto Trait Implementations§

§

impl Freeze for NodeId

§

impl RefUnwindSafe for NodeId

§

impl Send for NodeId

§

impl Sync for NodeId

§

impl Unpin for NodeId

§

impl UnwindSafe for NodeId

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V