Comparison

net/resolvers/service.lua @ 10440:1ee87b4979c2

net.resolvers.service: Pass IP literals directly to basic resolver IP literals will not work with SRV records anyways. Fixes s2s with IP literals.
author Kim Alvefur <zash@zash.se>
date Sun, 24 Nov 2019 04:43:14 +0100
parent 10401:1ef1f6c43c5b
child 10484:b13a31cea7d9
comparison
equal deleted inserted replaced
10438:55490be0dc29 10440:1ee87b4979c2
1 local adns = require "net.adns"; 1 local adns = require "net.adns";
2 local basic = require "net.resolvers.basic"; 2 local basic = require "net.resolvers.basic";
3 local inet_pton = require "util.net".pton;
3 local idna_to_ascii = require "util.encodings".idna.to_ascii; 4 local idna_to_ascii = require "util.encodings".idna.to_ascii;
4 local unpack = table.unpack or unpack; -- luacheck: ignore 113 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 };
67 ready(); 68 ready();
68 end, "_" .. self.service .. "._" .. self.conn_type .. "." .. self.hostname, "SRV", "IN"); 69 end, "_" .. self.service .. "._" .. self.conn_type .. "." .. self.hostname, "SRV", "IN");
69 end 70 end
70 71
71 local function new(hostname, service, conn_type, extra) 72 local function new(hostname, service, conn_type, extra)
73 local is_ip = inet_pton(hostname);
74 if not is_ip and hostname:sub(1,1) == '[' then
75 is_ip = inet_pton(hostname:sub(2,-2));
76 end
77 if is_ip and extra and extra.default_port then
78 return basic.new(hostname, extra.default_port, conn_type, extra);
79 end
80
72 return setmetatable({ 81 return setmetatable({
73 hostname = idna_to_ascii(hostname); 82 hostname = idna_to_ascii(hostname);
74 service = service; 83 service = service;
75 conn_type = conn_type or "tcp"; 84 conn_type = conn_type or "tcp";
76 extra = extra; 85 extra = extra;