From e9f83403baf5d1992efee162aefb7a167ba20328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 18 Sep 2022 17:55:39 +0200 Subject: [PATCH 1/4] udp: fix bug in TorrentData num_seeders/num_leechers updates --- aquatic_udp/src/workers/swarm/storage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aquatic_udp/src/workers/swarm/storage.rs b/aquatic_udp/src/workers/swarm/storage.rs index cebe1df..9122373 100644 --- a/aquatic_udp/src/workers/swarm/storage.rs +++ b/aquatic_udp/src/workers/swarm/storage.rs @@ -83,10 +83,10 @@ impl TorrentData { match opt_removed_peer.map(|peer| peer.is_seeder) { Some(true) => { - self.num_leechers -= 1; + self.num_seeders -= 1; } Some(false) => { - self.num_seeders -= 1; + self.num_leechers -= 1; } None => {} } From 8beb13db2962a503cc2c6d822c1f20e3cb97a8a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 18 Sep 2022 18:05:21 +0200 Subject: [PATCH 2/4] In scripts, explicitly choose what workspace member to build Otherwise, building aquatic_udp fails on other OS:es than Linux --- scripts/bench-udp-handlers.sh | 2 +- scripts/run-aquatic-http-private.sh | 2 +- scripts/run-aquatic-http.sh | 2 +- scripts/run-aquatic-udp.sh | 2 +- scripts/run-aquatic-ws.sh | 2 +- scripts/run-load-test-http.sh | 2 +- scripts/run-load-test-udp.sh | 2 +- scripts/run-load-test-ws.sh | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/bench-udp-handlers.sh b/scripts/bench-udp-handlers.sh index f273454..fc3dfc4 100755 --- a/scripts/bench-udp-handlers.sh +++ b/scripts/bench-udp-handlers.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --release --bin aquatic_udp_bench -- $@ \ No newline at end of file +cargo run --release -p aquatic_udp_bench -- $@ diff --git a/scripts/run-aquatic-http-private.sh b/scripts/run-aquatic-http-private.sh index 0a9ed31..9809ee8 100755 --- a/scripts/run-aquatic-http-private.sh +++ b/scripts/run-aquatic-http-private.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_http_private -- $@ +cargo run --profile "release-debug" -p aquatic_http_private -- $@ diff --git a/scripts/run-aquatic-http.sh b/scripts/run-aquatic-http.sh index e693fca..492f9be 100755 --- a/scripts/run-aquatic-http.sh +++ b/scripts/run-aquatic-http.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_http -- $@ +cargo run --profile "release-debug" -p aquatic_http -- $@ diff --git a/scripts/run-aquatic-udp.sh b/scripts/run-aquatic-udp.sh index 0814661..0007289 100755 --- a/scripts/run-aquatic-udp.sh +++ b/scripts/run-aquatic-udp.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_udp -- $@ +cargo run --profile "release-debug" -p aquatic_udp -- $@ diff --git a/scripts/run-aquatic-ws.sh b/scripts/run-aquatic-ws.sh index 297c71d..298a3d3 100755 --- a/scripts/run-aquatic-ws.sh +++ b/scripts/run-aquatic-ws.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_ws -- $@ +cargo run --profile "release-debug" -p aquatic_ws -- $@ diff --git a/scripts/run-load-test-http.sh b/scripts/run-load-test-http.sh index 58bfe4e..7a76099 100755 --- a/scripts/run-load-test-http.sh +++ b/scripts/run-load-test-http.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_http_load_test -- $@ \ No newline at end of file +cargo run --profile "release-debug" -p aquatic_http_load_test -- $@ diff --git a/scripts/run-load-test-udp.sh b/scripts/run-load-test-udp.sh index b307628..38ee3ab 100755 --- a/scripts/run-load-test-udp.sh +++ b/scripts/run-load-test-udp.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_udp_load_test -- $@ +cargo run --profile "release-debug" -p aquatic_udp_load_test -- $@ diff --git a/scripts/run-load-test-ws.sh b/scripts/run-load-test-ws.sh index 79dd720..9c86576 100755 --- a/scripts/run-load-test-ws.sh +++ b/scripts/run-load-test-ws.sh @@ -2,4 +2,4 @@ . ./scripts/env-native-cpu-without-avx-512 -cargo run --profile "release-debug" --bin aquatic_ws_load_test -- $@ \ No newline at end of file +cargo run --profile "release-debug" -p aquatic_ws_load_test -- $@ From 5889cb22f7c1e3a35250e9584023b6e4891c3733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 18 Sep 2022 18:06:31 +0200 Subject: [PATCH 3/4] udp: handle_announce_request: don't cast usize to i32, use try_into --- aquatic_udp/src/workers/swarm/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aquatic_udp/src/workers/swarm/mod.rs b/aquatic_udp/src/workers/swarm/mod.rs index 2c054b3..bc0003f 100644 --- a/aquatic_udp/src/workers/swarm/mod.rs +++ b/aquatic_udp/src/workers/swarm/mod.rs @@ -163,8 +163,8 @@ fn handle_announce_request( AnnounceResponse { transaction_id: request.transaction_id, announce_interval: AnnounceInterval(config.protocol.peer_announce_interval), - leechers: NumberOfPeers(torrent_data.num_leechers() as i32), - seeders: NumberOfPeers(torrent_data.num_seeders() as i32), + leechers: NumberOfPeers(torrent_data.num_leechers().try_into().unwrap_or(i32::MAX)), + seeders: NumberOfPeers(torrent_data.num_seeders().try_into().unwrap_or(i32::MAX)), peers: response_peers, } } From 9797f24299cf033f1e80195d977e2f367db463ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 18 Sep 2022 18:09:43 +0200 Subject: [PATCH 4/4] udp: handle_announce_request: remove two noop casts --- aquatic_udp/src/workers/swarm/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aquatic_udp/src/workers/swarm/mod.rs b/aquatic_udp/src/workers/swarm/mod.rs index bc0003f..d325bcd 100644 --- a/aquatic_udp/src/workers/swarm/mod.rs +++ b/aquatic_udp/src/workers/swarm/mod.rs @@ -136,11 +136,11 @@ fn handle_announce_request( peer_ip: I, peer_valid_until: ValidUntil, ) -> AnnounceResponse { - let max_num_peers_to_take = if request.peers_wanted.0 <= 0 { - config.protocol.max_response_peers as usize + let max_num_peers_to_take: usize = if request.peers_wanted.0 <= 0 { + config.protocol.max_response_peers } else { ::std::cmp::min( - config.protocol.max_response_peers as usize, + config.protocol.max_response_peers, request.peers_wanted.0.try_into().unwrap(), ) };