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 {
|
} else {
|
||||||
msg_die('Invalid info_hash: ' . $info_hash);
|
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) {
|
if (!isset($port) || $port < 0 || $port > 0xFFFF) {
|
||||||
msg_die('Invalid port: ' . $port);
|
msg_die('Invalid port: ' . $port);
|
||||||
|
@ -185,9 +187,14 @@ if ($lp_info) {
|
||||||
$tor_type = $row['tor_type'];
|
$tor_type = $row['tor_type'];
|
||||||
|
|
||||||
// Check hybrid torrents
|
// Check hybrid torrents
|
||||||
$is_hybrid = false;
|
|
||||||
if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) {
|
if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) {
|
||||||
|
// Helpful dev variables
|
||||||
$is_hybrid = true;
|
$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
|
// Ratio limits
|
||||||
|
@ -287,40 +294,40 @@ 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 ($lp_info) {
|
||||||
|
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
|
||||||
|
|
||||||
if ($lp_info) {
|
$sql .= ", seeder = $seeder";
|
||||||
$sql = "UPDATE " . BB_BT_TRACKER . " SET update_time = $update_time";
|
$sql .= ($releaser != $lp_info['releaser']) ? ", releaser = $releaser" : '';
|
||||||
|
|
||||||
$sql .= ", seeder = $seeder";
|
$sql .= ($tor_type != $lp_info['tor_type']) ? ", tor_type = $tor_type" : '';
|
||||||
$sql .= ($releaser != $lp_info['releaser']) ? ", releaser = $releaser" : '';
|
|
||||||
|
|
||||||
$sql .= ($tor_type != $lp_info['tor_type']) ? ", tor_type = $tor_type" : '';
|
$sql .= ($uploaded != $lp_info['uploaded']) ? ", uploaded = $uploaded" : '';
|
||||||
|
$sql .= ($downloaded != $lp_info['downloaded']) ? ", downloaded = $downloaded" : '';
|
||||||
|
$sql .= ", remain = $left";
|
||||||
|
|
||||||
$sql .= ($uploaded != $lp_info['uploaded']) ? ", uploaded = $uploaded" : '';
|
$sql .= $up_add ? ", up_add = up_add + $up_add" : '';
|
||||||
$sql .= ($downloaded != $lp_info['downloaded']) ? ", downloaded = $downloaded" : '';
|
$sql .= $down_add ? ", down_add = down_add + $down_add" : '';
|
||||||
$sql .= ", remain = $left";
|
|
||||||
|
|
||||||
$sql .= $up_add ? ", up_add = up_add + $up_add" : '';
|
$sql .= ", speed_up = $speed_up";
|
||||||
$sql .= $down_add ? ", down_add = down_add + $down_add" : '';
|
$sql .= ", speed_down = $speed_down";
|
||||||
|
|
||||||
$sql .= ", speed_up = $speed_up";
|
$sql .= " WHERE peer_hash = '$peer_hash'";
|
||||||
$sql .= ", speed_down = $speed_down";
|
$sql .= " LIMIT 1";
|
||||||
|
|
||||||
$sql .= " WHERE peer_hash = '$peer_hash'";
|
DB()->query($sql);
|
||||||
$sql .= " LIMIT 1";
|
|
||||||
|
|
||||||
DB()->query($sql);
|
$peer_info_updated = DB()->affected_rows();
|
||||||
|
}
|
||||||
|
|
||||||
$peer_info_updated = DB()->affected_rows();
|
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)");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Exit if stopped
|
||||||
if ($stopped) {
|
if ($stopped) {
|
||||||
silent_exit();
|
silent_exit();
|
||||||
|
@ -380,8 +387,8 @@ if (!$output) {
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
");
|
");
|
||||||
|
|
||||||
$seeders = $row['seeders'] ?? 0;
|
$seeders = $row['seeders'] ?? ($seeder ? 1 : 0);
|
||||||
$leechers = $row['leechers'] ?? 0;
|
$leechers = $row['leechers'] ?? (!$seeder ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = [
|
$output = [
|
||||||
|
@ -389,11 +396,12 @@ if (!$output) {
|
||||||
'min interval' => (int)$announce_interval,
|
'min interval' => (int)$announce_interval,
|
||||||
'complete' => (int)$seeders,
|
'complete' => (int)$seeders,
|
||||||
'incomplete' => (int)$leechers,
|
'incomplete' => (int)$leechers,
|
||||||
|
//'downloaded' => int($client_complete)
|
||||||
'warning message' => 'Statistics were updated',
|
'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);
|
CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return data to client
|
// Return data to client
|
||||||
|
|
|
@ -71,6 +71,7 @@ function dummy_exit($interval = 1800, $cache_dict = [])
|
||||||
if (!empty($cache_dict)) {
|
if (!empty($cache_dict)) {
|
||||||
$output['complete'] = $cache_dict['complete'];
|
$output['complete'] = $cache_dict['complete'];
|
||||||
$output['incomplete'] = $cache_dict['incomplete'];
|
$output['incomplete'] = $cache_dict['incomplete'];
|
||||||
|
//$output['downloaded'] = $cache_dict['downloaded'];
|
||||||
$output['warning message'] = 'Next statistics update in: ' . (floor($interval / 60) % 60) . ' minutes';
|
$output['warning message'] = 'Next statistics update in: ' . (floor($interval / 60) % 60) . ' minutes';
|
||||||
$output['peers'] = $cache_dict['peers'];
|
$output['peers'] = $cache_dict['peers'];
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,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: ' . $info_hash);
|
msg_die('Invalid info_hash');
|
||||||
}
|
}
|
||||||
|
|
||||||
$info_hash_hex = bin2hex($info_hash);
|
$info_hash_hex = bin2hex($info_hash);
|
||||||
|
@ -70,7 +70,7 @@ $output['files'][$info_hash] = [
|
||||||
'incomplete' => (int)$row['leechers'],
|
'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);
|
echo \SandFox\Bencode\Bencode::encode($output);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue