mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
Hybrid topics handling in announcer
This commit is contained in:
parent
1ce5edf531
commit
7aa6f0d45f
3 changed files with 39 additions and 30 deletions
|
@ -69,6 +69,8 @@ if (strlen($info_hash) == 32) {
|
|||
} else {
|
||||
msg_die('Invalid info_hash: ' . $info_hash);
|
||||
}
|
||||
// Hybrid torrent checks
|
||||
$is_hybrid = $hybrid_v1_hash = $hybrid_v2_hash = $hybrid_tor_update = false;
|
||||
|
||||
if (!isset($port) || $port < 0 || $port > 0xFFFF) {
|
||||
msg_die('Invalid port: ' . $port);
|
||||
|
@ -185,9 +187,14 @@ if ($lp_info) {
|
|||
$tor_type = $row['tor_type'];
|
||||
|
||||
// Check hybrid torrents
|
||||
$is_hybrid = false;
|
||||
if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) {
|
||||
// Helpful dev variables
|
||||
$is_hybrid = true;
|
||||
$hybrid_v1_hash = &$row['info_hash'];
|
||||
$hybrid_v2_hash = &$row['info_hash_v2'];
|
||||
if ($info_hash === $hybrid_v1_hash) {
|
||||
$hybrid_tor_update = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ratio limits
|
||||
|
@ -287,8 +294,8 @@ if ($bb_cfg['tracker']['freeleech'] && $down_add) {
|
|||
// Insert / update peer info
|
||||
$peer_info_updated = false;
|
||||
$update_time = ($stopped) ? 0 : TIMENOW;
|
||||
|
||||
if ($lp_info) {
|
||||
if (($is_hybrid && $hybrid_tor_update) || !$is_hybrid) { // Update statistics only for one topic
|
||||
if ($lp_info) {
|
||||
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
|
||||
|
||||
$sql .= ", seeder = $seeder";
|
||||
|
@ -312,15 +319,15 @@ if ($lp_info) {
|
|||
DB()->query($sql);
|
||||
|
||||
$peer_info_updated = DB()->affected_rows();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$lp_info || !$peer_info_updated) {
|
||||
if (!$lp_info || !$peer_info_updated) {
|
||||
$columns = 'peer_hash, topic_id, user_id, ip, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time';
|
||||
$values = "'$peer_hash', $topic_id, $user_id, '$ip_sql', $port, $seeder, $releaser, $tor_type, $uploaded, $downloaded, $left, $speed_up, $speed_down, $up_add, $down_add, $update_time";
|
||||
|
||||
DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)");
|
||||
}
|
||||
}
|
||||
|
||||
// Exit if stopped
|
||||
if ($stopped) {
|
||||
silent_exit();
|
||||
|
@ -380,8 +387,8 @@ if (!$output) {
|
|||
LIMIT 1
|
||||
");
|
||||
|
||||
$seeders = $row['seeders'] ?? 0;
|
||||
$leechers = $row['leechers'] ?? 0;
|
||||
$seeders = $row['seeders'] ?? ($seeder ? 1 : 0);
|
||||
$leechers = $row['leechers'] ?? (!$seeder ? 1 : 0);
|
||||
}
|
||||
|
||||
$output = [
|
||||
|
@ -389,11 +396,12 @@ if (!$output) {
|
|||
'min interval' => (int)$announce_interval,
|
||||
'complete' => (int)$seeders,
|
||||
'incomplete' => (int)$leechers,
|
||||
//'downloaded' => int($client_complete)
|
||||
'warning message' => 'Statistics were updated',
|
||||
'peers' => $peers,
|
||||
];
|
||||
|
||||
$peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
||||
CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
||||
}
|
||||
|
||||
// Return data to client
|
||||
|
|
|
@ -71,6 +71,7 @@ function dummy_exit($interval = 1800, $cache_dict = [])
|
|||
if (!empty($cache_dict)) {
|
||||
$output['complete'] = $cache_dict['complete'];
|
||||
$output['incomplete'] = $cache_dict['incomplete'];
|
||||
//$output['downloaded'] = $cache_dict['downloaded'];
|
||||
$output['warning message'] = 'Next statistics update in: ' . (floor($interval / 60) % 60) . ' minutes';
|
||||
$output['peers'] = $cache_dict['peers'];
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ if (strlen($info_hash) == 32) {
|
|||
} elseif (strlen($info_hash) == 20) {
|
||||
$is_bt_v2 = false;
|
||||
} else {
|
||||
msg_die('Invalid info_hash: ' . $info_hash);
|
||||
msg_die('Invalid info_hash');
|
||||
}
|
||||
|
||||
$info_hash_hex = bin2hex($info_hash);
|
||||
|
@ -70,7 +70,7 @@ $output['files'][$info_hash] = [
|
|||
'incomplete' => (int)$row['leechers'],
|
||||
];
|
||||
|
||||
$peers_list_cached = CACHE('tr_cache')->set(SCRAPE_LIST_PREFIX . $info_hash_hex, $output, SCRAPE_LIST_EXPIRE);;
|
||||
CACHE('tr_cache')->set(SCRAPE_LIST_PREFIX . $info_hash_hex, $output, SCRAPE_LIST_EXPIRE);
|
||||
|
||||
echo \SandFox\Bencode\Bencode::encode($output);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue