sigil-network · peer
Source declarations, signatures and documentation for peer.
Source: sigil/node/sigil-network/src/peer.rs. SHA-256: aa93cbb6f94e66934fc17b6b8ddf663a2c8ae134bda4b776ebe821ab233d89bf.
This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.
peer::PeerInfo
Metadata and state for a single known peer.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PeerInfo {
/// Unique peer identifier (e.g. libp2p PeerId).
pub peer_id: String,
/// OAS DID of the peer, if known.
pub did: Option<String>,
/// Chain ID the peer is operating on.
pub chain_id: String,
/// The peer's latest reported block height.
pub current_height: u64,
/// The peer's latest reported epoch.
pub current_epoch: u64,
/// Protocol version the peer advertised.
pub protocol_version: String,
/// Whether this peer is a registered validator.
pub is_validator: bool,
/// Reputation score in `[0.0, 1.0]`.
pub reputation_score: f64,
/// Unix timestamp of last successful communication.
pub last_seen: u64,
/// Current connection state.
pub connection_state: ConnectionState
}Source line: 23.
peer::ConnectionState
Connection state of a peer.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ConnectionState {
/// Actively connected and exchanging messages.
Connected,
/// Not currently connected.
Disconnected,
/// Connection attempt in progress.
Connecting,
/// Peer has been banned due to misbehaviour.
Banned,
}Source line: 48.
peer::ConnectionState::is_active
Returns true if the peer is in a live connection state.
pub fn is_active(&self) -> bool;Source line: 61.
peer::PeerAdmission
Proof class a peer presents at admission time.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PeerAdmission {
/// Staked validator DID with a recent chain attestation.
StakedValidator { did: String, attested_epoch: u64 },
/// Operator allowlisted by launch/bootstrap configuration.
AllowlistedBootstrap { operator_id: String },
/// Unstaked peer proof-of-work nonce.
ProofOfWork { nonce: u64 },
}Source line: 68.
peer::PeerDiversity
Eclipse-resistance metadata for a peer.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PeerDiversity {
pub asn: u32,
pub geo_region: String,
pub cloud_provider: String,
pub lineage_group: String
}Source line: 79.
peer::PeerSecurityConfig
Peer admission and diversity policy.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PeerSecurityConfig {
/// Enforce Sybil proof checks in [`PeerRegistry::add_peer_with_admission`].
pub enforce_admission: bool,
/// Current epoch for freshness checks.
pub current_epoch: u64,
/// Maximum age for validator attestations.
pub max_attestation_age_epochs: u64,
/// Minimum leading-zero PoW bits for unstaked peers.
pub min_pow_leading_zero_bits: u32,
/// Allowlisted bootstrap operator identifiers.
pub allowlisted_bootstrap_operators: HashSet<String>,
/// Enforce ASN/region/cloud diversity once enough peers are present.
pub enforce_diversity: bool,
/// Minimum distinct ASNs in the connected set.
pub min_asns: usize,
/// Minimum distinct geo regions in the connected set.
pub min_geo_regions: usize,
/// Minimum distinct cloud providers in the connected set.
pub min_cloud_providers: usize,
/// Maximum fraction of peers sharing one lineage group.
pub max_lineage_fraction: f64
}Source line: 88.
peer::PeerRegistry
Registry managing known peers and their metadata.
The registry enforces a maximum peer count and provides query methods for sync target selection and validator discovery.
#[derive(Debug)]
pub struct PeerRegistry {
}Source line: 212.
peer::PeerRegistry::new
Create a new registry with the given maximum peer count.
pub fn new(max_peers: usize) -> Self;Source line: 233.
peer::PeerRegistry::with_security
Create a new registry with explicit security policy.
pub fn with_security(max_peers: usize, security: PeerSecurityConfig) -> Self;Source line: 238.
peer::PeerRegistry::peer_count
Number of peers currently in the registry.
pub fn peer_count(&self) -> usize;Source line: 249.
peer::PeerRegistry::add_peer
Add a new peer to the registry.
Returns an error if the registry is full or if a peer with the
same ID already exists (use update_peer to
modify existing peers).
pub fn add_peer(&mut self, info: PeerInfo) -> NetworkResult<()>;Source line: 258.
peer::PeerRegistry::add_peer_with_admission
Add a peer after validating its admission proof and diversity metadata.
pub fn add_peer_with_admission(
&mut self,
info: PeerInfo,
admission: PeerAdmission,
diversity: Option<PeerDiversity>,
) -> NetworkResult<()>;Source line: 263.
peer::PeerRegistry::remove_peer
Remove a peer from the registry by ID.
Returns the removed [PeerInfo] or an error if not found.
pub fn remove_peer(&mut self, peer_id: &str) -> NetworkResult<PeerInfo>;Source line: 357.
peer::PeerRegistry::get_peer
Look up a peer by ID.
pub fn get_peer(&self, peer_id: &str) -> Option<&PeerInfo>;Source line: 366.
peer::PeerRegistry::get_peer_mut
Get mutable access to a peer's info.
pub fn get_peer_mut(&mut self, peer_id: &str) -> Option<&mut PeerInfo>;Source line: 371.
peer::PeerRegistry::get_scoring
Get a peer's scoring state.
pub fn get_scoring(&self, peer_id: &str) -> Option<&PeerScoring>;Source line: 376.
peer::PeerRegistry::get_scoring_mut
Get mutable access to a peer's scoring state.
pub fn get_scoring_mut(&mut self, peer_id: &str) -> Option<&mut PeerScoring>;Source line: 381.
peer::PeerRegistry::update_peer
Update an existing peer's metadata.
The updater closure receives a mutable reference to the peer info.
Returns an error if the peer is not found.
pub fn update_peer<F>(&mut self, peer_id: &str, updater: F) -> NetworkResult<()>
where
F: FnOnce(&mut PeerInfo),;Source line: 389.
peer::PeerRegistry::connected_peers
Iterate over all currently connected peers.
pub fn connected_peers(&self) -> impl Iterator<Item = &PeerInfo>;Source line: 402.
peer::PeerRegistry::validator_peers
Iterate over all peers that are registered validators.
pub fn validator_peers(&self) -> impl Iterator<Item = &PeerInfo>;Source line: 409.
peer::PeerRegistry::best_peers_for_sync
Return peers sorted by height (descending), suitable for block sync.
Only connected peers with a non-banned state are returned.
pub fn best_peers_for_sync(&self) -> Vec<&PeerInfo>;Source line: 416.
peer::PeerRegistry::should_ban
Determine whether a peer should be banned based on reputation and scoring state.
pub fn should_ban(&self, peer_id: &str) -> bool;Source line: 431.
peer::PeerRegistry::ban_peer
Ban a peer, setting its connection state to [ConnectionState::Banned].
pub fn ban_peer(&mut self, peer_id: &str) -> NetworkResult<()>;Source line: 448.
peer::PeerRegistry::peer_ids
Returns all peer IDs currently in the registry.
pub fn peer_ids(&self) -> Vec<String>;Source line: 455.
peer::PeerRegistry::decay_all_scores
Apply score decay across all peers.
pub fn decay_all_scores(&mut self, factor: f64);Source line: 460.