@@ -57,6 +57,8 @@ type GossipEvent = {eventType: Text, pubkey: Text, server: Text, timestamp: Int,
58*forwards : [{messageId: Text, toServer: Text, createdAt: Int}]
58*forwards : [{messageId: Text, toServer: Text, createdAt: Int}]
60+*ackedIds : [{messageId: Text, toKey: Text, ackedAt: Int}]
60-- ============================================
62-- ============================================
62-- ============================================
64-- ============================================
@@ -256,6 +258,7 @@ containsLocalhostSuffix = \s ->
256isBadServerName = \s ->
258isBadServerName = \s ->
257 let sn = toLower (stripTrailingDot s)
259 let sn = toLower (stripTrailingDot s)
259 || containsBadUrlChar sn
262 || containsBadUrlChar sn
260 || sn == "localhost" || take 10 sn == "localhost:"
263 || sn == "localhost" || take 10 sn == "localhost:"
261 || sn == "localhost.localdomain" || take 22 sn == "localhost.localdomain:"
264 || sn == "localhost.localdomain" || take 22 sn == "localhost.localdomain:"
@@ -364,6 +367,11 @@ pruneExpired = \t -> do
364 f <- forwards
367 f <- forwards
365 where f.createdAt >= t - messageMaxAge
368 where f.createdAt >= t - messageMaxAge
370+ ackedIds <- *ackedIds
373+ where a.ackedAt >= t - messageMaxAge
367 yield {expiredLocal: (do
375 yield {expiredLocal: (do
368 p <- presenceBefore
376 p <- presenceBefore
369 where p.expiresAt <= t
377 where p.expiresAt <= t
@@ -692,6 +700,13 @@ serve = \req -> case req of
692 set *messages = case session of
700 set *messages = case session of
693 Nothing {} -> messages
701 Nothing {} -> messages
694 Just {value: _} -> diff messages ackedMessages
702 Just {value: _} -> diff messages ackedMessages
703+ let ackedFederated = do
705+ where not (m.originServer == "")
706+ where not (m.originServer == serverHost)
707+ yield {messageId: m.messageId, toKey: m.toKey, ackedAt: t}
708+ ackedIds <- *ackedIds
709+ set *ackedIds = union ackedIds ackedFederated
695 let ok = case session of
710 let ok = case session of
696 Nothing {} -> False {}
711 Nothing {} -> False {}
697 _ -> True {}
712 _ -> True {}
@@ -966,7 +981,7 @@ serve = \req -> case req of
966 let effectiveEvents = do
981 let effectiveEvents = do
967 e <- validEvents
982 e <- validEvents
968 where count (do a <- gossipResult.appliedKeys; where a.pubkey == normalizeHex e.pubkey; where a.server == normalizeServerName e.server; yield a) > 0
983 where count (do a <- gossipResult.appliedKeys; where a.pubkey == normalizeHex e.pubkey; where a.server == normalizeServerName e.server; yield a) > 0
969− yield {eventType: e.eventType, pubkey: normalizeHex e.pubkey, server: normalizeServerName e.server, timestamp: e.timestamp, ttl: e.ttl}
984+ yield {eventType: e.eventType, pubkey: normalizeHex e.pubkey, server: normalizeServerName e.server, timestamp: e.timestamp, ttl: clampTtl e.ttl}
970 respond {ok: validRequest}
985 respond {ok: validRequest}
971 if not gossipResult.withinCapacity
986 if not gossipResult.withinCapacity
972 then println ("gossip: presence at capacity (" ++ show maxPresenceEntries ++ "), limiting new entries from " ++ fromServer)
987 then println ("gossip: presence at capacity (" ++ show maxPresenceEntries ++ "), limiting new entries from " ++ fromServer)
@@ -1008,12 +1023,19 @@ serve = \req -> case req of
1008 where m.toKey == toKey
1023 where m.toKey == toKey
1009 where m.receivedAt >= t - messageMaxAge
1024 where m.receivedAt >= t - messageMaxAge
1010 yield m)
1025 yield m)
1011− let exists = count (do
1026+ let existsInMessages = count (do
1012 m <- messages
1027 m <- messages
1013 where m.messageId == messageId
1028 where m.messageId == messageId
1014 where m.toKey == toKey
1029 where m.toKey == toKey
1015 where m.receivedAt >= t - messageMaxAge
1030 where m.receivedAt >= t - messageMaxAge
1016 yield m) > 0
1031 yield m) > 0
1032+ ackedIds <- *ackedIds
1033+ let existsInAcked = count (do
1035+ where a.messageId == messageId
1036+ where a.toKey == toKey
1038+ let exists = existsInMessages || existsInAcked
1017 let shouldInsert = authorized && validOrigin && validFields && not exists && recipientMsgCount < maxMessagesPerRecipient
1039 let shouldInsert = authorized && validOrigin && validFields && not exists && recipientMsgCount < maxMessagesPerRecipient
1018 set *seqCounter = if shouldInsert then seqTs else seqCounter
1040 set *seqCounter = if shouldInsert then seqTs else seqCounter
1019 set *messages = if shouldInsert
1041 set *messages = if shouldInsert