Chat Federation: refactoring ActivityPub data:

The data format used by plugin v6.3.0 was not well suited.
Here comes a new data format, with S2S informations.
The plugin can automatically upgrade old format.
It also continues to provide the old format, so than remote instance
that did not update the plugin will still work.
This commit is contained in:
John Livingston
2023-05-24 15:09:56 +02:00
parent 4f9534dc11
commit 6ed69d2c2f
10 changed files with 547 additions and 212 deletions

View File

@ -4,28 +4,22 @@ local path = require "util.paths";
local json = require "util.json";
local server_infos_dir = assert(module:get_option_string("peertubelivechat_server_infos_path", nil), "'peertubelivechat_server_infos_path' is a required option");
local instance_url = assert(module:get_option_string("peertubelivechat_instance_url", nil), "'peertubelivechat_instance_url' is a required option");
local current_instance_url = assert(module:get_option_string("peertubelivechat_instance_url", nil), "'peertubelivechat_instance_url' is a required option");
function discover_websocket_s2s(event)
local to_host = event.to_host;
module:log("debug", "Searching websocket s2s for remote host %s", to_host);
-- FIXME: dont to this room. prefix thing. Peertube should create needed files.
local to_host_room = to_host;
if string.sub(to_host_room, 1, 5) ~= 'room.' then
to_host_room = 'room.'..to_host_room;
end
local f_s2s = io.open(path.join(server_infos_dir, to_host_room, 's2s'), "r");
local f_s2s = io.open(path.join(server_infos_dir, to_host, 's2s'), "r");
if f_s2s ~= nil then
io.close(f_s2s);
module.log("debug", "Remote host is a known Peertube %s that has s2s activated, we will let legacy s2s module handle the connection", to_host_room);
module.log("debug", "Remote host is a known Peertube %s that has s2s activated, we will let legacy s2s module handle the connection", to_host);
return;
end
local f_ws_proxy = io.open(path.join(server_infos_dir, to_host_room, 'ws-s2s'), "r");
local f_ws_proxy = io.open(path.join(server_infos_dir, to_host, 'ws-s2s'), "r");
if f_ws_proxy == nil then
module:log("debug", "Remote host %s is not a known remote Peertube, we will let legacy s2s module handle the connection", to_host_room);
module:log("debug", "Remote host %s is not a known remote Peertube, we will let legacy s2s module handle the connection", to_host);
return;
end
local content = f_ws_proxy:read("*all");
@ -44,7 +38,7 @@ function discover_websocket_s2s(event)
module:log("debug", "Found a Websocket endpoint to proxify s2s communications to remote host %s", to_host);
local properties = {};
properties["extra_headers"] = {
["peertube-livechat-ws-s2s-instance-url"] = instance_url;
["peertube-livechat-ws-s2s-instance-url"] = current_instance_url;
};
properties["url"] = remote_ws_proxy_conf["url"];
return properties;