Skip to content

Commit

Permalink
feat(node): add markers for initial connection attempt/timeout
Browse files Browse the repository at this point in the history
Added AttemptingNetworkConnection marker/is_conn_active boolean for initial network activity and a NetworkConnectionTimedOut marker/error message if connection is timed out.
  • Loading branch information
aed900 committed Jul 27, 2023
1 parent 26c13ef commit ca099aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion sn_networking/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@ impl SwarmDriver {
peer_id,
connection_id,
} => trace!("Dialing {peer_id:?} on {connection_id:?}"),

SwarmEvent::Behaviour(NodeEvent::Autonat(event)) => match event {
autonat::Event::InboundProbe(e) => debug!("AutoNAT inbound probe: {e:?}"),
autonat::Event::OutboundProbe(e) => debug!("AutoNAT outbound probe: {e:?}"),
Expand Down
16 changes: 13 additions & 3 deletions sn_node/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ impl Node {
let network_clone = network.clone();
let node_event_sender = node_events_channel.clone();
let mut rng = StdRng::from_entropy();
let mut is_conn_active = false;

let initial_join_flows_done = Arc::new(AtomicBool::new(false));
let peers_connected = Arc::new(AtomicUsize::new(0));
Expand All @@ -134,6 +135,10 @@ impl Node {
net_event = network_event_receiver.recv() => {
match net_event {
Some(event) => {
if is_conn_active == false {
is_conn_active = true;
Marker::AttemptingNetworkConnection.log();
}
let mut stateless_node_copy = node.clone();
let _handle =
spawn(async move { stateless_node_copy.handle_network_event(event, peers_connected, initial_join_flows_done).await });
Expand All @@ -150,9 +155,14 @@ impl Node {

Marker::NoNetworkActivity( inactivity_timeout ).log();
debug!("No network activity in the past {inactivity_timeout:?}, performing a random get_closest query to target: {random_target:?}");
if let Ok(closest) = network_clone.node_get_closest_peers(&random_target).await {
debug!("Network inactivity: get_closest returned {closest:?}");
}
match network_clone.node_get_closest_peers(&random_target).await {
Ok(closest) => { debug!("Network inactivity: get_closest returned {closest:?}"); },
Err(e) => {
is_conn_active = false;
Marker::NetworkConnectionTimedOut.log();
println!("Network connection has timed out: {}", e);
},
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions sn_node/src/log_markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ use strum::Display;
/// Changing these log markers is a breaking change.
#[derive(Debug, Clone, Display)]
pub enum Marker<'a> {
/// Detected initial network activity
AttemptingNetworkConnection,

/// Network connection has timed out after a period of no network activity
NetworkConnectionTimedOut,

/// The node has started
NodeConnectedToNetwork,

Expand Down

0 comments on commit ca099aa

Please sign in to comment.