# HG changeset patch # User Kim Alvefur # Date 1638404095 -3600 # Node ID b5b799a2a10c29535ccae99773123de37d353865 # Parent 83bec90a352c7d7630c27aa035bd374ca2295161 util.id: Adjust entropy levels, with rationales Modules using ids for logging should not need the now pretty large medium one. diff -r 83bec90a352c -r b5b799a2a10c net/server_epoll.lua --- a/net/server_epoll.lua Tue Oct 05 18:15:06 2021 +0200 +++ b/net/server_epoll.lua Thu Dec 02 01:14:55 2021 +0100 @@ -26,7 +26,7 @@ local inet = require "util.net"; local inet_pton = inet.pton; local _SOCKETINVALID = socket._SOCKETINVALID or -1; -local new_id = require "util.id".medium; +local new_id = require "util.id".short; local xpcall = require "util.xpcall".xpcall; local poller = require "util.poll" diff -r 83bec90a352c -r b5b799a2a10c net/unbound.lua --- a/net/unbound.lua Tue Oct 05 18:15:06 2021 +0200 +++ b/net/unbound.lua Thu Dec 02 01:14:55 2021 +0100 @@ -18,7 +18,7 @@ local net_server = require "net.server"; local libunbound = require"lunbound"; local promise = require"util.promise"; -local new_id = require "util.id".medium; +local new_id = require "util.id".short; local gettime = require"socket".gettime; local dns_utils = require"util.dns"; diff -r 83bec90a352c -r b5b799a2a10c plugins/mod_scansion_record.lua --- a/plugins/mod_scansion_record.lua Tue Oct 05 18:15:06 2021 +0200 +++ b/plugins/mod_scansion_record.lua Thu Dec 02 01:14:55 2021 +0100 @@ -8,7 +8,7 @@ local dm = require "util.datamanager"; local st = require "util.stanza"; -local record_id = id.medium():lower(); +local record_id = id.short():lower(); local record_date = os.date("%Y%b%d"):lower(); local header_file = dm.getpath(record_id, "scansion", record_date, "scs", true); local record_file = dm.getpath(record_id, "scansion", record_date, "log", true); diff -r 83bec90a352c -r b5b799a2a10c util/id.lua --- a/util/id.lua Tue Oct 05 18:15:06 2021 +0200 +++ b/util/id.lua Thu Dec 02 01:14:55 2021 +0100 @@ -17,9 +17,20 @@ end return { - short = function () return b64url_random(6); end; - medium = function () return b64url_random(12); end; - long = function () return b64url_random(24); end; + -- sizes divisible by 3 fit nicely into base64 without padding== + + -- close to 8 bytes, should be good enough for relatively short lived or uses + -- scoped by host or users, half the size of an uuid + short = function() return b64url_random(9); end; + + -- more entropy than uuid at 2/3 the size + -- should be okay for globally scoped ids or security token + medium = function() return b64url_random(18); end; + + -- as long as an uuid but MOAR entropy + long = function() return b64url_random(27); end; + + -- pick your own adventure custom = function (size) return function () return b64url_random(size); end; end;