Skip to content

Commit 60655e4

Browse files
committed
feat: Tracing for DHT rpc requests
1 parent 7871c69 commit 60655e4

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

net/src/dht/driver.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,12 @@ impl DhtDriver {
454454
}
455455

456456
fn dispatch_rpc_response(&mut self, inbound_id: InboundId, response: DhtResponse) {
457+
let self_id = self.endpoint.id();
457458
let maybe_send = self.inbound_contexts.remove(&inbound_id);
458459
let io_tx = self.io_tx.clone();
459460
tokio::spawn(async move {
460461
if let Some((_conn, mut send)) = maybe_send {
462+
trace!("RPC RESPONSE: from {} to {:?}", self_id, _conn.to_info());
461463
let _ = write_response_to_stream(&mut send, &response).await;
462464
}
463465
let _ = io_tx.send(DhtIo::InboundDropped { inbound_id }).await;
@@ -687,12 +689,14 @@ async fn rpc_request(
687689
peer: NodeId,
688690
request: DhtRequest,
689691
) -> Result<DhtResponse, DhtIoError> {
692+
trace!("RPC_REQUEST: Connection to {} from {}", peer, endpoint.id());
690693
let conn = tokio::time::timeout(RPC_TIMEOUT, endpoint.connect(peer, DHT_ALPN))
691694
.await?
692695
.map_err(DhtIoError::network)?;
693696

694697
let (mut send, mut recv) = conn.open_bi().await.map_err(DhtIoError::network)?;
695698

699+
trace!("RPC_REQUEST: Sending request");
696700
let request_bytes = encode_request(&request)?;
697701
let len = (request_bytes.len() as u32).to_be_bytes();
698702
send.write_all(&len).await.map_err(DhtIoError::network)?;
@@ -702,6 +706,8 @@ async fn rpc_request(
702706
send.finish().map_err(DhtIoError::network)?;
703707

704708
let mut len_buf = [0u8; 4];
709+
710+
trace!("RPC_REQUEST: Receiving response");
705711
tokio::time::timeout(RPC_TIMEOUT, recv.read_exact(&mut len_buf))
706712
.await?
707713
.map_err(DhtIoError::network)?;

net/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use parking_lot::RwLock;
3636
use tokio::sync::{Mutex, mpsc, oneshot};
3737
use tokio::task::JoinHandle;
3838
use tokio_util::sync::CancellationToken;
39-
use tracing::{Instrument, Span, debug, warn};
39+
use tracing::{Instrument, Span, debug, trace, warn};
4040

4141
pub use dht::DhtHandle;
4242
pub use error::{NetError, Result};
@@ -457,6 +457,12 @@ impl NetHandle {
457457
peer_nodes.extend(peer_endpoints.iter().map(|endpoint| endpoint.id));
458458
let peer_nodes = unique_peer_nodes(peer_nodes, node_id);
459459
let dht_signed_authorized_nodes = Arc::new(RwLock::new(peer_nodes.clone()));
460+
461+
trace!(
462+
"DHT SIGNED NODES: {:?}",
463+
dht_signed_authorized_nodes.read()
464+
);
465+
460466
let peer_connectivity = Arc::new(Mutex::new(PeerConnectivityManagerState::new(
461467
&peer_nodes,
462468
"realm_config",

0 commit comments

Comments
 (0)