mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 22:03:49 -07:00
Switched from md5 to a faster xxHash hash function (#921)
* Support for IDN domains * Announcer support for answering stopped events * Update init_tr.php * Informing message * Update announce.php * Switched from md5 to a faster xxHash hash function --------- Co-authored-by: Roman Kelesidis <roman25052006.kelesh@gmail.com>
This commit is contained in:
parent
1d3ac71ac1
commit
1a0e5ea237
4 changed files with 10 additions and 14 deletions
|
@ -26,14 +26,11 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
|
||||||
$_GET['info_hash'] = $_GET['?info_hash'];
|
$_GET['info_hash'] = $_GET['?info_hash'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_bt_v2 = null;
|
|
||||||
$is_hybrid = $hybrid_v1_hash = $hybrid_v2_hash = $hybrid_tor_update = false;
|
|
||||||
|
|
||||||
// Initial request verification
|
// Initial request verification
|
||||||
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) {
|
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) {
|
||||||
msg_die('Please disable SCRAPE!');
|
msg_die('Please disable SCRAPE!');
|
||||||
}
|
}
|
||||||
if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key]) || strlen($_GET[$passkey_key]) != BT_AUTH_KEY_LENGTH) {
|
if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key]) || strlen($_GET[$passkey_key]) !== BT_AUTH_KEY_LENGTH) {
|
||||||
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)');
|
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +57,7 @@ $passkey = $$passkey_key ?? null;
|
||||||
if (!isset($peer_id)) {
|
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: ' . bin2hex($peer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,9 +70,9 @@ if (!isset($info_hash)) {
|
||||||
$info_hash_hex = bin2hex($info_hash);
|
$info_hash_hex = bin2hex($info_hash);
|
||||||
|
|
||||||
// Check info_hash version
|
// Check info_hash version
|
||||||
if (strlen($info_hash) == 32) {
|
if (strlen($info_hash) === 32) {
|
||||||
$is_bt_v2 = true;
|
$is_bt_v2 = true;
|
||||||
} 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: ' . $info_hash_hex);
|
msg_die('Invalid info_hash: ' . $info_hash_hex);
|
||||||
|
@ -125,8 +122,7 @@ if (!\TorrentPier\Helpers\IPHelper::isValid($ip)) {
|
||||||
$ip_sql = \TorrentPier\Helpers\IPHelper::ip2long($ip);
|
$ip_sql = \TorrentPier\Helpers\IPHelper::ip2long($ip);
|
||||||
|
|
||||||
// Peer unique id
|
// Peer unique id
|
||||||
$peer_hash = md5(rtrim($info_hash, ' ') . $passkey . $ip . $port);
|
$peer_hash = hash('xxh128', rtrim($info_hash, ' ') . $passkey . $ip . $port);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
$stopped = ($event === 'stopped');
|
$stopped = ($event === 'stopped');
|
||||||
|
|
||||||
|
@ -300,7 +296,7 @@ if ($bb_cfg['tracker']['freeleech'] && $down_add) {
|
||||||
// Insert / update peer info
|
// Insert / update peer info
|
||||||
$peer_info_updated = false;
|
$peer_info_updated = false;
|
||||||
$update_time = ($stopped) ? 0 : TIMENOW;
|
$update_time = ($stopped) ? 0 : TIMENOW;
|
||||||
if (($is_hybrid && $hybrid_tor_update) || !$is_hybrid) { // Update statistics only for one topic
|
if (isset($is_hybrid, $hybrid_tor_update) || !isset($is_hybrid)) { // Update statistics only for one topic
|
||||||
if ($lp_info) {
|
if ($lp_info) {
|
||||||
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
|
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
|
||||||
|
|
||||||
|
@ -408,11 +404,11 @@ if (!$output) {
|
||||||
'complete' => (int)$seeders,
|
'complete' => (int)$seeders,
|
||||||
'incomplete' => (int)$leechers,
|
'incomplete' => (int)$leechers,
|
||||||
'downloaded' => (int)$client_completed,
|
'downloaded' => (int)$client_completed,
|
||||||
'warning message' => 'Statistics were updated',
|
|
||||||
'peers' => $peers,
|
'peers' => $peers,
|
||||||
];
|
];
|
||||||
|
|
||||||
$peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
$peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
||||||
|
$output['warning message'] = 'Statistics were updated';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return data to client
|
// Return data to client
|
||||||
|
|
|
@ -131,7 +131,7 @@ $replace_in_parent = [
|
||||||
'last_topic_id'
|
'last_topic_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
$cache_name = 'index_sql_' . md5($sql);
|
$cache_name = 'index_sql_' . hash('xxh128', $sql);
|
||||||
if (!$cat_forums = CACHE('bb_cache')->get($cache_name)) {
|
if (!$cat_forums = CACHE('bb_cache')->get($cache_name)) {
|
||||||
$cat_forums = [];
|
$cat_forums = [];
|
||||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||||
|
|
|
@ -684,7 +684,7 @@ class Template
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$line = '<' . '?php ';
|
$line = '<' . '?php ';
|
||||||
$filehash = md5($params_str . $this->include_count . TIMENOW);
|
$filehash = hash('xxh128', $params_str . $this->include_count . TIMENOW);
|
||||||
$line .= ' $this->set_filename(\'xs_include_' . $filehash . '\', \'' . $params_str . '\', true); ';
|
$line .= ' $this->set_filename(\'xs_include_' . $filehash . '\', \'' . $params_str . '\', true); ';
|
||||||
$line .= ' $this->pparse(\'xs_include_' . $filehash . '\'); ';
|
$line .= ' $this->pparse(\'xs_include_' . $filehash . '\'); ';
|
||||||
$line .= ' ?' . '>';
|
$line .= ' ?' . '>';
|
||||||
|
|
|
@ -362,7 +362,7 @@ class Torrent
|
||||||
|
|
||||||
// Getting info_hash v1
|
// Getting info_hash v1
|
||||||
if ($bt_v1) {
|
if ($bt_v1) {
|
||||||
$info_hash = pack('H*', sha1(\SandFox\Bencode\Bencode::encode($info)));
|
$info_hash = pack('H*', hash('sha1', \SandFox\Bencode\Bencode::encode($info)));
|
||||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||||
$info_hash_where = "WHERE info_hash = '$info_hash_sql'";
|
$info_hash_where = "WHERE info_hash = '$info_hash_sql'";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue