Added server discovery for their relais configuration
This commit is contained in:
parent
bfc2bda9b6
commit
e65bd0325e
2
boot.php
2
boot.php
|
@ -41,7 +41,7 @@ define('FRIENDICA_PLATFORM', 'Friendica');
|
||||||
define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily');
|
define('FRIENDICA_CODENAME', 'The Tazmans Flax-lily');
|
||||||
define('FRIENDICA_VERSION', '2018-05-dev');
|
define('FRIENDICA_VERSION', '2018-05-dev');
|
||||||
define('DFRN_PROTOCOL_VERSION', '2.23');
|
define('DFRN_PROTOCOL_VERSION', '2.23');
|
||||||
define('DB_UPDATE_VERSION', 1258);
|
define('DB_UPDATE_VERSION', 1259);
|
||||||
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
|
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
14
database.sql
14
database.sql
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 2018-05-dev (The Tazmans Flax-lily)
|
-- Friendica 2018-05-dev (The Tazmans Flax-lily)
|
||||||
-- DB_UPDATE_VERSION 1258
|
-- DB_UPDATE_VERSION 1259
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,6 +397,8 @@ CREATE TABLE IF NOT EXISTS `gserver` (
|
||||||
`noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
`noscrape` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||||
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
|
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
|
||||||
`platform` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
`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',
|
||||||
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||||
`last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
`last_poco_query` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||||
`last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
`last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||||
|
@ -405,6 +407,16 @@ CREATE TABLE IF NOT EXISTS `gserver` (
|
||||||
UNIQUE INDEX `nurl` (`nurl`(190))
|
UNIQUE INDEX `nurl` (`nurl`(190))
|
||||||
) DEFAULT COLLATE utf8mb4_general_ci;
|
) DEFAULT COLLATE utf8mb4_general_ci;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- TABLE gserver-tag
|
||||||
|
--
|
||||||
|
CREATE TABLE IF NOT EXISTS `gserver-tag` (
|
||||||
|
`gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver',
|
||||||
|
`tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed',
|
||||||
|
PRIMARY KEY(`gserver-id`,`tag`),
|
||||||
|
INDEX `tag` (`tag`)
|
||||||
|
) DEFAULT COLLATE utf8mb4_general_ci;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- TABLE hook
|
-- TABLE hook
|
||||||
--
|
--
|
||||||
|
|
|
@ -1074,6 +1074,8 @@ class DBStructure
|
||||||
"noscrape" => ["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" => ""],
|
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
|
||||||
"platform" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
"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"],
|
||||||
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
|
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],
|
||||||
"last_poco_query" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
|
"last_poco_query" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
|
||||||
"last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
|
"last_contact" => ["type" => "datetime", "default" => NULL_DATE, "comment" => ""],
|
||||||
|
@ -1084,6 +1086,17 @@ class DBStructure
|
||||||
"nurl" => ["UNIQUE", "nurl(190)"],
|
"nurl" => ["UNIQUE", "nurl(190)"],
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
$database["gserver-tag"] = [
|
||||||
|
"comment" => "Tags that the server has subscribed",
|
||||||
|
"fields" => [
|
||||||
|
"gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1", "comment" => "The id of the gserver"],
|
||||||
|
"tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"],
|
||||||
|
],
|
||||||
|
"indexes" => [
|
||||||
|
"PRIMARY" => ["gserver-id", "tag"],
|
||||||
|
"tag" => ["tag"],
|
||||||
|
]
|
||||||
|
];
|
||||||
$database["hook"] = [
|
$database["hook"] = [
|
||||||
"comment" => "addon hook registry",
|
"comment" => "addon hook registry",
|
||||||
"fields" => [
|
"fields" => [
|
||||||
|
|
|
@ -1377,11 +1377,44 @@ class PortableContact
|
||||||
$fields['created'] = DateTimeFormat::utcNow();
|
$fields['created'] = DateTimeFormat::utcNow();
|
||||||
dba::insert('gserver', $fields);
|
dba::insert('gserver', $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array($fields['network'], [NETWORK_DFRN, NETWORK_DIASPORA])) {
|
||||||
|
self::discoverRelay(server_url);
|
||||||
|
}
|
||||||
|
|
||||||
logger("End discovery for server " . $server_url, LOGGER_DEBUG);
|
logger("End discovery for server " . $server_url, LOGGER_DEBUG);
|
||||||
|
|
||||||
return !$failure;
|
return !$failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function discoverRelay($server_url)
|
||||||
|
{
|
||||||
|
logger("Discover relay data for server " . $server_url, LOGGER_DEBUG);
|
||||||
|
|
||||||
|
$serverret = Network::curl($server_url."/.well-known/x-social-relay");
|
||||||
|
if (!$serverret["success"]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = json_decode($serverret['body']);
|
||||||
|
if (!is_object($data)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$gserver = dba::selectFirst('gserver', ['id'], ['nurl' => normalise_link($server_url)]);
|
||||||
|
if (!DBM::is_result($gserver)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = ['relay-subscribe' => $data->subscribe, 'relay-scope' => $data->scope];
|
||||||
|
dba::update('gserver', $fields, ['id' => $gserver['id']]);
|
||||||
|
|
||||||
|
dba::delete('gserver-tag', ['gserver-id' => $gserver['id']]);
|
||||||
|
foreach ($data->tags as $tag) {
|
||||||
|
dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns a list of all known servers
|
* @brief Returns a list of all known servers
|
||||||
* @return array List of server urls
|
* @return array List of server urls
|
||||||
|
@ -1463,8 +1496,8 @@ class PortableContact
|
||||||
$header = ['Authorization: Bearer '.$accesstoken];
|
$header = ['Authorization: Bearer '.$accesstoken];
|
||||||
$serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
|
$serverdata = Network::curl($api, false, $redirects, ['headers' => $header]);
|
||||||
if ($serverdata['success']) {
|
if ($serverdata['success']) {
|
||||||
$servers = json_decode($serverdata['body']);
|
$servers = json_decode($serverdata['body']);
|
||||||
foreach ($servers->instances as $server) {
|
foreach ($servers->instances as $server) {
|
||||||
$url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
|
$url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
|
||||||
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
|
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue