Skip to content

Commit

Permalink
Merge #873: Implment Request Stream for UDP Tracker
Browse files Browse the repository at this point in the history
84cc1a1 dev: use stream for udp requests (Cameron Garnham)

Pull request description:

  This pull request improves the UDP tracker `server.rs` request processing logic; now using a `tokio::stream` for getting the requests for the ring buffer.

  I hope this pull request will improve the performance of the tracker in multi-core setups.

  @josecelano This code will require a special code-review.

ACKs for top commit:
  josecelano:
    ACK 84cc1a1

Tree-SHA512: 84d33426583c12b0f39bd0c3a6c48f9a510fdfbbf36da000307e809bce4f7870a53b840eda326492d29f21b83611cdc610b03ec30aa675179635ac6ea19ddd34
  • Loading branch information
josecelano committed Jun 25, 2024
2 parents 27933b9 + 84cc1a1 commit b7bcd96
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 198 deletions.
1 change: 0 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ rustflags = [
"-D",
"unused",
]

2 changes: 2 additions & 0 deletions cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"codecov",
"codegen",
"completei",
"Condvar",
"connectionless",
"Containerfile",
"conv",
"curr",
"cvar",
"Cyberneering",
"dashmap",
"datagram",
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ pub mod bootstrap;
pub mod console;
pub mod core;
pub mod servers;
pub mod shared;
pub mod shared;

#[macro_use]
extern crate lazy_static;
Expand Down
8 changes: 3 additions & 5 deletions src/servers/udp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use aquatic_udp_protocol::{
ErrorResponse, Ipv4AddrBytes, Ipv6AddrBytes, NumberOfDownloads, NumberOfPeers, Port, Request, Response, ResponsePeer,
ScrapeRequest, ScrapeResponse, TorrentScrapeStatistics, TransactionId,
};
use tokio::net::UdpSocket;
use torrust_tracker_located_error::DynError;
use torrust_tracker_primitives::info_hash::InfoHash;
use tracing::debug;
Expand All @@ -34,13 +33,12 @@ use crate::shared::bit_torrent::common::MAX_SCRAPE_TORRENTS;
/// - Delegating the request to the correct handler depending on the request type.
///
/// It will return an `Error` response if the request is invalid.
pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker>, socket: Arc<UdpSocket>) -> Response {
pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker>, addr: SocketAddr) -> Response {
debug!("Handling Packets: {udp_request:?}");

let start_time = Instant::now();

let request_id = RequestId::make(&udp_request);
let server_socket_addr = socket.local_addr().expect("Could not get local_addr for socket.");

match Request::parse_bytes(&udp_request.payload[..udp_request.payload.len()], MAX_SCRAPE_TORRENTS).map_err(|e| {
Error::InternalServer {
Expand All @@ -49,7 +47,7 @@ pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker
}
}) {
Ok(request) => {
log_request(&request, &request_id, &server_socket_addr);
log_request(&request, &request_id, &addr);

let transaction_id = match &request {
Request::Connect(connect_request) => connect_request.transaction_id,
Expand All @@ -64,7 +62,7 @@ pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker

let latency = start_time.elapsed();

log_response(&response, &transaction_id, &request_id, &server_socket_addr, latency);
log_response(&response, &transaction_id, &request_id, &addr, latency);

response
}
Expand Down
Loading

0 comments on commit b7bcd96

Please sign in to comment.