]> git.mxchange.org Git - friendica.git/commitdiff
Set the server status directly after transmission
authorMichael <heluecht@pirati.ca>
Sun, 1 Jan 2023 17:34:05 +0000 (17:34 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 1 Jan 2023 17:34:05 +0000 (17:34 +0000)
src/Core/Worker/Cron.php
src/Model/GServer.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Util/HTTPSignature.php

index e358ccd853bace93e4a7d6f46fda1c480731498b..21f67c030bab8a96333707e216a9efa98e2adacd 100644 (file)
@@ -164,18 +164,15 @@ class Cron
         */
        private static function deliverAPPosts()
        {
-               $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`gsid`) AS `gsid`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` LEFT JOIN `inbox-status` ON `inbox-status`.`url` = `item-uri`.`uri` GROUP BY `inbox` ORDER BY RAND()");
+               $deliveries = DBA::p("SELECT `item-uri`.`uri` AS `inbox`, MAX(`gsid`) AS `gsid`, MAX(`shared`) AS `shared`, MAX(`failed`) AS `failed` FROM `post-delivery` INNER JOIN `item-uri` ON `item-uri`.`id` = `post-delivery`.`inbox-id` LEFT JOIN `inbox-status` ON `inbox-status`.`url` = `item-uri`.`uri` GROUP BY `inbox` ORDER BY RAND()");
                while ($delivery = DBA::fetch($deliveries)) {
                        if ($delivery['failed'] > 0) {
                                Logger::info('Removing failed deliveries', ['inbox' => $delivery['inbox'], 'failed' => $delivery['failed']]);
                                Post\Delivery::removeFailed($delivery['inbox']);
                        }
-                       if (($delivery['failed'] == 0) && !empty($delivery['gsid']) && GServer::isReachableById($delivery['gsid'])) {
+                       if (($delivery['failed'] == 0) && $delivery['shared'] && !empty($delivery['gsid']) && GServer::isReachableById($delivery['gsid'])) {
                                $result = ActivityPub\Delivery::deliver($delivery['inbox']);
                                Logger::info('Directly deliver inbox', ['inbox' => $delivery['inbox'], 'result' => $result['success']]);
-                               if (!$result['success']) {
-                                       GServer::setFailureById($delivery['gsid']);
-                               }
                                continue;
                        } elseif ($delivery['failed'] < 3) {
                                $priority = Worker::PRIORITY_HIGH;
index 10f4a3daf207eb32b2f79c799eedc432992cc833..1878befa9f2282440c44a3b0ad19351555cb047c 100644 (file)
@@ -360,13 +360,18 @@ class GServer
        /**
         * Reset failed server status by gserver id
         *
-        * @param int $gsid
+        * @param int    $gsid
+        * @param string $network
         */
-       public static function setReachableById(int $gsid)
+       public static function setReachableById(int $gsid, string $network)
        {
-               $gserver = DBA::selectFirst('gserver', ['url', 'failed', 'next_contact'], ['id' => $gsid]);
+               $gserver = DBA::selectFirst('gserver', ['url', 'failed', 'next_contact', 'network'], ['id' => $gsid]);
                if (DBA::isResult($gserver) && $gserver['failed']) {
-                       self::update(['failed' => false, 'last_contact' => DateTimeFormat::utcNow()], ['id' => $gsid]);
+                       $fields = ['failed' => false, 'last_contact' => DateTimeFormat::utcNow()];
+                       if (!empty($network) && !in_array($gserver['network'], Protocol::FEDERATED)) {
+                               $fields['network'] = $network;
+                       }
+                       self::update($fields, ['id' => $gsid]);
                        Logger::info('Reset failed status for server', ['url' => $gserver['url']]);
 
                        if (strtotime($gserver['next_contact']) < time()) {
index 6e1b0f9265a360334462c9c4dd4fe2e4dabba762..0b005570b230bc263e35318ae2fea405d0f69499 100644 (file)
@@ -1040,7 +1040,7 @@ class DFRN
                }
 
                if (!empty($contact['gsid'])) {
-                       GServer::setReachableById($contact['gsid']);
+                       GServer::setReachableById($contact['gsid'], Protocol::DFRN);
                }
 
                if (!empty($res->message)) {
index 19954d9b963bb6f3240bb014ee4a3f687289b0a3..bf6bfdd63dcefd078ff2fa36e4e86d40e198b15c 100644 (file)
@@ -2958,7 +2958,7 @@ class Diaspora
                if (!empty($contact['gsid']) && (empty($return_code) || $postResult->isTimeout())) {
                        GServer::setFailureById($contact['gsid']);
                } elseif (!empty($contact['gsid']) && ($return_code >= 200) && ($return_code <= 299)) {
-                       GServer::setReachableById($contact['gsid']);
+                       GServer::setReachableById($contact['gsid'], Protocol::DIASPORA);
                }
 
                Logger::notice('transmit: ' . $logid . '-' . $guid . ' to ' . $dest_url . ' returns: ' . $return_code);
index cca1ab0bdb9d7f577f8a00b19b4a5a7310a2a012..3936c70fcbcde95e62fec977c122050771e6f58f 100644 (file)
 namespace Friendica\Util;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\Database\Database;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\Contact;
+use Friendica\Model\GServer;
 use Friendica\Model\ItemURI;
 use Friendica\Model\User;
 use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
@@ -398,6 +400,14 @@ class HTTPSignature
                }
 
                DBA::update('inbox-status', $fields, ['url' => $url]);
+
+               if (!empty($status['gsid'])) {
+                       if ($success) {
+                               GServer::setReachableById($status['gsid'], Protocol::ACTIVITYPUB);
+                       } elseif ($status['shared']) {
+                               GServer::setFailureById($status['gsid']);
+                       }
+               }
        }
 
        /**