From ed8fe6fbf1de340e49eb50260cc2853af1eaacde Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Thu, 7 Sep 2023 18:25:46 +0700 Subject: [PATCH] Update announce.php --- bt/announce.php | 52 +++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index 0800cf618..9f7e55beb 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -113,10 +113,12 @@ if (!$bb_cfg['ignore_reported_ip'] && isset($_GET['ip']) && $ip !== $_GET['ip']) } } } + // Check that IP format is valid if (!\TorrentPier\Helpers\IPHelper::isValid($ip)) { msg_die("Invalid IP: $ip"); } + // Convert IP to HEX format $ip_sql = \TorrentPier\Helpers\IPHelper::ip2long($ip); @@ -133,31 +135,6 @@ if ($lp_info && (!isset($event) || $event !== 'stopped')) { drop_fast_announce($lp_info); } -// Functions -function drop_fast_announce($lp_info) -{ - global $announce_interval; - - if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) { - return; // if announce interval correct - } - - $new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW; - - dummy_exit($new_ann_intrv); -} - -function msg_die($msg) -{ - $output = \SandFox\Bencode\Bencode::encode([ - 'min interval' => (int)1800, - 'failure reason' => (string)$msg, - 'warning message' => (string)$msg, - ]); - - die($output); -} - // Start announcer require __DIR__ . '/includes/init_tr.php'; @@ -423,6 +400,31 @@ if (!$output) { $peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE); } +// Functions +function drop_fast_announce($lp_info) +{ + global $announce_interval; + + if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) { + return; // if announce interval correct + } + + $new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW; + + dummy_exit($new_ann_intrv); +} + +function msg_die($msg) +{ + $output = \SandFox\Bencode\Bencode::encode([ + 'min interval' => (int)1800, + 'failure reason' => (string)$msg, + 'warning message' => (string)$msg, + ]); + + die($output); +} + // Return data to client echo \SandFox\Bencode\Bencode::encode($output);