mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-04-26 04:59:16 -05:00
update: torrent annnounce
This commit is contained in:
@@ -291,7 +291,10 @@ class AnnounceController extends Controller
|
||||
$disabledGroup = \cache()->rememberForever('disabled_group', fn () => Group::where('slug', '=', 'disabled')->pluck('id'));
|
||||
|
||||
// Check Passkey Against Users Table
|
||||
$user = User::where('passkey', '=', $passkey)->first();
|
||||
$user = User::with('group')
|
||||
->select(['id', 'group_id', 'active', 'can_download', 'uploaded', 'downloaded'])
|
||||
->where('passkey', '=', $passkey)
|
||||
->first();
|
||||
|
||||
// If User Doesn't Exist Return Error to Client
|
||||
if ($user === null) {
|
||||
@@ -299,7 +302,7 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// If User Account Is Unactivated/Validating Return Error to Client
|
||||
if ($user->active === 0 || $user->group_id === $validatingGroup[0]) {
|
||||
if ($user->active === 0 || $user->group->id === $validatingGroup[0]) {
|
||||
throw new TrackerException(141, [':status' => 'Unactivated/Validating']);
|
||||
}
|
||||
|
||||
@@ -309,12 +312,12 @@ class AnnounceController extends Controller
|
||||
}
|
||||
|
||||
// If User Is Banned Return Error to Client
|
||||
if ($user->group_id === $bannedGroup[0]) {
|
||||
if ($user->group->id === $bannedGroup[0]) {
|
||||
throw new TrackerException(141, [':status' => 'Banned']);
|
||||
}
|
||||
|
||||
// If User Is Disabled Return Error to Client
|
||||
if ($user->group_id === $disabledGroup[0]) {
|
||||
if ($user->group->id === $disabledGroup[0]) {
|
||||
throw new TrackerException(141, [':status' => 'Disabled']);
|
||||
}
|
||||
|
||||
@@ -329,9 +332,10 @@ class AnnounceController extends Controller
|
||||
protected function checkTorrent($infoHash): object
|
||||
{
|
||||
// Check Info Hash Against Torrents Table
|
||||
$torrent = Torrent::withAnyStatus()
|
||||
->where('info_hash', '=', $infoHash)
|
||||
->first();
|
||||
$torrent = Torrent::select(['id', 'free', 'doubleup', 'seeders', 'leechers', 'times_completed'])
|
||||
->withAnyStatus()
|
||||
->where('info_hash', '=', $infoHash)
|
||||
->first();
|
||||
|
||||
// If Torrent Doesnt Exsist Return Error to Client
|
||||
if ($torrent === null) {
|
||||
@@ -361,12 +365,10 @@ class AnnounceController extends Controller
|
||||
*/
|
||||
private function checkPeer($torrent, $queries, $user): void
|
||||
{
|
||||
$peer = Peer::where('torrent_id', '=', $torrent->id)
|
||||
if (! Peer::where('torrent_id', '=', $torrent->id)
|
||||
->where('peer_id', $queries['peer_id'])
|
||||
->where('user_id', '=', $user->id)
|
||||
->first();
|
||||
|
||||
if ($peer === null && \strtolower($queries['event']) === 'completed') {
|
||||
->exists() && \strtolower($queries['event']) === 'completed') {
|
||||
throw new TrackerException(152);
|
||||
}
|
||||
}
|
||||
@@ -399,7 +401,9 @@ class AnnounceController extends Controller
|
||||
private function checkMaxConnections($torrent, $user): void
|
||||
{
|
||||
// Pull Count On Users Peers Per Torrent For Rate Limiting
|
||||
$connections = Peer::where('torrent_id', '=', $torrent->id)->where('user_id', '=', $user->id)->count();
|
||||
$connections = Peer::where('torrent_id', '=', $torrent->id)
|
||||
->where('user_id', '=', $user->id)
|
||||
->count();
|
||||
|
||||
// If Users Peer Count On A Single Torrent Is Greater Than X Return Error to Client
|
||||
if ($connections > \config('announce.rate_limit')) {
|
||||
@@ -415,10 +419,12 @@ class AnnounceController extends Controller
|
||||
private function checkDownloadSlots($user): void
|
||||
{
|
||||
if (\config('announce.slots_system.enabled')) {
|
||||
$max = $user->group()->download_slots;
|
||||
$max = $user->group->download_slots;
|
||||
|
||||
if ($max > 0) {
|
||||
$count = Peer::where('user_id', '=', $user->id)->where('seeder', '=', 0)->count();
|
||||
$count = Peer::where('user_id', '=', $user->id)
|
||||
->where('seeder', '=', 0)
|
||||
->count();
|
||||
if ($count >= $max) {
|
||||
throw new TrackerException(164, [':max' => $max]);
|
||||
}
|
||||
@@ -439,8 +445,8 @@ class AnnounceController extends Controller
|
||||
$repDict = [
|
||||
'interval' => \rand(self::MIN, self::MAX),
|
||||
'min interval' => self::MIN,
|
||||
'complete' => $torrent->seeders,
|
||||
'incomplete' => $torrent->leechers,
|
||||
'complete' => (int) $torrent->seeders,
|
||||
'incomplete' => (int) $torrent->leechers,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -448,14 +454,23 @@ class AnnounceController extends Controller
|
||||
* We query peers from database and send peerlist, otherwise just quick return.
|
||||
*/
|
||||
if (\strtolower($queries['event']) !== 'stopped') {
|
||||
$limit = ($queries['numwant'] <= 50 ? $queries['numwant'] : 50);
|
||||
$limit = ($queries['numwant'] <= 25 ? $queries['numwant'] : 25);
|
||||
|
||||
// Get Torrents Peers
|
||||
if ($queries['left'] == 0) {
|
||||
// Only include leechers in a seeder's peerlist
|
||||
$peers = Peer::where('torrent_id', '=', $torrent->id)->where('seeder', '=', 0)->where('user_id', '!=', $user->id)->take($limit)->get()->toArray();
|
||||
$peers = Peer::where('torrent_id', '=', $torrent->id)
|
||||
->where('seeder', '=', 0)
|
||||
->where('user_id', '!=', $user->id)
|
||||
->take($limit)
|
||||
->get(['peer_id', 'ip', 'port'])
|
||||
->toArray();
|
||||
} else {
|
||||
$peers = Peer::where('torrent_id', '=', $torrent->id)->where('user_id', '!=', $user->id)->take($limit)->get()->toArray();
|
||||
$peers = Peer::where('torrent_id', '=', $torrent->id)
|
||||
->where('user_id', '!=', $user->id)
|
||||
->take($limit)
|
||||
->get(['peer_id', 'ip', 'port'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$repDict['peers'] = $this->givePeers($peers, $queries['compact'], $queries['no_peer_id']);
|
||||
@@ -490,18 +505,7 @@ class AnnounceController extends Controller
|
||||
return [
|
||||
'failure reason' => $trackerException->getMessage(),
|
||||
'min interval' => self::MIN,
|
||||
/**
|
||||
* BEP 31: Failure Retry Extension.
|
||||
*
|
||||
* However most bittorrent client don't support it, so this feature is disabled default
|
||||
* - libtorrent-rasterbar (e.g. qBittorrent, Deluge )
|
||||
* This library will obey the `min interval` key if exist or it will retry in 60s (By default `min interval`)
|
||||
* - libtransmission (e.g. Transmission )
|
||||
* This library will ignore any other key if failed
|
||||
*
|
||||
* @see http://www.bittorrent.org/beps/bep_0031.html
|
||||
*/
|
||||
//'retry in' => self::MIN
|
||||
//'retry in' => self::MIN
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user