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
- Message Processing: Processing incoming and outgoing messages through middleware chains
- Message Routing: Determining the appropriate recipient for each message
- Event Publishing: Broadcasting node events to subscribers
- Scalability: Managing concurrent message processing through worker pools
§Lifecycle
- Create a node with appropriate configuration
- Register one or more agents with the node
- Start the processor pool (if high throughput is required)
- Process incoming/outgoing messages
- 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
impl TapNode
Sourcepub fn new(config: NodeConfig) -> Self
pub fn new(config: NodeConfig) -> Self
Create a new TAP node with the given configuration
Sourcepub async fn start(&mut self, config: ProcessorPoolConfig) -> Result<()>
pub async fn start(&mut self, config: ProcessorPoolConfig) -> Result<()>
Start the node
Sourcepub async fn receive_message(&self, message: Message) -> Result<()>
pub async fn receive_message(&self, message: Message) -> Result<()>
Receive and process an incoming message
This method handles the complete lifecycle of an incoming message:
- Processing the message through all registered processors
- Routing the message to determine the appropriate target agent
- Dispatching the message to the target agent
The processing pipeline may transform or even drop the message based on validation rules or other processing logic. If a message is dropped during processing, this method will return Ok(()) without an error.
§Parameters
message- The DIDComm message to be processed
§Returns
Ok(())if the message was successfully processed and dispatched (or intentionally dropped)Err(Error)if there was an error during processing, routing, or dispatching
§Errors
This method can return errors for several reasons:
- Processing errors from message processors
- Routing errors if no target agent can be determined
- Dispatch errors if the target agent cannot be found or fails to process the message
§Example
// Process an incoming message
node.receive_message(message).await?;Sourcepub async fn dispatch_message(
&self,
target_did: String,
message: Message,
) -> Result<()>
pub async fn dispatch_message( &self, target_did: String, message: Message, ) -> Result<()>
Dispatch a message to an agent by DID
Sourcepub async fn send_message(
&self,
from_did: &str,
to_did: &str,
message: Message,
) -> Result<String>
pub async fn send_message( &self, from_did: &str, to_did: &str, message: Message, ) -> Result<String>
Send a message from one agent to another
This method handles the processing, routing, and delivery of a message from one agent to another. It returns the packed message.
Sourcepub async fn register_agent(&self, agent: Arc<DefaultAgent>) -> Result<()>
pub async fn register_agent(&self, agent: Arc<DefaultAgent>) -> Result<()>
Register a new agent with the node
Sourcepub async fn unregister_agent(&self, did: &str) -> Result<()>
pub async fn unregister_agent(&self, did: &str) -> Result<()>
Unregister an agent from the node
Sourcepub fn get_all_agent_dids(&self) -> Vec<String>
pub fn get_all_agent_dids(&self) -> Vec<String>
Get all registered agent DIDs
Sourcepub fn get_event_bus(&self) -> Arc<EventBus>
pub fn get_event_bus(&self) -> Arc<EventBus>
Get the event bus
Sourcepub fn get_resolver(&self) -> Arc<NodeResolver>
pub fn get_resolver(&self) -> Arc<NodeResolver>
Get the resolver
Sourcepub fn config(&self) -> &NodeConfig
pub fn config(&self) -> &NodeConfig
Get the node config
Sourcepub fn agents(&self) -> &AgentRegistry
pub fn agents(&self) -> &AgentRegistry
Get the agent registry