1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Protocol 6: node identities, error codes, Synchronous, schema v8, examples

- Protocol 5: a client authenticates as a node (Node), its pushes go to the
  section's DefaultTopic unless they name one; old Identities refused at
  start with what to write instead.
- Topics listed by name, ids picked and kept by the server; nodes come from
  client sections, [BakaShrot.Nodes] optional, AcceptNodes = * by default.
- Protocol 6: every refusal carries a code, every client failure too
  (BakaShrot_ErrorCodes.pbi, BakaShrot_GetLastError(), ErrorCode in Python);
  nothing reconnects by itself, delivery is at least once.
- [BakaShrot.Server] Synchronous = FULL (default) or NORMAL, benchmarked.
- Schema v8: browse table and browse_messages view for database tools.
- Tools renamed BakaShrot<Name>, wait for Enter when started from Explorer.
- Examples/SingleServer: a server and a client with scripts (example keys,
  public on purpose).
- Restart-Test.ps1: servers killed mid-traffic and mid-catch-up.
- Docs: one server per node rule, DatabaseError() checked per thread,
  release notes' Compatibility section, Notes "Right now".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RwFeVQrLqMQPw9AZnsHqQH
This commit is contained in:
2026-11-09 23:57:55 +01:00
parent df61ef9719
commit 488ffe4bc8
67 changed files with 3163 additions and 1029 deletions
+36 -15
View File
@@ -5,19 +5,41 @@
; The DLL must be next to the tool, the identity and server come from an ini
; file laid out like the client.ini Build.ps1 writes:
; [BakaShrot]
; PrivateKey, PublicKey, Topic, Node, ServerHost, ServerPort,
; PrivateKey, PublicKey, Node, ServerHost, ServerPort,
; ServerPublicKey (the server's, it logs it when it starts)
; Topic and Node can be names or ids (Commons/Networking/Names.pbi). They
; were TopicId and NodeId before, still read when Topic and Node are missing.
; Node is the node the client writes as, a name or an id
; (Commons/Networking/Names.pbi); NodeId before, still read when Node is
; missing. A Topic (TopicId) left in it is ignored: the client's default
; topic is in the server's config (DefaultTopic).
; ============================================================================
XIncludeFile "../../Client/BakaShrot_Client_Prototypes.pbi"
XIncludeFile "ToolConsole.pbi"
; What a client error code (100+, BakaShrot_ErrorCodes.pbi) means, for the
; tools' messages.
Procedure.s ToolClient_Explain(Code.l)
Select Code
Case #BakaShrot_Error_NotConnected : ProcedureReturn "not connected"
Case #BakaShrot_Error_ConnectFailed : ProcedureReturn "nothing answers there"
Case #BakaShrot_Error_AuthRejected : ProcedureReturn "the server closed the connection: wrong ServerPublicKey, a key or node it doesn't allow, or another version (its log says which)"
Case #BakaShrot_Error_ServerNotVerified : ProcedureReturn "the server couldn't prove it holds ServerPublicKey's private key"
Case #BakaShrot_Error_ConnectionLost : ProcedureReturn "the connection to the server failed"
Case #BakaShrot_Error_ProtocolError : ProcedureReturn "the server answered something unexpected, the connection is closed"
Case #BakaShrot_Error_InvalidArgument : ProcedureReturn "an invalid argument"
Case #BakaShrot_Error_FileError : ProcedureReturn "a file couldn't be opened, read or written"
Case #BakaShrot_Error_AttachmentMismatch : ProcedureReturn "the attachment doesn't match its SHA-256"
Case #BakaShrot_Error_Internal : ProcedureReturn "out of memory, or another failure in the client"
EndSelect
ProcedureReturn BakaShrot_ErrorName(Code)
EndProcedure
; Loads the DLL, reads IniPath and connects to its server with its identity.
; Prints what failed and returns #False on failure, the DLL is then unloaded.
Procedure.i ToolClient_Connect(IniPath.s)
Protected PrivateKey.s, PublicKey.s, ServerPublicKey.s, Topic.s, Node.s, ServerHost.s, ServerPort.l
Protected PrivateKey.s, PublicKey.s, ServerPublicKey.s, Node.s, ServerHost.s, ServerPort.l
If Not OpenPreferences(IniPath)
PrintN("Failed to open '" + IniPath + "'")
@@ -27,7 +49,6 @@ Procedure.i ToolClient_Connect(IniPath.s)
PrivateKey = ReadPreferenceString("PrivateKey", "")
PublicKey = ReadPreferenceString("PublicKey", "")
ServerPublicKey = ReadPreferenceString("ServerPublicKey", "")
Topic = Trim(ReadPreferenceString("Topic", ReadPreferenceString("TopicId", "")))
Node = Trim(ReadPreferenceString("Node", ReadPreferenceString("NodeId", "")))
ServerHost = ReadPreferenceString("ServerHost", "")
ServerPort = ReadPreferenceLong("ServerPort", 0)
@@ -56,12 +77,6 @@ Procedure.i ToolClient_Connect(IniPath.s)
ProcedureReturn #False
EndIf
If Not BakaShrot_SetTopic(Topic)
PrintN("Invalid Topic '" + Topic + "' in '" + IniPath + "', expected a name or an id")
BakaShrot_UnloadClient()
ProcedureReturn #False
EndIf
If Not BakaShrot_SetNode(Node)
PrintN("Invalid Node '" + Node + "' in '" + IniPath + "', expected a name or an id")
BakaShrot_UnloadClient()
@@ -69,7 +84,7 @@ Procedure.i ToolClient_Connect(IniPath.s)
EndIf
If Not BakaShrot_Connect(ServerHost, ServerPort)
PrintN("Failed to connect and authenticate to " + ServerHost + ":" + Str(ServerPort))
PrintN("Failed to connect and authenticate to " + ServerHost + ":" + Str(ServerPort) + " (" + BakaShrot_ErrorName(BakaShrot_GetLastError()) + "): " + ToolClient_Explain(BakaShrot_GetLastError()))
BakaShrot_UnloadClient()
ProcedureReturn #False
EndIf
@@ -93,11 +108,17 @@ EndProcedure
; Prints why the last request failed.
; With its code's name (BakaShrot_ErrorCodes.pbi), for scripts to match on.
Procedure ToolClient_PrintFailure()
If BakaShrot_IsConnected()
PrintN("Refused by the server: " + BakaShrot_GetRefusalReasonString())
Protected Code.l = BakaShrot_GetLastError()
If BakaShrot_IsRefusalCode(Code)
PrintN("Refused by the server (" + BakaShrot_ErrorName(Code) + "): " + BakaShrot_GetRefusalReasonString())
ElseIf BakaShrot_GetRefusalReasonString() <> ""
; The client's own refusals: a message or attachment over the limits...
PrintN("Failed (" + BakaShrot_ErrorName(Code) + "): " + BakaShrot_GetRefusalReasonString())
Else
PrintN("The connection to the server failed")
PrintN("Failed (" + BakaShrot_ErrorName(Code) + "): " + ToolClient_Explain(Code))
EndIf
EndProcedure