Minor improvements (#889)

This commit is contained in:
Roman Kelesidis 2023-09-07 00:44:28 +07:00 committed by GitHub
commit 339f0ef948
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 22 deletions

View file

@ -25,10 +25,10 @@ if (isset($_GET['event']) && $_GET['event'] === 'completed') {
$announce_interval = $bb_cfg['announce_interval'];
$passkey_key = $bb_cfg['passkey_key'];
$max_left_val = 536870912000; // 500 GB
$max_up_down_val = 5497558138880; // 5 TB
$max_up_add_val = 85899345920; // 80 GB
$max_down_add_val = 85899345920; // 80 GB
$max_left_val = 536870912000; // 500 GB
$max_up_down_val = 5497558138880; // 5 TB
$max_up_add_val = 85899345920; // 80 GB
$max_down_add_val = 85899345920; // 80 GB
// Recover info_hash
if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
@ -139,7 +139,7 @@ function drop_fast_announce($lp_info)
global $announce_interval;
if ($lp_info['update_time'] < (TIMENOW - $announce_interval + 60)) {
return; // if announce interval correct
return; // if announce interval correct
}
$new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW;
@ -163,6 +163,7 @@ require __DIR__ . '/includes/init_tr.php';
$seeder = ($left == 0) ? 1 : 0;
$stopped = ($event === 'stopped');
$completed = ($event === 'completed');
// Stopped event
if ($stopped) {
@ -244,7 +245,7 @@ if ($lp_info) {
if (!$seeder && $bb_cfg['tracker']['leech_expire_factor'] && $user_ratio < 0.5) {
$sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']);
}
$sql .= " GROUP BY user_id";
$sql .= " GROUP BY user_id";
if ($row = DB()->fetch_row($sql)) {
if ($seeder && $bb_cfg['tracker']['limit_seed_count'] && $row['active_torrents'] >= $bb_cfg['tracker']['limit_seed_count']) {
@ -267,7 +268,7 @@ if ($lp_info) {
if (!$seeder && $bb_cfg['tracker']['leech_expire_factor']) {
$sql .= " AND update_time > " . (TIMENOW - 60 * $bb_cfg['tracker']['leech_expire_factor']);
}
$sql .= " GROUP BY topic_id";
$sql .= " GROUP BY topic_id";
if ($row = DB()->fetch_row($sql)) {
if ($seeder && $bb_cfg['tracker']['limit_seed_ips'] && $row['ips'] >= $bb_cfg['tracker']['limit_seed_ips']) {
@ -342,7 +343,7 @@ if ($lp_info) {
}
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';
$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)");
@ -397,8 +398,7 @@ if (!$output) {
}
}
$seeders = 0;
$leechers = 0;
$seeders = $leechers = 0;
if ($bb_cfg['tracker']['scrape']) {
$row = DB()->fetch_row("

View file

@ -103,7 +103,6 @@ define('BB_BT_TRACKER_SNAP', 'bb_bt_tracker_snap');
define('BB_BT_USERS', 'bb_bt_users');
define('BT_AUTH_KEY_LENGTH', 10);
define('PEER_HASH_PREFIX', 'peer_');
define('PEERS_LIST_PREFIX', 'peers_list_');
define('PEER_HASH_EXPIRE', round($bb_cfg['announce_interval'] * (0.85 * $bb_cfg['tracker']['expire_factor']))); // sec

View file

@ -232,7 +232,7 @@ if ($tor_reged && $tor_info) {
'TOR_SIZE' => humn_size($tor_size),
'TOR_LONGEVITY' => delta_time($tor_info['reg_time']),
'TOR_COMPLETED' => declension($tor_info['complete_count'], 'times'),
'TOR_COMPLETED' => declension((int)$tor_info['complete_count'], 'times'),
]);
}

View file

@ -66,6 +66,7 @@ $bb_cfg['cache'] = [
'redis' => [
'host' => '127.0.0.1',
'port' => 6379,
'pconnect' => true,
'con_required' => true,
],
// Available cache types: filecache, memcache, sqlite, redis, apcu (filecache by default)

View file

@ -27,7 +27,7 @@ class Memcache extends Common
public function __construct($cfg, $prefix = null)
{
if (!$this->is_installed()) {
die('Error: Memcached extension not installed');
die("Error: $this->engine extension not installed");
}
$this->cfg = $cfg;
@ -48,7 +48,7 @@ class Memcache extends Common
}
if (!$this->connected && $this->cfg['con_required']) {
die('Could not connect to memcached server');
die("Could not connect to $this->engine server");
}
$this->debug('stop');

View file

@ -27,7 +27,7 @@ class Redis extends Common
public function __construct($cfg, $prefix = null)
{
if (!$this->is_installed()) {
die('Error: Redis extension not installed');
die("Error: $this->engine extension not installed");
}
$this->cfg = $cfg;
@ -38,15 +38,17 @@ class Redis extends Common
public function connect()
{
$this->cur_query = 'connect ' . $this->cfg['host'] . ':' . $this->cfg['port'];
$connect_type = ($this->cfg['pconnect']) ? 'pconnect' : 'connect';
$this->cur_query = $connect_type . ' ' . $this->cfg['host'] . ':' . $this->cfg['port'];
$this->debug('start');
if (@$this->redis->connect($this->cfg['host'], $this->cfg['port'])) {
if (@$this->redis->$connect_type($this->cfg['host'], $this->cfg['port'])) {
$this->connected = true;
}
if (!$this->connected && $this->cfg['con_required']) {
die('Could not connect to redis server');
die("Could not connect to $this->engine server");
}
$this->debug('stop');

View file

@ -26,7 +26,7 @@ class Memcache extends Common
public function __construct($cfg, $prefix = null)
{
if (!$this->is_installed()) {
die('Error: Memcached extension not installed');
die("Error: $this->engine extension not installed");
}
$this->cfg = $cfg;
@ -47,7 +47,7 @@ class Memcache extends Common
}
if (!$this->connected && $this->cfg['con_required']) {
die('Could not connect to memcached server');
die("Could not connect to $this->engine server");
}
$this->debug('stop');

View file

@ -26,7 +26,7 @@ class Redis extends Common
public function __construct($cfg, $prefix = null)
{
if (!$this->is_installed()) {
die('Error: Redis extension not installed');
die("Error: $this->engine extension not installed");
}
$this->cfg = $cfg;
@ -45,7 +45,7 @@ class Redis extends Common
}
if (!$this->connected && $this->cfg['con_required']) {
die('Could not connect to redis server');
die("Could not connect to $this->engine server");
}
$this->debug('stop');