1
0
mirror of https://github.com/torrentpier/torrentpier.git synced 2025-03-12 04:35:42 -07:00

feat(announcer): Blocking all ports lower then 1024 ()

* feat(announcer): Blocking all ports lower then `1024`

* Update announce.php
This commit is contained in:
Roman Kelesidis 2025-01-16 14:50:28 +03:00 committed by GitHub
parent a1e0170770
commit 1bc7e09ddb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -100,12 +100,21 @@ $info_hash_hex = bin2hex($info_hash);
// Store peer id
$peer_id_sql = preg_replace('/[^a-zA-Z0-9\-\_]/', '', $peer_id);
// Stopped event
$stopped = ($event === 'stopped');
// Check info_hash length
if (strlen($info_hash) !== 20) {
msg_die('Invalid info_hash: ' . (mb_check_encoding($info_hash, 'UTF8') ? $info_hash : $info_hash_hex));
}
if (!isset($port) || $port < 0 || $port > 0xFFFF) {
if (
// https://github.com/HDInnovations/UNIT3D-Community-Edition/blob/c64275f0b5dcb3c4c845d5204871adfe24f359d6/app/Http/Controllers/AnnounceController.php#L284
// Block system-reserved ports since 99.9% of the time they're fake and thus not connectable
// Some clients will send port of 0 on 'stopped' events. Let them through as they won't receive peers anyway.
!isset($port)
|| ($port < 1024 && !$stopped)
|| $port > 0xFFFF) {
msg_die('Invalid port: ' . $port);
}
@ -158,9 +167,6 @@ if ($ip_version === 'ipv6') {
// Peer unique id
$peer_hash = hash('xxh128', $passkey . $info_hash_hex . $port);
// Events
$stopped = ($event === 'stopped');
// Set seeder & complete
$complete = $seeder = ($left == 0) ? 1 : 0;