From feb74b4d9aeecbcac2b81cd6f0e0c8cfde1464f3 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 19 Dec 2022 09:30:56 +0000 Subject: [PATCH] Don't perform a delivery to failing servers --- src/Model/GServer.php | 6 +++++- src/Worker/Notifier.php | 14 ++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Model/GServer.php b/src/Model/GServer.php index e93c347627..f68851af68 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -177,9 +177,13 @@ class GServer public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool { if ($server == '') { - $contact = Contact::getByURL($profile, null, ['baseurl']); + $contact = Contact::getByURL($profile, null, ['baseurl', 'network']); if (!empty($contact['baseurl'])) { $server = $contact['baseurl']; + } elseif ($contact['network'] == Protocol::DIASPORA) { + $parts = parse_url($profile); + unset($parts['path']); + $server = (string)Uri::fromParts($parts); } } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index c09faca89b..c820873cff 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -30,6 +30,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Conversation; use Friendica\Model\Group; +use Friendica\Model\GServer; use Friendica\Model\Item; use Friendica\Model\Post; use Friendica\Model\PushSubscriber; @@ -99,7 +100,7 @@ class Notifier $uid = $target_id; $condition = ['uid' => $target_id, 'self' => false, 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; - $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition); + $delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'baseurl', 'batch'], $condition); } else { $post = Post::selectFirst(['id'], ['uri-id' => $post_uriid, 'uid' => $sender_uid]); if (!DBA::isResult($post)) { @@ -425,7 +426,7 @@ class Notifier if (!empty($networks)) { $condition['network'] = $networks; } - $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'batch'], $condition); + $delivery_contacts_stmt = DBA::select('contact', ['id', 'addr', 'url', 'network', 'protocol', 'baseurl', 'batch'], $condition); } $conversants = []; @@ -437,7 +438,7 @@ class Notifier if ($diaspora_delivery && !$unlisted) { $batch_delivery = true; - $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'id', 'url', 'name'], + $participants = DBA::selectToArray('contact', ['batch', 'network', 'protocol', 'baseurl', 'id', 'url', 'name'], ["`network` = ? AND `batch` != '' AND `uid` = ? AND `rel` != ? AND NOT `blocked` AND NOT `pending` AND NOT `archive`", Protocol::DIASPORA, $owner['uid'], Contact::SHARING], ['group_by' => ['batch', 'network', 'protocol']]); @@ -449,7 +450,7 @@ class Notifier $condition = ['network' => Protocol::DFRN, 'uid' => $owner['uid'], 'blocked' => false, 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; - $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol'], $condition); + $contacts = DBA::selectToArray('contact', ['id', 'url', 'addr', 'name', 'network', 'protocol', 'baseurl'], $condition); $conversants = array_merge($contacts, $participants); @@ -563,6 +564,11 @@ class Notifier continue; } + if (!GServer::reachable($contact['url'], $contact['baseurl'], $contact['network'])) { + Logger::info('Server is not reachable', ['id' => $post_uriid, 'uid' => $sender_uid, 'contact' => $contact]); + continue; + } + Logger::info('Delivery', ['batch' => $in_batch, 'target' => $post_uriid, 'uid' => $sender_uid, 'guid' => $target_item['guid'] ?? '', 'to' => $contact]); // Ensure that posts with our own protocol arrives before Diaspora posts arrive. -- 2.39.5