Struct ChaincraftNode

Source
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 config: NodeConfig,
    pub running: Arc<RwLock<bool>>,
}
Expand description

Main node structure for Chaincraft network

Fields§

§id: PeerId

Unique 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

§config: NodeConfig

Node configuration

§running: Arc<RwLock<bool>>

Running flag

Implementations§

Source§

impl ChaincraftNode

Source

pub fn new(id: PeerId, storage: Arc<dyn Storage>) -> Self

Create a new Chaincraft node

Source

pub fn default() -> Self

Create a new Chaincraft node with default settings

Source

pub fn new_default() -> Self

Create a new Chaincraft node with default settings (alias for compatibility with examples)

Source

pub fn builder() -> ChaincraftNodeBuilder

Create a new node builder

Source

pub async fn start(&mut self) -> Result<()>

Start the node

Source

pub async fn stop(&mut self) -> Result<()>

Stop the node

Source

pub async fn close(&mut self) -> Result<()>

Close the node (alias for stop)

Source

pub async fn is_running_async(&self) -> bool

Check if the node is running (async version)

Source

pub async fn add_peer(&self, peer: PeerInfo) -> Result<()>

Add a peer to the node’s peer list

Source

pub async fn remove_peer(&self, peer_id: &PeerId) -> Result<()>

Remove a peer from the node’s peer list

Source

pub async fn connect_to_peer(&mut self, peer_addr: &str) -> Result<()>

Connect to a peer

Source

pub async fn connect_to_peer_with_discovery( &mut self, peer_addr: &str, _discovery: bool, ) -> Result<()>

Connect to a peer with optional discovery

Source

pub async fn get_peers(&self) -> Vec<PeerInfo>

Get all connected peers

Source

pub fn peers(&self) -> Vec<PeerInfo>

Get connected peers synchronously (for compatibility)

Source

pub fn id(&self) -> &PeerId

Get the node’s ID

Source

pub fn port(&self) -> u16

Get the node’s port

Source

pub fn host(&self) -> &str

Get the node’s host

Source

pub fn max_peers(&self) -> usize

Get maximum peers

Source

pub async fn create_shared_message(&mut self, data: String) -> Result<String>

Create a shared message

Source

pub fn has_object(&self, _hash: &str) -> bool

Check if the node has a specific object

Source

pub async fn get_object(&self, hash: &str) -> Result<String>

Get an object by hash

Source

pub fn db_size(&self) -> usize

Get the database size

Source

pub async fn add_shared_object( &self, object: Box<dyn ApplicationObject>, ) -> Result<SharedObjectId>

Add a shared object (application object)

Source

pub async fn shared_objects(&self) -> Vec<Box<dyn ApplicationObject>>

Get shared objects (for compatibility with Python tests)

Source

pub async fn shared_object_count(&self) -> usize

Get shared object count

Source

pub async fn create_shared_message_with_data( &mut self, data: Value, ) -> Result<String>

Create shared message with application object processing

Source

pub async fn get_state(&self) -> Result<Value>

Get node state for testing/debugging

Source

pub async fn get_discovery_info(&self) -> Value

Get discovery info for testing

Source

pub fn set_port(&mut self, port: u16)

Set port for testing

Source

pub fn is_running(&self) -> bool

Check if node is running (sync version for compatibility)

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more