mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-11 14:09:31 -06:00
(Add) Config to Disable / Enable Client Connectable Check
This commit is contained in:
@@ -126,7 +126,7 @@ class ProcessBasicAnnounceRequest implements ShouldQueue
|
||||
$peer->left = $this->queries['left'];
|
||||
$peer->torrent_id = $this->torrent->id;
|
||||
$peer->user_id = $this->user->id;
|
||||
//$peer->updateConnectableStateIfNeeded();
|
||||
$peer->updateConnectableStateIfNeeded();
|
||||
$peer->save();
|
||||
// End Peer Update
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class ProcessCompletedAnnounceRequest implements ShouldQueue
|
||||
$peer->left = 0;
|
||||
$peer->torrent_id = $this->torrent->id;
|
||||
$peer->user_id = $this->user->id;
|
||||
//$peer->updateConnectableStateIfNeeded();
|
||||
$peer->updateConnectableStateIfNeeded();
|
||||
$peer->save();
|
||||
// End Peer Update
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ class ProcessStartedAnnounceRequest implements ShouldQueue
|
||||
$peer->left = $this->queries['left'];
|
||||
$peer->torrent_id = $this->torrent->id;
|
||||
$peer->user_id = $this->user->id;
|
||||
//$peer->updateConnectableStateIfNeeded();
|
||||
$peer->updateConnectableStateIfNeeded();
|
||||
$peer->save();
|
||||
// End Peer Update
|
||||
|
||||
|
||||
@@ -128,7 +128,7 @@ class ProcessStoppedAnnounceRequest implements ShouldQueue
|
||||
$peer->left = $this->queries['left'];
|
||||
$peer->torrent_id = $this->torrent->id;
|
||||
$peer->user_id = $this->user->id;
|
||||
//$peer->updateConnectableStateIfNeeded();
|
||||
$peer->updateConnectableStateIfNeeded();
|
||||
$peer->save();
|
||||
// End Peer Update
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
|
||||
/**
|
||||
@@ -124,14 +125,28 @@ class Peer extends Model
|
||||
*/
|
||||
public function updateConnectableStateIfNeeded(): void
|
||||
{
|
||||
if (! \cache()->has('peers:connectable:'.$this->ip.'-'.$this->port.'-'.$this->agent)) {
|
||||
$con = @fsockopen($this->ip, $this->port, $_, $_, 1);
|
||||
if (\config('announce.connectable_check') == true) {
|
||||
|
||||
$this->connectable = \is_resource($con);
|
||||
\cache()->put('peers:connectable:'.$this->ip.'-'.$this->port.'-'.$this->agent, $this->connectable, now()->addDay());
|
||||
$tmp_ip = $this->ip;
|
||||
|
||||
if (\is_resource($con)) {
|
||||
\fclose($con);
|
||||
// IPv6 Check
|
||||
if (filter_var($tmp_ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$tmp_ip = '['.$tmp_ip.']';
|
||||
}
|
||||
|
||||
if (! \cache()->has('peers:connectable:'.$tmp_ip.'-'.$this->port.'-'.$this->agent)) {
|
||||
|
||||
$con = @fsockopen($tmp_ip, $this->port, $_, $_, 1);
|
||||
|
||||
$this->connectable = \is_resource($con);
|
||||
\cache()->put('peers:connectable:'.$tmp_ip.'-'.$this->port.'-'.$this->agent, $this->connectable, now()->addSeconds(config('announce.connectable_check_interval')));
|
||||
|
||||
if (\is_resource($con)) {
|
||||
\fclose($con);
|
||||
}
|
||||
|
||||
// See https://laracasts.com/discuss/channels/eloquent/use-update-without-updating-timestamps?page=1&replyId=680133
|
||||
Peer::where('ip', '=', $tmp_ip)->where('port', '=', $this->port)->where('agent', '=', $this->agent)->update(['connectable' => $this->connectable, 'updated_at' => DB::raw('updated_at')]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,19 @@ return [
|
||||
|
||||
'rate_limit' => 3,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Client Connectable Check
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option toggles Client connectivity check
|
||||
| !!! Attention: Will result in leaking the server IP !!!
|
||||
| It will result in higher disc / DB IO
|
||||
|
|
||||
*/
|
||||
|
||||
'connectable_check' => false,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Connectable check interval
|
||||
@@ -55,6 +68,6 @@ return [
|
||||
|
|
||||
*/
|
||||
|
||||
'connectable_check_interval' => 60 * 20,
|
||||
'connectable_check_interval' => 60 * 30,
|
||||
|
||||
];
|
||||
|
||||
@@ -547,7 +547,9 @@
|
||||
<th>@lang('torrent.started')</th>
|
||||
<th>@lang('torrent.last-update')</th>
|
||||
<th>@lang('torrent.torrents')</th>
|
||||
{{--<th>Connectable</th>--}}
|
||||
@if (\config('announce.connectable_check') == true)
|
||||
<th>Connectable</th>
|
||||
@endif
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -568,7 +570,9 @@
|
||||
<span itemprop="title" class="l-breadcrumb-item-link-title">{{ $count }}</span>
|
||||
</a>
|
||||
</td>
|
||||
{{--<td>@choice('user.client-connectable-state', $p->connectable)</td>--}}
|
||||
@if (\config('announce.connectable_check') == true)
|
||||
<td>@choice('user.client-connectable-state', $p->connectable)</td>
|
||||
@endif
|
||||
</tr>
|
||||
@php array_push($peer_array, [$p->ip, $p->port]); @endphp
|
||||
@endif
|
||||
|
||||
Reference in New Issue
Block a user