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:
@@ -21,10 +21,16 @@
|
||||
; Kept in the "topics" and "nodes" tables (Storage.pbi), so raw queries can
|
||||
; join on them (the "messages" view), and in memory for the server, guarded
|
||||
; by BakaShrot_Names_Mutex. Every id in "data" has a row:
|
||||
; origin "config" named in [BakaShrot.Topics] / [BakaShrot.Nodes]
|
||||
; origin "config" named by the config: in [BakaShrot.Topics] /
|
||||
; [BakaShrot.Nodes], or a peer's or client's Node
|
||||
; origin "id" unnamed, its name is its id in digits
|
||||
; origin "peer" sent by a peer, taken by a wildcard, named by the peer
|
||||
;
|
||||
; Ids are this server's to pick: a name the config lists without one keeps
|
||||
; the one these tables have for it, a new one gets the lowest free one
|
||||
; (LoadConfig(), after BakaShrot_Names_ReadKnown()). The config may still
|
||||
; pin one ("logs = 1").
|
||||
;
|
||||
; BakaShrot_Names_Load() reconciles the config with the tables at start (and
|
||||
; on restart). The config wins, except when it would give a name to another
|
||||
; id than the one the database has it under (or rename a "peer" one): that
|
||||
@@ -219,6 +225,47 @@ Procedure.i BakaShrot_Names_Load(DbId.i, *Config.BakaShrot_CoreConfig, *Error.St
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Fills *Known with what the database has, for LoadConfig() (Config.pbi):
|
||||
; the id of every name, and every id with a row or messages. Before the
|
||||
; config is loaded, on a connection of its own, the database set up.
|
||||
; Returns #False with the reason in *Error\s.
|
||||
Procedure.i BakaShrot_Names_ReadKnown(DbId.i, *Known.BakaShrot_KnownNames, *Error.String)
|
||||
Protected Name.s, Id.i
|
||||
|
||||
; Topics
|
||||
If Not DatabaseQuery(DbId, "SELECT topic_id, name FROM topics UNION SELECT DISTINCT topic_id, '' FROM node_heads")
|
||||
*Error\s = "can't read the topics: " + DatabaseError()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
While NextDatabaseRow(DbId)
|
||||
Id = GetDatabaseLong(DbId, 0)
|
||||
Name = GetDatabaseString(DbId, 1)
|
||||
*Known\TopicUsed(Str(Id)) = #True
|
||||
If Name <> "" And Not BakaShrot_IsDigits(Name)
|
||||
*Known\TopicIds(LCase(Name)) = Id
|
||||
EndIf
|
||||
Wend
|
||||
FinishDatabaseQuery(DbId)
|
||||
|
||||
; Nodes
|
||||
If Not DatabaseQuery(DbId, "SELECT node_id, name FROM nodes UNION SELECT DISTINCT node_id, '' FROM node_heads")
|
||||
*Error\s = "can't read the nodes: " + DatabaseError()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
While NextDatabaseRow(DbId)
|
||||
Id = GetDatabaseLong(DbId, 0)
|
||||
Name = GetDatabaseString(DbId, 1)
|
||||
*Known\NodeUsed(Str(Id)) = #True
|
||||
If Name <> "" And Not BakaShrot_IsDigits(Name)
|
||||
*Known\NodeIds(LCase(Name)) = Id
|
||||
EndIf
|
||||
Wend
|
||||
FinishDatabaseQuery(DbId)
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
|
||||
; --- Lookups -----------------------------------------------------------------
|
||||
|
||||
; The id Ref stands for: an id in digits is that id, a name must be known.
|
||||
|
||||
Reference in New Issue
Block a user