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
- 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: PlainMessage) -> Result<()>
pub async fn receive_message(&self, message: PlainMessage) -> 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: PlainMessage,
) -> Result<()>
pub async fn dispatch_message( &self, target_did: String, message: PlainMessage, ) -> Result<()>
Dispatch a message to an agent by DID
Sourcepub async fn send_message(
&self,
sender_did: String,
to_did: String,
message: PlainMessage,
) -> Result<String>
pub async fn send_message( &self, sender_did: String, to_did: String, message: PlainMessage, ) -> Result<String>
Send a message to an agent
Sourcepub async fn register_agent(&self, agent: Arc<TapAgent>) -> Result<()>
pub async fn register_agent(&self, agent: Arc<TapAgent>) -> 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 list_agents(&self) -> Vec<String>
pub fn list_agents(&self) -> Vec<String>
Get a list of registered agent DIDs
Sourcepub fn agents(&self) -> &Arc<AgentRegistry>
pub fn agents(&self) -> &Arc<AgentRegistry>
Get a reference to the agent registry
Sourcepub fn resolver(&self) -> &Arc<NodeResolver>
pub fn resolver(&self) -> &Arc<NodeResolver>
Get a reference to the resolver
Sourcepub fn processor_pool_mut(&mut self) -> &mut Option<ProcessorPool>
pub fn processor_pool_mut(&mut self) -> &mut Option<ProcessorPool>
Get a mutable reference to the processor pool
This is a reference to Option
Sourcepub fn config(&self) -> &NodeConfig
pub fn config(&self) -> &NodeConfig
Get the node configuration