]> git.mxchange.org Git - friendica.git/commitdiff
Added trust / isActivityGone
authorMichael <heluecht@pirati.ca>
Sun, 24 Jul 2022 14:26:06 +0000 (14:26 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 24 Jul 2022 14:26:06 +0000 (14:26 +0000)
database.sql
doc/database/db_inbox-entry.md
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Queue.php
src/Protocol/ActivityPub/Receiver.php
static/dbstructure.config.php

index 42624d4d1d62abb1b331ddbdda3effc981836f3e..6b8d7df2ffad17e28eaf9f21cbe3e7d2e6fd60d5 100644 (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`),
index 32dd1203dc9dc0da9309c18ee034c66b754bef4e..d10d3f242b4d0c606816c26a178fd82098809253 100644 (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
 ------------
index d1c3994e2aee306d275ff94435d80866f8a714e1..1ca6fce9021f2e66bcd7b2b2c5747d94ee1825ab 100644 (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);
 
index 011101eed7cb06bded425f04321afb45c7b919d6..faaf0aa3bc905b7deab933139ef6ef0dab4275e9 100644 (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']])) {
index 3e345107496b26404b0ad77bc4566888421d4bf1..84d1197514e96e8d3c1e728b31d1d0d33ec269b0 100644 (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'];
index 0b6af9b13ab6711bf3dc3bcb0a03440ebcd2ce40..53ceaa7ece227e0f77c622dcdd7c7ec7bfa86d43 100644 (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"],