Prioritize returning leecher list for seeder announces (#961)

* Show IPv6 peers for cached announces
This commit is contained in:
Cønstantine Kovalensky 2023-10-06 16:15:11 +04:00 committed by GitHub
commit 50e305390d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View file

@ -58,7 +58,7 @@ if (!isset($peer_id)) {
msg_die('peer_id was not provided'); msg_die('peer_id was not provided');
} }
if (strlen($peer_id) !== 20) { if (strlen($peer_id) !== 20) {
msg_die('Invalid peer_id: ' . bin2hex($peer_id)); msg_die('Invalid peer_id: ' . $peer_id);
} }
// Verify info_hash // Verify info_hash
@ -361,16 +361,19 @@ if (!$output) {
$numwant = (int)$bb_cfg['tracker']['numwant']; $numwant = (int)$bb_cfg['tracker']['numwant'];
$compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact)); $compact_mode = ($bb_cfg['tracker']['compact_mode'] || !empty($compact));
$leechers_only = $seeder ? 'AND seeder = 0' : ''; // Return leechers for seeders
$rowset = DB()->fetch_rowset(" $rowset = DB()->fetch_rowset("
SELECT ip, port SELECT ip, port
FROM " . BB_BT_TRACKER . " FROM " . BB_BT_TRACKER . "
WHERE topic_id = $topic_id WHERE topic_id = $topic_id
$leechers_only
ORDER BY RAND() ORDER BY RAND()
LIMIT $numwant LIMIT $numwant
"); ");
if (empty($rowset)) { if (empty($rowset)) {
$rowset[] = ['ip' => $ip, 'port' => $port]; $rowset[] = ['ip' => long2ip(rand(1, 4294967295)), 'port' => rand(1, 65536)];
} }
if ($compact_mode) { if ($compact_mode) {

View file

@ -74,6 +74,10 @@ function dummy_exit($interval = 1800, $cache_dict = [])
$output['peers'] = $cache_dict['peers']; $output['peers'] = $cache_dict['peers'];
} }
if (isset($cache_dict['peers6'])) {
$output['peers6'] = $cache_dict['peers6'];
}
$output = \Arokettu\Bencode\Bencode::encode($output); $output = \Arokettu\Bencode\Bencode::encode($output);
die($output); die($output);

View file

@ -61,7 +61,7 @@ class IPHelper extends Ip
* @return string * @return string
*/ */
public static function long2ip_extended($ip) public static function long2ip_extended(string $ip): string
{ {
return self::long2ip($ip, $ip > 4294967295); return self::long2ip($ip, $ip > 4294967295);
} }