This is my last forum post. So just wanted to share the last task I was assigned with.
I'm too far ahead to be any use here. I love to help but I like to see activity and feedback too. Both of those are lacking unfortunately. Time is also not on my side going forward, which effects my own site in the process. I've managed a good balance.
Now, this code checks the number of connections a user has established on the tracker for the torrent their starting/resuming, and if the number of connections exceeds a certain limit, it takes actions to adjust or reduce the number of connections, notifies user and logs the event.
Its up to you to port it for your tracker. I dont do old-school conversions anymore, code is as-is.
This is a good idea for most, who dont want their server flooded with so many connections. This manages the clients connection pool and makes decisions based on unique client keys (connections). uTorrent generates a new client key per each connection. So we compare keys and deny or accept the connection while providing the appropriate headers to maintain limitation state.
This is at user-level, so insert code after passkey authentication logic. I'm aware people can find other ways to flood, but that is outside of the scope of this mod.
I'm too far ahead to be any use here. I love to help but I like to see activity and feedback too. Both of those are lacking unfortunately. Time is also not on my side going forward, which effects my own site in the process. I've managed a good balance.
Now, this code checks the number of connections a user has established on the tracker for the torrent their starting/resuming, and if the number of connections exceeds a certain limit, it takes actions to adjust or reduce the number of connections, notifies user and logs the event.
Its up to you to port it for your tracker. I dont do old-school conversions anymore, code is as-is.
if (array_key_exists('key', $data)) {
$max_connections = $user_row['max_conn_allowed'];
$torrent_max_connections = 50;
$reduced_connections = min(5, $torrent_max_connections);
$checkdata = $db->query_params("SELECT clientkey FROM peers WHERE user_id = :user_id AND torrent_id = :torrent_id AND seeder = 'no' AND completed = 0", array(
'user_id' => $user_id,
'torrent_id' => $torrent_id
));
$num_connections = count(array_unique(array_column($checkdata->fetchAll(), 'clientkey')));
if ($user_row['max_conn_increased'] === 0) {
if ($num_connections > $max_connections) {
$db->query_params("DELETE p FROM peers p LEFT JOIN (SELECT clientkey FROM peers WHERE user_id = :user_id ORDER BY RAND() LIMIT :limit) excluded ON p.clientkey = excluded.clientkey WHERE p.user_id = :user_id AND p.torrent_id = :torrent_id AND p.seeder = 'no' AND p.completed = 0 AND excluded.clientkey IS NOT NULL", array(
'user_id' => $user_id,
'torrent_id' => $torrent_id,
'limit' => $reduced_connections
));
$num_connections = $reduced_connections;
}
if ($num_connections > 0) {
header('X-Connection-Limit: ' . $num_connections);
$account->sendNotif($user_row['user_id'], 'Connections reduced (' . $num_connections . ')', 'Tracker');
$logevent = $db->query_params('INSERT INTO announce_log (message, added) VALUES (:message, NOW())', array(
'message' => 'Connections reduced (' . $num_connections . ')'
));
}
} else {
header('X-Connection-Limit: ' . $max_connections);
}
}
ALTER TABLE users ADD COLUMN max_conn_increased TINYINT DEFAULT 0 NULL;
ALTER TABLE users ADD COLUMN max_conn_allowed TINYINT DEFAULT 5 NULL;
This is a good idea for most, who dont want their server flooded with so many connections. This manages the clients connection pool and makes decisions based on unique client keys (connections). uTorrent generates a new client key per each connection. So we compare keys and deny or accept the connection while providing the appropriate headers to maintain limitation state.
This is at user-level, so insert code after passkey authentication logic. I'm aware people can find other ways to flood, but that is outside of the scope of this mod.
Last edited by STorrents2020 on 2023-05-13 05:42:06
