tap_node/event/
trust_ping_handler.rs1use crate::event::{EventSubscriber, NodeEvent};
7use crate::message::sender::PlainMessageSender;
8use async_trait::async_trait;
9use std::sync::Arc;
10use tap_msg::didcomm::PlainMessage;
11
12#[derive(Debug)]
14pub struct TrustPingResponseHandler {
15 sender: Arc<dyn PlainMessageSender>,
17}
18
19impl TrustPingResponseHandler {
20 pub fn new(sender: Arc<dyn PlainMessageSender>) -> Self {
22 Self { sender }
23 }
24}
25
26#[async_trait]
27impl EventSubscriber for TrustPingResponseHandler {
28 async fn handle_event(&self, event: NodeEvent) {
29 if let NodeEvent::PlainMessageSent { message, from, to } = event {
30 if let Ok(plain_message) = serde_json::from_value::<PlainMessage>(message) {
32 if plain_message.type_ == "https://didcomm.org/trust-ping/2.0/ping-response" {
33 log::debug!(
34 "Processing Trust Ping response event: from={}, to={}",
35 from,
36 to
37 );
38
39 match serde_json::to_string(&plain_message) {
41 Ok(serialized_message) => {
42 if let Err(e) =
43 self.sender.send(serialized_message, vec![to.clone()]).await
44 {
45 log::warn!("Failed to send Trust Ping response to {}: {}", to, e);
46 } else {
47 log::info!("Successfully sent Trust Ping response to {}", to);
48 }
49 }
50 Err(e) => {
51 log::warn!("Failed to serialize Trust Ping response: {}", e);
52 }
53 }
54 }
55 }
56 }
57 }
58}