Software /
code /
prosody
Comparison
net/unbound.lua @ 11253:919e7b962f0b
net.unbound: Delay loading until server has started or first query
Shouldn't need a DNS resolver until later anyways. Might even be
sensible to only initialize if a query is actually attempted.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 05 Jan 2021 21:40:06 +0100 |
parent | 11252:ba335004ca60 |
child | 11302:6bb2986783d0 |
comparison
equal
deleted
inserted
replaced
11252:ba335004ca60 | 11253:919e7b962f0b |
---|---|
58 | 58 |
59 local function initialize() | 59 local function initialize() |
60 unbound = libunbound.new(unbound_config); | 60 unbound = libunbound.new(unbound_config); |
61 server_conn = connect_server(unbound, net_server); | 61 server_conn = connect_server(unbound, net_server); |
62 end | 62 end |
63 initialize(); | 63 if prosody then |
64 prosody.events.add_handler("server-started", initialize); | |
65 end | |
64 | 66 |
65 local answer_mt = { | 67 local answer_mt = { |
66 __tostring = function(self) | 68 __tostring = function(self) |
67 if self._string then return self._string end | 69 if self._string then return self._string end |
68 local h = s_format("Status: %s", errors[self.status]); | 70 local h = s_format("Status: %s", errors[self.status]); |
103 end | 105 end |
104 return setmetatable(a, answer_mt); | 106 return setmetatable(a, answer_mt); |
105 end | 107 end |
106 | 108 |
107 local function lookup(callback, qname, qtype, qclass) | 109 local function lookup(callback, qname, qtype, qclass) |
110 if not unbound then initialize(); end | |
108 qtype = qtype and s_upper(qtype) or "A"; | 111 qtype = qtype and s_upper(qtype) or "A"; |
109 qclass = qclass and s_upper(qclass) or "IN"; | 112 qclass = qclass and s_upper(qclass) or "IN"; |
110 local ntype, nclass = types[qtype], classes[qclass]; | 113 local ntype, nclass = types[qtype], classes[qclass]; |
111 local startedat = gettime(); | 114 local startedat = gettime(); |
112 local ret; | 115 local ret; |