pub enum NodeEvent {
PlainMessageReceived {
message: Value,
},
PlainMessageSent {
message: Value,
from: String,
to: String,
},
AgentRegistered {
did: String,
},
AgentUnregistered {
did: String,
},
DidResolved {
did: String,
success: bool,
},
AgentPlainMessage {
did: String,
message: Vec<u8>,
},
}Expand description
Event types that can be emitted by the TAP Node
The NodeEvent enum represents all the possible events that can occur
within a TAP Node. These events can be subscribed to using the EventBus
to enable reactive programming patterns and loose coupling between components.
§Event Categories
Events are broadly categorized into:
- PlainMessage Events: Related to message processing and delivery (PlainMessageReceived, PlainMessageSent)
- Agent Events: Related to agent lifecycle management (AgentRegistered, AgentUnregistered)
- Resolution Events: Related to DID resolution (DidResolved)
- Raw PlainMessage Events: Raw binary messages for agents (AgentPlainMessage)
§Usage
Events are typically consumed by matching on the event type and taking appropriate action:
use tap_node::event::NodeEvent;
fn process_event(event: NodeEvent) {
match event {
NodeEvent::PlainMessageReceived { message } => {
println!("PlainMessage received: {:?}", message);
},
NodeEvent::AgentRegistered { did } => {
println!("Agent registered: {}", did);
},
// Handle other event types...
_ => {}
}
}Variants§
PlainMessageReceived
A DIDComm message was received by the node
This event is triggered after a message has been successfully processed by the node’s incoming message processors. It contains the deserialized message content as a JSON Value.
§Parameters
message: The received message as a JSON Value
§Example Use Cases
- Monitoring and logging received messages
- Triggering follow-up actions based on message content
- Auditing message flow through the system
PlainMessageSent
A DIDComm message was sent from one agent to another
This event is triggered after a message has been successfully processed by the node’s outgoing message processors and prepared for delivery.
§Parameters
message: The sent message as a JSON Valuefrom: The DID of the sending agentto: The DID of the receiving agent
§Example Use Cases
- Tracking message delivery
- Analyzing communication patterns
- Generating message delivery receipts
Fields
AgentRegistered
A new agent was registered with the node
This event is triggered when an agent is successfully registered with the node’s agent registry. It contains the DID of the registered agent.
§Parameters
did: The DID of the registered agent
§Example Use Cases
- Tracking agent lifecycle
- Initializing resources for new agents
- Notifying other components of new agent availability
AgentUnregistered
An agent was unregistered from the node
This event is triggered when an agent is removed from the node’s agent registry. It contains the DID of the unregistered agent.
§Parameters
did: The DID of the unregistered agent
§Example Use Cases
- Cleanup of resources associated with the agent
- Notifying other components of agent removal
- Updating routing tables
DidResolved
A DID was resolved by the node’s resolver
This event is triggered when the node attempts to resolve a DID. It includes both the DID being resolved and whether the resolution was successful.
§Parameters
did: The DID that was resolvedsuccess: Whether the resolution was successful
§Example Use Cases
- Monitoring resolution failures
- Caching resolution results
- Diagnostics and debugging
AgentPlainMessage
A raw message event for an agent
This event contains raw binary message data intended for a specific agent. It is typically used for low-level message delivery mechanisms.
§Parameters
did: The DID of the target agentmessage: The raw binary message data
§Example Use Cases
- Direct message delivery to agents
- Integration with transport-specific mechanisms
- Binary protocol support