diff --git a/app/Jobs/ProcessBasicAnnounceRequest.php b/app/Jobs/ProcessBasicAnnounceRequest.php index fddcf6e6b..4e5ade77a 100644 --- a/app/Jobs/ProcessBasicAnnounceRequest.php +++ b/app/Jobs/ProcessBasicAnnounceRequest.php @@ -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 diff --git a/app/Jobs/ProcessCompletedAnnounceRequest.php b/app/Jobs/ProcessCompletedAnnounceRequest.php index ca048ab49..c2ad1da30 100644 --- a/app/Jobs/ProcessCompletedAnnounceRequest.php +++ b/app/Jobs/ProcessCompletedAnnounceRequest.php @@ -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 diff --git a/app/Jobs/ProcessStartedAnnounceRequest.php b/app/Jobs/ProcessStartedAnnounceRequest.php index 57a7189c4..1bb4faaa7 100644 --- a/app/Jobs/ProcessStartedAnnounceRequest.php +++ b/app/Jobs/ProcessStartedAnnounceRequest.php @@ -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 diff --git a/app/Jobs/ProcessStoppedAnnounceRequest.php b/app/Jobs/ProcessStoppedAnnounceRequest.php index 2b4f570cc..6f5b24b41 100644 --- a/app/Jobs/ProcessStoppedAnnounceRequest.php +++ b/app/Jobs/ProcessStoppedAnnounceRequest.php @@ -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 diff --git a/app/Models/Peer.php b/app/Models/Peer.php index 2b45a8956..cf82e55aa 100644 --- a/app/Models/Peer.php +++ b/app/Models/Peer.php @@ -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')]); } } } diff --git a/config/announce.php b/config/announce.php index 9ff18a451..cac2aab66 100644 --- a/config/announce.php +++ b/config/announce.php @@ -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, ]; diff --git a/resources/views/user/profile.blade.php b/resources/views/user/profile.blade.php index e7f010b19..d4030732f 100644 --- a/resources/views/user/profile.blade.php +++ b/resources/views/user/profile.blade.php @@ -547,7 +547,9 @@ @lang('torrent.started') @lang('torrent.last-update') @lang('torrent.torrents') - {{--Connectable--}} + @if (\config('announce.connectable_check') == true) + Connectable + @endif @@ -568,7 +570,9 @@ {{ $count }} - {{--@choice('user.client-connectable-state', $p->connectable)--}} + @if (\config('announce.connectable_check') == true) + @choice('user.client-connectable-state', $p->connectable) + @endif @php array_push($peer_array, [$p->ip, $p->port]); @endphp @endif