aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2022-01-21 17:56:20 +0100
committerKim Alvefur <zash@zash.se>2022-01-21 17:56:20 +0100
commitf31762a075f391c8ba2a8363f8c7d9b5a9713962 (patch)
treee8a6fd5adb9cd9016528ad5f06e6d4cf75c22a2c /net
parent991e6531ab3085b1265c0cf91ea84459da606291 (diff)
downloadprosody-f31762a075f391c8ba2a8363f8c7d9b5a9713962.tar.gz
prosody-f31762a075f391c8ba2a8363f8c7d9b5a9713962.zip
net.resolvers.chain: A resolver for combining other resolvers
Say if you wanted to try both _xmpp and _xmpps services
Diffstat (limited to 'net')
-rw-r--r--net/resolvers/chain.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/net/resolvers/chain.lua b/net/resolvers/chain.lua
new file mode 100644
index 00000000..b3135e67
--- /dev/null
+++ b/net/resolvers/chain.lua
@@ -0,0 +1,38 @@
+
+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;
+};