Added trust / isActivityGone

This commit is contained in:
Michael 2022-07-24 14:26:06 +00:00
parent 55b6a89c7c
commit 51cc1f679f
6 changed files with 31 additions and 27 deletions

View File

@ -739,7 +739,8 @@ CREATE TABLE IF NOT EXISTS `inbox-entry` (
`received` datetime COMMENT 'Receiving date',
`activity` mediumtext COMMENT 'The JSON activity',
`signer` varchar(255) COMMENT '',
`push` boolean NOT NULL DEFAULT '0' COMMENT '',
`push` boolean COMMENT 'Is the entry pushed or have pulled it?',
`trust` boolean COMMENT 'Do we trust this entry?',
`wid` int unsigned COMMENT 'Workerqueue id',
PRIMARY KEY(`id`),
UNIQUE INDEX `activity-id` (`activity-id`),

View File

@ -6,21 +6,22 @@ Incoming activity
Fields
------
| Field | Description | Type | Null | Key | Default | Extra |
| ------------------ | ------------------------------------ | -------------- | ---- | --- | ------- | -------------- |
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
| activity-id | id of the incoming activity | varbinary(255) | YES | | NULL | |
| object-id | | varbinary(255) | YES | | NULL | |
| in-reply-to-id | | varbinary(255) | YES | | NULL | |
| conversation | | varbinary(255) | YES | | NULL | |
| type | Type of the activity | varchar(64) | YES | | NULL | |
| object-type | Type of the object activity | varchar(64) | YES | | NULL | |
| object-object-type | Type of the object's object activity | varchar(64) | YES | | NULL | |
| received | Receiving date | datetime | YES | | NULL | |
| activity | The JSON activity | mediumtext | YES | | NULL | |
| signer | | varchar(255) | YES | | NULL | |
| push | | boolean | NO | | 0 | |
| wid | Workerqueue id | int unsigned | YES | | NULL | |
| Field | Description | Type | Null | Key | Default | Extra |
| ------------------ | -------------------------------------- | -------------- | ---- | --- | ------- | -------------- |
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
| activity-id | id of the incoming activity | varbinary(255) | YES | | NULL | |
| object-id | | varbinary(255) | YES | | NULL | |
| in-reply-to-id | | varbinary(255) | YES | | NULL | |
| conversation | | varbinary(255) | YES | | NULL | |
| type | Type of the activity | varchar(64) | YES | | NULL | |
| object-type | Type of the object activity | varchar(64) | YES | | NULL | |
| object-object-type | Type of the object's object activity | varchar(64) | YES | | NULL | |
| received | Receiving date | datetime | YES | | NULL | |
| activity | The JSON activity | mediumtext | YES | | NULL | |
| signer | | varchar(255) | YES | | NULL | |
| push | Is the entry pushed or have pulled it? | boolean | YES | | NULL | |
| trust | Do we trust this entry? | boolean | YES | | NULL | |
| wid | Workerqueue id | int unsigned | YES | | NULL | |
Indexes
------------

View File

@ -303,7 +303,7 @@ class Processor
Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
if ($recursion_depth < 10) {
$result = self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
if (empty($result) && self::ActivityIsGone($activity['reply-to-id'])) {
if (empty($result) && self::isActivityGone($activity['reply-to-id'])) {
// Recursively delete this and all depending entries
Queue::deleteById($activity['entry-id']);
return [];
@ -466,7 +466,7 @@ class Processor
*
* @return boolean
*/
private static function ActivityIsGone(string $url): bool
private static function isActivityGone(string $url): bool
{
$curlResult = HTTPSignature::fetchRaw($url, 0);

View File

@ -42,7 +42,7 @@ class Queue
* @param boolean $push
* @return array
*/
public static function add(array $activity, string $type, int $uid, string $http_signer, bool $push): array
public static function add(array $activity, string $type, int $uid, string $http_signer, bool $push, bool $trust_source): array
{
$fields = [
'activity-id' => $activity['id'],
@ -52,6 +52,7 @@ class Queue
'activity' => json_encode($activity, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
'received' => DateTimeFormat::utcNow(),
'push' => $push,
'trust' => $trust_source,
];
if (!empty($activity['reply-to-id'])) {
@ -204,7 +205,7 @@ class Queue
*/
public static function processAll()
{
$entries = DBA::select('inbox-entry', ['id', 'type', 'object-type', 'object-id', 'in-reply-to-id'], ["`wid` IS NULL"], ['order' => ['id' => true]]);
$entries = DBA::select('inbox-entry', ['id', 'type', 'object-type', 'object-id', 'in-reply-to-id'], ["`trust` AND `wid` IS NULL"], ['order' => ['id' => true]]);
while ($entry = DBA::fetch($entries)) {
// We don't need to process entries that depend on already existing entries.
if (!empty($entry['in-reply-to-id']) && DBA::exists('inbox-entry', ["`id` != ? AND `object-id` = ?", $entry['id'], $entry['in-reply-to-id']])) {

View File

@ -530,11 +530,6 @@ class Receiver
$type = $object_data['type'];
}
if (!$trust_source) {
Logger::info('Activity trust could not be achieved.', ['id' => $object_data['object_id'], 'type' => $type, 'signer' => $signer, 'actor' => $actor, 'attributedTo' => $attributed_to]);
return;
}
if (!empty($body) && empty($object_data['raw'])) {
$object_data['raw'] = $body;
}
@ -561,7 +556,12 @@ class Receiver
$object_data['object_activity'] = $activity;
}
$object_data = Queue::add($object_data, $type, $uid, $http_signer, $push);
$object_data = Queue::add($object_data, $type, $uid, $http_signer, $push, $trust_source);
if (!$trust_source) {
Logger::info('Activity trust could not be achieved.', ['id' => $object_data['object_id'], 'type' => $type, 'signer' => $signer, 'actor' => $actor, 'attributedTo' => $attributed_to]);
return;
}
if (!empty($activity['recursion-depth'])) {
$object_data['recursion-depth'] = $activity['recursion-depth'];

View File

@ -798,7 +798,8 @@ return [
"received" => ["type" => "datetime", "comment" => "Receiving date"],
"activity" => ["type" => "mediumtext", "comment" => "The JSON activity"],
"signer" => ["type" => "varchar(255)", "comment" => ""],
"push" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"push" => ["type" => "boolean", "comment" => "Is the entry pushed or have pulled it?"],
"trust" => ["type" => "boolean", "comment" => "Do we trust this entry?"],
"wid" => ["type" => "int unsigned", "foreign" => ["workerqueue" => "id"], "comment" => "Workerqueue id"], ],
"indexes" => [
"PRIMARY" => ["id"],