mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Precalc/reuse some tables and values
This commit is contained in:
@@ -108,7 +108,10 @@ function enc (p, hexExtend)
|
||||
end
|
||||
|
||||
|
||||
local db32table_standard = setmetatable({}, {__index = function (t, k) error "invalid encoding: invalid character" end})
|
||||
local db32metatable = {
|
||||
__index = function (t, k) error "invalid encoding: invalid character" end
|
||||
}
|
||||
local db32table_standard = setmetatable({}, db32metatable)
|
||||
do
|
||||
local r = {["="] = 0}
|
||||
for i, v in ipairs(b32standard) do
|
||||
@@ -118,7 +121,7 @@ do
|
||||
db32table_standard[i] = r[char(i)]
|
||||
end
|
||||
end
|
||||
local db32table_hex = setmetatable({}, {__index = function (t, k) error "invalid encoding: invalid character" end})
|
||||
local db32table_hex = setmetatable({}, db32metatable)
|
||||
do
|
||||
local r = {["="] = 0}
|
||||
for i, v in ipairs(b32hexExtend) do
|
||||
|
||||
@@ -62,6 +62,7 @@ DHCP6.OptionTypes = {
|
||||
OPTION_CLIENT_FQDN = 0x27,
|
||||
}
|
||||
|
||||
local DHCP6_EPOCH = os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0})
|
||||
-- DHCP6 options
|
||||
DHCP6.Option = {
|
||||
|
||||
@@ -110,7 +111,7 @@ DHCP6.Option = {
|
||||
type = DHCP6.OptionTypes.OPTION_CLIENTID,
|
||||
duid = duid or 1,
|
||||
hwtype = hwtype or 1,
|
||||
time = time or os.time() - os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0}),
|
||||
time = time or os.time() - DHCP6_EPOCH,
|
||||
mac = mac,
|
||||
}
|
||||
setmetatable(o, self)
|
||||
@@ -131,7 +132,7 @@ DHCP6.Option = {
|
||||
end
|
||||
opt.hwtype, opt.time = string.unpack(">I2I4", data, pos)
|
||||
opt.mac = data:sub(pos)
|
||||
opt.time = opt.time + os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0})
|
||||
opt.time = opt.time + DHCP6_EPOCH
|
||||
return opt
|
||||
end,
|
||||
|
||||
|
||||
@@ -1034,19 +1034,19 @@ local function cmp_last_used (r1, r2)
|
||||
return (r1.last_used or 0) < (r2.last_used or 0);
|
||||
end
|
||||
|
||||
local arg_max_cache_size = tonumber(stdnse.get_script_args({'http.max-cache-size', 'http-max-cache-size'}) or 1e6);
|
||||
local function check_size (cache)
|
||||
local max_size = tonumber(stdnse.get_script_args({'http.max-cache-size', 'http-max-cache-size'}) or 1e6);
|
||||
|
||||
local size = cache.size;
|
||||
|
||||
if size > max_size then
|
||||
if size > arg_max_cache_size then
|
||||
stdnse.debug1(
|
||||
"Current http cache size (%d bytes) exceeds max size of %d",
|
||||
size, max_size);
|
||||
size, arg_max_cache_size);
|
||||
table.sort(cache, cmp_last_used);
|
||||
|
||||
for i, record in ipairs(cache) do
|
||||
if size <= max_size then break end
|
||||
if size <= arg_max_cache_size then break end
|
||||
local result = record.result;
|
||||
if type(result.body) == "string" then
|
||||
size = size - record.size;
|
||||
@@ -1056,7 +1056,7 @@ local function check_size (cache)
|
||||
cache.size = size;
|
||||
end
|
||||
stdnse.debug2("Final http cache size (%d bytes) of max size of %d",
|
||||
size, max_size);
|
||||
size, arg_max_cache_size);
|
||||
return size;
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user