Skip to content

Commit aaca370

Browse files
committed
feat: [#539] change log for UDP tracker
From: ``` 2023-12-22T12:32:53.016911160+00:00 [torrust_tracker::servers::udp::server][INFO] Received 109 bytes 2023-12-22T12:32:53.016953899+00:00 [torrust_tracker::servers::udp::server][INFO] Sending 43 bytes ... 2023-12-22T12:32:53.017038257+00:00 [torrust_tracker::servers::udp::server][INFO] 43 bytes sent ``` To: ``` 2023-12-22T12:35:51.320114322+00:00 [UDP][INFO] "CONNECT TxID 1583189312" 2023-12-22T12:35:51.345003905+00:00 [UDP][INFO] "ANNOUNCE TxID 1583189313 IH 443c7602b4fde83d1154d6d9da48808418b181b6" 2023-12-22T12:35:51.320114322+00:00 [SCRAPE][INFO] "CONNECT TxID 1583189312" ```` - The target is more generic "UDP" and it will be always the same even if we rearrange the packages. - The info is more usueful. It includes the request type, the transaction ID to identify client, and the info-hash. That would allow to extract statistics from the logs. NOTE: In the long-term maybe this should be configurable.
1 parent 20b052d commit aaca370

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/servers/udp/handlers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use aquatic_udp_protocol::{
77
AnnounceInterval, AnnounceRequest, AnnounceResponse, ConnectRequest, ConnectResponse, ErrorResponse, NumberOfDownloads,
88
NumberOfPeers, Port, Request, Response, ResponsePeer, ScrapeRequest, ScrapeResponse, TorrentScrapeStatistics, TransactionId,
99
};
10-
use log::debug;
10+
use log::{debug, info};
1111

1212
use super::connection_cookie::{check, from_connection_id, into_connection_id, make};
1313
use crate::core::{statistics, Tracker};
@@ -73,6 +73,7 @@ pub async fn handle_request(request: Request, remote_addr: SocketAddr, tracker:
7373
///
7474
/// This function does not ever return an error.
7575
pub async fn handle_connect(remote_addr: SocketAddr, request: &ConnectRequest, tracker: &Tracker) -> Result<Response, Error> {
76+
info!(target: "UDP", "\"CONNECT TxID {}\"", request.transaction_id.0);
7677
debug!("udp connect request: {:#?}", request);
7778

7879
let connection_cookie = make(&remote_addr);
@@ -136,6 +137,8 @@ pub async fn handle_announce(
136137

137138
authenticate(&info_hash, tracker).await?;
138139

140+
info!(target: "UDP", "\"ANNOUNCE TxID {} IH {}\"", announce_request.transaction_id.0, info_hash.to_hex_string());
141+
139142
let mut peer = peer_builder::from_request(&wrapped_announce_request, &remote_client_ip);
140143

141144
let response = tracker.announce(&info_hash, &mut peer, &remote_client_ip).await;
@@ -210,6 +213,7 @@ pub async fn handle_announce(
210213
///
211214
/// This function does not ever return an error.
212215
pub async fn handle_scrape(remote_addr: SocketAddr, request: &ScrapeRequest, tracker: &Tracker) -> Result<Response, Error> {
216+
info!(target: "UDP", "\"SCRAPE TxID {}\"", request.transaction_id.0);
213217
debug!("udp scrape request: {:#?}", request);
214218

215219
// Convert from aquatic infohashes

src/servers/udp/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Udp {
191191
Ok((valid_bytes, remote_addr)) = socket.recv_from(&mut data) => {
192192
let payload = data[..valid_bytes].to_vec();
193193

194-
info!("Received {} bytes", payload.len());
194+
debug!("Received {} bytes", payload.len());
195195
debug!("From: {}", &remote_addr);
196196
debug!("Payload: {:?}", payload);
197197

@@ -227,7 +227,7 @@ impl Udp {
227227
Ok((valid_bytes, remote_addr)) = socket.recv_from(&mut data) => {
228228
let payload = data[..valid_bytes].to_vec();
229229

230-
info!("Received {} bytes", payload.len());
230+
debug!("Received {} bytes", payload.len());
231231
debug!("From: {}", &remote_addr);
232232
debug!("Payload: {:?}", payload);
233233

@@ -249,13 +249,13 @@ impl Udp {
249249
let position = cursor.position() as usize;
250250
let inner = cursor.get_ref();
251251

252-
info!("Sending {} bytes ...", &inner[..position].len());
252+
debug!("Sending {} bytes ...", &inner[..position].len());
253253
debug!("To: {:?}", &remote_addr);
254254
debug!("Payload: {:?}", &inner[..position]);
255255

256256
Udp::send_packet(socket, &remote_addr, &inner[..position]).await;
257257

258-
info!("{} bytes sent", &inner[..position].len());
258+
debug!("{} bytes sent", &inner[..position].len());
259259
}
260260
Err(_) => {
261261
error!("could not write response to bytes.");

0 commit comments

Comments
 (0)