Comparison

net/dns.lua @ 6464:737c81bd898e

Merge 0.9->0.10
author Kim Alvefur <zash@zash.se>
date Sun, 05 Oct 2014 15:37:21 +0200
parent 6312:1940a014aeca
parent 6463:460584257cc9
child 6510:8273236a995f
comparison
equal deleted inserted replaced
6460:6d3187f24608 6464:737c81bd898e
133 end 133 end
134 134
135 135
136 local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune 136 local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune
137 time = time or socket.gettime(); 137 time = time or socket.gettime();
138 for i,rr in pairs(rrs) do 138 for i,rr in ipairs(rrs) do
139 if rr.tod then 139 if rr.tod then
140 -- rr.tod = rr.tod - 50 -- accelerated decripitude 140 -- rr.tod = rr.tod - 50 -- accelerated decripitude
141 rr.ttl = math.floor(rr.tod - time); 141 rr.ttl = math.floor(rr.tod - time);
142 if rr.ttl <= 0 then 142 if rr.ttl <= 0 then
143 rrs[rr[rr.type:lower()]] = nil;
143 table.remove(rrs, i); 144 table.remove(rrs, i);
144 return prune(rrs, time, soft); -- Re-iterate 145 return prune(rrs, time, soft); -- Re-iterate
145 end 146 end
146 elseif soft == 'soft' then -- What is this? I forget! 147 elseif soft == 'soft' then -- What is this? I forget!
147 assert(rr.ttl == 0); 148 assert(rr.ttl == 0);
148 rrs[i] = nil; 149 rrs[rr[rr.type:lower()]] = nil;
150 table.remove(rrs, i);
149 end 151 end
150 end 152 end
151 end 153 end
152 154
153 155
186 188
187 189
188 local rrs_metatable = {}; -- - - - - - - - - - - - - - - - - - rrs_metatable 190 local rrs_metatable = {}; -- - - - - - - - - - - - - - - - - - rrs_metatable
189 function rrs_metatable.__tostring(rrs) 191 function rrs_metatable.__tostring(rrs)
190 local t = {}; 192 local t = {};
191 for i,rr in pairs(rrs) do 193 for i,rr in ipairs(rrs) do
192 append(t, tostring(rr)..'\n'); 194 append(t, tostring(rr)..'\n');
193 end 195 end
194 return table.concat(t); 196 return table.concat(t);
195 end 197 end
196 198
679 end 681 end
680 682
681 self.cache = self.cache or setmetatable({}, cache_metatable); 683 self.cache = self.cache or setmetatable({}, cache_metatable);
682 local rrs = get(self.cache, qclass, type, qname) or 684 local rrs = get(self.cache, qclass, type, qname) or
683 set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); 685 set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable));
684 append(rrs, rr); 686 if not rrs[rr[qtype:lower()]] then
687 rrs[rr[qtype:lower()]] = true;
688 append(rrs, rr);
689 end
685 690
686 if type == 'MX' then self.unsorted[rrs] = true; end 691 if type == 'MX' then self.unsorted[rrs] = true; end
687 end 692 end
688 693
689 694