comparison mod_s2sout_override/mod_s2sout_override.lua @ 5486:71243bedb2b0

mod_s2sout_override: New module for overriding s2s connections This takes advantage of the new event added in Prosody rev d5f322dd424b which enables a cleaner way to override the connection using a resolver.
author Kim Alvefur <zash@zash.se>
date Wed, 24 May 2023 15:56:26 +0200
parents
children 6cf2f32dbf40
comparison
equal deleted inserted replaced
5485:67190744b1eb 5486:71243bedb2b0
1 --% requires: s2sout-pre-connect-event
2
3 local url = require"socket.url";
4 local basic_resolver = require "net.resolvers.basic";
5
6 local override_for = module:get_option(module.name, {}); -- map of host to "tcp://example.com:5269"
7
8 module:hook("s2sout-pre-connect", function(event)
9 local override = override_for[event.session.to_host];
10 if type(override) == "string" then
11 override = url.parse(override);
12 end
13 if type(override) == "table" and override.scheme == "tcp" and type(override.host) == "string" then
14 event.resolver = basic_resolver.new(override.host, tonumber(override.port) or 5269, override.scheme, {});
15 end
16 end);