Software /
code /
prosody
Annotate
net/resolvers/chain.lua @ 12481:2ee27587fec7
net: refactor sslconfig to not depend on LuaSec
This now requires that the network backend exposes a tls_builder
function, which essentially wraps the former util.sslconfig.new()
function, passing a factory to create the eventual SSL context.
That allows a net.server backend to pick whatever it likes as SSL
context factory, as long as it understands the config table passed by
the SSL config builder. Heck, a backend could even mock and replace the
entire SSL config builder API.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Sat, 02 Apr 2022 11:15:33 +0200 |
parent | 12204:7c397a49d163 |
rev | line source |
---|---|
12204
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local methods = {}; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local resolver_mt = { __index = methods }; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- Find the next target to connect to, and |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 -- pass it to cb() |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 function methods:next(cb) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 if self.resolvers then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 if not self.resolver then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 if #self.resolvers == 0 then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 cb(nil); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 return; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local next_resolver = table.remove(self.resolvers, 1); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 self.resolver = next_resolver; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 self.resolver:next(function (...) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 if self.resolver then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 self.last_error = self.resolver.last_error; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 if ... == nil then |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 self.resolver = nil; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 self:next(cb); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 else |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 cb(...); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 return; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local function new(resolvers) |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return setmetatable({ resolvers = resolvers }, resolver_mt); |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 end |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 return { |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 new = new; |
7c397a49d163
net.resolvers.chain: A resolver for combining other resolvers
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 }; |