Tweak logging
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use nym_ip_packet_requests::response::IpPacketResponse;
|
||||
use nym_sdk::mixnet::{MixnetMessageSender, Recipient};
|
||||
|
||||
use crate::{
|
||||
constants::CLIENT_HANDLER_ACTIVITY_TIMEOUT,
|
||||
error::{IpPacketRouterError, Result},
|
||||
util::create_message::create_input_message,
|
||||
};
|
||||
|
||||
const ACTIVITY_TIMEOUT_SEC: u64 = 10 * 60;
|
||||
|
||||
// Data flow
|
||||
// Out: mixnet_listener -> decode -> handle_packet -> write_to_tun
|
||||
// In: tun_listener -> [connected_client_handler -> encode] -> mixnet_sender
|
||||
@@ -42,7 +39,7 @@ impl ConnectedClientHandler {
|
||||
let (forward_from_tun_tx, forward_from_tun_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
// Reset so that we don't get the first tick immediately
|
||||
let mut activity_timeout = tokio::time::interval(Duration::from_secs(ACTIVITY_TIMEOUT_SEC));
|
||||
let mut activity_timeout = tokio::time::interval(CLIENT_HANDLER_ACTIVITY_TIMEOUT);
|
||||
activity_timeout.reset();
|
||||
|
||||
let connected_client_handler = ConnectedClientHandler {
|
||||
@@ -80,28 +77,28 @@ impl ConnectedClientHandler {
|
||||
loop {
|
||||
tokio::select! {
|
||||
_ = &mut self.close_rx => {
|
||||
log::info!("ConnectedClientHandler: received shutdown");
|
||||
log::info!("client handler stopping: received close: {}", self.nym_address);
|
||||
break;
|
||||
},
|
||||
_ = self.activity_timeout.tick() => {
|
||||
log::info!("ConnectedClientHandler: activity timeout reached for {}", self.nym_address);
|
||||
log::info!("client handler stopping: activity timeout: {}", self.nym_address);
|
||||
break;
|
||||
}
|
||||
packet = self.forward_from_tun_rx.recv() => match packet {
|
||||
Some(packet) => {
|
||||
if let Err(err) = self.handle_packet(packet).await {
|
||||
log::error!("connected client handler: failed to handle packet: {err}");
|
||||
log::error!("client handler: failed to handle packet: {err}");
|
||||
}
|
||||
},
|
||||
None => {
|
||||
log::info!("connected client handler: tun channel closed");
|
||||
log::info!("client handler stopping: tun channel closed");
|
||||
break;
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("ConnectedClientHandler: exiting");
|
||||
log::debug!("ConnectedClientHandler: exiting");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,12 @@ pub const TUN_BASE_NAME: &str = "nymtun";
|
||||
pub const TUN_DEVICE_ADDRESS: &str = "10.0.0.1";
|
||||
pub const TUN_DEVICE_NETMASK: &str = "255.255.255.0";
|
||||
|
||||
// We routinely check if any clients needs to be disconnected at this interval
|
||||
pub(crate) const DISCONNECT_TIMER_INTERVAL: Duration = Duration::from_secs(10);
|
||||
pub(crate) const CLIENT_INACTIVITY_TIMEOUT: Duration = Duration::from_secs(5 * 60);
|
||||
|
||||
// We consider a client inactive if it hasn't sent any mixnet packets in this duration
|
||||
pub(crate) const CLIENT_MIXNET_INACTIVITY_TIMEOUT: Duration = Duration::from_secs(5 * 60);
|
||||
|
||||
// We consider a client handler inactive if it hasn't received any packets from the tun device in
|
||||
// this duration
|
||||
pub(crate) const CLIENT_HANDLER_ACTIVITY_TIMEOUT: Duration = Duration::from_secs(10 * 60);
|
||||
|
||||
@@ -21,7 +21,7 @@ use tokio::io::AsyncWriteExt;
|
||||
use crate::{
|
||||
config::Config,
|
||||
connected_client_handler,
|
||||
constants::{CLIENT_INACTIVITY_TIMEOUT, DISCONNECT_TIMER_INTERVAL},
|
||||
constants::{CLIENT_MIXNET_INACTIVITY_TIMEOUT, DISCONNECT_TIMER_INTERVAL},
|
||||
error::{IpPacketRouterError, Result},
|
||||
request_filter::{self},
|
||||
tun_listener,
|
||||
@@ -144,7 +144,7 @@ impl ConnectedClients {
|
||||
self.clients
|
||||
.iter()
|
||||
.filter_map(|(ip, client)| {
|
||||
if now.duration_since(client.last_activity) > CLIENT_INACTIVITY_TIMEOUT {
|
||||
if now.duration_since(client.last_activity) > CLIENT_MIXNET_INACTIVITY_TIMEOUT {
|
||||
Some((*ip, client.nym_address))
|
||||
} else {
|
||||
None
|
||||
@@ -155,7 +155,7 @@ impl ConnectedClients {
|
||||
|
||||
fn disconnect_stopped_client_handlers(&mut self, stopped_clients: Vec<(IpAddr, Recipient)>) {
|
||||
for (ip, _) in &stopped_clients {
|
||||
log::info!("Removing stopped client: {ip}");
|
||||
log::info!("Disconnect stopped client: {ip}");
|
||||
self.clients.remove(ip);
|
||||
self.tun_listener_connected_client_tx
|
||||
.send(ConnectedClientEvent::Disconnect(DisconnectEvent(*ip)))
|
||||
@@ -211,9 +211,8 @@ impl ConnectedClient {
|
||||
|
||||
impl Drop for ConnectedClient {
|
||||
fn drop(&mut self) {
|
||||
log::info!("Dropping client: {}", self.nym_address);
|
||||
log::debug!("signal to close client: {}", self.nym_address);
|
||||
if let Some(close_tx) = self.close_tx.take() {
|
||||
log::trace!("Sending close signal to connected client handler");
|
||||
close_tx.send(()).ok();
|
||||
}
|
||||
}
|
||||
@@ -445,7 +444,7 @@ impl MixnetListener {
|
||||
}
|
||||
} else {
|
||||
// If the client is not connected, just drop the packet silently
|
||||
log::info!("Dropping packet: no connected client for {src_addr}");
|
||||
log::info!("dropping packet from mixnet: no registered client for packet with source: {src_addr}");
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
@@ -531,7 +530,7 @@ impl MixnetListener {
|
||||
// connect handshake.
|
||||
async fn handle_response(&self, response: IpPacketResponse) -> Result<()> {
|
||||
let Some(recipient) = response.recipient() else {
|
||||
log::error!("no recipient in response packet, this should NOT happen!");
|
||||
log::error!("No recipient in response packet, this should NOT happen!");
|
||||
return Err(IpPacketRouterError::NoRecipientInResponse);
|
||||
};
|
||||
|
||||
|
||||
@@ -93,7 +93,9 @@ impl TunListener {
|
||||
));
|
||||
}
|
||||
} else {
|
||||
log::info!("No registered client for packet with destination {dst_addr} - dropping");
|
||||
log::info!(
|
||||
"dropping packet from network: no registered client for destination: {dst_addr}"
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user