From 4da406588e5177c0b663f2658336888b29795d13 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 24 Dec 2018 03:00:27 +0100 Subject: net.adns: Silence individual luacheck warnings instead of ignoring entire file --- net/adns.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index 560e4b53..4fa01f8a 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -14,7 +14,7 @@ local log = require "util.logger".init("adns"); local coroutine, tostring, pcall = coroutine, tostring, pcall; local setmetatable = setmetatable; -local function dummy_send(sock, data, i, j) return (j-i)+1; end +local function dummy_send(sock, data, i, j) return (j-i)+1; end -- luacheck: ignore 212 local _ENV = nil; -- luacheck: std none @@ -29,8 +29,7 @@ local function new_async_socket(sock, resolver) local peername = ""; local listener = {}; local handler = {}; - local err; - function listener.onincoming(conn, data) + function listener.onincoming(conn, data) -- luacheck: ignore 212/conn if data then resolver:feed(handler, data); end @@ -46,9 +45,12 @@ local function new_async_socket(sock, resolver) resolver:servfail(conn); -- Let the magic commence end end - handler, err = server.wrapclient(sock, "dns", 53, listener); - if not handler then - return nil, err; + do + local err; + handler, err = server.wrapclient(sock, "dns", 53, listener); + if not handler then + return nil, err; + end end handler.settimeout = function () end @@ -89,7 +91,7 @@ function async_resolver_methods:lookup(handler, qname, qtype, qclass) end)(resolver:peek(qname, qtype, qclass)); end -function query_methods:cancel(call_handler, reason) +function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason log("warn", "Cancelling DNS lookup for %s", tostring(self[4])); self[1].cancel(self[2], self[3], self[4], self[5], call_handler); end -- cgit v1.2.3 From 75bfec7731e0d42ad5733a62b9772db9c72aeef9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 30 Jul 2019 02:35:17 +0200 Subject: net.*: Remove tostring call from logging Taken care of by loggingmanager now --- net/adns.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index 4fa01f8a..5050c23b 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -73,11 +73,11 @@ function async_resolver_methods:lookup(handler, qname, qtype, qclass) handler(peek); return; end - log("debug", "Records for %s not in cache, sending query (%s)...", qname, tostring(coroutine.running())); + log("debug", "Records for %s not in cache, sending query (%s)...", qname, coroutine.running()); local ok, err = resolver:query(qname, qtype, qclass); if ok then coroutine.yield(setmetatable({ resolver, qclass or "IN", qtype or "A", qname, coroutine.running()}, query_mt)); -- Wait for reply - log("debug", "Reply for %s (%s)", qname, tostring(coroutine.running())); + log("debug", "Reply for %s (%s)", qname, coroutine.running()); end if ok then ok, err = pcall(handler, resolver:peek(qname, qtype, qclass)); @@ -86,13 +86,13 @@ function async_resolver_methods:lookup(handler, qname, qtype, qclass) ok, err = pcall(handler, nil, err); end if not ok then - log("error", "Error in DNS response handler: %s", tostring(err)); + log("error", "Error in DNS response handler: %s", err); end end)(resolver:peek(qname, qtype, qclass)); end function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason - log("warn", "Cancelling DNS lookup for %s", tostring(self[4])); + log("warn", "Cancelling DNS lookup for %s", self[4]); self[1].cancel(self[2], self[3], self[4], self[5], call_handler); end -- cgit v1.2.3 From bf79ad07b26e43fe579a8761865f61e74cc682b9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 30 Jul 2019 02:36:15 +0200 Subject: net.adns: Remove unused local [luacheck] --- net/adns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index 5050c23b..d7266958 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -11,7 +11,7 @@ local new_resolver = require "net.dns".resolver; local log = require "util.logger".init("adns"); -local coroutine, tostring, pcall = coroutine, tostring, pcall; +local coroutine, pcall = coroutine, pcall; local setmetatable = setmetatable; local function dummy_send(sock, data, i, j) return (j-i)+1; end -- luacheck: ignore 212 -- cgit v1.2.3 From 5ac8804435ba7378a39d6fd213da35c57165c483 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 24 Jan 2020 13:50:02 +0000 Subject: net.adns: Add :lookup_promise() method --- net/adns.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index d7266958..bf6c11ab 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -8,6 +8,7 @@ local server = require "net.server"; local new_resolver = require "net.dns".resolver; +local promise = require "util.promise"; local log = require "util.logger".init("adns"); @@ -91,6 +92,18 @@ function async_resolver_methods:lookup(handler, qname, qtype, qclass) end)(resolver:peek(qname, qtype, qclass)); end +function async_resolver_methods:lookup_promise(qname, qtype, qclass) + return promise.new(function (resolve, reject) + local function handler(answer) + if not answer then + return reject(); + end + resolve(answer); + end + self:lookup(handler, qname, qtype, qclass); + end); +end + function query_methods:cancel(call_handler, reason) -- luacheck: ignore 212/reason log("warn", "Cancelling DNS lookup for %s", self[4]); self[1].cancel(self[2], self[3], self[4], self[5], call_handler); -- cgit v1.2.3 From bde46d79cdd729cb2e7dbea290e4a05e18e5b0ad Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 25 Jun 2020 17:55:24 +0200 Subject: net.adns: Log a warning if loaded (because net.unbound wasn't) --- net/adns.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index bf6c11ab..852f3f4f 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -12,6 +12,8 @@ local promise = require "util.promise"; local log = require "util.logger".init("adns"); +log("warn", "Old async DNS library used, lua-unbound missing?"); -- TODO write docs about luaunbound + local coroutine, pcall = coroutine, pcall; local setmetatable = setmetatable; -- cgit v1.2.3 From 8c73ea0b2286fed2d1a91333c8d92dab247fd568 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 27 Jun 2020 14:25:57 +0200 Subject: util.dependencies: Tone down lua-unbound dependency for now At least until packages are available Wording from MattJ --- net/adns.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'net/adns.lua') diff --git a/net/adns.lua b/net/adns.lua index 852f3f4f..8fe05653 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -12,7 +12,8 @@ local promise = require "util.promise"; local log = require "util.logger".init("adns"); -log("warn", "Old async DNS library used, lua-unbound missing?"); -- TODO write docs about luaunbound +log("debug", "Using legacy DNS API (missing lua-unbound?)"); -- TODO write docs about luaunbound +-- TODO Raise log level once packages are available local coroutine, pcall = coroutine, pcall; local setmetatable = setmetatable; -- cgit v1.2.3