@@ -545,22 +545,16 @@ mapEach = \items getKey action -> case headOf items of
545545 rest <- mapEach (filter items (\y -> getKey y != getKey x)) getKey action
546546 yield (union [r] rest)
547547
548−-- Hex tokens (callers just pass raw bits).
548+-- Hex tokens: one random hex char per recursive call.
549549hexDigit : Int -> Text
550550hexDigit = \n -> take 1 (drop (mod n 16) "0123456789abcdef")
551551
552−byteToHex : Int -> Text
553−byteToHex = \n -> hexDigit (n / 16) ++ hexDigit n
554−
555−intTo3Hex : Int -> Text
556−intTo3Hex = \n -> byteToHex (n / 65536) ++ byteToHex (n / 256) ++ byteToHex n
557−
558552genTokenN = \n -> if n <= 0 then yield "" else do
559− chunk <- randomInt 16777216
553+ d <- randomInt 16
560554 rest <- genTokenN (n - 1)
561− yield (intTo3Hex chunk ++ rest)
555+ yield (hexDigit d ++ rest)
562556
563−genToken = genTokenN 8
557+genToken = genTokenN 48
564558
565559tooLong : Text -> Int -> Bool
566560tooLong = \s maxLen -> count (chars s) > maxLen
@@ -568,7 +562,8 @@ tooLong = \s maxLen -> count (chars s) > maxLen
568562isValidHex : Text -> Bool
569563isValidHex = \s ->
570564 let cs = chars s in
571− count cs > 0 && mod (count cs) 2 == 0 && all cs (\c -> contains c "0123456789abcdef")
565+ let n = count cs in
566+ n > 0 && mod n 2 == 0 && all cs (\c -> contains c "0123456789abcdef")
572567
573568normalizeHex : Text -> Text
574569normalizeHex = \s -> bytesToHex (bytesFromHex s)
@@ -660,7 +655,7 @@ generateFederationAuth : Text -> Timestamp -> IO {network} Text
660655generateFederationAuth = \scope requestTimestamp ->
661656 if serverFederationPrivateKeyHex != ""
662657 then do
663− nonce <- genTokenN 8
658+ nonce <- genTokenN 48
664659 let message = textToBytes (scope ++ "|" ++ show requestTimestamp ++ "|" ++ serverHostN ++ "|" ++ nonce)
665660 let sig = sign (bytesFromHex serverFederationPrivateKeyHex) message
666661 yield ("Signed " ++ bytesToHex sig ++ ":" ++ nonce)
@@ -1888,7 +1883,15 @@ handleMetrics = \authorization respond -> do
18881883 aps <- *activePolls
18891884 sa <- *startedAt
18901885 dp <- *drainPhase
1891− let metrics = "skrepka_messages_total " ++ show (count msgs) ++ "\nskrepka_sessions_total " ++ show (count ses) ++ "\nskrepka_presence_total " ++ show (count pres) ++ "\nskrepka_forwards_total " ++ show (count fwds) ++ "\nskrepka_active_polls " ++ show (count aps) ++ "\nskrepka_uptime_seconds " ++ show ((t - sa) / 1000) ++ "\nskrepka_draining " ++ (if dp > 0 then "1" else "0") ++ "\n"
1886+ let rows = [
1887+ {k: "skrepka_messages_total", v: count msgs},
1888+ {k: "skrepka_sessions_total", v: count ses},
1889+ {k: "skrepka_presence_total", v: count pres},
1890+ {k: "skrepka_forwards_total", v: count fwds},
1891+ {k: "skrepka_active_polls", v: count aps},
1892+ {k: "skrepka_uptime_seconds", v: (t - sa) / 1000},
1893+ {k: "skrepka_draining", v: if dp > 0 then 1 else 0}]
1894+ let metrics = fold (\acc r -> acc ++ r.k ++ " " ++ show r.v ++ "\n") "" rows
18921895 yield (respond {metrics: metrics, ok: True {}})
18931896
18941897-- ============================================