net.dns: Handle being loaded outside of Prosody
`if timer ...` suggests that this was intended, but it did not work
because net.timer depends on net.server which refuses to be loaded
outside of Prosody.
--- a/net/dns.lua Mon Feb 24 18:38:09 2020 +0100
+++ b/net/dns.lua Mon Feb 24 20:21:46 2020 +0100
@@ -13,7 +13,7 @@
local socket = require "socket";
-local timer = require "util.timer";
+local have_timer, timer = pcall(require, "util.timer");
local new_ip = require "util.ip".new_ip;
local have_util_net, util_net = pcall(require, "util.net");
@@ -871,7 +871,7 @@
set(self.wanted, qclass, qtype, qname, co, true);
end
- if timer and self.timeout then
+ if have_timer and self.timeout then
local num_servers = #self.server;
local i = 1;
timer.add_task(self.timeout, function ()