Added trust / isActivityGone
This commit is contained in:
parent
55b6a89c7c
commit
51cc1f679f
6 changed files with 31 additions and 27 deletions
|
@ -739,7 +739,8 @@ CREATE TABLE IF NOT EXISTS `inbox-entry` (
|
||||||
`received` datetime COMMENT 'Receiving date',
|
`received` datetime COMMENT 'Receiving date',
|
||||||
`activity` mediumtext COMMENT 'The JSON activity',
|
`activity` mediumtext COMMENT 'The JSON activity',
|
||||||
`signer` varchar(255) COMMENT '',
|
`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',
|
`wid` int unsigned COMMENT 'Workerqueue id',
|
||||||
PRIMARY KEY(`id`),
|
PRIMARY KEY(`id`),
|
||||||
UNIQUE INDEX `activity-id` (`activity-id`),
|
UNIQUE INDEX `activity-id` (`activity-id`),
|
||||||
|
|
|
@ -7,7 +7,7 @@ Fields
|
||||||
------
|
------
|
||||||
|
|
||||||
| Field | Description | Type | Null | Key | Default | Extra |
|
| Field | Description | Type | Null | Key | Default | Extra |
|
||||||
| ------------------ | ------------------------------------ | -------------- | ---- | --- | ------- | -------------- |
|
| ------------------ | -------------------------------------- | -------------- | ---- | --- | ------- | -------------- |
|
||||||
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
||||||
| activity-id | id of the incoming activity | varbinary(255) | YES | | NULL | |
|
| activity-id | id of the incoming activity | varbinary(255) | YES | | NULL | |
|
||||||
| object-id | | varbinary(255) | YES | | NULL | |
|
| object-id | | varbinary(255) | YES | | NULL | |
|
||||||
|
@ -19,7 +19,8 @@ Fields
|
||||||
| received | Receiving date | datetime | YES | | NULL | |
|
| received | Receiving date | datetime | YES | | NULL | |
|
||||||
| activity | The JSON activity | mediumtext | YES | | NULL | |
|
| activity | The JSON activity | mediumtext | YES | | NULL | |
|
||||||
| signer | | varchar(255) | YES | | NULL | |
|
| signer | | varchar(255) | YES | | NULL | |
|
||||||
| push | | boolean | NO | | 0 | |
|
| 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 | |
|
| wid | Workerqueue id | int unsigned | YES | | NULL | |
|
||||||
|
|
||||||
Indexes
|
Indexes
|
||||||
|
|
|
@ -303,7 +303,7 @@ class Processor
|
||||||
Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
|
Logger::notice('Parent not found. Try to refetch it.', ['parent' => $activity['reply-to-id'], 'recursion-depth' => $recursion_depth]);
|
||||||
if ($recursion_depth < 10) {
|
if ($recursion_depth < 10) {
|
||||||
$result = self::fetchMissingActivity($activity['reply-to-id'], $activity, '', Receiver::COMPLETION_AUTO);
|
$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
|
// Recursively delete this and all depending entries
|
||||||
Queue::deleteById($activity['entry-id']);
|
Queue::deleteById($activity['entry-id']);
|
||||||
return [];
|
return [];
|
||||||
|
@ -466,7 +466,7 @@ class Processor
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private static function ActivityIsGone(string $url): bool
|
private static function isActivityGone(string $url): bool
|
||||||
{
|
{
|
||||||
$curlResult = HTTPSignature::fetchRaw($url, 0);
|
$curlResult = HTTPSignature::fetchRaw($url, 0);
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class Queue
|
||||||
* @param boolean $push
|
* @param boolean $push
|
||||||
* @return array
|
* @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 = [
|
$fields = [
|
||||||
'activity-id' => $activity['id'],
|
'activity-id' => $activity['id'],
|
||||||
|
@ -52,6 +52,7 @@ class Queue
|
||||||
'activity' => json_encode($activity, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
'activity' => json_encode($activity, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
'received' => DateTimeFormat::utcNow(),
|
'received' => DateTimeFormat::utcNow(),
|
||||||
'push' => $push,
|
'push' => $push,
|
||||||
|
'trust' => $trust_source,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!empty($activity['reply-to-id'])) {
|
if (!empty($activity['reply-to-id'])) {
|
||||||
|
@ -204,7 +205,7 @@ class Queue
|
||||||
*/
|
*/
|
||||||
public static function processAll()
|
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)) {
|
while ($entry = DBA::fetch($entries)) {
|
||||||
// We don't need to process entries that depend on already existing 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']])) {
|
if (!empty($entry['in-reply-to-id']) && DBA::exists('inbox-entry', ["`id` != ? AND `object-id` = ?", $entry['id'], $entry['in-reply-to-id']])) {
|
||||||
|
|
|
@ -530,11 +530,6 @@ class Receiver
|
||||||
$type = $object_data['type'];
|
$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'])) {
|
if (!empty($body) && empty($object_data['raw'])) {
|
||||||
$object_data['raw'] = $body;
|
$object_data['raw'] = $body;
|
||||||
}
|
}
|
||||||
|
@ -561,7 +556,12 @@ class Receiver
|
||||||
$object_data['object_activity'] = $activity;
|
$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'])) {
|
if (!empty($activity['recursion-depth'])) {
|
||||||
$object_data['recursion-depth'] = $activity['recursion-depth'];
|
$object_data['recursion-depth'] = $activity['recursion-depth'];
|
||||||
|
|
|
@ -798,7 +798,8 @@ return [
|
||||||
"received" => ["type" => "datetime", "comment" => "Receiving date"],
|
"received" => ["type" => "datetime", "comment" => "Receiving date"],
|
||||||
"activity" => ["type" => "mediumtext", "comment" => "The JSON activity"],
|
"activity" => ["type" => "mediumtext", "comment" => "The JSON activity"],
|
||||||
"signer" => ["type" => "varchar(255)", "comment" => ""],
|
"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"], ],
|
"wid" => ["type" => "int unsigned", "foreign" => ["workerqueue" => "id"], "comment" => "Workerqueue id"], ],
|
||||||
"indexes" => [
|
"indexes" => [
|
||||||
"PRIMARY" => ["id"],
|
"PRIMARY" => ["id"],
|
||||||
|
|
Loading…
Reference in a new issue