update: announce controller

- This stops announce from sending peers to the users client that are from the same user.
- This does not stop a user from manually adding their other peer to the client to seed to themselves.
This commit is contained in:
HDVinnie
2020-08-22 15:48:57 -04:00
parent 79d34fa967
commit 2bd2f4f71a

View File

@@ -106,7 +106,7 @@ class AnnounceController extends Controller
/**
* Generate A Response For The Torrent Clent.
*/
$rep_dict = $this->generateSuccessAnnounceResponse($queries, $torrent);
$rep_dict = $this->generateSuccessAnnounceResponse($queries, $torrent, $user);
} catch (TrackerException $exception) {
$rep_dict = $this->generateFailedAnnounceResponse($exception);
} finally {
@@ -414,10 +414,11 @@ class AnnounceController extends Controller
/**
* @param $queries
* @param $torrent
* @param $user
*
* @return array
*/
private function generateSuccessAnnounceResponse($queries, $torrent)
private function generateSuccessAnnounceResponse($queries, $torrent, $user)
{
// Build Response For Bittorrent Client
$rep_dict = [
@@ -435,7 +436,7 @@ class AnnounceController extends Controller
$limit = (int) ($queries['numwant'] <= 50 ? $queries['numwant'] : 50);
// Get Torrents Peers
$peers = Peer::where('torrent_id', '=', $torrent->id)->take($limit)->get()->toArray();
$peers = Peer::where('torrent_id', '=', $torrent->id)->where('user_id', '!=', $user->id)->take($limit)->get()->toArray();
$rep_dict['peers'] = $this->givePeers($peers, $queries['compact'], $queries['no_peer_id'], FILTER_FLAG_IPV4);
$rep_dict['peers6'] = $this->givePeers($peers, $queries['compact'], $queries['no_peer_id'], FILTER_FLAG_IPV6);