sforkowany z mirror/friendica
Discovery of peers of other servers
rodzic
ca2267a4a6
commit
bb70258d48
|
@ -1591,9 +1591,9 @@ class GServer
|
|||
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
|
||||
FROM `gserver`
|
||||
WHERE NOT `failed`
|
||||
AND `poco` != ''
|
||||
AND `directory-type` != ?
|
||||
AND `last_poco_query` < ?
|
||||
ORDER BY RAND()", $last_update
|
||||
ORDER BY RAND()", self::DT_NONE, $last_update
|
||||
);
|
||||
|
||||
while ($gserver = DBA::fetch($gservers)) {
|
||||
|
@ -1604,8 +1604,13 @@ class GServer
|
|||
continue;
|
||||
}
|
||||
|
||||
Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
|
||||
Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
|
||||
Logger::info('Update peer list', ['server' => $gserver['url'], 'id' => $gserver['id']]);
|
||||
Worker::add(PRIORITY_LOW, 'UpdateServerPeers', $gserver['url']);
|
||||
|
||||
if ($gserver['directory-type'] == self::DT_POCO) {
|
||||
Logger::info('Update directory', ['server' => $gserver['url'], 'id' => $gserver['id']]);
|
||||
Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', $gserver);
|
||||
}
|
||||
|
||||
if (--$no_of_queries == 0) {
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2020, Friendica
|
||||
*
|
||||
* @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\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class UpdateServerPeers
|
||||
{
|
||||
/**
|
||||
* Query the given server for their known peers
|
||||
* @param string $gserver Server URL
|
||||
*/
|
||||
public static function execute(string $url)
|
||||
{
|
||||
$ret = DI::httpRequest()->get($url . '/api/v1/instance/peers');
|
||||
if (!$ret->isSuccess() || empty($ret->getBody())) {
|
||||
Logger::info('Server is not reachable or does not offer the "peers" endpoint', ['url' => $url]);
|
||||
return;
|
||||
}
|
||||
|
||||
$peers = json_decode($ret->getBody());
|
||||
if (empty($peers) || !is_array($peers)) {
|
||||
Logger::info('Server does not have any peers listed', ['url' => $url]);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger::info('Server peer update start', ['url' => $url]);
|
||||
|
||||
$total = 0;
|
||||
$added = 0;
|
||||
foreach ($peers as $peer) {
|
||||
++$total;
|
||||
if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink('http://' . $peer)])) {
|
||||
// We already know this server
|
||||
continue;
|
||||
}
|
||||
// This endpoint doesn't offer the schema. So we assume that it is HTTPS.
|
||||
Worker::add(PRIORITY_LOW, 'UpdateGServer', 'https://' . $peer);
|
||||
++$added;
|
||||
}
|
||||
Logger::info('Server peer update ended', ['total' => $total, 'added' => $added, 'url' => $url]);
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue