Collect data about used protocols for delivery

This commit is contained in:
Michael
2019-06-28 09:03:58 +00:00
parent 5e4ace271b
commit 0a15222576
7 changed files with 73 additions and 25 deletions
+29 -2
View File
@@ -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);
}
/**
+1 -11
View File
@@ -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']) {
+1 -1
View File
@@ -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);
}
}
}
+15 -6
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -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);
}
}