Skip to content

Commit

Permalink
Merge torrust#549: Change log for UDP tracker
Browse files Browse the repository at this point in the history
ff3928e fix: clippy error (Jose Celano)
6e607c3 feat: [torrust#539] change log for UDP tracker (Jose Celano)

Pull request description:

  Changed log lines format for the UDP tracker:

  From:

  ```s
  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:

  ```s
  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 [UDP][INFO] "SCRAPE 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 useful. It includes the request type, the transaction ID to identify the client, and the info-hash. That would allow us to extract statistics from the logs.

  NOTE:

  In the long term maybe this should be configurable.

ACKs for top commit:
  josecelano:
    ACK ff3928e

Tree-SHA512: 3a718fb29ec92bddc54ce28177bd4f400865b5f4fb076b2770643e267dd652b87102fe9908a7910bf43cfd4d895ead7003ee7f98ac79795e218bc873d746d232
  • Loading branch information
josecelano committed Dec 22, 2023
2 parents 20b052d + ff3928e commit 2b859d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contrib/bencode/src/reference/decode_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl BDecodeOpt {
///
/// It may be useful to disable this if for example, the input bencode is prepended to
/// some payload and you would like to disassociate it. In this case, to find where the
/// rest of the payload starts that wasn't decoded, get the bencode buffer, and call len().
/// rest of the payload starts that wasn't decoded, get the bencode buffer, and call `len()`.
#[must_use]
pub fn enforce_full_decode(&self) -> bool {
self.enforce_full_decode
Expand Down
6 changes: 5 additions & 1 deletion src/servers/udp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use aquatic_udp_protocol::{
AnnounceInterval, AnnounceRequest, AnnounceResponse, ConnectRequest, ConnectResponse, ErrorResponse, NumberOfDownloads,
NumberOfPeers, Port, Request, Response, ResponsePeer, ScrapeRequest, ScrapeResponse, TorrentScrapeStatistics, TransactionId,
};
use log::debug;
use log::{debug, info};

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

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

authenticate(&info_hash, tracker).await?;

info!(target: "UDP", "\"ANNOUNCE TxID {} IH {}\"", announce_request.transaction_id.0, info_hash.to_hex_string());

let mut peer = peer_builder::from_request(&wrapped_announce_request, &remote_client_ip);

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

// Convert from aquatic infohashes
Expand Down
8 changes: 4 additions & 4 deletions src/servers/udp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Udp {
Ok((valid_bytes, remote_addr)) = socket.recv_from(&mut data) => {
let payload = data[..valid_bytes].to_vec();

info!("Received {} bytes", payload.len());
debug!("Received {} bytes", payload.len());
debug!("From: {}", &remote_addr);
debug!("Payload: {:?}", payload);

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

info!("Received {} bytes", payload.len());
debug!("Received {} bytes", payload.len());
debug!("From: {}", &remote_addr);
debug!("Payload: {:?}", payload);

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

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

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

info!("{} bytes sent", &inner[..position].len());
debug!("{} bytes sent", &inner[..position].len());
}
Err(_) => {
error!("could not write response to bytes.");
Expand Down

0 comments on commit 2b859d6

Please sign in to comment.