Store the server transport protocol
This commit is contained in:
parent
ca8e4066fc
commit
bf563a1a39
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2020.12-rc (Red Hot Poker)
|
||||
-- DB_UPDATE_VERSION 1384
|
||||
-- Friendica 2021.03-dev (Red Hot Poker)
|
||||
-- DB_UPDATE_VERSION 1385
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS `gserver` (
|
|||
`poco` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
|
||||
`protocol` tinyint unsigned COMMENT 'The protocol of the server',
|
||||
`platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`relay-subscribe` boolean NOT NULL DEFAULT '0' COMMENT 'Has the server subscribed to the relay system',
|
||||
`relay-scope` varchar(10) NOT NULL DEFAULT '' COMMENT 'The scope of messages that the server wants to get',
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Model;
|
|||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Exception;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
|
@ -1734,4 +1735,65 @@ class GServer
|
|||
|
||||
DI::config()->set('poco', 'last_federation_discovery', time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the protocol for the given server
|
||||
*
|
||||
* @param int $gsid Server id
|
||||
* @param int $protocol Protocol id
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
static function setProtocol(int $gsid, int $protocol)
|
||||
{
|
||||
if (empty($gsid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gserver = DBA::selectFirst('gserver', ['protocol', 'url'], ['id' => $gsid]);
|
||||
if (!DBA::isResult($gserver)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$old = $gserver['protocol'];
|
||||
|
||||
if (!is_null($old)) {
|
||||
/*
|
||||
The priority for the protocols is:
|
||||
1. ActivityPub
|
||||
2. DFRN via Diaspora
|
||||
3. Legacy DFRN
|
||||
4. Diaspora
|
||||
5. OStatus
|
||||
*/
|
||||
|
||||
// We don't need to change it when nothing is to be changed
|
||||
if ($old == $protocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We don't want to mark a server as OStatus when it had been marked with any other protocol before
|
||||
if ($protocol == Post\DeliveryData::OSTATUS) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the server is marked as ActivityPub then we won't change it to anything different
|
||||
if ($old == Post\DeliveryData::ACTIVITYPUB) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't change it to anything lower than DFRN if the new one wasn't ActivityPub
|
||||
if (($old == Post\DeliveryData::DFRN) && ($protocol != Post\DeliveryData::ACTIVITYPUB)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't change it to Diaspora when it is a legacy DFRN server
|
||||
if (($old == Post\DeliveryData::LEGACY_DFRN) && ($protocol == Post\DeliveryData::DIASPORA)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logger::info('Protocol for server', ['protocol' => $protocol, 'old' => $old, 'id' => $gsid, 'url' => $gserver['url']]);
|
||||
DBA::update('gserver', ['protocol' => $protocol], ['id' => $gsid]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Core\Logger;
|
|||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
class PushSubscriber
|
||||
{
|
||||
|
@ -170,5 +171,13 @@ class PushSubscriber
|
|||
$fields = ['push' => 0, 'next_try' => DBA::NULL_DATETIME, 'last_update' => $last_update];
|
||||
DBA::update('push_subscriber', $fields, ['id' => $id]);
|
||||
Logger::log('Subscriber ' . $subscriber['callback_url'] . ' for ' . $subscriber['nickname'] . ' is marked as vital', Logger::DEBUG);
|
||||
|
||||
$parts = parse_url($subscriber['callback_url']);
|
||||
unset($parts['path']);
|
||||
$server_url = Network::unparseURL($parts);
|
||||
$gsid = GServer::getID($server_url, true);
|
||||
if (!empty($gsid)) {
|
||||
GServer::setProtocol($gsid, Post\DeliveryData::OSTATUS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\GServer;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
|
@ -82,6 +83,7 @@ class APDelivery
|
|||
// This should never fail and is temporariy (until the move to the "post" structure)
|
||||
$item = Item::selectFirst(['uri-id'], ['id' => $item_id]);
|
||||
$uriid = $item['uri-id'] ?? 0;
|
||||
$gsid = null;
|
||||
|
||||
foreach ($receivers as $receiver) {
|
||||
$contact = Contact::getById($receiver);
|
||||
|
@ -89,6 +91,8 @@ class APDelivery
|
|||
continue;
|
||||
}
|
||||
|
||||
$gsid = $gsid ?: $contact['gsid'];
|
||||
|
||||
if ($success) {
|
||||
Contact::unmarkForArchival($contact);
|
||||
} else {
|
||||
|
@ -96,6 +100,10 @@ class APDelivery
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($gsid)) {
|
||||
GServer::setProtocol($gsid, Post\DeliveryData::ACTIVITYPUB);
|
||||
}
|
||||
|
||||
if (!$success && !Worker::defer() && in_array($cmd, [Delivery::POST])) {
|
||||
Post\DeliveryData::incrementQueueFailed($uriid);
|
||||
} elseif ($success && in_array($cmd, [Delivery::POST])) {
|
||||
|
|
|
@ -360,6 +360,8 @@ class Delivery
|
|||
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
|
||||
if (($deliver_status >= 200) && ($deliver_status <= 299)) {
|
||||
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
|
||||
|
||||
Model\GServer::setProtocol($contact['gsid'], $protocol);
|
||||
} else {
|
||||
Model\Post\DeliveryData::incrementQueueFailed($target_item['uri-id']);
|
||||
}
|
||||
|
@ -391,6 +393,8 @@ class Delivery
|
|||
// We successfully delivered a message, the contact is alive
|
||||
Model\Contact::unmarkForArchival($contact);
|
||||
|
||||
Model\GServer::setProtocol($contact['gsid'], $protocol);
|
||||
|
||||
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
|
||||
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], $protocol);
|
||||
}
|
||||
|
@ -476,6 +480,8 @@ class Delivery
|
|||
// We successfully delivered a message, the contact is alive
|
||||
Model\Contact::unmarkForArchival($contact);
|
||||
|
||||
Model\GServer::setProtocol($contact['gsid'], Model\Post\DeliveryData::DIASPORA);
|
||||
|
||||
if (in_array($cmd, [Delivery::POST, Delivery::POKE])) {
|
||||
Model\Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Model\Post\DeliveryData::DIASPORA);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1384);
|
||||
define('DB_UPDATE_VERSION', 1385);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -75,6 +75,7 @@ return [
|
|||
"poco" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"noscrape" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"protocol" => ["type" => "tinyint unsigned", "comment" => "The protocol of the server"],
|
||||
"platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"relay-subscribe" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Has the server subscribed to the relay system"],
|
||||
"relay-scope" => ["type" => "varchar(10)", "not null" => "1", "default" => "", "comment" => "The scope of messages that the server wants to get"],
|
||||
|
|
Loading…
Reference in New Issue
Block a user