1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Specialized node invite request-response protocol event handler
use calimero_network_primitives::messages::NetworkEvent;
use calimero_network_primitives::specialized_node_invite::{
SpecializedNodeInvitationResponse, VerificationRequest,
};
use libp2p::request_response::Event;
use owo_colors::OwoColorize;
use tracing::debug;
use super::{EventHandler, NetworkManager};
impl EventHandler<Event<VerificationRequest, SpecializedNodeInvitationResponse>>
for NetworkManager
{
fn handle(&mut self, event: Event<VerificationRequest, SpecializedNodeInvitationResponse>) {
debug!("{}: {:?}", "specialized_node_invite".yellow(), event);
match event {
Event::Message { peer, message, .. } => match message {
libp2p::request_response::Message::Request {
request_id,
request,
channel,
} => {
debug!(
%peer,
?request_id,
nonce = %hex::encode(request.nonce()),
"Received specialized node verification request"
);
// Forward to NodeManager for handling
let _ignored = self.event_dispatcher.dispatch(
NetworkEvent::SpecializedNodeVerificationRequest {
peer_id: peer,
request_id,
request,
channel,
},
);
}
libp2p::request_response::Message::Response {
request_id,
response,
} => {
debug!(
%peer,
?request_id,
has_invitation = response.invitation_bytes.is_some(),
has_error = response.error.is_some(),
"Received specialized node invitation response"
);
// Forward to NodeManager for handling
let _ignored = self.event_dispatcher.dispatch(
NetworkEvent::SpecializedNodeInvitationResponse {
peer_id: peer,
request_id,
response,
},
);
}
},
Event::OutboundFailure {
peer,
request_id,
error,
..
} => {
debug!(
%peer,
?request_id,
%error,
"Specialized node invite outbound failure"
);
}
Event::InboundFailure {
peer,
request_id,
error,
..
} => {
debug!(
%peer,
?request_id,
%error,
"Specialized node invite inbound failure"
);
}
Event::ResponseSent {
peer, request_id, ..
} => {
debug!(
%peer,
?request_id,
"Specialized node invite response sent"
);
}
}
}
}