net/resolvers/chain.lua
author Kim Alvefur <zash@zash.se>
Fri, 27 May 2022 14:45:35 +0200
branch0.12
changeset 12530 252ed01896dd
parent 12208 7c397a49d163
permissions -rw-r--r--
mod_smacks: Bounce unhandled stanzas from local origin (fix #1759) Sending stanzas with a remote session as origin when the stanzas have a local JID in the from attribute trips validation in core.stanza_router, leading to warnings: > Received a stanza claiming to be from remote.example, over a stream authed for localhost.example Using module:send() uses the local host as origin, which is fine here.


local methods = {};
local resolver_mt = { __index = methods };

-- Find the next target to connect to, and
-- pass it to cb()
function methods:next(cb)
	if self.resolvers then
		if not self.resolver then
			if #self.resolvers == 0 then
				cb(nil);
				return;
			end
			local next_resolver = table.remove(self.resolvers, 1);
			self.resolver = next_resolver;
		end
		self.resolver:next(function (...)
			if self.resolver then
				self.last_error = self.resolver.last_error;
			end
			if ... == nil then
				self.resolver = nil;
				self:next(cb);
			else
				cb(...);
			end
		end);
		return;
	end
end

local function new(resolvers)
	return setmetatable({ resolvers = resolvers }, resolver_mt);
end

return {
	new = new;
};