From: Michael Date: Fri, 28 Jun 2019 09:03:58 +0000 (+0000) Subject: Collect data about used protocols for delivery X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0a152225765a5080bc81ce430c30ec4ccca55a79;p=friendica.git Collect data about used protocols for delivery --- diff --git a/config/dbstructure.config.php b/config/dbstructure.config.php index 57e4378376..5c6948a62f 100755 --- a/config/dbstructure.config.php +++ b/config/dbstructure.config.php @@ -34,7 +34,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1313); + define('DB_UPDATE_VERSION', 1314); } return [ @@ -742,6 +742,11 @@ return [ "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"], "queue_count" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Initial number of delivery recipients, used as item.delivery_queue_count"], "queue_done" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries, used as item.delivery_queue_done"], + "activitypub" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via ActivityPub"], + "dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via DFRN"], + "legacy_dfrn" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via legacy DFRN"], + "diaspora" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via Diaspora"], + "ostatus" => ["type" => "mediumint", "not null" => "1", "default" => "0", "comment" => "Number of successful deliveries via OStatus"], ], "indexes" => [ "PRIMARY" => ["iid"], diff --git a/database.sql b/database.sql index dde37cd376..67ae8b4c2c 100644 --- a/database.sql +++ b/database.sql @@ -1,9 +1,20 @@ -- ------------------------------------------ --- Friendica 2019.06-dev (Dalmatian Bellflower) --- DB_UPDATE_VERSION 1311 +-- Friendica 2019.09-dev (Dalmatian Bellflower) +-- DB_UPDATE_VERSION 1314 -- ------------------------------------------ +-- +-- TABLE 2fa_recovery_codes +-- +CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` ( + `uid` mediumint unsigned NOT NULL COMMENT 'User ID', + `code` varchar(50) NOT NULL COMMENT 'Recovery code string', + `generated` datetime NOT NULL COMMENT 'Datetime the code was generated', + `used` datetime COMMENT 'Datetime the code was used', + PRIMARY KEY(`uid`,`code`) +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes'; + -- -- TABLE addon -- @@ -187,7 +198,8 @@ CREATE TABLE IF NOT EXISTS `contact` ( `term-date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `last-item` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'date of the last post', `priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', - `blocked` boolean NOT NULL DEFAULT '1' COMMENT '', + `blocked` boolean NOT NULL DEFAULT '1' COMMENT 'Node-wide block status', + `block_reason` text COMMENT 'Node-wide block reason', `readonly` boolean NOT NULL DEFAULT '0' COMMENT 'posts of the contact are readonly', `writable` boolean NOT NULL DEFAULT '0' COMMENT '', `forum` boolean NOT NULL DEFAULT '0' COMMENT 'contact is a forum', @@ -662,6 +674,11 @@ CREATE TABLE IF NOT EXISTS `item-delivery-data` ( `inform` mediumtext COMMENT 'Additional receivers of the linked item', `queue_count` mediumint NOT NULL DEFAULT 0 COMMENT 'Initial number of delivery recipients, used as item.delivery_queue_count', `queue_done` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries, used as item.delivery_queue_done', + `activitypub` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via ActivityPub', + `dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via DFRN', + `legacy_dfrn` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via legacy DFRN', + `diaspora` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via Diaspora', + `ostatus` mediumint NOT NULL DEFAULT 0 COMMENT 'Number of successful deliveries via OStatus', PRIMARY KEY(`iid`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Delivery data for items'; diff --git a/src/Model/ItemDeliveryData.php b/src/Model/ItemDeliveryData.php index b1fd28e3cb..1d5c37de2d 100644 --- a/src/Model/ItemDeliveryData.php +++ b/src/Model/ItemDeliveryData.php @@ -23,6 +23,12 @@ class ItemDeliveryData 'queue_done' => 'delivery_queue_done', ]; + const ACTIVITYPUB = 1; + const DFRN = 2; + const LEGACY_DFRN = 3; + const DIASPORA = 4; + const OSTATUS = 5; + /** * Extract delivery data from the provided item fields * @@ -53,12 +59,33 @@ class ItemDeliveryData * Avoids racing condition between multiple delivery threads. * * @param integer $item_id + * @param integer $protocol * @return bool * @throws \Exception */ - public static function incrementQueueDone($item_id) + public static function incrementQueueDone($item_id, $protocol = 0) { - return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1 WHERE `iid` = ?', $item_id); + $sql = ''; + + switch ($protocol) { + case self::ACTIVITYPUB: + $sql = ", `activitypub` = `activitypub` + 1"; + break; + case self::DFRN: + $sql = ", `dfrn` = `dfrn` + 1"; + break; + case self::LEGACY_DFRN: + $sql = ", `legacy_dfrn` = `legacy_dfrn` + 1"; + break; + case self::DIASPORA: + $sql = ", `diaspora` = `diaspora` + 1"; + break; + case self::OSTATUS: + $sql = ", `ostatus` = `ostatus` + 1"; + break; + } + + return DBA::e('UPDATE `item-delivery-data` SET `queue_done` = `queue_done` + 1' . $sql . ' WHERE `iid` = ?', $item_id); } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 91ca2545db..a5deb490b0 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1176,23 +1176,13 @@ class DFRN * @param string $atom Content that will be transmitted * @param bool $dissolve (to be documented) * - * @param bool $legacy_transport * @return int Deliver status. Negative values mean an error. * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException * @todo Add array type-hint for $owner, $contact */ - public static function deliver($owner, $contact, $atom, $dissolve = false, $legacy_transport = false) + public static function deliver($owner, $contact, $atom, $dissolve = false) { - // At first try the Diaspora transport layer - if (!$dissolve && !$legacy_transport) { - $curlResult = self::transmit($owner, $contact, $atom); - if ($curlResult >= 200) { - Logger::log('Delivery via Diaspora transport layer was successful with status ' . $curlResult); - return $curlResult; - } - } - $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); if ($contact['duplex'] && $contact['dfrn-id']) { diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index fcd4a76725..625ed5f2cb 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -49,7 +49,7 @@ class APDelivery extends BaseObject if (!empty($data)) { $success = HTTPSignature::transmit($data, $inbox, $uid); if ($success && in_array($cmd, [Delivery::POST])) { - ItemDeliveryData::incrementQueueDone($target_id); + ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::ACTIVITYPUB); } } } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 97a0968510..261065ae9a 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -286,12 +286,14 @@ class Delivery extends BaseObject DFRN::import($atom, $target_importer); if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { - Model\ItemDeliveryData::incrementQueueDone($target_item['id']); + Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DFRN); } return; } + $protocol = Model\ItemDeliveryData::DFRN; + // We don't have a relationship with contacts on a public post. // Se we transmit with the new method and via Diaspora as a fallback if (!empty($items) && (($items[0]['uid'] == 0) || ($contact['uid'] == 0))) { @@ -312,9 +314,16 @@ class Delivery extends BaseObject return; } } elseif ($cmd != self::RELOCATION) { - $deliver_status = DFRN::deliver($owner, $contact, $atom); + // DFRN payload over Diaspora transport layer + $deliver_status = DFRN::transmit($owner, $contact, $atom); + if ($deliver_status < 200) { + // Legacy DFRN + $deliver_status = DFRN::deliver($owner, $contact, $atom); + $protocol = Model\ItemDeliveryData::LEGACY_DFRN; + } } else { - $deliver_status = DFRN::deliver($owner, $contact, $atom, false, true); + $deliver_status = DFRN::deliver($owner, $contact, $atom); + $protocol = Model\ItemDeliveryData::LEGACY_DFRN; } Logger::info('DFRN Delivery', ['cmd' => $cmd, 'url' => $contact['url'], 'guid' => defaults($target_item, 'guid', $target_item['id']), 'return' => $deliver_status]); @@ -324,7 +333,7 @@ class Delivery extends BaseObject Model\Contact::unmarkForArchival($contact); if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { - Model\ItemDeliveryData::incrementQueueDone($target_item['id']); + Model\ItemDeliveryData::incrementQueueDone($target_item['id'], $protocol); } } else { // The message could not be delivered. We mark the contact as "dead" @@ -405,7 +414,7 @@ class Delivery extends BaseObject Model\Contact::unmarkForArchival($contact); if (in_array($cmd, [Delivery::POST, Delivery::POKE])) { - Model\ItemDeliveryData::incrementQueueDone($target_item['id']); + Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA); } } else { // The message could not be delivered. We mark the contact as "dead" @@ -416,7 +425,7 @@ class Delivery extends BaseObject // defer message for redelivery Worker::defer(); } elseif (in_array($cmd, [Delivery::POST, Delivery::POKE])) { - Model\ItemDeliveryData::incrementQueueDone($target_item['id']); + Model\ItemDeliveryData::incrementQueueDone($target_item['id'], Model\ItemDeliveryData::DIASPORA); } } } diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 36c6e92a04..f119fae580 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -514,7 +514,7 @@ class Notifier Logger::log('Salmon delivery of item ' . $target_id . ' to ' . $url); /// @TODO Redeliver/queue these items on failure, though there is no contact record Salmon::slapper($owner, $url, $slap); - ItemDeliveryData::incrementQueueDone($target_id); + ItemDeliveryData::incrementQueueDone($target_id, ItemDeliveryData::OSTATUS); } }