mirror of
https://github.com/friendica/friendica
synced 2024-11-09 16:22:56 +00:00
Collect data about used protocols for delivery
This commit is contained in:
parent
5e4ace271b
commit
0a15222576
7 changed files with 73 additions and 25 deletions
|
@ -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"],
|
||||
|
|
23
database.sql
23
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';
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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']) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue