Skip to content

Commit b7bcd96

Browse files
committed
Merge torrust#873: Implment Request Stream for UDP Tracker
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
2 parents 27933b9 + 84cc1a1 commit b7bcd96

File tree

8 files changed

+425
-198
lines changed

8 files changed

+425
-198
lines changed

.cargo/config.toml

-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ rustflags = [
2323
"-D",
2424
"unused",
2525
]
26-

cSpell.json

+2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
"codecov",
3535
"codegen",
3636
"completei",
37+
"Condvar",
3738
"connectionless",
3839
"Containerfile",
3940
"conv",
4041
"curr",
42+
"cvar",
4143
"Cyberneering",
4244
"dashmap",
4345
"datagram",

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ pub mod bootstrap;
494494
pub mod console;
495495
pub mod core;
496496
pub mod servers;
497-
pub mod shared;
497+
pub mod shared;
498498

499499
#[macro_use]
500500
extern crate lazy_static;

src/servers/udp/handlers.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use aquatic_udp_protocol::{
1010
ErrorResponse, Ipv4AddrBytes, Ipv6AddrBytes, NumberOfDownloads, NumberOfPeers, Port, Request, Response, ResponsePeer,
1111
ScrapeRequest, ScrapeResponse, TorrentScrapeStatistics, TransactionId,
1212
};
13-
use tokio::net::UdpSocket;
1413
use torrust_tracker_located_error::DynError;
1514
use torrust_tracker_primitives::info_hash::InfoHash;
1615
use tracing::debug;
@@ -34,13 +33,12 @@ use crate::shared::bit_torrent::common::MAX_SCRAPE_TORRENTS;
3433
/// - Delegating the request to the correct handler depending on the request type.
3534
///
3635
/// It will return an `Error` response if the request is invalid.
37-
pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker>, socket: Arc<UdpSocket>) -> Response {
36+
pub(crate) async fn handle_packet(udp_request: UdpRequest, tracker: &Arc<Tracker>, addr: SocketAddr) -> Response {
3837
debug!("Handling Packets: {udp_request:?}");
3938

4039
let start_time = Instant::now();
4140

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

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

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

6563
let latency = start_time.elapsed();
6664

67-
log_response(&response, &transaction_id, &request_id, &server_socket_addr, latency);
65+
log_response(&response, &transaction_id, &request_id, &addr, latency);
6866

6967
response
7068
}

0 commit comments

Comments
 (0)