interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / open / route.om

2639 lines · 53796 bytes Raw Blame History
1note open/route.om: Open Humanity's shelf of open builds, inside forged. Prefix oh* (functions),
2note go* (globals), to* (texts). Composed after the salvage and social slices, whose form reader,
3note write precheck and session it uses (slformvalid, slgetform, slffeq, sowpre, soratev, soerr).
4note A person signed in with a Radicle key names the Radicle id (RID) of a project that is not
5note finished, or not right yet. forged does not fetch anything: it has no network and cannot run
6note rad. It appends one line to <data>open/queue and the intake service (open/intake.om, its own
7note program outside the sandbox) seeds and fetches the project within limits and rewrites
8note <data>open/list.tsv, which this unit shows.
9note GET <base>open/ the shelf: every project the intake accepted, marked unfinished and not
10note verified; JSON when the request asks for it
11note GET <base>open/<rid> one listed project: its row and the snapshot the intake took (head,
12note last commits, top-level files, README); JSON interplane/open-build/1
13note GET <base>open.json and <base>open/<rid>.json the same JSON under names of their own
14note POST <base>open/ action=bring (rid, note, consent=yes) or action=withdraw (rid)
15note Queue lines: B <tab> rid <tab> did <tab> note and W <tab> rid <tab> did
16note list.tsv rows: rid, state, did, date, kilobytes, name, description, note. States "open" and
17note "held" and "stored" are listed for everyone; any other state is shown only to the key that
18note brought the project.
19note Every field is escaped on output. Every write under open/ needs room by the intake's measure (ohroom).
20note One-command bring and get (contract: one-command-contract.md, slice HUB):
21note POST <base>open/up action=chunk (sha, seq, data) or action=finish (files, bytes, name, note,
22note consent=yes, sig); text/plain answers; the same write gate as every forge
23note write. Queue line: U <tab> sha <tab> did <tab> files <tab> bytes <tab>
24note name <tab> note
25note GET <base>open/up/<sha>.json the status of the signed-in key's upload of that archive
26note GET <base>open/<rid>.tar the snapshot of a shelf project (git archive of HEAD) the intake
27note wrote to <data>open/a/<rid>.tar; 404 when there is none
28note GET <base>open/alarms.json the intake's alarms (<data>open/alarms.json)
29note GET <base>bring.sh, <base>get.sh and <base>withdraw.sh <data>open/tools/bring.sh, get.sh
30note and withdraw.sh; 404 when absent
31note The shelf and page JSON carry stored_by_hub, download and download_sha256; a stored row says
32note who signed what.
33text tohtmlct "text/html; charset=utf-8"
34text topath "/open/"
35text topat2 "/open"
36text topjsn "/open.json"
37text toejs ".json"
38text tonavl "open/\">Open builds</a>"
39text toag1 "<p>For agents: this list as JSON at <code>"
40text toag2 "open.json</code>, each project at <code>"
41text toag3 "open/&lt;rid&gt;.json</code>. The same JSON answers at the page addresses with <code>Accept: application/json</code>.</p>"
42text todir "open/"
43text toq "queue"
44text tolist "list.tsv"
45text toti "Open builds"
46text torid "rid"
47text tonote "note"
48text tocons "consent"
49text toyes "yes"
50text toact "action"
51text tobring "bring"
52text towith "withdraw"
53text tostop "open"
54text toheld "held"
55text tob58 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
56text torad "rad:"
57text tologin "login"
58text tomsg1 "The form was refused. Give the id of your project, tick the permission box, and keep the note under 200 bytes."
59text tomsgq "The intake queue is full. Nothing was saved. Try again later."
60text toh1 "<div class=\"sl\"><h1>Open builds</h1><p>Bring the project that is not finished, or not right yet. It stays open here so other builders and their agents can pick it up. Nothing on this shelf is verified until a revision carries a receipt.</p>"
61text toh2 "<article class=\"sl-card\"><h2>Bring a project</h2><p>Bringing new projects is closed until Interplane's own store accepts them. There is no limit on how many projects one person brings and no size limit. This computer keeps part of its disk free for its own work; a bring that would use that part is refused with the reason (this computer is nearly full; try again later), and nothing is stored. Any signed-in key can bring a project while the operator keeps intake open; if it is limited to a list of keys, a key that is not on the list sees the refusal here. The operator can take down a listing, or every listing of a key. You can withdraw yours at any time.</p>"
62text toh3 "<p><a href=\""
63text toh4 "\">Sign in with your key</a> to bring a project.</p></article>"
64text tof1 "<form method=\"post\" action=\""
65text tof2 "\"><input type=\"hidden\" name=\"csrf\" value=\""
66text tof3 "\"><input type=\"hidden\" name=\"action\" value=\"bring\"><p><label>Project id <input name=\"rid\" maxlength=\"48\" required></label></p><p><label>What is unfinished, in one line <input name=\"note\" maxlength=\"200\"></label></p><p><label><input type=\"checkbox\" name=\"consent\" value=\"yes\" required> I have the right to share this project and it carries an open license.</label></p><p><button type=\"submit\">Bring it</button></p></form></article>"
67text tol1 "<h2>On the shelf</h2>"
68text tol0 "<p>The shelf is waiting for its first project. Unfinished is welcome.</p>"
69text toc1 "<article class=\"sl-card\"><h3>"
70text toc2 "</h3><p>"
71text toc3 "</p>"
72text tounf1 "<p><strong>Unfinished:</strong> "
73text tounf2 "</p>"
74text toc5 "<p>Not verified. Brought by "
75text toc6 " on "
76text toc7 ", "
77text toc8 " KiB.</p>"
78text toc9 "</article>"
79text tow1 "\"><input type=\"hidden\" name=\"action\" value=\"withdraw\"><input type=\"hidden\" name=\"rid\" value=\""
80text tow2 "\"><button type=\"submit\">Withdraw</button></form>"
81text tor1 "<article class=\"sl-card\"><h3>"
82text tor2 "</h3><p>Only you see this. Intake result: "
83text tor3 "</p></article>"
84text toend "</div>"
85text tocl1 "<a href=\""
86text tocl2 "\">"
87text tocl3 "</a>"
88text topdir "p/"
89text toptxt ".txt"
90text top1 "<div class=\"sl\"><p><a href=\""
91text top2 "\">Open builds</a></p><h1>"
92text top3 "</h1><p>"
93text top4 "</p>"
94text top5 "<p>No public Git URL yet: Interplane does not serve Git clones yet.</p>"
95text tdv1 "<section class=\"pj-dev\" id=\"For-developers\"><h2>For developers</h2><dl class=\"pj-terms\"><dt>Download</dt><dd>"
96text tdvtar ".tar\">"
97text tdvtar2 ".tar</a>, SHA-256 <code>"
98text tdvcode "</code>"
99text tdvnone "None yet."
100text tdv4 "</dd><dt>Brought by</dt><dd><code>"
101text tdv5 "</code></dd><dt>Their public key</dt><dd><code>"
102text tdv6 "</code></dd>"
103text tdv7 "</code></dd>"
104text tdvhub "<dt>The hub&#39;s key</dt><dd><code>"
105text tdv8 "</dl><p>Stored by the Interplane hub. The hub&#39;s key"
106text tdv9 " ("
107text tdv10 ")"
108text tdv11 " created this repository and signs its history: that shows the hub stored these exact bytes, not who wrote them. The person who brought it signed the list of files (<code>.interplane/brought.txt</code>, signature <code>.interplane/brought.sig</code>) with a key made on their own computer: that shows the same key vouched for exactly these files; it does not show who that person is or that they wrote the code. To check it: <code>ssh-keygen -Y check-novalidate -n interplane-bring -f &lt;their public key&gt; -s .interplane/brought.sig</code>, reading the first five lines of <code>brought.txt</code> on standard input.</p></section>"
109text tdidp8 "did:key:"
110text tdvsshn "ssh-ed25519"
111text top6 "<p>Not verified. Brought by "
112text top7 " on "
113text top8 ". What follows is a snapshot taken when the project was listed.</p>"
114text toph "<p>Head <code>"
115text tophe "</code></p>"
116text topc "<h2>Latest commits</h2><ul>"
117text topt "<h2>Files</h2><ul>"
118text topr "<h2>README</h2><pre>"
119text topul "</ul>"
120text toppre "</pre>"
121text topli "<li>"
122text toplie "</li>"
123text topno "<p>No snapshot of this project yet.</p>"
124text topj1 "{\"schema\":\"interplane/open-build/1\",\"rid\":\""
125text topj2 "\",\"verified\":false,\"head\":\""
126text topj3 "\",\"commits\":["
127text topj4 "],\"files\":["
128text topj5 "],\"readme\":\""
129text topj6 "\",\"parts\":["
130text topj7 "]}\n"
131text topa1 "<h2>Parts taken from this project</h2><p>Submissions whose origin is this project. A source is shown as it was submitted. An Omega part is only published after its declared example was reproduced; the receipt is on its page.</p><ul>"
132text topa2 " (Omega part, verified)"
133text topa3 " (source, not verified)"
134text topa4 "<h2>Parts taken from this project</h2><p>None yet. Submit one source from it at <a href=\""
135text topa5 "salvage/new\">Bring your build</a> with the origin <code>"
136text topa6 "</code>. A derived Omega part whose example is reproduced is listed here with its receipt.</p>"
137text topk1 "{\"id\":\""
138text topk2 "\",\"title\":\""
139text topk3 "\",\"kind\":\"omega-part\",\"verified\":true}"
140text topk4 "\",\"kind\":\"source\",\"verified\":false}"
141text toj1 "{\"schema\":\"interplane/open-builds/1\",\"note\":\"unfinished projects brought to this shelf; nothing here is verified\",\"projects\":["
142text toj2 "{\"rid\":\""
143text toj3 "\",\"brought_by\":\""
144text toj4 "\",\"date\":\""
145text toj5 "\",\"kib\":"
146text toj6 ",\"name\":\""
147text toj7 "\",\"description\":\""
148text toj8 "\",\"unfinished\":\""
149text toj9 "\",\"verified\":false}"
150text toj10 "]}\n"
151text toctj "application/json; charset=utf-8"
152text tohex "0123456789abcdef"
153text tou00 "\\u00"
154note toterms: the terms ohterm looks for, lower case, split by |. Read by code only, never sent.
155text toterms "radicle|heartwood|rad:z|rad clone|rad init|rad sync|rad id|rad patch|rad auth|/rad/"
156text tocopy ": copy kept from its GitHub history"
157text todnone "No description yet."
158global gorid uchar 48
159global goridl ulong 1
160global godid uchar 96
161global godidl ulong 1
162global gonote uchar 208
163global gonotel ulong 1
164global gol uchar 65536
165global goll ulong 1
166global goc uchar 65536
167global gost ulong 4
168global gobody ulong 3
169global gojs ulong 1
170global gop uchar 65536
171global gopl ulong 1
172global gotit uchar 208
173global gotitl ulong 1
174global gosha uchar 64
175global godh uchar 16
176global goname uchar 64
177global gonamel ulong 1
178global gosig uchar 65544
179global gosigl ulong 1
180global gonx ulong 2
181global gosat ulong 1
182global goscnt ulong 1
183global gospv ulong 3
184text tospace "space"
185text tospf "free "
186text tospr " reserve "
187text tospa " at "
188text tomfull "503 this computer is nearly full; try again later\n"
189text tomnr "503 the hub is not ready to take files; try again later\n"
190text tomroom "This computer is nearly full. Nothing was saved. Try again later."
191text toup "/open/up"
192text toupd "/open/up/"
193text toalj "/open/alarms.json"
194text tobrsh "/bring.sh"
195text togtsh "/get.sh"
196text towdsh "/withdraw.sh"
197text toupdir "up/"
198text toadir "a/"
199text totools "tools/"
200text tobrf "bring.sh"
201text togtf "get.sh"
202text towdf "withdraw.sh"
203text toalf "alarms.json"
204text tob64 ".b64"
205text tosig ".sig"
206text totar ".tar"
207text tosha ".sha256"
208text toproj "project"
209text totxt "text/plain; charset=utf-8"
210text totarct "application/x-tar"
211text tocda "attachment; filename=\""
212text tofsha "sha"
213text tofseq "seq"
214text tofdata "data"
215text tofchnk "chunk"
216text toffin "finish"
217text toffile "files"
218text tofbyte "bytes"
219text tofname "name"
220text tofsig "sig"
221text tonext "next "
222text toqd "queued "
223text tostor "stored"
224text tosgb "-----BEGIN SSH SIGNATURE-----"
225text tosge "-----END SSH SIGNATURE-----"
226text tosbh "<p>Stored by the Interplane hub: the hub's key signs the repository's history. The person who brought it signed the list of files.</p>"
227text toj9a "\",\"verified\":false"
228text tosbh1 ",\"stored_by_hub\":"
229text totrue "true"
230text tofalse "false"
231text todl1 ",\"download\":\""
232text todl2 ".tar\",\"download_sha256\":\""
233text todl0 ",\"download\":null,\"download_sha256\":null"
234text topj2b ",\"head\":\""
235text tous1 "{\"schema\":\"interplane/open-upload/1\",\"state\":\""
236text tous2 "\",\"rid\":null,\"page\":null}\n"
237text torecv "receiving"
238text toqueue "queued"
239text tom403 "403 sign in first, then send the session cookie and the csrf field\n"
240text tom400 "400 the form was refused\n"
241text tom503 "503 the queue or the storage is full; try again later\n"
242text tom429 "429 too many writes; wait and send the same chunk again\n"
243text tom404 "404 no upload of this archive under your key\n"
244note ohb58: c is a base58 character
245fn ohb58 c uchar to bool
246for i ulong len tob58 bound 64
247if eq get tob58 i c
248ret true
249end
250end
251ret false
252end
253note ohrid: the form value gcfv[0, n) as a RID into gorid: an optional "rad:", then z and base58,
254note 20 to 44 characters in all
255fn ohrid n ulong to bool
256a = ulong 0
257if ge n 4
258same = true
259for i ulong 4
260if ne get gcfv i get torad i
261same = false
262end
263end
264if same
265a = ulong 4
266end
267end
268m = sub n a
269if or lt m 20 gt m 44
270ret false
271end
272if ne get gcfv a 122
273ret false
274end
275for i ulong m bound 44
276c = get gcfv add a i
277if not ohb58 c
278ret false
279end
280put gorid i c
281end
282put goridl 0 m
283ret true
284end
285note ohdid: the signed-in key's DID into godid. False when signed out or the string is not plain.
286fn ohdid to bool
287who = get gscur 0
288if eq who 0
289ret false
290end
291n = get gssl who
292if or eq n 0 gt n 96
293ret false
294end
295o = get gsso who
296for i ulong n bound 96
297c = get gsstr add o i
298if or le c 32 ge c 127
299ret false
300end
301put godid i c
302end
303put godidl 0 n
304ret true
305end
306note ohnote: the form value gcfv[0, n) into gonote: at most 200 bytes, control bytes become spaces
307fn ohnote n ulong to bool
308if gt n 200
309ret false
310end
311for i ulong n bound 200
312c = get gcfv i
313if or lt c 32 eq c 127
314c = uchar 32
315end
316put gonote i c
317end
318put gonotel 0 n
319ret true
320end
321note ohfile: ffile = <data>open/<name>
322fn ohfile name view uchar * to void
323put ffilel 0 0
324for i ulong len tfdata bound 128
325ffilc get tfdata i
326end
327for i ulong len todir bound 16
328ffilc get todir i
329end
330for i ulong len name bound 16
331ffilc get name i
332end
333end
334note ohappend: one queue line of the given kind (66 B or 87 W). 0 done, else the status to answer.
335fn ohappend kind uchar to long
336b = new uchar 400 0
337rm = ohroom 400
338if or eq rm 1 eq rm 3
339ret 507
340end
341ohfile tostop
342put ffilel 0 sub get ffilel 0 len tostop
343r = makedir ffile 0 get ffilel 0 448
344ohfile toq
345fd = fopen ffile 0 get ffilel 0 558145 384
346if lt fd 0
347ret 503
348end
349sz = ohsize int fd
350n = ulong 0
351put b 0 kind
352put b 1 9
353n = ulong 2
354for i ulong get goridl 0 bound 44
355put b add n i get gorid i
356end
357n = add n get goridl 0
358put b n 9
359n = add n 1
360for i ulong get godidl 0 bound 96
361put b add n i get godid i
362end
363n = add n get godidl 0
364if eq kind 66
365put b n 9
366n = add n 1
367for i ulong get gonotel 0 bound 200
368put b add n i get gonote i
369end
370n = add n get gonotel 0
371end
372put b n 10
373n = add n 1
374w = write int fd b 0 n
375if ne w long n
376if ge sz 0
377r = ftrunc int fd sz
378end
379x = fclose int fd
380ret 503
381end
382x = fclose int fd
383ohused n
384ret 0
385end
386note ohgo: 303 to <base>open/
387fn ohgo to long
388flocb
389floct todir
390put fkind 0 2
391ret 303
392end
393fn ohpost to long
394r = sowpre
395if ne r 0
396ret r
397end
398soratev get gscur 0 get gsnow 0
399if not slformvalid
400ret soerr 400 tomsg1
401end
402if ne slgetform tsfcsrf 32
403ret soerr 400 tomsg1
404end
405if not ohdid
406ret 403
407end
408n = slgetform torid
409if le n 0
410ret soerr 400 tomsg1
411end
412if not ohrid ulong n
413ret soerr 400 tomsg1
414end
415if slffeq toact towith
416r = ohappend 87
417if eq r 507
418ret soerr 503 tomroom
419end
420if ne r 0
421ret soerr 503 tomsgq
422end
423ret ohgo
424end
425if not slffeq toact tobring
426ret soerr 400 tomsg1
427end
428if not slffeq tocons toyes
429ret soerr 400 tomsg1
430end
431n = slgetform tonote
432if lt n 0
433ret soerr 400 tomsg1
434end
435if not ohnote ulong n
436ret soerr 400 tomsg1
437end
438r = ohappend 66
439if eq r 507
440ret soerr 503 tomroom
441end
442if ne r 0
443ret soerr 503 tomsgq
444end
445ret ohgo
446end
447note ---- room: forged cannot measure free space itself (the pinned omc has no statfs host word), so
448note it reads the intake's measure, <data>open/space: "free <digits> reserve <digits> at <digits>\n"
449note (at most 80 bytes, a regular file, opened O_NOFOLLOW|O_NONBLOCK, parsed strictly). forged
450note counts the bytes it writes under open/ after that measure (a new "at" starts the count again),
451note so a stale file cannot let it write past the reserve. The folder is forged's own, so this is
452note advisory for forged only; the intake checks the reserve again before it uses any of it.
453note ohroom: room for n more bytes: 0 yes, 1 no room, 2 no measure (no file), 3 malformed
454fn ohroom n ulong to ulong
455b = new uchar 96 0
456ohfb tospace
457fd = fopen ffile 0 get ffilel 0 559104 0
458if lt fd 0
459ret 2
460end
461k = long -1
462if ohreg int fd
463k = read int fd b 0 96
464end
465x = fclose int fd
466if or lt k 1 gt k 80
467ret 3
468end
469if not ohspace b ulong k
470ret 3
471end
472if ne get gospv 2 get gosat 0
473put gosat 0 get gospv 2
474put goscnt 0 0
475end
476fr = get gospv 0
477rs = get gospv 1
478if lt fr rs
479ret 1
480end
481if lt sub fr rs add get goscnt 0 n
482ret 1
483end
484ret 0
485end
486fn ohused n ulong to void
487put goscnt 0 add get goscnt 0 n
488end
489fn ohreg fd int to bool
490st = new uchar 128 0
491r = fstat fd st 0 128
492if ne r 0
493ret false
494end
495m = or ulong get st 16 shl ulong get st 17 8
496ret eq and m 61440 32768
497end
498note ohspace: b[0, k) is exactly the space line: its three numbers into gospv
499fn ohspace b view uchar 96 k ulong to bool
500p = ohsplit b k 0 tospf
501if lt p 0
502ret false
503end
504p = ohspnum b k ulong p 0
505if lt p 0
506ret false
507end
508p = ohsplit b k ulong p tospr
509if lt p 0
510ret false
511end
512p = ohspnum b k ulong p 1
513if lt p 0
514ret false
515end
516p = ohsplit b k ulong p tospa
517if lt p 0
518ret false
519end
520p = ohspnum b k ulong p 2
521if lt p 0
522ret false
523end
524if ne ulong p sub k 1
525ret false
526end
527ret eq get b ulong p 10
528end
529note ohsplit: t at b[p]; the index after it, or -1
530fn ohsplit b view uchar 96 k ulong p ulong t view uchar * to long
531if gt add p len t k
532ret -1
533end
534for i ulong len t bound 16
535if ne get b add p i get t i
536ret -1
537end
538end
539ret long add p len t
540end
541note ohspnum: 1 to 19 digits at b[p] into gospv i (realns has 19); the index after them, or -1
542fn ohspnum b view uchar 96 k ulong p ulong i ulong to long
543v = ulong 0
544q = p
545while lt q k bound 96
546c = get b q
547if or lt c 48 gt c 57
548break
549end
550v = add mul v 10 ulong sub c 48
551q = add q 1
552if gt sub q p 19
553ret -1
554end
555end
556if eq q p
557ret -1
558end
559put gospv i v
560ret long q
561end
562fn ohnoroom r ulong to void
563if eq r 1
564ohtx tomfull
565ret
566end
567ohtx tomnr
568end
569note ---- the shelf's "Unfinished:" line is left out when the note is empty (no placeholder)
570note ohunf: "<p><strong>Unfinished:</strong> <note></p>" for the row s..e, or nothing
571fn ohunf s ulong e ulong to void
572a = ohfld s e 7
573b = ohfe a e
574if le ohdend a b a
575ret
576end
577fput tounf1
578ohdsc s e 7 200 false
579fput tounf2
580end
581note ---- the developer section of a project the hub stored (classes of the curated project page,
582note server/pages.om, in forge.css): download and its SHA-256, the bringer's
583note DID and public key (ssh form, encoded from the did:key), the hub's key as the intake read it from
584note the node (rad self --did, snapshot line N; left out when the snapshot has none), and what each
585note signature shows. Every value is escaped.
586fn ohdev s ulong e ulong to void
587fput tdv1
588h = new uchar 64 0
589if ohdlsha h
590fput tocl1
591fputb
592fput todir
593ohesc s e 0 44
594fput tdvtar
595ohesc s e 0 44
596fput tdvtar2
597for i ulong 64
598fescc get h i
599end
600fput tdvcode
601else
602fput tdvnone
603end
604fput tdv4
605ohesc s e 2 96
606fput tdv5
607ohsshkey s e
608fput tdv6
609hub = ohnode
610if hub
611fput tdvhub
612ohnodeout
613fput tdv7
614end
615fput tdv8
616if hub
617fput tdv9
618ohnodeout
619fput tdv10
620end
621fput tdv11
622end
623note ohnode: the snapshot has an N line (the hub's DID); ohnodeout writes it escaped
624fn ohnode to bool
625ret gt ohpcnt 78 0
626end
627fn ohnodeout to void
628lim = get gopl 0
629s = ulong 0
630while lt s lim bound 65536
631e = ohpeol s
632if ohpk 78 s e
633ohpesc add s 2 e
634ret
635end
636s = add e 1
637end
638end
639note ohsshkey: the row's did:key as "ssh-ed25519 <base64 of the wire blob>", escaped; nothing when the
640note did is not an Ed25519 did:key
641fn ohsshkey s ulong e ulong to void
642a = ohfld s e 2
643b = ohfe a e
644d = new uchar 96 0
645n = sub b a
646if or le n 9 gt n 96
647ret
648end
649for i ulong n bound 96
650put d i get gol add a i
651end
652for i ulong len tdidp8 bound 16
653if ne get d i get tdidp8 i
654ret
655end
656end
657pk = new uchar 32 0
658if not sodidpk part d 8 sub n 8 pk
659ret
660end
661ohsshout pk
662end
663fn ohsshout pk view uchar 32 to void
664blob = new uchar 51 0
665put blob 3 11
666for i ulong 11
667put blob add i 4 get tdvsshn i
668end
669put blob 18 32
670for i ulong 32
671put blob add i 19 get pk i
672end
673o = new uchar 80 0
674m = sob64 blob o
675fput tdvsshn
676fputc 32
677for i ulong m bound 80
678fescc get o i
679end
680end
681note ---- the list, a row at a time. It has no size limit: <data>open/list.tsv is read in chunks of
682note 65,536 bytes into goc (pread at gost 3) and each row goes to gol (goll bytes from 0), so the
683note row helpers take s = 0 and e = goll. gol holds the first 4,096 bytes of each field (every tab
684note is kept, so the fields keep their places); every field shown is cut shorter than that anyway
685note (ohesc, ohjs: at most 400), so a row of any length is listed. The intake keeps every row whole
686note in the file; its list_row_bytes alarm measures the longest. A failed read sets fobtr: the
687note reply is a whole 500, never a cut list. gost: 0 fd + 1 (0 closed), 1 next byte of goc, 2
688note bytes in goc, 3 the file offset of goc.
689fn ohlopen to void
690ohlclose
691ohfile tolist
692fd = fopen ffile 0 get ffilel 0 557056 0
693if lt fd 0
694ret
695end
696put gost 0 add ulong fd 1
697put gost 1 0
698put gost 2 0
699put gost 3 0
700end
701fn ohlclose to void
702f = get gost 0
703if gt f 0
704x = fclose int sub f 1
705end
706put gost 0 0
707end
708fn ohlfill to bool
709pos = add get gost 3 get gost 2
710k = long -4
711while eq k -4 bound 1000000
712k = pread int sub get gost 0 1 goc 0 65536 long pos
713end
714if lt k 0
715put fobtr 0 1
716ret false
717end
718if eq k 0
719ret false
720end
721put gost 3 pos
722put gost 2 ulong k
723put gost 1 0
724ret true
725end
726note ohlnext: the next row into gol; false at the end of the list (the file is closed then)
727fn ohlnext to bool
728if eq get gost 0 0
729ret false
730end
731n = ulong 0
732fl = ulong 0
733got = false
734while true bound 9223372036854775807
735p = get gost 1
736if ge p get gost 2
737if ohlfill
738continue
739end
740if ne get fobtr 0 0
741ohlclose
742put goll 0 0
743ret false
744end
745if not got
746ohlclose
747ret false
748end
749break
750end
751put gost 1 add p 1
752got = true
753c = get goc p
754if eq c 10
755break
756end
757if eq c 9
758fl = ulong 0
759end
760if and lt fl 4096 lt n 65536
761put gol n c
762n = add n 1
763end
764if ne c 9
765fl = add fl 1
766end
767end
768put goll 0 n
769ret true
770end
771note ohfld: start of field k of the row s..e (e when the row has fewer fields)
772fn ohfld s ulong e ulong k ulong to ulong
773p = s
774j = ulong 0
775while lt j k bound 16
776while lt p e bound 262144
777if eq get gol p 9
778break
779end
780p = add p 1
781end
782if lt p e
783p = add p 1
784end
785j = add j 1
786end
787ret p
788end
789fn ohfe a ulong e ulong to ulong
790p = a
791while lt p e bound 262144
792if eq get gol p 9
793ret p
794end
795p = add p 1
796end
797ret e
798end
799note ohesc / ohjs: field k of the row s..e, HTML-escaped or as JSON string bytes, at most cap bytes
800fn ohesc s ulong e ulong k ulong cap ulong to void
801a = ohfld s e k
802b = ohfe a e
803if gt sub b a cap
804b = add a cap
805end
806ohescr a b
807end
808note ohescr: gol[a, b) HTML-escaped
809fn ohescr a ulong b ulong to void
810i = a
811while lt i b bound 262144
812c = get gol i
813if ge c 32
814fescc c
815end
816i = add i 1
817end
818end
819fn ohjs s ulong e ulong k ulong cap ulong to void
820a = ohfld s e k
821b = ohfe a e
822if gt sub b a cap
823b = add a cap
824end
825ohjsr a b
826end
827note ohjsr: gol[a, b) as JSON string bytes
828fn ohjsr a ulong b ulong to void
829i = a
830while lt i b bound 262144
831c = get gol i
832if or eq c 34 eq c 92
833fputc 92
834fputc c
835else
836if lt c 32
837fput tou00
838fputc get tohex ulong shr c 4
839fputc get tohex ulong and c 15
840else
841fputc c
842end
843end
844i = add i 1
845end
846end
847note ohterm: gol[a, b) (w 0, the list row) or gop[a, b) (w 1, the snapshot) holds a term of
848note toterms, case-insensitive. Radicle was removed on 2026-11-14 and the shelf must not point
849note anyone to it, but list.tsv rows and snapshots written before then still carry its wording
850note (38 descriptions read "public Radicle home while GitHub is suspended (rad init ...)"). The
851note stored data stays as it is: every description, note, state and snapshot line is checked
852note here when it is shown (ohdend, ohdsc, ohpshow).
853fn ohterm w ulong a ulong b ulong to bool
854nt = len toterms
855t = ulong 0
856while lt t nt bound 64
857k = ulong 0
858while lt add t k nt bound 64
859if eq get toterms add t k 124
860break
861end
862k = add k 1
863end
864i = a
865while le add i k b bound 262144
866m = ulong 0
867while lt m k bound 16
868c = uchar 0
869if eq w 0
870c = get gol add i m
871else
872c = get gop add i m
873end
874if and ge c 65 le c 90
875c = add c 32
876end
877if ne c get toterms add t m
878break
879end
880m = add m 1
881end
882if eq m k
883ret true
884end
885i = add i 1
886end
887t = add add t k 1
888end
889ret false
890end
891note ohdend: the end of the part of the list field gol[a, b) that may be shown: b when it has no
892note term; else the place of its first ": " when the part before it has none (shown with tocopy);
893note else a (nothing of it is shown)
894fn ohdend a ulong b ulong to ulong
895if not ohterm 0 a b
896ret b
897end
898p = a
899while lt add p 1 b bound 262144
900if and eq get gol p 58 eq get gol add p 1 32
901if ohterm 0 a p
902ret a
903end
904ret p
905end
906p = add p 1
907end
908ret a
909end
910note ohdsc: field k (1 state, 6 description, 7 note) of the row s..e as ohesc (json false) or ohjs
911note (json true) show it, through ohdend: a cut part is followed by tocopy (not for a state); a
912note description with nothing left is todnone, a note or state with nothing left is empty
913fn ohdsc s ulong e ulong k ulong cap ulong json bool to void
914a = ohfld s e k
915b = ohfe a e
916r = ohdend a b
917c = r
918if gt sub c a cap
919c = add a cap
920end
921if json
922ohjsr a c
923else
924ohescr a c
925end
926if and gt r a lt r b
927if ne k 1
928fput tocopy
929end
930ret
931end
932if and eq r a lt a b
933if eq k 6
934fput todnone
935end
936end
937end
938note ohis: field k of the row equals t
939fn ohis s ulong e ulong k ulong t view uchar * to bool
940a = ohfld s e k
941b = ohfe a e
942if ne sub b a len t
943ret false
944end
945for i ulong len t bound 64
946if ne get gol add a i get t i
947ret false
948end
949end
950ret true
951end
952note ohpub: the row is on the shelf: state open (fetched by the intake), held (the node already
953note had the project) or stored (brought with the one-command tool; the hub created it)
954fn ohpub s ulong e ulong to bool
955if ohis s e 1 tostop
956ret true
957end
958if ohis s e 1 toheld
959ret true
960end
961ret ohis s e 1 tostor
962end
963note ohmine: the row's did (field 2) is the signed-in key (godid)
964fn ohmine s ulong e ulong to bool
965n = get godidl 0
966if eq n 0
967ret false
968end
969a = ohfld s e 2
970b = ohfe a e
971if ne sub b a n
972ret false
973end
974for i ulong n bound 96
975if ne get gol add a i get godid i
976ret false
977end
978end
979ret true
980end
981note ohrow: a row needs its 8 fields and a well-formed rid
982fn ohrow s ulong e ulong to bool
983a = ohfld s e 7
984if gt a e
985ret false
986end
987if eq a e
988if lt e 1
989ret false
990end
991if ne get gol sub e 1 9
992ret false
993end
994end
995b = ohfe s e
996n = sub b s
997if or lt n 20 gt n 44
998ret false
999end
1000for i ulong n bound 44
1001if not ohb58 get gol add s i
1002ret false
1003end
1004end
1005ret true
1006end
1007fn ohcard s ulong e ulong to void
1008fput toc1
1009fput tocl1
1010fputb
1011fput todir
1012ohesc s e 0 44
1013fput tocl2
1014ohesc s e 5 120
1015fput tocl3
1016fput toc2
1017ohdsc s e 6 400 false
1018fput toc3
1019ohunf s e
1020fput toc5
1021ohesc s e 2 96
1022fput toc6
1023ohesc s e 3 10
1024fput toc7
1025ohesc s e 4 10
1026fput toc8
1027if ohis s e 1 tostor
1028fput tosbh
1029end
1030if ohmine s e
1031fput tof1
1032fputb
1033fput todir
1034fput tof2
1035socsrfout
1036fput tow1
1037ohesc s e 0 44
1038fput tow2
1039end
1040fput toc9
1041end
1042fn ohrefused s ulong e ulong to void
1043fput tor1
1044ohesc s e 0 44
1045fput tor2
1046ohdsc s e 1 80 false
1047fput tor3
1048end
1049note ohnum: field 4 (kilobytes) as a number
1050fn ohnum s ulong e ulong to ulong
1051a = ohfld s e 4
1052b = ohfe a e
1053v = ulong 0
1054i = a
1055while lt i b bound 12
1056c = get gol i
1057if and ge c 48 le c 57
1058v = add mul v 10 ulong sub c 48
1059end
1060i = add i 1
1061end
1062ret v
1063end
1064fn ohjson to long
1065put gobody 0 0
1066put gobody 1 1
1067put gobody 2 0
1068put fkind 0 5
1069fsetct toctj
1070ret 200
1071end
1072note ohjrow: one shelf JSON row (the comma is emitted by the generator)
1073fn ohjrow s ulong e ulong to void
1074fput toj2
1075ohjs s e 0 44
1076fput toj3
1077ohjs s e 2 96
1078fput toj4
1079ohjs s e 3 10
1080fput toj5
1081fnum ohnum s e
1082fput toj6
1083ohjs s e 5 120
1084fput toj7
1085ohdsc s e 6 400 true
1086fput toj8
1087ohdsc s e 7 200 true
1088fput toj9a
1089ohdlj s e
1090fputc 125
1091end
1092note ohnav: the forge row entry (server/pages.om fhead)
1093fn ohnav to void
1094fput tocl1
1095fputb
1096fput tonavl
1097end
1098note ohwj: the request wants JSON: it used a .json name (gojs) or says so in Accept. The .json
1099note names exist because a cache in front of forged may key on the address alone.
1100fn ohwj to bool
1101if ne get gojs 0 0
1102ret true
1103end
1104ret fjwant
1105end
1106fn ohpage to long
1107put godidl 0 0
1108signed = ohdid
1109if ohwj
1110ret ohjson
1111end
1112put gobody 0 0
1113put gobody 1 0
1114put gobody 2 0
1115put fkind 0 5
1116fsetti toti
1117fsetct tohtmlct
1118ret 200
1119end
1120note ohintro: the page fragment's prefix (called by ohbody after the layout header)
1121fn ohintro to void
1122fput toh1
1123fput toh2
1124if ne get godidl 0 0
1125fput tof1
1126fputb
1127fput todir
1128fput tof2
1129socsrfout
1130fput tof3
1131else
1132fput toh3
1133fputb
1134fput tologin
1135fput toh4
1136end
1137fput tol1
1138end
1139fn ohoutro to void
1140if eq get gobody 2 0
1141fput tol0
1142end
1143fput toag1
1144fputb
1145fput toag2
1146fputb
1147fput toag3
1148fput toend
1149end
1150note ohbody: the next bounded batch of the shelf response, not a bounded shelf. fsend5 sends it
1151note chunked then asks for another batch, until the file ends. Each row is complete in a batch:
1152note the HTML translation pass sees whole elements. A row uses at most a few KiB after escaping;
1153note the 1 MiB high-water mark leaves room for one more row, not a limit on the response.
1154note gobody: 0 phase (0 layout and intro, 1 rows, 2 tail/layout footer, 3 done), 1 JSON, 2 rows.
1155fn ohbody to bool
1156put fobl 0 0
1157if eq get gobody 0 3
1158ret false
1159end
1160if eq get gobody 0 0
1161ohlopen
1162if ne get gobody 1 0
1163fput toj1
1164else
1165if not ftxwant
1166fhead
1167end
1168ohintro
1169end
1170put gobody 0 1
1171ret true
1172end
1173if eq get gobody 0 1
1174while ohlnext bound 9223372036854775807
1175s = ulong 0
1176e = get goll 0
1177if ohrow s e
1178if ohpub s e
1179if ne get gobody 1 0
1180if gt get gobody 2 0
1181fputc 44
1182end
1183ohjrow s e
1184else
1185ohcard s e
1186end
1187put gobody 2 add get gobody 2 1
1188else
1189if and eq get gobody 1 0 ohmine s e
1190ohrefused s e
1191end
1192end
1193end
1194if ge get fobl 0 1048576
1195ret true
1196end
1197end
1198put gobody 0 2
1199if ne get fobtr 0 0
1200ret false
1201end
1202if gt get fobl 0 0
1203ret true
1204end
1205end
1206if ne get gobody 1 0
1207fput toj10
1208else
1209ohoutro
1210if not ftxwant
1211ffoot
1212end
1213end
1214put gobody 0 3
1215ret true
1216end
1217fn ohbodyend to void
1218ohlclose
1219end
1220note ---- the project page: <base>open/<rid>
1221note Drawn from the shelf row (name, description, note, who, when) and the snapshot the intake wrote
1222note at <data>open/p/<rid>.txt: lines "kind <tab> text" with kind H (head and date), C (a commit),
1223note T (a top-level file: type letter, tab, name) or R (a README line). Only a rid whose row is on
1224note the shelf (open or held) has a page; every byte is escaped here, whatever the file holds.
1225note ohprid: the path after /open/ as a rid into gorid
1226fn ohprid to bool
1227a = len topath
1228n = sub get fpathl 0 a
1229if gt n 5
1230same = true
1231for i ulong 5
1232if ne fpathat add sub add a n 5 i get toejs i
1233same = false
1234end
1235end
1236if same
1237n = sub n 5
1238put gojs 0 1
1239end
1240end
1241if or lt n 20 gt n 44
1242ret false
1243end
1244for i ulong n bound 44
1245c = fpathat add a i
1246if not ohb58 c
1247ret false
1248end
1249put gorid i c
1250end
1251if ne get gorid 0 122
1252ret false
1253end
1254put goridl 0 n
1255ret true
1256end
1257fn ohpis s ulong e ulong to bool
1258b = ohfe s e
1259n = get goridl 0
1260if ne sub b s n
1261ret false
1262end
1263for i ulong n bound 44
1264if ne get gol add s i get gorid i
1265ret false
1266end
1267end
1268ret true
1269end
1270note ohprow: the shelf row (open, held or stored) of gorid into gol (true), else false
1271fn ohprow to bool
1272ohlopen
1273while ohlnext bound 9223372036854775807
1274s = ulong 0
1275e = get goll 0
1276if ohrow s e
1277if ohpub s e
1278if ohpis s e
1279ohlclose
1280ret true
1281end
1282end
1283end
1284end
1285ret false
1286end
1287note ohpload: <data>open/p/<rid>.txt into gop (at most 65,535 bytes; a longer file is shown cut)
1288fn ohpload to void
1289put gopl 0 0
1290put ffilel 0 0
1291for i ulong len tfdata bound 128
1292ffilc get tfdata i
1293end
1294for i ulong len todir bound 16
1295ffilc get todir i
1296end
1297for i ulong len topdir bound 8
1298ffilc get topdir i
1299end
1300for i ulong get goridl 0 bound 44
1301ffilc get gorid i
1302end
1303for i ulong len toptxt bound 8
1304ffilc get toptxt i
1305end
1306fd = fopen ffile 0 get ffilel 0 557056 0
1307if lt fd 0
1308ret
1309end
1310n = ulong 0
1311k = long 1
1312while gt k 0 bound 65536
1313k = read int fd gop n sub 65535 n
1314if gt k 0
1315n = add n ulong k
1316end
1317end
1318x = fclose int fd
1319put gopl 0 n
1320end
1321fn ohpeol a ulong to ulong
1322lim = get gopl 0
1323i = a
1324while lt i lim bound 65536
1325if eq get gop i 10
1326ret i
1327end
1328i = add i 1
1329end
1330ret lim
1331end
1332note ohpesc: gop[a, b) escaped for HTML; a tab becomes a space
1333fn ohpesc a ulong b ulong to void
1334i = a
1335while lt i b bound 65536
1336c = get gop i
1337if eq c 9
1338c = uchar 32
1339end
1340if ge c 32
1341fescc c
1342end
1343i = add i 1
1344end
1345end
1346note ohpjs: gop[a, b) as JSON string bytes; a tab becomes a space
1347fn ohpjs a ulong b ulong to void
1348i = a
1349while lt i b bound 65536
1350c = get gop i
1351if eq c 9
1352c = uchar 32
1353end
1354if or eq c 34 eq c 92
1355fputc 92
1356fputc c
1357else
1358if lt c 32
1359fput tou00
1360fputc get tohex ulong shr c 4
1361fputc get tohex ulong and c 15
1362else
1363fputc c
1364end
1365end
1366i = add i 1
1367end
1368end
1369note ohpk: gop[s, e) is a snapshot line of this kind
1370fn ohpk kind uchar s ulong e ulong to bool
1371if lt e add s 2
1372ret false
1373end
1374if ne get gop s kind
1375ret false
1376end
1377ret eq get gop add s 1 9
1378end
1379note ohpshow: gop[s, e) is a snapshot line of this kind whose text has no ohterm term (a line
1380note that has one is left out)
1381fn ohpshow kind uchar s ulong e ulong to bool
1382if not ohpk kind s e
1383ret false
1384end
1385ret not ohterm 1 add s 2 e
1386end
1387fn ohpcnt kind uchar to ulong
1388lim = get gopl 0
1389n = ulong 0
1390s = ulong 0
1391while lt s lim bound 65536
1392e = ohpeol s
1393if ohpshow kind s e
1394n = add n 1
1395end
1396s = add e 1
1397end
1398ret n
1399end
1400note ohpitem: one snapshot line as HTML
1401fn ohpitem kind uchar s ulong e ulong to void
1402if eq kind 84
1403if lt e add s 4
1404ret
1405end
1406fput topli
1407ohpesc add s 4 e
1408if eq get gop add s 2 116
1409fputc 47
1410end
1411fput toplie
1412ret
1413end
1414if eq kind 67
1415fput topli
1416ohpesc add s 2 e
1417fput toplie
1418ret
1419end
1420ohpesc add s 2 e
1421if eq kind 82
1422fputc 10
1423end
1424end
1425note ohpsec: every snapshot line of one kind, with its heading; nothing when there is none
1426fn ohpsec kind uchar to void
1427if eq ohpcnt kind 0
1428ret
1429end
1430if eq kind 72
1431fput toph
1432end
1433if eq kind 67
1434fput topc
1435end
1436if eq kind 84
1437fput topt
1438end
1439if eq kind 82
1440fput topr
1441end
1442lim = get gopl 0
1443s = ulong 0
1444while lt s lim bound 65536
1445e = ohpeol s
1446if ohpshow kind s e
1447ohpitem kind s e
1448end
1449s = add e 1
1450end
1451if eq kind 72
1452fput tophe
1453end
1454if or eq kind 67 eq kind 84
1455fput topul
1456end
1457if eq kind 82
1458fput toppre
1459end
1460end
1461note ohpjarr: the lines of a kind as JSON strings (a file: its name, a folder with a slash)
1462fn ohpjarr kind uchar to void
1463lim = get gopl 0
1464n = ulong 0
1465s = ulong 0
1466while lt s lim bound 65536
1467e = ohpeol s
1468if ohpshow kind s e
1469if gt n 0
1470fputc 44
1471end
1472fputc 34
1473if eq kind 84
1474if ge e add s 4
1475ohpjs add s 4 e
1476if eq get gop add s 2 116
1477fputc 47
1478end
1479end
1480else
1481ohpjs add s 2 e
1482end
1483fputc 34
1484n = add n 1
1485end
1486s = add e 1
1487end
1488end
1489note ohpjtxt: the lines of a kind in one JSON string: only the first one, or all joined by \n
1490fn ohpjtxt kind uchar first bool to void
1491lim = get gopl 0
1492s = ulong 0
1493while lt s lim bound 65536
1494e = ohpeol s
1495if ohpshow kind s e
1496ohpjs add s 2 e
1497if first
1498ret
1499end
1500fputc 92
1501fputc 110
1502end
1503s = add e 1
1504end
1505end
1506note ---- parts taken from the project: the link between the shelf and the submission journey
1507note A submission (salvage/) names where it came from in its origin field. A source whose origin
1508note is exactly <rid> or rad:<rid>, and an Omega part derived from such a source, are listed on the
1509note project page. The salvage slice publishes a derived part only with a passing receipt, so a
1510note listed part is a verified one; a source is listed as not verified. The project itself stays
1511note "Not verified": this is a list of facts, not a verdict on the project. Only the newest 200
1512note submissions are looked at. Nothing is listed while the salvage store is off.
1513note ohtit: the title of the loaded record into gotit
1514fn ohtit to void
1515n = get gllen 1
1516if gt n 200
1517n = ulong 200
1518end
1519o = get gloff 1
1520for i ulong n bound 200
1521put gotit i get glrec add o i
1522end
1523put gotitl 0 n
1524end
1525note ohorig: the origin field of the loaded record is exactly <gorid>, or rad:<gorid> as sources
1526note named it before the shelf showed the bare id
1527fn ohorig to bool
1528n = get gllen 2
1529m = get goridl 0
1530if eq n m
1531q = get gloff 2
1532for i ulong m bound 44
1533if ne get glrec add q i get gorid i
1534ret false
1535end
1536end
1537ret true
1538end
1539if ne n add 4 m
1540ret false
1541end
1542o = get gloff 2
1543for i ulong 4
1544if ne get glrec add o i get torad i
1545ret false
1546end
1547end
1548for i ulong m bound 44
1549if ne get glrec add add o 4 i get gorid i
1550ret false
1551end
1552end
1553ret true
1554end
1555note ohmatch: 0 the public submission id is not from this project, 1 it is a source from it, 2 it
1556note is a published Omega part derived from a source from it. Its title is left in gotit.
1557fn ohmatch id view uchar * to ulong
1558pid = new uchar 64 0
1559if not slpublic id
1560ret 0
1561end
1562ohtit
1563if eq get glrec 8 1
1564if ohorig
1565ret 1
1566end
1567ret 0
1568end
1569if ne get glrec 8 2
1570ret 0
1571end
1572if ne get gllen 6 64
1573ret 0
1574end
1575o = get gloff 6
1576for i ulong 64
1577put pid i get glrec add o i
1578end
1579if not slload pid
1580ret 0
1581end
1582if ne get glrec 8 1
1583ret 0
1584end
1585if ohorig
1586ret 2
1587end
1588ret 0
1589end
1590fn ohtjs to void
1591for i ulong get gotitl 0 bound 200
1592c = get gotit i
1593if or eq c 34 eq c 92
1594fputc 92
1595fputc c
1596else
1597if lt c 32
1598fput tou00
1599fputc get tohex ulong shr c 4
1600fputc get tohex ulong and c 15
1601else
1602fputc c
1603end
1604end
1605end
1606end
1607fn ohpart id view uchar * k ulong json bool shown ulong to void
1608if json
1609if gt shown 0
1610fputc 44
1611end
1612fput topk1
1613for i ulong 64
1614fputc get id i
1615end
1616fput topk2
1617ohtjs
1618if eq k 2
1619fput topk3
1620else
1621fput topk4
1622end
1623ret
1624end
1625if eq shown 0
1626fput topa1
1627end
1628fput topli
1629fput tlhref
1630fputb
1631fput tlslug
1632for i ulong 64
1633fputc get id i
1634end
1635fput tlendh
1636for i ulong get gotitl 0 bound 200
1637fescc get gotit i
1638end
1639fput tlenda
1640if eq k 2
1641fput topa2
1642else
1643fput topa3
1644end
1645fput toplie
1646end
1647fn ohparts json bool to void
1648id = new uchar 64 0
1649if not slboot
1650ret
1651end
1652n = get glidxn 0
1653shown = ulong 0
1654for it ulong 200
1655if eq n 0
1656break
1657end
1658n = sub n 1
1659for i ulong 64
1660put id i get glidx add mul n 65 i
1661end
1662k = ohmatch id
1663if gt k 0
1664ohpart id k json shown
1665shown = add shown 1
1666end
1667end
1668if json
1669ret
1670end
1671if eq shown 0
1672fput topa4
1673fputb
1674fput topa5
1675for i ulong get goridl 0 bound 44
1676fescc get gorid i
1677end
1678fput topa6
1679else
1680fput topul
1681end
1682end
1683fn ohpjson s ulong e ulong to long
1684put fkind 0 1
1685fsetct toctj
1686fput topj1
1687ohjs s e 0 44
1688fput toj3
1689ohjs s e 2 96
1690fput toj4
1691ohjs s e 3 10
1692fput toj5
1693fnum ohnum s e
1694fput toj6
1695ohjs s e 5 120
1696fput toj7
1697ohdsc s e 6 400 true
1698fput toj8
1699ohdsc s e 7 200 true
1700fput toj9a
1701ohdlj s e
1702fput topj2b
1703ohpjtxt 72 true
1704fput topj3
1705ohpjarr 67
1706fput topj4
1707ohpjarr 84
1708fput topj5
1709ohpjtxt 82 false
1710fput topj6
1711ohparts true
1712fput topj7
1713ret 200
1714end
1715fn ohproj to long
1716if not fget
1717ret 405
1718end
1719if not ohprid
1720ret 404
1721end
1722if not ohprow
1723ret 404
1724end
1725s = ulong 0
1726e = get goll 0
1727ohpload
1728if ohwj
1729ret ohpjson s e
1730end
1731put fkind 0 0
1732fsetti toti
1733fput top1
1734fputb
1735fput todir
1736fput top2
1737ohesc s e 5 120
1738fput top3
1739ohdsc s e 6 400 false
1740fput top4
1741ohunf s e
1742fput top5
1743fput top6
1744ohesc s e 2 96
1745fput top7
1746ohesc s e 3 10
1747fput top8
1748if eq get gopl 0 0
1749fput topno
1750end
1751ohpsec 72
1752ohpsec 67
1753ohpsec 84
1754ohpsec 82
1755if ohis s e 1 tostor
1756ohdev s e
1757end
1758ohparts false
1759fput toend
1760ret 200
1761end
1762note ohroute: 0 = not an open-builds path
1763fn ohroute to long
1764put gojs 0 0
1765if fpeq tobrsh
1766ret ohtool tobrf
1767end
1768if fpeq togtsh
1769ret ohtool togtf
1770end
1771if fpeq towdsh
1772ret ohtool towdf
1773end
1774if fpeq topjsn
1775if not fget
1776ret 405
1777end
1778put gojs 0 1
1779ret ohpage
1780end
1781if fpeq topat2
1782flocb
1783floct todir
1784put fkind 0 2
1785ret 301
1786end
1787if not fpre topath
1788ret 0
1789end
1790if fpeq toup
1791ret ohup
1792end
1793if fpre toupd
1794ret ohupst
1795end
1796if fpeq toalj
1797ret ohalarm
1798end
1799if ohistar
1800ret ohtar
1801end
1802if not fpeq topath
1803ret ohproj
1804end
1805if eq get fmeth 0 3
1806ret ohpost
1807end
1808if not fget
1809ret 405
1810end
1811ret ohpage
1812end
1813note ---- one-command bring: the upload (contract one-command-contract.md, slice HUB)
1814note The spool of one upload is <data>open/up/<sha>.<didhash>.b64, didhash the first 8 bytes of
1815note sha256(did) in hex, so a key only ever appends to its own spool. One line per chunk, in seq
1816note order: the base64url data, a tab, the seq and the archive bytes received so far as 10 decimal
1817note digits each, a line feed. The last 22 bytes of the file are always the newest seq and total, so
1818note a chunk costs one short read whatever the size of the spool. finish writes
1819note <sha>.<didhash>.sig (the armored signature of the bring statement) and one queue line. The
1820note intake (outside this sandbox) checks everything again and writes <sha>.<didhash>.json, the
1821note status. Nothing here decodes, unpacks or runs what was brought.
1822note ohtx: a text/plain answer
1823fn ohtx t view uchar * to void
1824put fobl 0 0
1825put fkind 0 1
1826fsetct totxt
1827fput t
1828end
1829fn ohnext n ulong to void
1830ohtx tonext
1831fnum n
1832fputc 10
1833end
1834note ohpre: the text answer for a status of the write gate (sowpre)
1835fn ohpre r long to void
1836if eq r 429
1837ohtx tom429
1838ret
1839end
1840if eq r 503
1841ohtx tom503
1842ret
1843end
1844if eq r 403
1845ohtx tom403
1846ret
1847end
1848ohtx tom400
1849end
1850note ohfb: ffile = <data>open/ then t
1851fn ohfb t view uchar * to void
1852put ffilel 0 0
1853for i ulong len tfdata bound 128
1854ffilc get tfdata i
1855end
1856for i ulong len todir bound 16
1857ffilc get todir i
1858end
1859for i ulong len t bound 16
1860ffilc get t i
1861end
1862end
1863note ohupf: ffile = <data>open/up/<sha>.<didhash> then ext
1864fn ohupf ext view uchar * to void
1865ohfb toupdir
1866for i ulong 64
1867ffilc get gosha i
1868end
1869ffilc 46
1870for i ulong 16
1871ffilc get godh i
1872end
1873for i ulong len ext bound 16
1874ffilc get ext i
1875end
1876end
1877note ohupmk: <data>open/ and <data>open/up/ exist (made 0700)
1878fn ohupmk to void
1879ohfb toupdir
1880put ffilel 0 sub get ffilel 0 len toupdir
1881r = makedir ffile 0 get ffilel 0 448
1882ohfb toupdir
1883r = makedir ffile 0 get ffilel 0 448
1884end
1885fn ohhex c uchar to bool
1886ret or and ge c 48 le c 57 and ge c 97 le c 102
1887end
1888fn ohb64c c uchar to bool
1889if and ge c 65 le c 90
1890ret true
1891end
1892if and ge c 97 le c 122
1893ret true
1894end
1895if and ge c 48 le c 57
1896ret true
1897end
1898ret or eq c 45 eq c 95
1899end
1900fn ohws c uchar to bool
1901ret or or eq c 32 eq c 10 or eq c 9 eq c 13
1902end
1903fn ohsigc c uchar to bool
1904if ohb64c c
1905ret true
1906end
1907ret or or eq c 43 eq c 47 or or eq c 61 eq c 32 eq c 10
1908end
1909note ohsha: the form value gcfv[0, n) is 64 lowercase hex: into gosha
1910fn ohsha n long to bool
1911if ne n 64
1912ret false
1913end
1914for i ulong 64
1915c = get gcfv i
1916if not ohhex c
1917ret false
1918end
1919put gosha i c
1920end
1921ret true
1922end
1923note ohdec: gcfv[0, n) as a decimal number of 1 to 18 digits; -1 when it is not one
1924fn ohdec n long to long
1925if or lt n 1 gt n 18
1926ret -1
1927end
1928v = long 0
1929for i ulong ulong n bound 18
1930c = get gcfv i
1931if or lt c 48 gt c 57
1932ret -1
1933end
1934v = add mul v 10 long sub c 48
1935end
1936ret v
1937end
1938note ohname: gcfv[0, n) is a project name of the contract: 1 to 64 bytes of [a-z0-9-], no '-'
1939note first, last or twice in a row (what the tool makes of a folder name): into goname
1940fn ohname n long to bool
1941if or lt n 1 gt n 64
1942ret false
1943end
1944p = uchar 45
1945for i ulong ulong n bound 64
1946c = get gcfv i
1947ok = or and ge c 97 le c 122 and ge c 48 le c 57
1948if eq c 45
1949if eq p 45
1950ret false
1951end
1952ok = true
1953end
1954if not ok
1955ret false
1956end
1957put goname i c
1958p = c
1959end
1960if eq p 45
1961ret false
1962end
1963put gonamel 0 ulong n
1964ret true
1965end
1966note ohsig: gcfv[0, n) is an armored SSH signature (its BEGIN and END lines, base64 and line feeds
1967note between; white space around it is dropped): into gosig with one line feed at the end
1968fn ohsig n long to bool
1969if lt n 1
1970ret false
1971end
1972a = ulong 0
1973b = ulong n
1974for i ulong ulong n bound 65536
1975if not ohws get gcfv a
1976break
1977end
1978a = add a 1
1979end
1980for i ulong ulong n bound 65536
1981if le b a
1982break
1983end
1984if not ohws get gcfv sub b 1
1985break
1986end
1987b = sub b 1
1988end
1989k = sub b a
1990if lt k add len tosgb len tosge
1991ret false
1992end
1993for i ulong len tosgb
1994if ne get gcfv add a i get tosgb i
1995ret false
1996end
1997end
1998for i ulong len tosge
1999if ne get gcfv add sub b len tosge i get tosge i
2000ret false
2001end
2002end
2003for i ulong k bound 65536
2004c = get gcfv add a i
2005if not ohsigc c
2006ret false
2007end
2008put gosig i c
2009end
2010put gosig k 10
2011put gosigl 0 add k 1
2012ret true
2013end
2014note ohdh: godh = hex of the first 8 bytes of sha256(godid)
2015fn ohdh to void
2016m = new uchar 96 0
2017o = new uchar 32 0
2018n = get godidl 0
2019for i ulong n bound 96
2020put m i get godid i
2021end
2022k = sha2_digest 256 part m 0 n o
2023for i ulong 8
2024c = get o i
2025put godh mul i 2 get tohex ulong shr c 4
2026put godh add mul i 2 1 get tohex ulong and c 15
2027end
2028end
2029fn ohsize fd int to long
2030st = new uchar 128 0
2031r = fstat fd st 0 128
2032if ne r 0
2033ret -1
2034end
2035sz = ulong 0
2036for i ulong 8
2037sz = or sz shl ulong get st add 48 i mul i 8
2038end
2039ret long sz
2040end
2041note ohtail: the next seq and the total so far of the spool fd of size sz into gonx; false when the
2042note file does not end in a well-formed record
2043fn ohtail fd int sz ulong to bool
2044put gonx 0 0
2045put gonx 1 0
2046if eq sz 0
2047ret true
2048end
2049if lt sz 45
2050ret false
2051end
2052b = new uchar 42 0
2053k = pread fd b 0 42 long sub sz 42
2054if ne k 42
2055ret false
2056end
2057if or ne get b 20 9 ne get b 41 10
2058ret false
2059end
2060s = ulong 0
2061t = ulong 0
2062for i ulong 20
2063c = get b i
2064d = get b add i 21
2065if or or lt c 48 gt c 57 or lt d 48 gt d 57
2066ret false
2067end
2068if or gt s 999999999999999999 gt t 999999999999999999
2069ret false
2070end
2071s = add mul s 10 ulong sub c 48
2072t = add mul t 10 ulong sub d 48
2073end
2074put gonx 0 add s 1
2075put gonx 1 t
2076ret true
2077end
2078note oh20: v as 20 decimal digits at b[o]: every ulong fits (2^64 - 1 has 20), so the running
2079note total of a spool never wraps (it was 10 digits, which wrapped at 10^10 bytes)
2080fn oh20 b edit uchar * o ulong v ulong to void
2081x = v
2082for i ulong 20
2083put b sub add o 19 i uchar add 48 rem x 10
2084x = div x 10
2085end
2086end
2087fn ohexist to bool
2088ret eq faccess ffile 0 get ffilel 0 0 0
2089end
2090note ohchunk: action=chunk. 409 "next <n>" when seq is not the next one (or the upload is finished),
2091note 503 when the chunk would take the data filesystem below its reserve (ohroom) or the spool
2092note cannot be written. There is no size limit and no 413: the data reserve bounds the spool.
2093fn ohchunk to long
2094seq = ohdec slgetform tofseq
2095if lt seq 0
2096ohtx tom400
2097ret 400
2098end
2099m = slgetform tofdata
2100if or lt m 2 gt m 60000
2101ohtx tom400
2102ret 400
2103end
2104if eq rem m 4 1
2105ohtx tom400
2106ret 400
2107end
2108for i ulong ulong m bound 60000
2109if not ohb64c get gcfv i
2110ohtx tom400
2111ret 400
2112end
2113end
2114rm = ohroom add ulong m 43
2115if ne rm 0
2116ohnoroom rm
2117ret 503
2118end
2119r4 = rem ulong m 4
2120dec = mul div ulong m 4 3
2121if gt r4 0
2122dec = add dec sub r4 1
2123end
2124ohupmk
2125ohupf tob64
2126fl = int 558082
2127if eq seq 0
2128fl = int 558146
2129end
2130fd = fopen ffile 0 get ffilel 0 fl 384
2131if lt fd 0
2132if gt seq 0
2133ohnext 0
2134ret 409
2135end
2136ohtx tom503
2137ret 503
2138end
2139r = ohchunk2 int fd ulong seq ulong m dec
2140x = fclose int fd
2141ret r
2142end
2143fn ohchunk2 fd int seq ulong m ulong dec ulong to long
2144sz = ohsize fd
2145if lt sz 0
2146ohtx tom503
2147ret 503
2148end
2149if not ohtail fd ulong sz
2150ohtx tom503
2151ret 503
2152end
2153nx = get gonx 0
2154ohupf tosig
2155if ohexist
2156ohnext nx
2157ret 409
2158end
2159if ne seq nx
2160ohnext nx
2161ret 409
2162end
2163tot = add get gonx 1 dec
2164if eq seq 0
2165ohupf toejs
2166r = unlink ffile 0 get ffilel 0
2167end
2168b = new uchar 60048 0
2169for i ulong m bound 60000
2170put b i get gcfv i
2171end
2172put b m 9
2173oh20 b add m 1 seq
2174put b add m 21 9
2175oh20 b add m 22 tot
2176put b add m 42 10
2177w = write fd b 0 add m 43
2178if ne w long add m 43
2179r = ftrunc fd sz
2180ohtx tom503
2181ret 503
2182end
2183ohused add m 43
2184ohnext add seq 1
2185ret 200
2186end
2187note ohqnum: v in decimal at b[o]; the index after it
2188fn ohqnum b edit uchar * o ulong v ulong to ulong
2189d = new uchar 20 0
2190k = ulong 0
2191x = v
2192if eq x 0
2193put d 0 48
2194k = ulong 1
2195end
2196while gt x 0 bound 20
2197put d k uchar add 48 rem x 10
2198x = div x 10
2199k = add k 1
2200end
2201for i ulong k bound 20
2202put b add o i get d sub sub k 1 i
2203end
2204ret add o k
2205end
2206note ohqup: the queue line U <tab> sha <tab> did <tab> files <tab> bytes <tab> name <tab> note;
2207note 0 done, else 503 (the queue's 1 MiB cap, as for B and W lines)
2208fn ohqup files ulong byt ulong to long
2209b = new uchar 640 0
2210ohfb toq
2211fd = fopen ffile 0 get ffilel 0 558145 384
2212if lt fd 0
2213ret 503
2214end
2215note the size first: a short write (a full disk) is cut back to it, so no fragment joins the next line
2216sz = ohsize int fd
2217put b 0 85
2218put b 1 9
2219for i ulong 64
2220put b add 2 i get gosha i
2221end
2222put b 66 9
2223n = ulong 67
2224for i ulong get godidl 0 bound 96
2225put b add n i get godid i
2226end
2227n = add n get godidl 0
2228put b n 9
2229n = ohqnum b add n 1 files
2230put b n 9
2231n = ohqnum b add n 1 byt
2232put b n 9
2233n = add n 1
2234for i ulong get gonamel 0 bound 64
2235put b add n i get goname i
2236end
2237n = add n get gonamel 0
2238put b n 9
2239n = add n 1
2240for i ulong get gonotel 0 bound 200
2241put b add n i get gonote i
2242end
2243n = add n get gonotel 0
2244put b n 10
2245n = add n 1
2246w = write int fd b 0 n
2247if ne w long n
2248if ge sz 0
2249r = ftrunc int fd sz
2250end
2251x = fclose int fd
2252ret 503
2253end
2254x = fclose int fd
2255ohused n
2256ret 0
2257end
2258fn ohqd to void
2259ohtx toqd
2260for i ulong 64
2261fputc get gosha i
2262end
2263fputc 10
2264end
2265note ohfin: action=finish. The chunks must add up to bytes (fewer: 409 "next <n>"). A finish that
2266note was already queued answers "queued" again and queues nothing.
2267fn ohfin to long
2268if not slffeq tocons toyes
2269ohtx tom400
2270ret 400
2271end
2272files = ohdec slgetform toffile
2273byt = ohdec slgetform tofbyte
2274if or lt files 0 lt byt 1
2275ohtx tom400
2276ret 400
2277end
2278if not ohname slgetform tofname
2279ohtx tom400
2280ret 400
2281end
2282put gonotel 0 0
2283n = slgetform tonote
2284if ge n 0
2285if not ohnote ulong n
2286ohtx tom400
2287ret 400
2288end
2289end
2290if not ohsig slgetform tofsig
2291ohtx tom400
2292ret 400
2293end
2294ohupf tob64
2295fd = fopen ffile 0 get ffilel 0 557056 0
2296if lt fd 0
2297ohtx tom404
2298ret 404
2299end
2300sz = ohsize int fd
2301ok = false
2302if gt sz 0
2303ok = ohtail int fd ulong sz
2304end
2305x = fclose int fd
2306if not ok
2307ohtx tom503
2308ret 503
2309end
2310ret ohfin2 ulong files ulong byt
2311end
2312fn ohfin2 files ulong byt ulong to long
2313tot = get gonx 1
2314if lt tot byt
2315ohnext get gonx 0
2316ret 409
2317end
2318if gt tot byt
2319ohtx tom400
2320ret 400
2321end
2322ohupf tosig
2323if ohexist
2324ohqd
2325ret 200
2326end
2327rm = ohroom add get gosigl 0 640
2328if ne rm 0
2329ohnoroom rm
2330ret 503
2331end
2332ohupf tosig
2333fd = fopen ffile 0 get ffilel 0 557249 384
2334if lt fd 0
2335ohtx tom503
2336ret 503
2337end
2338w = write int fd gosig 0 get gosigl 0
2339ohused get gosigl 0
2340x = fclose int fd
2341if ne w long get gosigl 0
2342r = unlink ffile 0 get ffilel 0
2343ohtx tom503
2344ret 503
2345end
2346r = ohqup files byt
2347if ne r 0
2348ohupf tosig
2349r = unlink ffile 0 get ffilel 0
2350ohtx tom503
2351ret 503
2352end
2353ohqd
2354ret 200
2355end
2356note ohup: POST <base>open/up. Signed out is 403 here (the tool reads a status, not a page); then
2357note the forge write gate (CSRF, the per-IP and per-key write limits, the store), unchanged.
2358fn ohup to long
2359if ne get fmeth 0 3
2360ret 405
2361end
2362if eq get gscur 0 0
2363ohtx tom403
2364ret 403
2365end
2366r = sowpre
2367if ne r 0
2368ohpre r
2369ret r
2370end
2371soratev get gscur 0 get gsnow 0
2372if not slformvalid
2373ohtx tom400
2374ret 400
2375end
2376if ne slgetform tsfcsrf 32
2377ohtx tom403
2378ret 403
2379end
2380put godidl 0 0
2381if not ohdid
2382ohtx tom403
2383ret 403
2384end
2385if not ohsha slgetform tofsha
2386ohtx tom400
2387ret 400
2388end
2389ohdh
2390if slffeq toact tofchnk
2391ret ohchunk
2392end
2393if slffeq toact toffin
2394ret ohfin
2395end
2396ohtx tom400
2397ret 400
2398end
2399fn ohust t view uchar * to void
2400put fobl 0 0
2401put fkind 0 1
2402fsetct toctj
2403fput tous1
2404fput t
2405fput tous2
2406end
2407note ohupst: GET <base>open/up/<sha>.json for the signed-in key: the intake's status file when there
2408note is one (stored or refused), else queued (finished) or receiving (chunks only); 404 for none
2409fn ohupst to long
2410if not fget
2411ret 405
2412end
2413a = len toupd
2414if ne get fpathl 0 add a 69
2415ret 404
2416end
2417for i ulong 64
2418c = fpathat add a i
2419if not ohhex c
2420ret 404
2421end
2422put gosha i c
2423end
2424for i ulong 5
2425if ne fpathat add add a 64 i get toejs i
2426ret 404
2427end
2428end
2429put godidl 0 0
2430if not ohdid
2431ohtx tom403
2432ret 403
2433end
2434ohdh
2435ohupf toejs
2436if ohexist
2437put fkind 0 3
2438fsetct toctj
2439ret 200
2440end
2441ohupf tosig
2442if ohexist
2443ohust toqueue
2444ret 200
2445end
2446ohupf tob64
2447if ohexist
2448ohust torecv
2449ret 200
2450end
2451ohtx tom404
2452ret 404
2453end
2454note ---- get: <base>open/<rid>.tar, the snapshot the intake wrote for a shelf row
2455fn ohistar to bool
2456n = get fpathl 0
2457a = len topath
2458if le n add a 4
2459ret false
2460end
2461for i ulong 4
2462if ne fpathat add sub n 4 i get totar i
2463ret false
2464end
2465end
2466ret true
2467end
2468note ohaf: ffile = <data>open/a/<gorid> then ext
2469fn ohaf ext view uchar * to void
2470ohfb toadir
2471for i ulong get goridl 0 bound 44
2472ffilc get gorid i
2473end
2474for i ulong len ext bound 16
2475ffilc get ext i
2476end
2477end
2478note ohcdn: Content-Disposition attachment; filename="<name>.tar" from the row's name: lowercase
2479note letters and digits kept, every other run of bytes one '-', "project" when nothing is left
2480fn ohnamec c uchar to bool
2481ret or and ge c 97 le c 122 and ge c 48 le c 57
2482end
2483fn ohcdn s ulong e ulong to void
2484w = new uchar 64 0
2485a = ohfld s e 5
2486b = ohfe a e
2487k = ulong 0
2488i = a
2489while and lt i b lt k 64 bound 262144
2490c = get gol i
2491if and ge c 65 le c 90
2492c = uchar add c 32
2493end
2494if not ohnamec c
2495c = uchar 45
2496end
2497if eq c 45
2498if gt k 0
2499if ne get w sub k 1 45
2500put w k c
2501k = add k 1
2502end
2503end
2504else
2505put w k c
2506k = add k 1
2507end
2508i = add i 1
2509end
2510if gt k 0
2511if eq get w sub k 1 45
2512k = sub k 1
2513end
2514end
2515fsetcd tocda
2516if eq k 0
2517for j ulong len toproj
2518fcdc get toproj j
2519end
2520end
2521for j ulong k bound 64
2522fcdc get w j
2523end
2524for j ulong len totar
2525fcdc get totar j
2526end
2527fcdc 34
2528end
2529fn ohtar to long
2530if not fget
2531ret 405
2532end
2533a = len topath
2534n = sub sub get fpathl 0 a 4
2535if or lt n 20 gt n 44
2536ret 404
2537end
2538for i ulong n bound 44
2539c = fpathat add a i
2540if not ohb58 c
2541ret 404
2542end
2543put gorid i c
2544end
2545if ne get gorid 0 122
2546ret 404
2547end
2548put goridl 0 n
2549if not ohprow
2550ret 404
2551end
2552s = ulong 0
2553e = get goll 0
2554ohaf totar
2555put fkind 0 3
2556fsetct totarct
2557ohcdn s e
2558ret 200
2559end
2560note ohdlsha: the snapshot <data>open/a/<gorid>.tar exists and <gorid>.sha256 holds 64 hex: into h
2561fn ohdlsha h edit uchar 64 to bool
2562ohaf totar
2563if not ohexist
2564ret false
2565end
2566ohaf tosha
2567fd = fopen ffile 0 get ffilel 0 557056 0
2568if lt fd 0
2569ret false
2570end
2571k = read int fd h 0 64
2572x = fclose int fd
2573if ne k 64
2574ret false
2575end
2576for i ulong 64
2577if not ohhex get h i
2578ret false
2579end
2580end
2581ret true
2582end
2583note ohdlj: the JSON fields stored_by_hub, download and download_sha256 of the row s..e
2584fn ohdlj s ulong e ulong to void
2585fput tosbh1
2586if ohis s e 1 tostor
2587fput totrue
2588else
2589fput tofalse
2590end
2591b = ohfe s e
2592n = sub b s
2593if or lt n 20 gt n 44
2594fput todl0
2595ret
2596end
2597for i ulong n bound 44
2598put gorid i get gol add s i
2599end
2600put goridl 0 n
2601h = new uchar 64 0
2602if not ohdlsha h
2603fput todl0
2604ret
2605end
2606fput todl1
2607fputb
2608fput todir
2609for i ulong n bound 44
2610fputc get gorid i
2611end
2612fput todl2
2613for i ulong 64
2614fputc get h i
2615end
2616fputc 34
2617end
2618note ---- files the intake and the operator leave for forged to serve as they are
2619fn ohtool name view uchar * to long
2620if not fget
2621ret 405
2622end
2623ohfb totools
2624for i ulong len name bound 16
2625ffilc get name i
2626end
2627put fkind 0 3
2628fsetct totxt
2629ret 200
2630end
2631fn ohalarm to long
2632if not fget
2633ret 405
2634end
2635ohfb toalf
2636put fkind 0 3
2637fsetct toctj
2638ret 200
2639end