mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Add pushed_at timestamps and per-topic retention
- Every message is stamped with the time its push arrived (UTC ms since 1970, the server's clock), carried as is by replication. Exposed in LatestMessage and Messages, BakaShrot_GetMessagePushedAt() in the DLL, Message.pushed_at / .pushed in Python, GetMessages --time, GetLatestMessage, and the messages view (pushed_at, pushed_utc). - [BakaShrot.Retention] in each server's config: a max age per topic, by name, id, pattern or *, ages like 30d or 1d12h. A background pass (Server/Storage/Retention.pbi, every RetentionInterval seconds) deletes what's older, in batches through the writer. node_heads is left as is, so ids never go back and peers don't resend what was deleted. - Replicated messages already past the receiver's max age are skipped on arrival, their head still raised so they aren't sent again. - Schema v6: data.pushed_at (older databases stamped at upgrade time), a (topic_id, pushed_at) index, the unused archives table dropped. The writer takes the next id from node_heads. - Folded into protocol 3, not released yet. - Tests/Retention-Test.ps1 (52 checks), Python checks for pushed_at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVPXGLs3KK1MAQn3ouP
This commit is contained in:
@@ -18,7 +18,8 @@ EndStructure
|
||||
#BakaShrot_ProtocolMagic = $42534854 ; "BSHT"
|
||||
; 2: topics and nodes by name (Commons/Networking/Names.pbi), see Design/Packets.md.
|
||||
; 3: the Hello sealed for the server, a key per connection, everything after
|
||||
; the ChallengeRequest encrypted (Connections.pbi).
|
||||
; the ChallengeRequest encrypted (Connections.pbi). Messages carry when
|
||||
; they were pushed (PushedAt).
|
||||
#BakaShrot_ProtocolVersion = 3
|
||||
|
||||
; Size in bytes of the nonce sent in a challenge request and echoed in its response.
|
||||
@@ -39,6 +40,16 @@ EndStructure
|
||||
; (#BakaShrot_Ed25519_SignatureSize).
|
||||
#BakaShrot_HandshakeSignatureSize = 64
|
||||
|
||||
; When a message was pushed: milliseconds since 1970-01-01 00:00:00 UTC, set
|
||||
; by the server it was pushed to, and kept as is by every server it's
|
||||
; replicated to. Anything outside 1 to #BakaShrot_MaxTimestamp (9999-12-31)
|
||||
; is invalid on the wire.
|
||||
#BakaShrot_MaxTimestamp = 253402300799999
|
||||
|
||||
Procedure.i BakaShrot_IsValidTimestamp(Timestamp.q)
|
||||
ProcedureReturn Bool(Timestamp >= 1 And Timestamp <= #BakaShrot_MaxTimestamp)
|
||||
EndProcedure
|
||||
|
||||
; Biggest packet accepted on the wire once authenticated, anything bigger
|
||||
; aborts the connection. Before that, only #BakaShrot_MaxHandshakePacketSize
|
||||
; (Connections.pbi).
|
||||
|
||||
@@ -8,12 +8,14 @@ XIncludeFile "../Packets.pbi"
|
||||
; S2C, answers a GetLatestMessage with the latest message of that topic/node combination.
|
||||
; TopicId, NodeId: the server's own ids for them.
|
||||
; TopicName, NodeName: their names, or their ids in digits if they have none.
|
||||
; PushedAt: when it was pushed, see Packets.pbi.
|
||||
Structure BakaShrot_LatestMessage Extends BakaShrot_PacketBase
|
||||
TopicId.l
|
||||
NodeId.l
|
||||
TopicName.s
|
||||
NodeName.s
|
||||
MessageId.q
|
||||
PushedAt.q
|
||||
JsonData.s
|
||||
EndStructure
|
||||
|
||||
@@ -56,6 +58,9 @@ Procedure.i BakaShrot_LatestMessagePacket_Encode(*Latest.BakaShrot_LatestMessage
|
||||
If MsgPackWriteInteger(*MsgPackData, *Latest\MessageId) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
If MsgPackWriteInteger(*MsgPackData, *Latest\PushedAt) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
|
||||
If MsgPackWriteString(*MsgPackData, *Latest\JsonData) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
@@ -139,6 +144,15 @@ Procedure.i BakaShrot_LatestMessagePacket_Decode(*MsgPackData.MsgPackData)
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
|
||||
; PushedAt
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_Integer
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
*Latest\PushedAt = MsgPackReadInteger(*MsgPackData)
|
||||
If MsgPackLastError(*MsgPackData) <> #MsgPack_Error_Success Or Not BakaShrot_IsValidTimestamp(*Latest\PushedAt)
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
|
||||
; JsonData
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_String
|
||||
Goto DecodeFailed
|
||||
|
||||
@@ -9,6 +9,8 @@ XIncludeFile "GetMessagesPacket.pbi"
|
||||
; One message of a Messages answer.
|
||||
Structure BakaShrot_MessagesEntry
|
||||
MessageId.q
|
||||
; When it was pushed, see Packets.pbi.
|
||||
PushedAt.q
|
||||
JsonData.s
|
||||
EndStructure
|
||||
|
||||
@@ -19,7 +21,7 @@ EndStructure
|
||||
; Encoded size of the answer's own fields, and of each message on top of its
|
||||
; JSON, rounded up. Used to stop an answer before it gets over #BakaShrot_MaxPacketSize.
|
||||
#BakaShrot_MessagesOverhead = 64 + 2 * (#BakaShrot_MaxNameLength + 2)
|
||||
#BakaShrot_MessagesMessageOverhead = 16
|
||||
#BakaShrot_MessagesMessageOverhead = 25
|
||||
|
||||
; S2C, answers a GetMessages with the messages of that topic/node combination
|
||||
; stored after the asked id, in message id order: as many as were asked for,
|
||||
@@ -91,6 +93,9 @@ Procedure.i BakaShrot_MessagesPacket_Encode(*Answer.BakaShrot_Messages, *OutSize
|
||||
If MsgPackWriteInteger(*MsgPackData, *Answer\Messages()\MessageId) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
If MsgPackWriteInteger(*MsgPackData, *Answer\Messages()\PushedAt) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
If MsgPackWriteString(*MsgPackData, *Answer\Messages()\JsonData) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
@@ -200,6 +205,15 @@ Procedure.i BakaShrot_MessagesPacket_Decode(*MsgPackData.MsgPackData)
|
||||
EndIf
|
||||
PreviousMessageId = *Answer\Messages()\MessageId
|
||||
|
||||
; PushedAt
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_Integer
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
*Answer\Messages()\PushedAt = MsgPackReadInteger(*MsgPackData)
|
||||
If MsgPackLastError(*MsgPackData) <> #MsgPack_Error_Success Or Not BakaShrot_IsValidTimestamp(*Answer\Messages()\PushedAt)
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
|
||||
; JsonData
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_String
|
||||
Goto DecodeFailed
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
XIncludeFile "../Packets.pbi"
|
||||
|
||||
; One message of a ReplicateMessages batch.
|
||||
; PushedAt: when it was pushed to its origin (Packets.pbi), stored as is.
|
||||
Structure BakaShrot_ReplicatedMessage
|
||||
MessageId.q
|
||||
PushedAt.q
|
||||
JsonData.s
|
||||
EndStructure
|
||||
|
||||
@@ -24,14 +26,14 @@ EndStructure
|
||||
; Encoded size of a batch's own fields, and of each message on top of its
|
||||
; JSON, rounded up. Used to stop a batch before it gets over #BakaShrot_MaxPacketSize.
|
||||
#BakaShrot_ReplicateBatchOverhead = 64 + 2 * (#BakaShrot_MaxNameLength + 2)
|
||||
#BakaShrot_ReplicateMessageOverhead = 16
|
||||
#BakaShrot_ReplicateMessageOverhead = 25
|
||||
|
||||
; Peer -> Server, messages the server is missing for one topic/node, in
|
||||
; message id order, with the message ids they were stored under on their
|
||||
; origin. Topic and Node are names, never ids (Commons/Networking/Names.pbi):
|
||||
; the server stores them under its own ids for those names, and refuses
|
||||
; names it doesn't know.
|
||||
; On the wire: topic, node, message count, then each message's id and JSON.
|
||||
; On the wire: topic, node, message count, then each message's id, PushedAt and JSON.
|
||||
; Answered with a MessagePushed carrying the last message's id, or a RequestRefused.
|
||||
Structure BakaShrot_ReplicateMessages Extends BakaShrot_PacketBase
|
||||
Topic.s
|
||||
@@ -79,6 +81,9 @@ Procedure.i BakaShrot_ReplicateMessagesPacket_Encode(*Batch.BakaShrot_ReplicateM
|
||||
If MsgPackWriteInteger(*MsgPackData, *Batch\Messages()\MessageId) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
If MsgPackWriteInteger(*MsgPackData, *Batch\Messages()\PushedAt) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
If MsgPackWriteString(*MsgPackData, *Batch\Messages()\JsonData) <> #MsgPack_Error_Success
|
||||
Goto EncodeFailed
|
||||
EndIf
|
||||
@@ -158,6 +163,15 @@ Procedure.i BakaShrot_ReplicateMessagesPacket_Decode(*MsgPackData.MsgPackData)
|
||||
EndIf
|
||||
PreviousMessageId = *Batch\Messages()\MessageId
|
||||
|
||||
; PushedAt
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_Integer
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
*Batch\Messages()\PushedAt = MsgPackReadInteger(*MsgPackData)
|
||||
If MsgPackLastError(*MsgPackData) <> #MsgPack_Error_Success Or Not BakaShrot_IsValidTimestamp(*Batch\Messages()\PushedAt)
|
||||
Goto DecodeFailed
|
||||
EndIf
|
||||
|
||||
; JsonData
|
||||
If MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData)) <> #MsgPack_DataTypes_String
|
||||
Goto DecodeFailed
|
||||
|
||||
Reference in New Issue
Block a user