mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Add attachments (protocol 4), their edge-case tests, and handoff docs
- One optional attachment per message, any size up to the server's MaxAttachmentSize (default 1G), sent and stored in 1 MB parts, checked with its SHA-256. Uploaded before its message (UploadStart, UploadChunk), then attached by the PushMessage in the same transaction; uploads never pushed expire after UploadTimeout. Read back a part at a time (GetAttachment). - Replicated separately, after the messages: the message carries the size and SHA-256, then each check-in lists what the peer is missing (MissingAttachments) and sends the parts from where it stopped. Over the receiver's limit, the attachment is marked not kept. - Deleted with its message by the retention, parts cleaned up in the background. Schema v7 (attachments, blobs, blob_chunks), replacing the unused attachements table. - DLL: PushMessageWithFile/WithData, SaveAttachment, LoadAttachment, GetMessageAttachmentSize, IsMessageAttachmentReady. Python: push(..., attachment=), get_attachment(), save_attachment(). Tools: PushMessage -a, GetAttachment. The release smoke test round-trips one. - Tests/Attachments-Test.ps1 (39 checks) and Tests/AttachmentEdges-Test.ps1 (51 checks, with a raw protocol client): wrong SHA-256, bad parts, others' uploads, expiry, replication resuming after a kill, a corrupted stored copy. Found: a corrupted copy is re-sent to peers forever, noted as open item 3 in Notes.md with a proposed fix. - CLAUDE.md: how to build, test, the traps and working rules, for the next session. Notes.md and the Design docs updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVPXGLs3KK1MAQn3ouP
This commit is contained in:
@@ -20,7 +20,8 @@ EndStructure
|
||||
; 3: the Hello sealed for the server, a key per connection, everything after
|
||||
; the ChallengeRequest encrypted (Connections.pbi). Messages carry when
|
||||
; they were pushed (PushedAt).
|
||||
#BakaShrot_ProtocolVersion = 3
|
||||
; 4: attachments (Design/Attachments.md).
|
||||
#BakaShrot_ProtocolVersion = 4
|
||||
|
||||
; Size in bytes of the nonce sent in a challenge request and echoed in its response.
|
||||
; It MUST be filled with CryptRandomData(), never reused, and be checked against the one the
|
||||
@@ -50,6 +51,32 @@ Procedure.i BakaShrot_IsValidTimestamp(Timestamp.q)
|
||||
ProcedureReturn Bool(Timestamp >= 1 And Timestamp <= #BakaShrot_MaxTimestamp)
|
||||
EndProcedure
|
||||
|
||||
; Attachments (Design/Attachments.md): at most one per message, sent and
|
||||
; stored in parts of #BakaShrot_AttachmentChunkSize bytes (the last one what's
|
||||
; left), checked with their SHA-256. #BakaShrot_MaxAttachmentSize is the
|
||||
; protocol's limit, each server sets its own ([BakaShrot.Server]
|
||||
; MaxAttachmentSize).
|
||||
#BakaShrot_AttachmentChunkSize = 1048576
|
||||
#BakaShrot_MaxAttachmentSize = 1099511627776
|
||||
#BakaShrot_MaxAttachmentChunks = #BakaShrot_MaxAttachmentSize / #BakaShrot_AttachmentChunkSize
|
||||
#BakaShrot_Sha256Size = 32
|
||||
|
||||
; How many parts Size bytes take.
|
||||
Procedure.q BakaShrot_AttachmentChunkCount(Size.q)
|
||||
ProcedureReturn (Size + #BakaShrot_AttachmentChunkSize - 1) / #BakaShrot_AttachmentChunkSize
|
||||
EndProcedure
|
||||
|
||||
; How big part Index of Size bytes is, 0 if there's no such part.
|
||||
Procedure.i BakaShrot_AttachmentChunkBytes(Size.q, Index.q)
|
||||
Protected Left.q = Size - Index * #BakaShrot_AttachmentChunkSize
|
||||
If Index < 0 Or Left <= 0
|
||||
ProcedureReturn 0
|
||||
ElseIf Left > #BakaShrot_AttachmentChunkSize
|
||||
ProcedureReturn #BakaShrot_AttachmentChunkSize
|
||||
EndIf
|
||||
ProcedureReturn Left
|
||||
EndProcedure
|
||||
|
||||
; Biggest packet accepted on the wire once authenticated, anything bigger
|
||||
; aborts the connection. Before that, only #BakaShrot_MaxHandshakePacketSize
|
||||
; (Connections.pbi).
|
||||
@@ -97,6 +124,20 @@ Enumeration BakaShrot_PacketTypes
|
||||
; A run of messages of a topic/node, only accepted once authenticated.
|
||||
#BakaShrot_PacketType_GetMessages = 22
|
||||
#BakaShrot_PacketType_Messages = 23
|
||||
|
||||
; Attachments, only accepted once authenticated: uploading one (before
|
||||
; its PushMessage), and reading one, in parts.
|
||||
#BakaShrot_PacketType_UploadStart = 24
|
||||
#BakaShrot_PacketType_UploadStarted = 25
|
||||
#BakaShrot_PacketType_UploadChunk = 26
|
||||
#BakaShrot_PacketType_ChunkStored = 27
|
||||
#BakaShrot_PacketType_GetAttachment = 28
|
||||
#BakaShrot_PacketType_AttachmentChunk = 29
|
||||
|
||||
; Replicating attachments, only accepted from peers, once their messages are.
|
||||
#BakaShrot_PacketType_MissingAttachmentsRequest = 30
|
||||
#BakaShrot_PacketType_MissingAttachments = 31
|
||||
#BakaShrot_PacketType_ReplicateAttachmentChunk = 32
|
||||
EndEnumeration
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user