Skip to content

Commit

Permalink
update: use queued announce updates
Browse files Browse the repository at this point in the history
There were very minor edge cases with the previous system that had issues when users paused a torrent immediately after they completed it, causing data to be duplicated. We now opt to use DTOs to transfer the data into the job queue instead of models to prevent the extra database queries caused by passing models into a job queue.
  • Loading branch information
Roardom committed Feb 4, 2024
1 parent 58aaf82 commit eb2e598
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 420 deletions.
24 changes: 24 additions & 0 deletions app/DTO/AnnounceGroupDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\DTO;

readonly class AnnounceGroupDTO
{
public function __construct(
public bool $isFreeleech,
public bool $isDoubleUpload,
public bool $isImmune,
) {
}
}
25 changes: 25 additions & 0 deletions app/DTO/AnnouncePeerDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\DTO;

readonly class AnnouncePeerDTO
{
public function __construct(
public bool $active,
public int $uploaded,
public int $downloaded,
public int $left,
) {
}
}
66 changes: 66 additions & 0 deletions app/DTO/AnnounceQueryDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\DTO;

readonly class AnnounceQueryDTO
{
private string $agent;
private string $infoHash;
private string $peerId;
private string $ip;

public function __construct(
public int $port,
public int $uploaded,
public int $downloaded,
public int $left,
public int $corrupt,
public int $numwant,
public string $event,
public string $key,
string $agent,
string $infoHash,
string $peerId,
string $ip,
) {
$this->agent = bin2hex($agent);
$this->infoHash = bin2hex($infoHash);
$this->peerId = bin2hex($peerId);
$this->ip = bin2hex($ip);
}

public function getAgent(): string
{
/** @var string */
return hex2bin($this->agent);
}

public function getInfoHash(): string
{
/** @var string */
return hex2bin($this->infoHash);
}

public function getPeerId(): string
{
/** @var string */
return hex2bin($this->peerId);
}

public function getIp(): string
{
/** @var string */
return hex2bin($this->ip);
}
}
24 changes: 24 additions & 0 deletions app/DTO/AnnounceTorrentDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\DTO;

readonly class AnnounceTorrentDTO
{
public function __construct(
public int $id,
public int $percentFree,
public bool $isDoubleUpload,
) {
}
}
23 changes: 23 additions & 0 deletions app/DTO/AnnounceUserDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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 Roardom <roardom@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\DTO;

readonly class AnnounceUserDTO
{
public function __construct(
public int $id,
public AnnounceGroupDTO $group,
) {
}
}
Loading

0 comments on commit eb2e598

Please sign in to comment.