Comparison

net/resolvers/basic.lua @ 10438:55490be0dc29

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sun, 24 Nov 2019 04:30:32 +0100
parent 10401:1ef1f6c43c5b
parent 10437:fcfc8f4d14a8
child 10441:f2c9abc71f08
comparison
equal deleted inserted replaced
10435:6e3fa523c969 10438:55490be0dc29
32 if n > 0 then return; end 32 if n > 0 then return; end
33 self.targets = targets; 33 self.targets = targets;
34 self:next(cb); 34 self:next(cb);
35 end 35 end
36 36
37 local is_ip = inet_pton(self.hostname);
38 if is_ip then
39 if #is_ip == 16 then
40 cb(self.conn_type.."6", self.hostname, self.port, self.extra);
41 elseif #is_ip == 4 then
42 cb(self.conn_type.."4", self.hostname, self.port, self.extra);
43 end
44 return;
45 end
46
47 -- Resolve DNS to target list 37 -- Resolve DNS to target list
48 local dns_resolver = adns.resolver(); 38 local dns_resolver = adns.resolver();
49 dns_resolver:lookup(function (answer) 39 dns_resolver:lookup(function (answer)
50 if answer then 40 if answer then
51 for _, record in ipairs(answer) do 41 for _, record in ipairs(answer) do
64 ready(); 54 ready();
65 end, self.hostname, "AAAA", "IN"); 55 end, self.hostname, "AAAA", "IN");
66 end 56 end
67 57
68 local function new(hostname, port, conn_type, extra) 58 local function new(hostname, port, conn_type, extra)
59 local ascii_host = idna_to_ascii(hostname);
60 local targets = nil;
61
62 local is_ip = inet_pton(hostname);
63 if not is_ip and hostname:sub(1,1) == '[' then
64 is_ip = inet_pton(hostname:sub(2,-2));
65 end
66 if is_ip then
67 if #is_ip == 16 then
68 targets = { { conn_type.."6", hostname, port, extra } };
69 elseif #is_ip == 4 then
70 targets = { { conn_type.."4", hostname, port, extra } };
71 end
72 end
73
69 return setmetatable({ 74 return setmetatable({
70 hostname = idna_to_ascii(hostname); 75 hostname = ascii_host;
71 port = port; 76 port = port;
72 conn_type = conn_type or "tcp"; 77 conn_type = conn_type or "tcp";
73 extra = extra; 78 extra = extra;
79 targets = targets;
74 }, resolver_mt); 80 }, resolver_mt);
75 end 81 end
76 82
77 return { 83 return {
78 new = new; 84 new = new;