on master help sign in
Simplify server code: reuse removeOffline result for appliedOffline, remove unused PruneResult type
commit0c01684669d23bd7adb3031ed0f0cf565c623656 authoriko <mail@iko.soy> dateFri 10 Apr 2026, 19:35 (6 months ago) parenta6088f1
12 files changed+20−25
client/ApiClient.fs+4−5 client/App.fs+11−8 client/bin/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.dll client/bin/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.pdb client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfo.fs+1−1 client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfoInputs.cache+1−1 client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.dll client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.pdb client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.sourcelink.json+1−1 client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/ref/Skrepka.dll client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/refint/Skrepka.dll server.knot+2−9
client/ApiClient.fs+4−5
@@ -12,7 +12,7 @@ module ApiClient =
1212 [<CLIMutable>]
1313 type EventPayload = { EncryptedBlob: string; Timestamp: int64 }
1414
15− type EventType = Message | UnknownEvent of string
15+ type EventType = Message | Ack | UnknownEvent of string
1616
1717 [<CLIMutable>]
1818 type PollEvent = { Id: string; EventType: EventType; Payload: EventPayload }
@@ -66,11 +66,13 @@ module ApiClient =
6666 override _.Read(reader, _, _) =
6767 match reader.GetString() with
6868 | "message" -> Message
69+ | "ack" -> Ack
6970 | s -> UnknownEvent s
7071 override _.Write(writer, value, _) =
7172 writer.WriteStringValue(
7273 match value with
7374 | Message -> "message"
75+ | Ack -> "ack"
7476 | UnknownEvent s -> s)
7577
7678 let private jsonOpts =
@@ -128,10 +130,7 @@ module ApiClient =
128130
129131 let poll (serverUrl: string) (token: string) (cursor: int64) =
130132 let body = JsonSerializer.Serialize({| cursor = cursor; timeout = 30000 |})
131− async {
132− let! response = postJson<PollResponse> pollClient $"{serverUrl}/poll" body (Some token)
133− return { response with Events = response.Events |> Array.filter (fun e -> e.EventType = Message) }
134− }
133+ postJson<PollResponse> pollClient $"{serverUrl}/poll" body (Some token)
135134
136135 let ackMessages (serverUrl: string) (token: string) (messageIds: string list) =
137136 let body = JsonSerializer.Serialize({| messageIds = messageIds |})
client/App.fs+11−8
@@ -137,7 +137,8 @@ module App =
137137
138138 let private tryParsePubkey (input: string) =
139139 let input = input.Trim()
140− (Phonemic.fromOb input |> Option.orElseWith (fun () -> Crypto.tryFromHex input))
140+ Phonemic.fromOb input
141+ |> Option.orElseWith (fun () -> Crypto.tryFromHex input)
141142 |> Option.filter (fun bytes -> bytes.Length = 32)
142143
143144 let private contactName (contacts: Contact list) (pk: string) =
@@ -287,10 +288,9 @@ module App =
287288 | _ -> model, []
288289
289290 | CopyPubKey ->
290− model,
291− [ match model.Auth with
292− | Identified(id, _) -> CmdCopyToClipboard(hexToOb id.PubKeyHex)
293− | NoIdentity -> () ]
291+ match model.Auth with
292+ | Identified(id, _) -> model, [ CmdCopyToClipboard(hexToOb id.PubKeyHex) ]
293+ | NoIdentity -> model, []
294294
295295 | DismissError -> { model with Error = None }, []
296296
@@ -381,9 +381,12 @@ module App =
381381 let messages, errors =
382382 Array.foldBack
383383 (fun (evt: PollEvent) (msgs, errs) ->
384− match decryptEvent session.Identity.PrivKey evt.Payload with
385− | Ok msg -> (msg :: msgs, errs)
386− | Error err -> (msgs, err :: errs))
384+ match evt.EventType with
385+ | Message ->
386+ match decryptEvent session.Identity.PrivKey evt.Payload with
387+ | Ok msg -> (msg :: msgs, errs)
388+ | Error err -> (msgs, err :: errs)
389+ | Ack | UnknownEvent _ -> (msgs, errs))
387390 response.Events
388391 ([], [])
389392
client/bin/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.dll

Binary file not shown.

client/bin/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.pdb

Binary file not shown.

client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfo.fs+1−1
@@ -10,7 +10,7 @@ open System.Reflection
1010[<assembly: System.Reflection.AssemblyCompanyAttribute("Skrepka")>]
1111[<assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")>]
1212[<assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")>]
13−[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0+6b1d74aecd0ed0fb71c97a95acff19b5fb9bf149")>]
13+[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0+a6088f11f8b9f333baecd765cfde004d371fea16")>]
1414[<assembly: System.Reflection.AssemblyProductAttribute("Skrepka")>]
1515[<assembly: System.Reflection.AssemblyTitleAttribute("Skrepka")>]
1616[<assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")>]
client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.AssemblyInfoInputs.cache+1−1
@@ -1 +1 @@
1−da506a85f5b894cd8a51d8e06d0587022d2d4a29f8441cc3975ed09d776ba256
1+c792c6af7fcf4a9f3bc9ffab40c693a5335abf2b4bd4c1fd73018e15acd8228b
client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.dll

Binary file not shown.

client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.pdb

Binary file not shown.

client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/Skrepka.sourcelink.json+1−1
@@ -1 +1 @@
1−{"documents":{"/Users/iko/Developer/skrepka/*":"https://raw.githubusercontent.com/ilyakooo0/skrepka/6b1d74aecd0ed0fb71c97a95acff19b5fb9bf149/*"}}
1+{"documents":{"/Users/iko/Developer/skrepka/*":"https://raw.githubusercontent.com/ilyakooo0/skrepka/a6088f11f8b9f333baecd765cfde004d371fea16/*"}}
client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/ref/Skrepka.dll

Binary file not shown.

client/obj/Debug/net10.0-maccatalyst/maccatalyst-arm64/refint/Skrepka.dll

Binary file not shown.

server.knot+2−9
@@ -115,7 +115,6 @@ type PresenceEntry = {pubkey: PubkeyHex, server: AnyServerName, expiresAt: Times
115115type ForwardEntry = {messageId: MessageIdHex, toServer: ServerName, createdAt: Timestamp, toKey: PubkeyHex, fromKey: PubkeyHex, encryptedBlob: BlobHex, timestamp: Timestamp}
116116type AckedEntry = {messageId: MessageIdHex, toKey: PubkeyHex, ackedAt: Timestamp, originServer: ServerName}
117117type AuthResult = Authorized {pubkey: PubkeyHex} | Unauthorized {}
118−type PruneResult = {expiredLocal: [PresenceEntry], peerServers: [ServerName]}
119118type SendResult = SendUnauthorized {} | SendRejected {} | SendDone {status: MessageStatus, remoteServers: [ServerName], fromKey: PubkeyHex}
120119
121120
@@ -943,10 +942,7 @@ serve = \req -> case req of
943942 e <- offlineEntries
944943 where none onlineEntries (\o -> samePubkeyServer o e && o.timestamp > e.timestamp)
945944 yield e
946− let trustedOffline = do
947− e <- allValidEntries
948− where not (isGossipOnline e.eventType) && e.server == fromServer
949− yield e
945+ let trustedOffline = do e <- offlineEntries; where e.server == fromServer; yield e
950946 let deduped = mergeByPubkeyServer [] filteredOnline
951947 gossipResult <- atomic do
952948 pr <- maybePrune t
@@ -964,11 +960,8 @@ serve = \req -> case req of
964960 e <- allValidEntries
965961 where none trustedDeduped (\d -> samePubkeyServer d e)
966962 yield e
967− let appliedOffline = do
968− k <- offlineOnlyKeys
969− where any presence (\p -> samePubkeyServer p k && any trustedOffline (\o -> samePubkeyServer o k && (if o.timestamp > t then t else o.timestamp) > p.timestamp))
970− yield {pubkey: k.pubkey, server: k.server}
971963 let afterOffline = removeOffline merged offlineOnlyKeys trustedOffline t
964+ let appliedOffline = do p <- diff merged afterOffline; yield {pubkey: p.pubkey, server: p.server}
972965 let capResult = capGossipPresence afterOffline appliedOnline trustedDeduped presence offlineOnlyKeys trustedOffline t
973966 set *presence = capResult.finalPresence
974967 let gossipPeerServers = collectPeerServers capResult.finalPresence (\p -> p.server)