Struct TapNode

Source
pub struct TapNode { /* private fields */ }
Expand description

§The TAP Node

The TAP Node is the core component responsible for coordinating message processing, routing, and delivery to TAP Agents. It serves as a central hub for all TAP communications and transaction coordination.

§Core Responsibilities

  • Agent Management: Registration and deregistration of TAP Agents
  • PlainMessage Processing: Processing incoming and outgoing messages through middleware chains
  • PlainMessage Routing: Determining the appropriate recipient for each message
  • Event Publishing: Broadcasting node events to subscribers
  • Scalability: Managing concurrent message processing through worker pools

§Lifecycle

  1. Create a node with appropriate configuration
  2. Register one or more agents with the node
  3. Start the processor pool (if high throughput is required)
  4. Process incoming/outgoing messages
  5. Publish and respond to events

§Thread Safety

The TapNode is designed to be thread-safe and can be shared across multiple threads using an Arc<TapNode>. All internal mutability is handled through appropriate synchronization primitives.

Implementations§

Source§

impl TapNode

Source

pub fn new(config: NodeConfig) -> Self

Create a new TAP node with the given configuration

Source

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

Initialize storage asynchronously

Source

pub async fn start(&mut self, config: ProcessorPoolConfig) -> Result<()>

Start the node

Source

pub async fn receive_message(&self, message: Value) -> Result<()>

Receive and process an incoming message

This method handles the complete lifecycle of an incoming message:

  1. Determining the message type (plain, signed, or encrypted)
  2. Verifying signatures or routing to agents for decryption
  3. Processing the resulting plain messages through the pipeline
  4. Routing and dispatching to the appropriate agents
§Parameters
  • message - The message as a JSON Value (can be plain, JWS, or JWE)
§Returns
  • Ok(()) if the message was successfully processed
  • Err(Error) if there was an error during processing
Source

pub async fn receive_message_from_source( &self, message: Value, source_type: SourceType, source_identifier: Option<&str>, ) -> Result<()>

Receive and process an incoming message with source information

This method handles the complete lifecycle of an incoming message with tracking of where the message came from.

§Parameters
  • message - The message as a JSON Value (can be plain, JWS, or JWE)
  • source_type - The type of source (https, internal, websocket, etc.)
  • source_identifier - Optional identifier for the source (URL, agent DID, etc.)
§Returns
  • Ok(()) if the message was successfully processed
  • Err(Error) if there was an error during processing
Source

pub async fn dispatch_message( &self, target_did: String, message: PlainMessage, ) -> Result<()>

Dispatch a message to an agent by DID

Source

pub async fn send_message( &self, sender_did: String, message: PlainMessage, ) -> Result<String>

Send a message to an agent

This method now includes comprehensive delivery tracking and actual message delivery. For internal recipients (registered agents), messages are delivered directly. For external recipients, messages are delivered via HTTP with tracking.

Source

pub async fn register_agent(&self, agent: Arc<TapAgent>) -> Result<()>

Register a new agent with the node

This method registers an agent with the TAP Node and automatically initializes DID-specific storage for the agent. The storage directory structure follows:

  • ~/.tap/{sanitized_did}/transactions.db (default)
  • {tap_root}/{sanitized_did}/transactions.db (if custom TAP root is configured)
§Storage Initialization

When an agent is registered, a dedicated SQLite database is created for that agent’s DID. This ensures transaction isolation between different agents while maintaining a consistent storage structure. If storage initialization fails, the agent registration continues but a warning is logged.

§Arguments
  • agent - The TapAgent to register with the node
§Returns
  • Ok(()) if the agent was successfully registered
  • Err(Error) if agent registration fails
Source

pub async fn unregister_agent(&self, did: &str) -> Result<()>

Unregister an agent from the node

Source

pub fn list_agents(&self) -> Vec<String>

Get a list of registered agent DIDs

Source

pub fn agents(&self) -> &Arc<AgentRegistry>

Get a reference to the agent registry

Source

pub fn event_bus(&self) -> &Arc<EventBus>

Get a reference to the event bus

Source

pub fn resolver(&self) -> &Arc<MultiResolver>

Get a reference to the resolver

Source

pub fn processor_pool_mut(&mut self) -> &mut Option<ProcessorPool>

Get a mutable reference to the processor pool This is a reference to Option<ProcessorPool> to allow starting the pool after node creation

Source

pub fn config(&self) -> &NodeConfig

Get the node configuration

Source

pub fn storage(&self) -> Option<&Arc<Storage>>

Get a reference to the storage (if available)

Source

pub fn agent_storage_manager(&self) -> Option<&Arc<AgentStorageManager>>

Get a reference to the agent storage manager (if available)

Source

pub async fn set_storage(&mut self, storage: Storage) -> Result<()>

Set storage for testing purposes This allows injecting in-memory databases for complete test isolation

Trait Implementations§

Source§

impl Clone for TapNode

Source§

fn clone(&self) -> TapNode

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,