forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge torrust#703: Refactor UDP Tracker logs
4a2d902 feat: [torrust#698] refactor UDP logs (Jose Celano) Pull request description: Refactor UDP Tracker logs. - Use `tracing` crate format. - Include request ID matching request and response. - Include service identification with the server socket address. - Rename target from `UDP Tracker` to `UDP TRACKER`. Example: ``` 2024-02-19T17:10:05.243973520+00:00 [UDP TRACKER][INFO] request; server_socket_addr=0.0.0.0:6969 action=CONNECT transaction_id=-888840697 request_id=03b92de0-c9f8-4c40-a808-5d706ce770f4 2024-02-19T17:10:05.244016141+00:00 [UDP TRACKER][INFO] response; server_socket_addr=0.0.0.0:6969 transaction_id=-888840697 request_id=03b92de0-c9f8-4c40-a808-5d706ce770f4 2024-02-19T17:10:05.244042841+00:00 [UDP TRACKER][INFO] request; server_socket_addr=0.0.0.0:6969 action=ANNOUNCE transaction_id=-888840697 request_id=2113eb8c-61f4-476b-b3d5-02892f0a2fdb connection_id=-7190270103145546231 info_hash=9c38422213e30bff212b30c360d26f9a02136422 2024-02-19T17:10:05.244052082+00:00 [UDP TRACKER][INFO] response; server_socket_addr=0.0.0.0:6969 transaction_id=-888840697 request_id=2113eb8c-61f4-476b-b3d5-02892f0a2fdb ``` It does not include any response data to keep log files small. ACKs for top commit: josecelano: ACK 4a2d902 Tree-SHA512: 6d1c5e2d79d6f908d04edf277d066e241aa02acfd20af2001fb7dad80b87409fd87857b36b6258dfa9415dc999aceea976f8e6d59c2d71d269ae7b1cedb0b820
- Loading branch information
Showing
6 changed files
with
134 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//! Logging for UDP Tracker requests and responses. | ||
use std::net::SocketAddr; | ||
|
||
use aquatic_udp_protocol::{Request, Response, TransactionId}; | ||
|
||
use super::handlers::RequestId; | ||
use crate::shared::bit_torrent::info_hash::InfoHash; | ||
|
||
pub fn log_request(request: &Request, request_id: &RequestId, server_socket_addr: &SocketAddr) { | ||
let action = map_action_name(request); | ||
|
||
match &request { | ||
Request::Connect(connect_request) => { | ||
let transaction_id = connect_request.transaction_id; | ||
let transaction_id_str = transaction_id.0.to_string(); | ||
|
||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "request", server_socket_addr = %server_socket_addr, action = %action, transaction_id = %transaction_id_str, request_id = %request_id); | ||
} | ||
Request::Announce(announce_request) => { | ||
let transaction_id = announce_request.transaction_id; | ||
let transaction_id_str = transaction_id.0.to_string(); | ||
let connection_id_str = announce_request.connection_id.0.to_string(); | ||
let info_hash_str = InfoHash::from_bytes(&announce_request.info_hash.0).to_hex_string(); | ||
|
||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "request", server_socket_addr = %server_socket_addr, action = %action, transaction_id = %transaction_id_str, request_id = %request_id, connection_id = %connection_id_str, info_hash = %info_hash_str); | ||
} | ||
Request::Scrape(scrape_request) => { | ||
let transaction_id = scrape_request.transaction_id; | ||
let transaction_id_str = transaction_id.0.to_string(); | ||
let connection_id_str = scrape_request.connection_id.0.to_string(); | ||
|
||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "request", server_socket_addr = %server_socket_addr, action = %action, transaction_id = %transaction_id_str, request_id = %request_id, connection_id = %connection_id_str); | ||
} | ||
}; | ||
} | ||
|
||
fn map_action_name(udp_request: &Request) -> String { | ||
match udp_request { | ||
Request::Connect(_connect_request) => "CONNECT".to_owned(), | ||
Request::Announce(_announce_request) => "ANNOUNCE".to_owned(), | ||
Request::Scrape(_scrape_request) => "SCRAPE".to_owned(), | ||
} | ||
} | ||
|
||
pub fn log_response( | ||
_response: &Response, | ||
transaction_id: &TransactionId, | ||
request_id: &RequestId, | ||
server_socket_addr: &SocketAddr, | ||
) { | ||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "response", server_socket_addr = %server_socket_addr, transaction_id = %transaction_id.0.to_string(), request_id = %request_id); | ||
} | ||
|
||
pub fn log_bad_request(request_id: &RequestId) { | ||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "bad request", request_id = %request_id); | ||
} | ||
|
||
pub fn log_error_response(request_id: &RequestId) { | ||
tracing::span!( | ||
target: "UDP TRACKER", | ||
tracing::Level::INFO, "response", request_id = %request_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters