TAP Node
A high-performance, asynchronous node implementation for the Transaction Authorization Protocol (TAP). This crate provides a complete node infrastructure for managing TAP agents, routing messages, and coordinating secure financial transactions.
Overview
The TAP Node acts as a central hub for TAP communications, managing multiple agents, processing messages, and coordinating the transaction lifecycle. It is designed for high-throughput environments, with support for concurrent message processing, event-driven architecture, and robust error handling.
Key Features
- Multi-Agent Management: Register and manage multiple TAP agents with different roles and capabilities
- Message Processing Pipeline: Process messages through configurable middleware chains
- Message Routing: Intelligently route messages to the appropriate agent based on DID addressing
- Concurrent Processing: Scale to high throughput with worker pools for message processing
- Event Publishing: Comprehensive event system for monitoring and reacting to node activities
- Flexible Message Delivery: Send messages via HTTP or WebSockets with robust error handling
- Cross-Platform Support: Native and WASM environments for both HTTP and WebSocket transports
- DID Resolution: Resolve DIDs for message verification and routing
- Configurable Components: Customize node behavior with pluggable components
- Thread-Safe Design: Safely share the node across threads with appropriate synchronization
- WASM Compatibility: Optional WASM support for browser environments
Installation
Add the crate to your Cargo.toml:
[]
= { = "../tap-node" }
= { = "../tap-agent" }
= { = "../tap-msg" }
# Optional features
= { = "../tap-node", = ["native"] } # Enable HTTP support
= { = "../tap-node", = ["websocket"] } # Enable WebSocket support
= { = "../tap-node", = ["native-with-websocket"] } # Enable both HTTP and WebSocket
= { = "../tap-node", = ["wasm"] } # Enable WASM support
= { = "../tap-node", = ["wasm-with-websocket"] } # Enable WASM with WebSocket
Architecture
The TAP Node is built with a modular architecture:
┌───────────────────────────────────────────────┐
│ TAP Node │
├───────────────┬───────────────┬───────────────┤
│ Agent Registry│ Message Router│ Event Bus │
├───────────────┼───────────────┼───────────────┤
│ Message │ Processor Pool│ Resolver │
│ Processors │ │ │
└───────────────┴───────────────┴───────────────┘
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ TAP Agent │ │ TAP Agent │ │ TAP Agent │
└───────────────┘ └───────────────┘ └───────────────┘
Usage
Basic Setup
use ;
use ;
use ;
use MultiResolver;
use Arc;
use Duration;
async
Processing Messages
use PlainMessage;
// Receive and process an incoming message
async
// Send a message from one agent to another
async
Event Handling and Logging
The TAP Node includes a powerful event system with configurable logging capabilities:
use Arc;
use async_trait;
use ;
use ;
use ;
// Create a TAP Node with event logging enabled
let mut config = default;
config.event_logger = Some;
// Initialize node with event logging
let node = new;
// Create a custom event subscriber
;
// Subscribe to events
async
Event Logger Configuration
The event logger supports different destinations:
// Log to console
let config = EventLoggerConfig ;
// Log to file with rotation
let config = EventLoggerConfig ;
// Custom logging function
let custom_logger = new;
let config = EventLoggerConfig ;
Custom Message Processors
You can create custom message processors to extend the node's capabilities:
use async_trait;
use Result;
use MessageProcessor;
use PlainMessage;
;
Message Transport
TAP Node provides multiple options for sending messages between nodes:
HTTP Message Sender
For standard request-response communication patterns:
use ;
// Create an HTTP sender with default settings
let sender = new;
// Create with custom settings (timeout and retries)
let sender = with_options;
// Send a packed message to recipients
sender.send.await?;
WebSocket Message Sender
For real-time bidirectional communication:
use ;
// Create a WebSocket sender with default settings
let sender = new;
// Create with custom settings
let sender = with_options;
// Send a message over an established WebSocket connection
sender.send.await?;
Key benefits of the WebSocket transport:
- Persistent connections for lower latency
- Bidirectional communication
- Connection state awareness
- Reduced overhead for frequent messages
Integration with Other Crates
The TAP Node integrates with the TAP ecosystem:
- tap-agent: Provides the agent implementation used by the node
- tap-msg: Defines the message types and formats
- tap-caip: Handles chain-agnostic identifiers used in transactions
- tap-http: Can be used to create HTTP endpoints for the node
- tap-wasm: Enables WASM compatibility for browser environments
Performance Considerations
The TAP Node is designed for high performance:
- Use processor pools for concurrent message processing
- Configure worker counts based on your hardware
- Consider message validation trade-offs
- Use appropriate channel capacities for your workload
- Profile your specific use case for optimal settings
Examples
The package includes several examples:
benches/stress_test.rs- Benchmark of node performance with different message loadsexamples/http_message_flow.rs- Example of using HTTP for message deliveryexamples/websocket_message_flow.rs- Example of using WebSockets for real-time communication
Run examples with:
# Run with HTTP support
# Run with WebSocket support
License
This crate is licensed under the terms of the MIT license.