1
1
use colored:: Colorize ;
2
2
use dkn_p2p:: libp2p:: {
3
- request_response:: { self , ResponseChannel } ,
3
+ request_response:: { self , OutboundRequestId , ResponseChannel } ,
4
4
PeerId ,
5
5
} ;
6
6
use eyre:: { eyre, Result } ;
@@ -43,7 +43,7 @@ impl DriaComputeNode {
43
43
request_id,
44
44
} => {
45
45
log:: debug!( "Received a response ({}) from {}" , request_id, peer_id) ;
46
- if let Err ( e) = self . handle_response ( peer_id, response) . await {
46
+ if let Err ( e) = self . handle_response ( peer_id, request_id , response) . await {
47
47
log:: error!( "Error handling response: {:?}" , e) ;
48
48
}
49
49
}
@@ -55,12 +55,16 @@ impl DriaComputeNode {
55
55
/// - Internally, the data is expected to be some JSON serialized data that is expected to be parsed and handled.
56
56
/// - Can be inlined because it is only called by [`DriaComputeNode::handle_reqres`].
57
57
#[ inline]
58
- async fn handle_response ( & mut self , peer_id : PeerId , data : Vec < u8 > ) -> Result < ( ) > {
58
+ async fn handle_response (
59
+ & mut self ,
60
+ peer_id : PeerId ,
61
+ request_id : OutboundRequestId ,
62
+ data : Vec < u8 > ,
63
+ ) -> Result < ( ) > {
59
64
if let Ok ( heartbeat_response) = HeartbeatRequester :: try_parse_response ( & data) {
60
65
log:: info!(
61
- "Received a {} response from {}" ,
66
+ "Received a {} response ({request_id}) from {peer_id }" ,
62
67
"heartbeat" . blue( ) ,
63
- peer_id
64
68
) ;
65
69
HeartbeatRequester :: handle_ack ( self , heartbeat_response) . await
66
70
} else {
@@ -97,19 +101,17 @@ impl DriaComputeNode {
97
101
channel : ResponseChannel < Vec < u8 > > ,
98
102
) -> Result < ( ) > {
99
103
log:: info!(
100
- "Got a {} request from peer {} with id {}" ,
104
+ "Got a {} request from peer {peer_id } with id {}" ,
101
105
"spec" . green( ) ,
102
- peer_id,
103
106
spec_request. request_id
104
107
) ;
105
108
106
109
let response = SpecResponder :: respond ( spec_request, self . spec_collector . collect ( ) . await ) ;
107
110
let response_data = serde_json:: to_vec ( & response) ?;
108
111
109
112
log:: info!(
110
- "Responding to {} request from peer {} with id {}" ,
113
+ "Responding to {} request from peer {peer_id } with id {}" ,
111
114
"spec" . green( ) ,
112
- peer_id,
113
115
response. request_id
114
116
) ;
115
117
self . p2p . respond ( response_data, channel) . await ?;
0 commit comments