Minor improvements (#905)

This commit is contained in:
Roman Kelesidis 2023-09-18 16:20:03 +07:00 committed by GitHub
commit 0cf8250c69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,12 +57,20 @@ $passkey = ${$passkey_key} ?? null;
// Verify request // Verify request
// Required params (info_hash, peer_id, port, uploaded, downloaded, left, passkey) // Required params (info_hash, peer_id, port, uploaded, downloaded, left, passkey)
if (!isset($peer_id)) {
msg_die('peer_id was not provided');
}
if (strlen($peer_id) != 20) {
msg_die('Invalid peer_id: ' . bin2hex($peer_id));
}
// Verify info_hash
if (!isset($info_hash)) { if (!isset($info_hash)) {
msg_die('info_hash was not provided'); msg_die('info_hash was not provided');
} }
if (!isset($peer_id) || strlen($peer_id) != 20) {
msg_die('Invalid peer_id: ' . bin2hex($peer_id)); // Store info hash in hex format
} $info_hash_hex = bin2hex($info_hash);
// Check info_hash version // Check info_hash version
if (strlen($info_hash) == 32) { if (strlen($info_hash) == 32) {
@ -70,7 +78,7 @@ if (strlen($info_hash) == 32) {
} elseif (strlen($info_hash) == 20) { } elseif (strlen($info_hash) == 20) {
$is_bt_v2 = false; $is_bt_v2 = false;
} else { } else {
msg_die('Invalid info_hash: ' . bin2hex($info_hash)); msg_die('Invalid info_hash: ' . $info_hash_hex);
} }
if (!isset($port) || $port < 0 || $port > 0xFFFF) { if (!isset($port) || $port < 0 || $port > 0xFFFF) {
@ -172,7 +180,7 @@ if ($lp_info) {
// Verify if torrent registered on tracker and user authorized // Verify if torrent registered on tracker and user authorized
if (empty($row['topic_id'])) { if (empty($row['topic_id'])) {
msg_die('Torrent not registered, info_hash = ' . bin2hex($info_hash)); msg_die('Torrent not registered, info_hash = ' . $info_hash_hex);
} }
if (empty($row['user_id'])) { if (empty($row['user_id'])) {
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (user not found)'); msg_die('Please LOG IN and RE-DOWNLOAD this torrent (user not found)');