mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-01-20 19:11:33 -06:00
Now that we upsert history records without first selecting them, we can't rely on storing a peer's last uploaded/downloaded values in the history record to determine the user's uploaded/downloaded delta between the last announce. If a user has internet issues for a brief period of time but their client continues working, then their change of upload/download between the two announces needs to be kept track of. This is usually kept track of in the peer record, but if the peer is deleted after 2 hours of not announcing, then their last uploaded/downloaded data is deleted with it. We previously stored this data in the history table to handle such cases but this became erroneous if the user had multiple peers on a torrent. This new solution keeps the peers in the database for 2 days before concluding that the peer isn't coming back and deletes the peer permanently. After which point, a new peer will be created and an assumption is made that they uploaded/downloaded 0 data within their downtime.
52 lines
1.8 KiB
PHP
52 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* NOTICE OF LICENSE.
|
|
*
|
|
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
|
|
* The details is bundled with this project in the file LICENSE.txt.
|
|
*
|
|
* @project UNIT3D Community Edition
|
|
*
|
|
* @author HDVinnie <hdinnovations@protonmail.com>
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
|
|
*/
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Peer;
|
|
use App\Models\Scopes\ApprovedScope;
|
|
use App\Models\Torrent;
|
|
|
|
class TorrentPeerController extends Controller
|
|
{
|
|
/**
|
|
* Display Peers Of A Torrent.
|
|
*/
|
|
public function index(int $id): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
{
|
|
$torrent = Torrent::withoutGlobalScope(ApprovedScope::class)->findOrFail($id);
|
|
|
|
return view('torrent.peers', [
|
|
'torrent' => $torrent,
|
|
'peers' => Peer::query()
|
|
->with('user')
|
|
->select(['torrent_id', 'user_id', 'uploaded', 'downloaded', 'left', 'port', 'agent', 'created_at', 'updated_at', 'seeder', 'active'])
|
|
->selectRaw('INET6_NTOA(ip) as ip')
|
|
->where('torrent_id', '=', $id)
|
|
->orderByDesc('active')
|
|
->orderByDesc('seeder')
|
|
->get()
|
|
->map(function ($peer) use ($torrent) {
|
|
$progress = 100 * (1 - $peer->left / $torrent->size);
|
|
$peer['progress'] = match (true) {
|
|
0 < $progress && $progress < 1 => 1,
|
|
99 < $progress && $progress < 100 => 99,
|
|
default => round($progress),
|
|
};
|
|
|
|
return $peer;
|
|
}),
|
|
]);
|
|
}
|
|
}
|