diff --git a/aquatic_udp/src/workers/swarm/mod.rs b/aquatic_udp/src/workers/swarm/mod.rs index 2c054b3..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(), ) }; @@ -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, } } 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 => {} } 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 -- $@