interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / door / ev1decl.om

497 lines · 11776 bytes Raw Blame History
1note door/ (the agent door, docs/AGENT-DOOR.md): the public activity stream <base>events.json
2note (schema interplane/events/1, also <base>events and <base>feed with Accept: application/json),
3note the feed page <base>feed, and their store: the append-only, hash-chained file <data>events/log.
4note Names: functions ev*, globals gev*, texts tev*. Needs collab/ (corefs, coload: the COB model) and
5note social/ (the social log parser and the account names) composed; otherwise run.sh composes the
6note seam server/nodoor.om, which answers 501 for these pages.
7note Collection is change-triggered, never on a clock: before a page of the stream is answered, evcollect
8note compares cheap fingerprints (the size of the social log, the change time of the open shelf list,
9note and per public repository the change times of the ref folders that every Radicle ref update
10note renames into) with the last ones and reads only what changed (docs/AGENT-DOOR.md).
11note Log line, tab-separated, sanitized (no tab, newline or control byte inside a field):
12note seq time kind actor rid source path json x subject prev
13note seq from 1, time epoch seconds from the source record, kind 1..14, actor a did:key or empty, rid
14note without rad: or empty, source the object id the event was read from, path and json relative to
15note the base, x the verdict word (review) or "<old sha> <count>" (branch moved) or the followed did
16note (follow) or the shelf name (open), prev the hex sha256 of the previous line (64 zeros for line 1).
17const EVMAX ulong 262144
18const EVLMAX ulong 8192
19const EVBMAX ulong 32768
20text tevdir "events"
21text tevrdir "events/r"
22text tevlog "events/log"
23text tevrp "events/r/"
24text tevtmp ".tmp"
25text tevlist "open/list.tsv"
26text tevfer "for-each-ref"
27text tevfmt "--format=%(objectname) %(creatordate:unix) %(refname)"
28text tevrh "refs/heads/"
29text tevrt "refs/tags"
30text tevrtp "refs/tags/"
31text tevns "refs/namespaces/"
32text tevnst "/refs/tags"
33text tevnstp "/refs/tags/"
34text tevcpg "refs/namespaces/*/refs/cobs/xyz.radicle.patch/*"
35text tevcig "refs/namespaces/*/refs/cobs/xyz.radicle.issue/*"
36text tevcpm "/refs/cobs/xyz.radicle.patch/"
37text tevcim "/refs/cobs/xyz.radicle.issue/"
38text tevrl "rev-list"
39text tevcnt "--count"
40text tevdots ".."
41text tevsrh "/refs/heads"
42text tevsrt "/refs/tags"
43text tevsns "/refs/namespaces"
44text tevspk "/packed-refs"
45text tevsrad "/refs/rad"
46text tevdidk "did:key:"
47text tevsocs "social.log:"
48text tevopns "open/list.tsv:"
49text tevopnp "open/"
50text tevopnj "open.json"
51text tevjsx ".json"
52text tevpatp "/patches/"
53text tevissp "/issues/"
54text tevrelp "/releases/tag/"
55text tevcmpp "/compare/"
56text tevtdot "..."
57text tevheld "held"
58text tevstor "stored"
59text tevwdr "withdrawn"
60text tevvacc "accept"
61text tevvrej "reject"
62text tevmovd " moved"
63text tevncom " new commit"
64text tevncs "s"
65text tevon " on "
66text tevlbad "EVENTS-LOG TAMPER: events off at line "
67text tevlwr "EVENTS-LOG write failed: events off"
68text tevlpas "events: pass "
69text tevlpus " us, sources read "
70text tevlpev ", events added "
71text tevlcob "events: COB not loaded, no events from it: "
72text tevlcut "events: ref list longer than the buffer, repository skipped: "
73text tevlbfl "events: batch full, flushed early"
74note the log index: gevoff[k] is the byte offset of line k (seq k+1); gevoff[gevn] is the end
75global gevoff ulong 262145
76global gevn ulong 1
77note gevok: 0 not loaded, 1 loaded and appendable, 2 refused (the chain did not verify, a write failed)
78global gevok ulong 1
79global gevprv uchar 32
80note gevset: open-addressing set of event keys (FNV-1a 64 of kind, rid, source and x; never 0)
81global gevset ulong 524288
82note per allow-list index: the fingerprint of the repository's ref folders when it was last read
83global gevfp ulong 256
84note the social log bytes already read, and the open list fingerprint
85global gevsoff ulong 1
86global gevofp ulong 1
87note read buffer (log lines, social lines), the old ref snapshot of one repository, the new one
88global gevrb uchar 2097152
89global gevold uchar 4194304
90global gevoldl ulong 1
91global gevnew uchar 4194304
92global gevnewl ulong 1
93global gevst uchar 128
94global gevde uchar 16384
95note the line being written
96global gevln uchar 8192
97global gevlnl ulong 1
98note the event being built: kind, time, and its byte fields (each a buffer and its length)
99global gevk ulong 1
100global gevt ulong 1
101global gevact uchar 128
102global gevactl ulong 1
103global gevrid uchar 64
104global gevridl ulong 1
105global gevsub uchar 512
106global gevsubl ulong 1
107global gevpth uchar 1024
108global gevpthl ulong 1
109global gevjs uchar 1024
110global gevjsl ulong 1
111global gevsrc uchar 128
112global gevsrcl ulong 1
113global gevx uchar 192
114global gevxl ulong 1
115note the batch of one collection pass: partial lines (time .. subject) sorted by time before append
116global gevbat uchar 16777216
117global gevbatl ulong 1
118global gevbo ulong 32768
119global gevbl ulong 32768
120global gevbt ulong 32768
121global gevbi ulong 32768
122global gevbj ulong 32768
123global gevbn ulong 1
124note counters of one collection pass (its stderr line names them with its cost in microseconds)
125global gevpr ulong 1
126global gevpe ulong 1
127note changed COB ids of the repository being read: id (40 bytes) and kind (1 patch, 2 issue)
128global gevcid uchar 163840
129global gevckd ulong 4096
130global gevcn ulong 1
131note one stderr line (evgb, evgt, evgn, evgc, then evgout)
132global gevlg uchar 512
133global gevlgl ulong 1
134fn evgb to void
135put gevlgl 0 0
136end
137fn evgc c uchar to void
138n = get gevlgl 0
139if lt n 510
140put gevlg n c
141put gevlgl 0 add n 1
142end
143end
144fn evgt t view uchar * to void
145for i ulong len t bound 256
146evgc get t i
147end
148end
149fn evgn v ulong to void
150d = new uchar 24 0
151k = evdec v d
152for j ulong k bound 24
153evgc get d j
154end
155end
156fn evgout to void
157evgc 10
158w = write 2 gevlg 0 get gevlgl 0
159end
160note ---- byte helpers for the line being written
161fn evlc c uchar to void
162n = get gevlnl 0
163if lt n sub EVLMAX 1
164put gevln n c
165put gevlnl 0 add n 1
166end
167end
168note evdec v d: the decimal digits of v into d at 0; returns their count
169fn evdec v ulong d edit uchar 24 to ulong
170t = new uchar 24 0
171k = ulong 0
172x = v
173for it ulong 21
174put t k uchar add rem x 10 48
175k = add k 1
176x = div x 10
177if eq x 0
178break
179end
180end
181for j ulong k bound 24
182put d j get t sub sub k j 1
183end
184ret k
185end
186fn evlnum v ulong to void
187d = new uchar 24 0
188k = evdec v d
189for j ulong k bound 24
190evlc get d j
191end
192end
193note evsafe: a field byte as stored: tab, newline and the other control bytes become a space
194fn evsafe c uchar to uchar
195if or lt c 32 eq c 127
196ret uchar 32
197end
198ret c
199end
200note ---- path helpers: fpth = <data><t>
201fn evpath t view uchar * to void
202fpb
203fpt tfdata
204fpt t
205end
206note evmkdirs: <data>events and <data>events/r (an existing folder is fine)
207fn evmkdirs to void
208evpath tevdir
209x = makedir fpth 0 get fpthl 0 448
210evpath tevrdir
211y = makedir fpth 0 get fpthl 0 448
212end
213note evstat: stat fpth into gevst; a fingerprint of its change time and size, 0 when it is missing
214fn evstat to ulong
215r = stat fpth 0 get fpthl 0 gevst 0 128
216if lt r 0
217ret 0
218end
219h = ulong 14695981039346656037
220for k ulong 8
221h = evfnv h get gevst add 48 k
222h = evfnv h get gevst add 104 k
223h = evfnv h get gevst add 112 k
224end
225ret h
226end
227fn evst64 o ulong to ulong
228v = ulong 0
229for i ulong 8
230b = ulong get gevst add o i
231v = or v shl b mul i 8
232end
233ret v
234end
235note ---- event field setters (a collector fills one event, then evemit)
236fn evclr to void
237put gevk 0 0
238put gevt 0 0
239put gevactl 0 0
240put gevridl 0 0
241put gevsubl 0 0
242put gevpthl 0 0
243put gevjsl 0 0
244put gevsrcl 0 0
245put gevxl 0 0
246end
247fn evactc c uchar to void
248n = get gevactl 0
249if lt n len gevact
250put gevact n evsafe c
251put gevactl 0 add n 1
252end
253end
254fn evactt t view uchar * to void
255for i ulong len t bound 128
256evactc get t i
257end
258end
259fn evridc c uchar to void
260n = get gevridl 0
261if lt n len gevrid
262put gevrid n evsafe c
263put gevridl 0 add n 1
264end
265end
266note evsubc: the subject is one line of at most 400 bytes (evsubend cuts it at a character start)
267fn evsubc c uchar to void
268n = get gevsubl 0
269if lt n 400
270put gevsub n evsafe c
271put gevsubl 0 add n 1
272end
273end
274fn evsubt t view uchar * to void
275for i ulong len t bound 400
276evsubc get t i
277end
278end
279fn evsubend to void
280n = get gevsubl 0
281if lt n 400
282ret
283end
284for it ulong 4
285k = get gevsubl 0
286if eq k 0
287ret
288end
289c = get gevsub sub k 1
290if ne and c 192 128
291put gevsubl 0 sub k 1
292ret
293end
294put gevsubl 0 sub k 1
295end
296end
297note evpthc: one byte of a URL path, percent-encoded unless unreserved or /; evpthr: raw
298fn evpthc c uchar to void
299if evunres c
300evpthr c
301ret
302end
303evpthr 37
304evpthr evhexu shr ulong c 4
305evpthr evhexu and ulong c 15
306end
307fn evpthr c uchar to void
308n = get gevpthl 0
309if lt n len gevpth
310put gevpth n c
311put gevpthl 0 add n 1
312end
313end
314fn evptht t view uchar * to void
315for i ulong len t bound 64
316evpthr get t i
317end
318end
319fn evunres c uchar to bool
320if and ge c 97 le c 122
321ret true
322end
323if and ge c 65 le c 90
324ret true
325end
326if and ge c 48 le c 57
327ret true
328end
329ret or or eq c 45 eq c 46 or or eq c 95 eq c 126 eq c 47
330end
331fn evhexu v ulong to uchar
332if lt v 10
333ret uchar add v 48
334end
335ret uchar add v 55
336end
337note evpthrepo i: path = <owner>/<repo name of i>
338fn evpthrepo i ulong to void
339put gevpthl 0 0
340evptht tfowner
341evpthr 47
342for k ulong frnlen i bound 128
343evpthc frnbyte i k
344end
345end
346note evjsame: json = path (the page answers JSON at its own address with Accept: application/json)
347fn evjsame to void
348n = get gevpthl 0
349for k ulong n bound 1024
350put gevjs k get gevpth k
351end
352put gevjsl 0 n
353end
354fn evjsc c uchar to void
355n = get gevjsl 0
356if lt n len gevjs
357put gevjs n c
358put gevjsl 0 add n 1
359end
360end
361fn evjst t view uchar * to void
362for i ulong len t bound 64
363evjsc get t i
364end
365end
366fn evsrcc c uchar to void
367n = get gevsrcl 0
368if lt n len gevsrc
369put gevsrc n evsafe c
370put gevsrcl 0 add n 1
371end
372end
373fn evsrct t view uchar * to void
374for i ulong len t bound 64
375evsrcc get t i
376end
377end
378fn evsrcnum v ulong to void
379d = new uchar 24 0
380k = evdec v d
381for j ulong k bound 24
382evsrcc get d j
383end
384end
385fn evxc c uchar to void
386n = get gevxl 0
387if lt n len gevx
388put gevx n evsafe c
389put gevxl 0 add n 1
390end
391end
392fn evxt t view uchar * to void
393for i ulong len t bound 64
394evxc get t i
395end
396end
397note evridi i: the event is about allow-list repository i
398fn evridi i ulong to void
399put gevridl 0 0
400for k ulong fridlen i bound 64
401evridc fridbyte i k
402end
403end
404note evowndid: the actor is the node delegate (did:key:<tfnid>)
405fn evowndid to void
406put gevactl 0 0
407evactt tevdidk
408evactt tfnid
409end
410note ---- FNV-1a 64
411fn evfnv h ulong c uchar to ulong
412x = xor h ulong c
413ret mul x 1099511628211
414end
415note evkey: the key of the event being built (kind, rid, source, x)
416fn evkey to ulong
417h = evfnv ulong 14695981039346656037 uchar get gevk 0
418h = evfnv h 0
419for i ulong get gevridl 0 bound 64
420h = evfnv h get gevrid i
421end
422h = evfnv h 0
423for i ulong get gevsrcl 0 bound 128
424h = evfnv h get gevsrc i
425end
426h = evfnv h 0
427for i ulong get gevxl 0 bound 192
428h = evfnv h get gevx i
429end
430if eq h 0
431ret ulong 1
432end
433ret h
434end
435note ---- the key set
436fn evhas k ulong to bool
437m = sub len gevset 1
438s = and k m
439for it ulong len gevset
440v = get gevset s
441if eq v 0
442ret false
443end
444if eq v k
445ret true
446end
447s = and add s 1 m
448end
449ret false
450end
451fn evput k ulong to void
452m = sub len gevset 1
453s = and k m
454for it ulong len gevset
455v = get gevset s
456if or eq v 0 eq v k
457put gevset s k
458ret
459end
460s = and add s 1 m
461end
462end
463note ---- digits
464fn evdig c uchar to bool
465ret and ge c 48 le c 57
466end
467fn evhexd c uchar to bool
468if evdig c
469ret true
470end
471ret and ge c 97 le c 102
472end
473fn evhexc v ulong to uchar
474if lt v 10
475ret uchar add v 48
476end
477ret uchar add v 87
478end
479note evridpub: the allow-list index of the event's RID (gevrid, no rad:), 9999 when it is not public
480fn evridpub to ulong
481n = get gevridl 0
482for i ulong get fan 0 bound FAMAX
483if eq fridlen i n
484same = true
485for k ulong n bound 64
486if ne fridbyte i k get gevrid k
487same = false
488break
489end
490end
491if same
492ret i
493end
494end
495end
496ret ulong 9999
497end