on master help sign in
Fix 4 bugs: remove dead code, handle long strings in safeCompare, parallelize federation I/O, prevent overlapping prune cycles
55073b2iko
server.knot+19−24
@@ -236,12 +236,6 @@ isAllDigitsOrDotsUntilColonOrEnd = \s ->
236 else if isDigitChar (take 1 s) || take 1 s == "." then isAllDigitsOrDotsUntilColonOrEnd (drop 1 s)
236 else if isDigitChar (take 1 s) || take 1 s == "." then isAllDigitsOrDotsUntilColonOrEnd (drop 1 s)
237 else False {}
237 else False {}
238
238
239−isAllDigitsUntilColonOrEnd = \s ->
240− if s == "" then True {}
241− else if take 1 s == ":" then True {}
242− else if isDigitChar (take 1 s) then isAllDigitsUntilColonOrEnd (drop 1 s)
243− else False {}
244−
245toLowerChar = \c ->
239toLowerChar = \c ->
246 if c == "A" then "a" else if c == "B" then "b" else if c == "C" then "c"
240 if c == "A" then "a" else if c == "B" then "b" else if c == "C" then "c"
247 else if c == "D" then "d" else if c == "E" then "e" else if c == "F" then "f"
241 else if c == "D" then "d" else if c == "E" then "e" else if c == "F" then "f"
@@ -393,8 +387,8 @@ evictOldestAckedIds = \items n ->
393 in diff items toEvict
387 in diff items toEvict
394
388
395safeCompareLoop = \s1 s2 n result ->
389safeCompareLoop = \s1 s2 n result ->
396− if n <= 0
390+ if n <= 0 && s1 == "" && s2 == ""
397− then result + (if s1 == "" then 0 else 1) + (if s2 == "" then 0 else 1)
391+ then result
398 else safeCompareLoop (drop 1 s1) (drop 1 s2) (n - 1) (result + (if take 1 s1 == take 1 s2 then 0 else 1))
392 else safeCompareLoop (drop 1 s1) (drop 1 s2) (n - 1) (result + (if take 1 s1 == take 1 s2 then 0 else 1))
399
393
400safeCompare = \a b ->
394safeCompare = \a b ->
@@ -410,7 +404,7 @@ sendToEach = \servers action ->
410 if server == ""
404 if server == ""
411 then yield {}
405 then yield {}
412 else do
406 else do
413− action server
407+ fork (action server)
414 sendToEach rest action
408 sendToEach rest action
415
409
416pruneExpired = \t -> do
410pruneExpired = \t -> do
@@ -551,20 +545,21 @@ sendAcksAndClean = \pendingAcks servers ->
551 if server == ""
545 if server == ""
552 then yield {}
546 then yield {}
553 else do
547 else do
548+ fork (do
554− let serverAcks = do a <- pendingAcks; where a.originServer == server; yield a
549+ let serverAcks = do a <- pendingAcks; where a.originServer == server; yield a
555− result <- fetch (federationScheme ++ server) (FederationAck {
550+ result <- fetch (federationScheme ++ server) (FederationAck {
556− authorization: "Bearer " ++ federationSecret,
551+ authorization: "Bearer " ++ federationSecret,
557− messageIds: (do a <- serverAcks; yield a.messageId),
552+ messageIds: (do a <- serverAcks; yield a.messageId),
558− originServer: server, fromServer: serverHostN})
553+ originServer: server, fromServer: serverHostN})
559− case result of
554+ case result of
560− Ok _ ->
555+ Ok _ ->
561− atomic do
556+ atomic do
562− ackedIds <- *ackedIds
557+ ackedIds <- *ackedIds
563− set *ackedIds = do
558+ set *ackedIds = do
564− a <- ackedIds
559+ a <- ackedIds
565− where not (a.originServer == server && count (do sa <- serverAcks; where sa.messageId == a.messageId; where sa.toKey == a.toKey; yield sa) > 0)
560+ where not (a.originServer == server && count (do sa <- serverAcks; where sa.messageId == a.messageId; where sa.toKey == a.toKey; yield sa) > 0)
566− yield a
561+ yield a
567− Err _ -> yield {}
562+ Err _ -> yield {})
568 sendAcksAndClean pendingAcks rest
563 sendAcksAndClean pendingAcks rest
569
564
570pollOnce = \token cursor -> do
565pollOnce = \token cursor -> do
@@ -1378,7 +1373,6 @@ backgroundPrune = do
1378 where not (a.originServer == serverHostN)
1373 where not (a.originServer == serverHostN)
1379 yield a
1374 yield a
1380 yield {expiredLocal: pr.expiredLocal, peerServers: pr.peerServers, pendingForwards: pendingForwards, pendingAcks: pendingAcks}
1375 yield {expiredLocal: pr.expiredLocal, peerServers: pr.peerServers, pendingForwards: pendingForwards, pendingAcks: pendingAcks}
1381− fork backgroundPrune
1382 broadcastOfflineGossip t result.peerServers result.expiredLocal
1376 broadcastOfflineGossip t result.peerServers result.expiredLocal
1383 if not (federationSecret == "") && count result.pendingForwards > 0
1377 if not (federationSecret == "") && count result.pendingForwards > 0
1384 then retryPendingForwards result.pendingForwards
1378 then retryPendingForwards result.pendingForwards
@@ -1390,6 +1384,7 @@ backgroundPrune = do
1390 else union acc [a.originServer]) [] result.pendingAcks
1384 else union acc [a.originServer]) [] result.pendingAcks
1391 sendAcksAndClean result.pendingAcks ackOriginServers
1385 sendAcksAndClean result.pendingAcks ackOriginServers
1392 else yield {}
1386 else yield {}
1387+ fork backgroundPrune
1393
1388
1394main = do
1389main = do
1395 println "Skrepka relay server starting on port 8080..."
1390 println "Skrepka relay server starting on port 8080..."