Software /
code /
prosody
Comparison
net/dns.lua @ 8151:2c65f8be38aa
net.dns: Simplify expiry calculation (fixes #919)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 22 May 2017 05:32:11 +0200 |
parent | 7093:388281be2bc7 |
child | 8154:6300394bb713 |
child | 8163:a55eb6c3b45c |
comparison
equal
deleted
inserted
replaced
8093:8d1fd6d34bda | 8151:2c65f8be38aa |
---|---|
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 ipairs(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 if rr.tod < time then |
141 rr.ttl = math.floor(rr.tod - time); | |
142 if rr.ttl <= 0 then | |
143 rrs[rr[rr.type:lower()]] = nil; | 141 rrs[rr[rr.type:lower()]] = nil; |
144 table.remove(rrs, i); | 142 table.remove(rrs, i); |
145 return prune(rrs, time, soft); -- Re-iterate | 143 return prune(rrs, time, soft); -- Re-iterate |
146 end | 144 end |
147 elseif soft == 'soft' then -- What is this? I forget! | 145 elseif soft == 'soft' then -- What is this? I forget! |
513 rr.type = dns.type[self:word()] or rr.type; | 511 rr.type = dns.type[self:word()] or rr.type; |
514 rr.class = dns.class[self:word()] or rr.class; | 512 rr.class = dns.class[self:word()] or rr.class; |
515 rr.ttl = 0x10000*self:word() + self:word(); | 513 rr.ttl = 0x10000*self:word() + self:word(); |
516 rr.rdlength = self:word(); | 514 rr.rdlength = self:word(); |
517 | 515 |
518 if rr.ttl <= 0 then | 516 rr.tod = self.time + rr.ttl; |
519 rr.tod = self.time + 30; | |
520 else | |
521 rr.tod = self.time + rr.ttl; | |
522 end | |
523 | 517 |
524 local remember = self.offset; | 518 local remember = self.offset; |
525 local rr_parser = self[dns.type[rr.type]]; | 519 local rr_parser = self[dns.type[rr.type]]; |
526 if rr_parser then rr_parser(self, rr); end | 520 if rr_parser then rr_parser(self, rr); end |
527 self.offset = remember; | 521 self.offset = remember; |