X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FDelivery.php;h=5bb09dfa85c0e73e8a06e04cfa2cca5e7c9de998;hb=5f5298125530857f009ca236139853954511a94e;hp=6f9272be0842a00775181caee2e345010fbc5600;hpb=b1a2de5cb5b3f30b15a0b60e12cd70232d8f7620;p=friendica.git diff --git a/src/Protocol/ActivityPub/Delivery.php b/src/Protocol/ActivityPub/Delivery.php index 6f9272be08..5bb09dfa85 100644 --- a/src/Protocol/ActivityPub/Delivery.php +++ b/src/Protocol/ActivityPub/Delivery.php @@ -1,6 +1,6 @@ $inbox]); + Logger::notice('Inbox delivery has a server failure', ['inbox' => $inbox]); $serverfail = true; } + Worker::coolDown(); } if ($serverfail || (!$result['success'] && !$result['drop'])) { @@ -72,19 +83,26 @@ class Delivery * @param string $cmd * @param integer $item_id * @param string $inbox - * @param integer $uid + * @param array $owner Sender owner-view record * @param array $receivers * @param integer $uri_id * @return array */ - public static function deliverToInbox(string $cmd, int $item_id, string $inbox, int $uid, array $receivers, int $uri_id): array + public static function deliverToInbox(string $cmd, int $item_id, string $inbox, array $owner, array $receivers, int $uri_id): array { + /** @var int $uid */ + $uid = $owner['uid']; + if (empty($item_id) && !empty($uri_id) && !empty($uid)) { - $item = Post::selectFirst(['id', 'parent', 'origin'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); + $item = Post::selectFirst(['id', 'parent', 'origin', 'gravity', 'verb'], ['uri-id' => $uri_id, 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (empty($item['id'])) { - Logger::notice('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]); + Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]); Post\Delivery::remove($uri_id, $inbox); - return true; + return ['success' => true, 'serverfailure' => false, 'drop' => false]; + } elseif (!DI::config()->get('system', 'redistribute_activities') && !$item['origin'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) { + Logger::notice('Activities are not relayed, removing delivery', ['verb' => $item['verb'], 'uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]); + Post\Delivery::remove($uri_id, $inbox); + return ['success' => true, 'serverfailure' => false, 'drop' => false]; } else { $item_id = $item['id']; } @@ -94,26 +112,24 @@ class Delivery $serverfail = false; $drop = false; - if ($cmd == WorkerDelivery::MAIL) { + if ($cmd == ProtocolDelivery::MAIL) { $data = ActivityPub\Transmitter::createActivityFromMail($item_id); if (!empty($data)) { - $success = HTTPSignature::transmit($data, $inbox, $uid); + $success = HTTPSignature::transmit($data, $inbox, $owner); } - } elseif ($cmd == WorkerDelivery::SUGGESTION) { - $success = ActivityPub\Transmitter::sendContactSuggestion($uid, $inbox, $item_id); - } elseif ($cmd == WorkerDelivery::RELOCATION) { + } elseif ($cmd == ProtocolDelivery::SUGGESTION) { + $success = ActivityPub\Transmitter::sendContactSuggestion($owner, $inbox, $item_id); + } elseif ($cmd == ProtocolDelivery::RELOCATION) { // @todo Implementation pending - } elseif ($cmd == WorkerDelivery::POKE) { - // Implementation not planned - } elseif ($cmd == WorkerDelivery::REMOVAL) { - $success = ActivityPub\Transmitter::sendProfileDeletion($uid, $inbox); - } elseif ($cmd == WorkerDelivery::PROFILEUPDATE) { - $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox); + } elseif ($cmd == ProtocolDelivery::REMOVAL) { + $success = ActivityPub\Transmitter::sendProfileDeletion($owner, $inbox); + } elseif ($cmd == ProtocolDelivery::PROFILEUPDATE) { + $success = ActivityPub\Transmitter::sendProfileUpdate($owner, $inbox); } else { $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id); if (!empty($data)) { $timestamp = microtime(true); - $response = HTTPSignature::post($data, $inbox, $uid); + $response = HTTPSignature::post($data, $inbox, $owner); $runtime = microtime(true) - $timestamp; $success = $response->isSuccess(); $serverfail = $response->isTimeout(); @@ -144,11 +160,16 @@ class Delivery if (!empty($actor)) { $drop = !ActivityPub\Transmitter::sendRelayFollow($actor); Logger::notice('Resubscribed to relay', ['url' => $actor, 'success' => !$drop]); + } elseif ($cmd = ProtocolDelivery::DELETION) { + // Remote systems not always accept our deletion requests, so we drop them if rejected. + // Situation is: In Friendica we allow the thread owner to delete foreign comments to their thread. + // Most AP systems don't allow this, so they will reject the deletion request. + $drop = true; } } - Logger::info('Delivery failed', ['retcode' => $response->getReturnCode(), 'serverfailure' => $serverfail, 'drop' => $drop, 'runtime' => round($runtime, 3), 'uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox]); + Logger::notice('Delivery failed', ['retcode' => $response->getReturnCode(), 'serverfailure' => $serverfail, 'drop' => $drop, 'runtime' => round($runtime, 3), 'uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox]); } if ($uri_id) { if ($success) { @@ -157,14 +178,16 @@ class Delivery Post\Delivery::incrementFailed($uri_id, $inbox); } } + } elseif ($uri_id) { + Post\Delivery::remove($uri_id, $inbox); } } self::setSuccess($receivers, $success); - Logger::debug('Delivered', ['uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox, 'success' => $success]); + Logger::debug('Delivered', ['uri-id' => $uri_id, 'uid' => $uid, 'item_id' => $item_id, 'cmd' => $cmd, 'inbox' => $inbox, 'success' => $success, 'serverfailure' => $serverfail, 'drop' => $drop]); - if ($success && in_array($cmd, [WorkerDelivery::POST])) { + if (($success || $drop) && in_array($cmd, [ProtocolDelivery::POST])) { Post\DeliveryData::incrementQueueDone($uri_id, Post\DeliveryData::ACTIVITYPUB); } @@ -179,7 +202,9 @@ class Delivery */ private static function fetchActorForRelayInbox(string $inbox): string { - return DBA::selectFirst('apcontact', ['url'], ['sharedinbox' => $inbox, 'type' => 'Application']) ?: ''; + $apcontact = DBA::selectFirst('apcontact', ['url'], ["`sharedinbox` = ? AND `type` = ? AND `url` IN (SELECT `url` FROM `contact` WHERE `uid` = ? AND `rel` = ?)", + $inbox, 'Application', 0, Contact::FRIEND]); + return $apcontact['url'] ?? ''; } /** @@ -191,9 +216,15 @@ class Delivery */ private static function setSuccess(array $receivers, bool $success) { - $gsid = null; + $gsid = null; + $update_counter = 0; foreach ($receivers as $receiver) { + // Only update the first 10 receivers to avoid flooding the remote system with requests + if ($success && ($update_counter < 10) && Contact::updateByIdIfNeeded($receiver)) { + $update_counter++; + } + $contact = Contact::getById($receiver); if (empty($contact)) { continue;