News "blocked" field on the gserver table

This commit is contained in:
Michael 2023-01-17 17:25:19 +00:00
parent d63aca97b8
commit 356a2a9a5a
14 changed files with 140 additions and 15 deletions

View file

@ -85,8 +85,6 @@ class Cron
// Hourly cron calls
if ((DI::keyValue()->get('last_cron_hourly') ?? 0) + 3600 < time()) {
// Update trending tags cache for the community page
Tag::setLocalTrendingHashtags(24, 20);
Tag::setGlobalTrendingHashtags(24, 20);
@ -145,6 +143,9 @@ class Cron
// Resubscribe to relay servers
Relay::reSubscribe();
// Update "blocked" status of servers
Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers');
DI::keyValue()->set('last_cron_daily', time());
}

View file

@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Worker;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\Model\GServer;
use Friendica\Util\Network;
class UpdateBlockedServers
{
/**
* Updates the server blocked status
*/
public static function execute()
{
Logger::debug('Update blocked servers - start');
$gservers = DBA::select('gserver', ['id', 'url', 'blocked']);
while ($gserver = DBA::fetch($gservers)) {
$blocked = Network::isUrlBlocked($gserver['url']);
if (!is_null($gserver['blocked']) && ($blocked == $gserver['blocked'])) {
continue;
}
if ($blocked) {
GServer::setBlockedById($gserver['id']);
} else {
GServer::setUnblockedById($gserver['id']);
}
}
DBA::close($gservers);
Logger::debug('Update blocked servers - done');
}
}

View file

@ -55,6 +55,7 @@ class UpdateGServer
// Silently dropping the worker task if the server domain is blocked
if (Network::isUrlBlocked($filtered)) {
GServer::setBlockedByUrl($filtered);
return;
}
@ -84,6 +85,7 @@ class UpdateGServer
{
// Dropping the worker task if the server domain is blocked
if (Network::isUrlBlocked($serverUrl)) {
GServer::setBlockedByUrl($serverUrl);
return 0;
}

View file

@ -27,7 +27,6 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
use GuzzleHttp\Psr7\Uri;
class UpdateGServers
{
@ -49,7 +48,7 @@ class UpdateGServers
}
$total = DBA::count('gserver');
$condition = ["`next_contact` < ? AND (`nurl` != ? OR `url` != ?)", DateTimeFormat::utcNow(), '', ''];
$condition = ["NOT `blocked` AND `next_contact` < ? AND (`nurl` != ? OR `url` != ?)", DateTimeFormat::utcNow(), '', ''];
$outdated = DBA::count('gserver', $condition);
Logger::info('Server status', ['total' => $total, 'outdated' => $outdated, 'updating' => $limit]);

View file

@ -27,6 +27,7 @@ use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\GServer;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Util\Network;
use Friendica\Util\Strings;
class UpdateServerPeers
@ -56,6 +57,11 @@ class UpdateServerPeers
$total = 0;
$added = 0;
foreach ($peers as $peer) {
if (Network::isUrlBlocked('http://' . $peer)) {
// Ignore blocked systems as soon as possible in the loop to avoid being slowed down by tar pits
continue;
}
++$total;
if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink('http://' . $peer)])) {
// We already know this server