From 9b3d2a4ebd00b993957c5cc294091de5455aaef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B8nstantine=20Kovalensky?= <45331093+kovalensky@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:51:08 +0400 Subject: [PATCH] Better way to prioritize peers (#962) --- bt/announce.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index 4654be022..37e2ea1d4 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -361,19 +361,16 @@ if (!$output) { $numwant = (int)$bb_cfg['tracker']['numwant']; $compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact)); - $leechers_only = $seeder ? 'AND seeder = 0' : ''; // Return leechers for seeders - $rowset = DB()->fetch_rowset(" - SELECT ip, port - FROM " . BB_BT_TRACKER . " - WHERE topic_id = $topic_id - $leechers_only - ORDER BY RAND() - LIMIT $numwant - "); + SELECT ip, port + FROM " . BB_BT_TRACKER . " + WHERE topic_id = $topic_id + ORDER BY seeder ASC, RAND() + LIMIT $numwant + "); if (empty($rowset)) { - $rowset[] = ['ip' => long2ip(rand(1, 4294967295)), 'port' => rand(1, 65536)]; + $rowset[] = ['ip' => \TorrentPier\Helpers\IPHelper::ip2long($ip), 'port' => (int)$port]; } if ($compact_mode) {