picodns is a simple interface to interact with DNS providers in a concurrent way. It's loosely based on OpenResty's DNS resolver and uses a bit modified LuaResolver's parser for now.
I'm aware that both of the modules mentioned earlier do the same thing but in order to achieve non-blocking connect
calls on luasocket, DNS resolving had to be done concurrently. Unfortunately, LuaResolver does not support non-blocking and lua-resty-dns requires cosocket API of ngx_lua, so the options didn't satisfy me.
local dns = require "picodns"
-- custom DNS endpoints can be used
-- normally it uses cloudflare, google and quad9
local resolver = dns.newResolver({ "1.1.1.1" })
-- blocking DNS query
local data, err = resolver:query("lua.org")
if err then
error(err)
end
-- when called in a coroutine,
-- it becomes a non-blocking call
local co = coroutine.create(function()
local answers, err = resolver:query("luajit.org")
if err then
error(err)
end
for _, answer in ipairs(answers) do
print(string.format("%s => %s", answer.name, answer.content))
end
end)
-- so you have to wait 'till it's done,
-- good thing is you can do your other fancy stuff in this loop concurrently!
repeat
local status = coroutine.resume(co)
print "do other work here!"
until not status
git clone git@github.com:nikneym/picodns.git
in your project directory and include it
local dns = require "picodns"
Will be added to GitHub wiki page. How-to
section mostly explains it though.
You need busted in order to run the tests.
GNU General Public License v3.0, check out license.