added caching for complex lookups

This commit is contained in:
2020-12-29 13:15:27 -05:00
parent bce23ab9fe
commit 1ff7d3cb4f
5 changed files with 230 additions and 27 deletions
+30
View File
@@ -0,0 +1,30 @@
local socket = assert(require "socket.unix"())
local function connect(path)
assert(socket:settimeout(.05))
local status,err = pcall(function() assert(socket:connect(path)) end)
if status then return true end
io.stderr:write(err.." ("..path..")\n")
return false
end
local json = require "lunajson"
local res
if connect("/var/run/proxy_lookup.socket") then
host = "payments.blah.com"
assert(socket:send(json.encode({domain = host})))
while 1 do
local s, status, partial = socket:receive()
if partial then
res = json.decode(partial)
break
end
end
end
print(res['ip'])