(Add) Config to Disable / Enable Client Connectable Check

This commit is contained in:
Alkl58
2021-10-22 20:37:01 +02:00
parent d2dcb98c92
commit 0c677ffa44
7 changed files with 45 additions and 13 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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')]);
}
}
}

View File

@@ -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,
];

View File

@@ -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