From feb74b4d9aeecbcac2b81cd6f0e0c8cfde1464f3 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 19 Dec 2022 09:30:56 +0000 Subject: [PATCH 1/2] 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 e93c34762..f68851af6 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 c09faca89..c820873cf 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. From 8f22b4f33d0d4a2c7f556bdc1490fcfc4e4592ff Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 19 Dec 2022 15:22:21 +0100 Subject: [PATCH 2/2] Update src/Model/GServer.php Co-authored-by: Hypolite Petovan --- src/Model/GServer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/GServer.php b/src/Model/GServer.php index f68851af6..ec7a4b080 100644 --- a/src/Model/GServer.php +++ b/src/Model/GServer.php @@ -183,7 +183,7 @@ class GServer } elseif ($contact['network'] == Protocol::DIASPORA) { $parts = parse_url($profile); unset($parts['path']); - $server = (string)Uri::fromParts($parts); + $server = (string)Uri::fromParts($parts); } }