aboutsummaryrefslogtreecommitdiffstats
path: root/net/dns.lua
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2014-10-05 14:28:40 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2014-10-05 14:28:40 +0200
commit121b64847546320d919c0fb4e8997e2d6813b714 (patch)
treefd47d58d7994b3839a524479b784a6b1cd7c9174 /net/dns.lua
parent0ccb1f50b0a19d478470156eec62f2fa1767ed0d (diff)
downloadprosody-121b64847546320d919c0fb4e8997e2d6813b714.tar.gz
prosody-121b64847546320d919c0fb4e8997e2d6813b714.zip
net.dns: Avoid duplicate cache entries
Diffstat (limited to 'net/dns.lua')
-rw-r--r--net/dns.lua13
1 files changed, 9 insertions, 4 deletions
diff --git a/net/dns.lua b/net/dns.lua
index 89bd3564..dc2da1b6 100644
--- a/net/dns.lua
+++ b/net/dns.lua
@@ -134,17 +134,19 @@ end
local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune
time = time or socket.gettime();
- for i,rr in pairs(rrs) do
+ for i,rr in ipairs(rrs) do
if rr.tod then
-- rr.tod = rr.tod - 50 -- accelerated decripitude
rr.ttl = math.floor(rr.tod - time);
if rr.ttl <= 0 then
+ rrs[rr[rr.type:lower()]] = nil;
table.remove(rrs, i);
return prune(rrs, time, soft); -- Re-iterate
end
elseif soft == 'soft' then -- What is this? I forget!
assert(rr.ttl == 0);
- rrs[i] = nil;
+ rrs[rr[rr.type:lower()]] = nil;
+ table.remove(rrs, i);
end
end
end
@@ -187,7 +189,7 @@ end
local rrs_metatable = {}; -- - - - - - - - - - - - - - - - - - rrs_metatable
function rrs_metatable.__tostring(rrs)
local t = {};
- for i,rr in pairs(rrs) do
+ for i,rr in ipairs(rrs) do
append(t, tostring(rr)..'\n');
end
return table.concat(t);
@@ -674,7 +676,10 @@ function resolver:remember(rr, type) -- - - - - - - - - - - - - - remember
self.cache = self.cache or setmetatable({}, cache_metatable);
local rrs = get(self.cache, qclass, type, qname) or
set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable));
- append(rrs, rr);
+ if not rrs[rr[qtype:lower()]] then
+ rrs[rr[qtype:lower()]] = true;
+ append(rrs, rr);
+ end
if type == 'MX' then self.unsorted[rrs] = true; end
end