pub struct NodeID(/* private fields */);Expand description
Unique identifier for a peer in the P2P network.
NodeID is a 4-byte identifier typically based on an IPv4 address.
Each peer in the network must have a unique NodeID for routing purposes.
§Examples
use rustp2p::NodeID;
use std::net::Ipv4Addr;
// Create from IPv4 address
let node_id: NodeID = Ipv4Addr::new(10, 0, 0, 1).into();
// Create from u32
let node_id: NodeID = 0x0A000001u32.into();
// Convert back to IPv4
let addr: Ipv4Addr = node_id.into();
assert_eq!(addr, Ipv4Addr::new(10, 0, 0, 1));Implementations§
Source§impl NodeID
impl NodeID
Sourcepub fn broadcast() -> NodeID
pub fn broadcast() -> NodeID
Returns a broadcast NodeID (255.255.255.255).
Messages sent to this ID will be broadcast to all peers.
§Examples
use rustp2p::NodeID;
let broadcast = NodeID::broadcast();
assert!(broadcast.is_broadcast());Sourcepub fn unspecified() -> NodeID
pub fn unspecified() -> NodeID
Returns an unspecified NodeID (0.0.0.0).
§Examples
use rustp2p::NodeID;
let unspec = NodeID::unspecified();
assert!(unspec.is_unspecified());Sourcepub fn is_unspecified(&self) -> bool
pub fn is_unspecified(&self) -> bool
Checks if this NodeID is unspecified (all zeros).
§Examples
use rustp2p::NodeID;
let unspec = NodeID::unspecified();
assert!(unspec.is_unspecified());Sourcepub fn is_broadcast(&self) -> bool
pub fn is_broadcast(&self) -> bool
Checks if this NodeID is a broadcast address (all 255s).
§Examples
use rustp2p::NodeID;
let broadcast = NodeID::broadcast();
assert!(broadcast.is_broadcast());Trait Implementations§
Source§impl Ord for NodeID
impl Ord for NodeID
Source§impl PartialOrd for NodeID
impl PartialOrd for NodeID
impl Copy for NodeID
impl Eq for NodeID
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> 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
Mutably borrows from an owned value. Read more