Software /
code /
prosody
Comparison
net/resolvers/basic.lua @ 10436:0d702ec77f0c 0.11
net.resolvers.basic: Move IP literal check to constructor
This is to prepare for fixing #1459. An IPv6 literal in [ ] brackets
does not pass IDNA and resolving it fails there.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 24 Nov 2019 04:23:51 +0100 |
parent | 10400:4c2d789a106b |
child | 10437:fcfc8f4d14a8 |
comparison
equal
deleted
inserted
replaced
10433:7777f25d5266 | 10436:0d702ec77f0c |
---|---|
31 if n > 0 then return; end | 31 if n > 0 then return; end |
32 self.targets = targets; | 32 self.targets = targets; |
33 self:next(cb); | 33 self:next(cb); |
34 end | 34 end |
35 | 35 |
36 local is_ip = inet_pton(self.hostname); | |
37 if is_ip then | |
38 if #is_ip == 16 then | |
39 cb(self.conn_type.."6", self.hostname, self.port, self.extra); | |
40 elseif #is_ip == 4 then | |
41 cb(self.conn_type.."4", self.hostname, self.port, self.extra); | |
42 end | |
43 return; | |
44 end | |
45 | |
46 -- Resolve DNS to target list | 36 -- Resolve DNS to target list |
47 local dns_resolver = adns.resolver(); | 37 local dns_resolver = adns.resolver(); |
48 dns_resolver:lookup(function (answer) | 38 dns_resolver:lookup(function (answer) |
49 if answer then | 39 if answer then |
50 for _, record in ipairs(answer) do | 40 for _, record in ipairs(answer) do |
63 ready(); | 53 ready(); |
64 end, self.hostname, "AAAA", "IN"); | 54 end, self.hostname, "AAAA", "IN"); |
65 end | 55 end |
66 | 56 |
67 local function new(hostname, port, conn_type, extra) | 57 local function new(hostname, port, conn_type, extra) |
58 local ascii_host = idna_to_ascii(hostname); | |
59 local targets = nil; | |
60 | |
61 local is_ip = inet_pton(hostname); | |
62 if is_ip then | |
63 if #is_ip == 16 then | |
64 targets = { { conn_type.."6", hostname, port, extra } }; | |
65 elseif #is_ip == 4 then | |
66 targets = { { conn_type.."4", hostname, port, extra } }; | |
67 end | |
68 end | |
69 | |
68 return setmetatable({ | 70 return setmetatable({ |
69 hostname = idna_to_ascii(hostname); | 71 hostname = ascii_host; |
70 port = port; | 72 port = port; |
71 conn_type = conn_type or "tcp"; | 73 conn_type = conn_type or "tcp"; |
72 extra = extra; | 74 extra = extra; |
75 targets = targets; | |
73 }, resolver_mt); | 76 }, resolver_mt); |
74 end | 77 end |
75 | 78 |
76 return { | 79 return { |
77 new = new; | 80 new = new; |