on master help sign in
Simplify helpers: drop mod check, inline let bindings, flatten expressions
commiteb0684c4b81df9330da8510e1b406fd652a143fd authoriko <mail@iko.soy> dateMon 27 Apr 2026, 13:12 (6 months ago) parent7687a69
1 file changed+5−7
server.knot+5−7
server.knot+5−7
@@ -540,7 +540,7 @@ mapEach = \items getKey action -> case headOf items of
540540
541541-- Hex tokens: one random hex char per recursive call.
542542hexDigit : Int -> Text
543−hexDigit = \n -> take 1 (drop (mod n 16) "0123456789abcdef")
543+hexDigit = \n -> take 1 (drop n "0123456789abcdef")
544544
545545genTokenN = \n -> if n <= 0 then yield "" else do
546546 d <- randomInt 16
@@ -553,7 +553,7 @@ tooLong : Text -> Int -> Bool
553553tooLong = \s maxLen -> count (chars s) > maxLen
554554
555555isValidHex : Text -> Bool
556−isValidHex = \s -> let cs = chars s in count cs > 0 && mod (count cs) 2 == 0 && all cs (\c -> contains c "0123456789abcdef")
556+isValidHex = \s -> count (chars s) > 0 && mod (count (chars s)) 2 == 0 && all (chars s) (\c -> contains c "0123456789abcdef")
557557
558558normalizeHex : Text -> Text
559559normalizeHex = \s -> bytesToHex (bytesFromHex s)
@@ -574,8 +574,7 @@ hasPrefix = \pre s -> take (count (chars pre)) s == pre
574574
575575containsSuffix : Text -> Text -> Bool
576576containsSuffix = \suffix s ->
577− let d = count (chars s) - count (chars suffix) in
578− d >= 0 && drop d s == suffix
577+ drop (max 0 (count (chars s) - count (chars suffix))) s == suffix
579578
580579-- Block private/reserved/internal hostnames (SSRF defense). Skips obscure encoding
581580-- tricks (octal, hex, percent-encoding) but covers the high-value cases.
@@ -826,9 +825,8 @@ knownPeerServersFromPresence = \presence -> collectPeers presence (\p -> p.serve
826825-- Last-write-wins merge by (pubkey, server), keeping the entry with the larger expiresAt.
827826mergePresence = \existing incoming ->
828827 fold (\acc e ->
829− let same = \x -> x.pubkey == e.pubkey && x.server == e.server in
830− if any acc (\x -> same x && x.expiresAt >= e.expiresAt) then acc
831− else union (removeWhere acc same) [e]) existing incoming
828+ if any acc (\x -> x.pubkey == e.pubkey && x.server == e.server && x.expiresAt >= e.expiresAt) then acc
829+ else union (removeWhere acc (\x -> x.pubkey == e.pubkey && x.server == e.server)) [e]) existing incoming
832830
833831-- ============================================
834832-- Pruning