Software /
code /
prosody
Comparison
net/resolvers/basic.lua @ 11120:b2331f3dfeea
Merge 0.11->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 09:50:33 +0100 |
parent | 11008:fd735fe2fc50 |
child | 11414:5a71f14ab77c |
comparison
equal
deleted
inserted
replaced
11119:68df52bf08d5 | 11120:b2331f3dfeea |
---|---|
1 local adns = require "net.adns"; | 1 local adns = require "net.adns"; |
2 local inet_pton = require "util.net".pton; | 2 local inet_pton = require "util.net".pton; |
3 local inet_ntop = require "util.net".ntop; | 3 local inet_ntop = require "util.net".ntop; |
4 local idna_to_ascii = require "util.encodings".idna.to_ascii; | 4 local idna_to_ascii = require "util.encodings".idna.to_ascii; |
5 local unpack = table.unpack or unpack; -- luacheck: ignore 113 | |
5 | 6 |
6 local methods = {}; | 7 local methods = {}; |
7 local resolver_mt = { __index = methods }; | 8 local resolver_mt = { __index = methods }; |
9 | |
10 -- FIXME RFC 6724 | |
8 | 11 |
9 -- Find the next target to connect to, and | 12 -- Find the next target to connect to, and |
10 -- pass it to cb() | 13 -- pass it to cb() |
11 function methods:next(cb) | 14 function methods:next(cb) |
12 if self.targets then | 15 if self.targets then |
34 self:next(cb); | 37 self:next(cb); |
35 end | 38 end |
36 | 39 |
37 -- Resolve DNS to target list | 40 -- Resolve DNS to target list |
38 local dns_resolver = adns.resolver(); | 41 local dns_resolver = adns.resolver(); |
39 dns_resolver:lookup(function (answer) | 42 |
40 if answer then | 43 if not self.extra or self.extra.use_ipv4 ~= false then |
41 for _, record in ipairs(answer) do | 44 dns_resolver:lookup(function (answer) |
42 table.insert(targets, { self.conn_type.."4", record.a, self.port, self.extra }); | 45 if answer then |
46 for _, record in ipairs(answer) do | |
47 table.insert(targets, { self.conn_type.."4", record.a, self.port, self.extra }); | |
48 end | |
43 end | 49 end |
44 end | 50 ready(); |
51 end, self.hostname, "A", "IN"); | |
52 else | |
45 ready(); | 53 ready(); |
46 end, self.hostname, "A", "IN"); | 54 end |
47 | 55 |
48 dns_resolver:lookup(function (answer) | 56 if not self.extra or self.extra.use_ipv6 ~= false then |
49 if answer then | 57 dns_resolver:lookup(function (answer) |
50 for _, record in ipairs(answer) do | 58 if answer then |
51 table.insert(targets, { self.conn_type.."6", record.aaaa, self.port, self.extra }); | 59 for _, record in ipairs(answer) do |
60 table.insert(targets, { self.conn_type.."6", record.aaaa, self.port, self.extra }); | |
61 end | |
52 end | 62 end |
53 end | 63 ready(); |
64 end, self.hostname, "AAAA", "IN"); | |
65 else | |
54 ready(); | 66 ready(); |
55 end, self.hostname, "AAAA", "IN"); | 67 end |
56 end | 68 end |
57 | 69 |
58 local function new(hostname, port, conn_type, extra) | 70 local function new(hostname, port, conn_type, extra) |
59 local ascii_host = idna_to_ascii(hostname); | 71 local ascii_host = idna_to_ascii(hostname); |
60 local targets = nil; | 72 local targets = nil; |