pub struct ChaincraftNode {
pub id: PeerId,
pub registry: Arc<RwLock<SharedObjectRegistry>>,
pub app_objects: Arc<RwLock<ApplicationObjectRegistry>>,
pub discovery: Option<DiscoveryManager>,
pub storage: Arc<dyn Storage>,
pub peers: Arc<RwLock<HashMap<PeerId, PeerInfo>>>,
pub banned_peers: Arc<RwLock<HashSet<SocketAddr>>>,
pub known_hashes: Arc<RwLock<HashSet<String>>>,
pub socket: Option<Arc<UdpSocket>>,
pub config: NodeConfig,
pub running: Arc<RwLock<bool>>,
}Expand description
Main node structure for Chaincraft network
Fields§
§id: PeerIdUnique identifier for this node
registry: Arc<RwLock<SharedObjectRegistry>>Registry of shared objects
app_objects: Arc<RwLock<ApplicationObjectRegistry>>Registry of application objects
discovery: Option<DiscoveryManager>Discovery manager
storage: Arc<dyn Storage>Storage backend
peers: Arc<RwLock<HashMap<PeerId, PeerInfo>>>Connected peers
banned_peers: Arc<RwLock<HashSet<SocketAddr>>>Banned peer addresses (loaded from and saved to storage)
known_hashes: Arc<RwLock<HashSet<String>>>Known message hashes for gossip
socket: Option<Arc<UdpSocket>>UDP socket for networking (if initialized)
config: NodeConfigNode configuration
running: Arc<RwLock<bool>>Running flag
Implementations§
Source§impl ChaincraftNode
impl ChaincraftNode
Sourcepub fn new_default() -> Self
pub fn new_default() -> Self
Create a new Chaincraft node with default settings (alias for compatibility with examples)
Sourcepub fn builder() -> ChaincraftNodeBuilder
pub fn builder() -> ChaincraftNodeBuilder
Create a new node builder
Sourcepub async fn is_running_async(&self) -> bool
pub async fn is_running_async(&self) -> bool
Check if the node is running (async version)
Sourcepub async fn add_peer(&self, peer: PeerInfo) -> Result<()>
pub async fn add_peer(&self, peer: PeerInfo) -> Result<()>
Add a peer to the node’s peer list. Rejects if peer address is banned.
Sourcepub async fn remove_peer(&self, peer_id: &PeerId) -> Result<()>
pub async fn remove_peer(&self, peer_id: &PeerId) -> Result<()>
Remove a peer from the node’s peer list
Sourcepub async fn ban_peer(
&self,
addr: SocketAddr,
duration: Option<Duration>,
) -> Result<()>
pub async fn ban_peer( &self, addr: SocketAddr, duration: Option<Duration>, ) -> Result<()>
Ban a peer address for a duration. Persisted to storage.
Sourcepub async fn unban_peer(&self, addr: SocketAddr) -> Result<()>
pub async fn unban_peer(&self, addr: SocketAddr) -> Result<()>
Unban a peer address. Persisted to storage.
Sourcepub async fn is_banned(&self, addr: SocketAddr) -> bool
pub async fn is_banned(&self, addr: SocketAddr) -> bool
Check if an address is banned
Sourcepub async fn connect_to_peer(&mut self, peer_addr: &str) -> Result<()>
pub async fn connect_to_peer(&mut self, peer_addr: &str) -> Result<()>
Connect to a peer
Sourcepub async fn connect_to_peer_with_discovery(
&mut self,
peer_addr: &str,
_discovery: bool,
) -> Result<()>
pub async fn connect_to_peer_with_discovery( &mut self, peer_addr: &str, _discovery: bool, ) -> Result<()>
Connect to a peer with optional discovery
Create a shared message
Sourcepub fn has_object(&self, _hash: &str) -> bool
pub fn has_object(&self, _hash: &str) -> bool
Check if the node has a specific object
Sourcepub async fn get_object(&self, hash: &str) -> Result<String>
pub async fn get_object(&self, hash: &str) -> Result<String>
Get an object by hash
Add a shared object (application object)
Get shared objects (for compatibility with Python tests)
Get shared object count
Create shared message with application object processing
Sourcepub async fn get_discovery_info(&self) -> Value
pub async fn get_discovery_info(&self) -> Value
Get discovery info for testing
Sourcepub fn disable_local_discovery(&mut self)
pub fn disable_local_discovery(&mut self)
Disable local discovery (for single-node tests)
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Check if node is running (sync version for compatibility)