interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / salvage / collector.om

98 lines · 2897 bytes Raw Blame History
1note collector.om: the salvage collector as its own program. Compose om2 + pinned om/tls/sha2.om +
2note salvage/00core.om + salvage/10verify.om + this unit. It runs outside the server's namespace,
3note because verification needs the pinned compiler, bwrap and prlimit and the server has none of them.
4note Environment, all required:
5note INTERPLANE_SALVAGE_DIR the store the server uses (absolute, ending in /)
6note INTERPLANE_SALVAGE_WORK a private scratch folder (absolute, ending in /), never inside the
7note store: the sandboxed server can write the store, and scratch files
8note are compiled and executed
9note OMEGA_COMPILER absolute path of the pinned omc; slverify refuses any other digest
10note It polls the one job file about three times a second, verifies the queued record in the
11note sandbox, writes the receipt with the store's key and removes the job. It never creates the
12note store or its key: until the server has made them it waits. With any argument it makes one pass
13note and exits: 0 nothing queued, 1 a receipt was written, 2 the job ended without one, 3 no key yet.
14note The store is input from a less trusted process: names are fixed, the job must be a record id,
15note the record must hash to that id, every read is bounded and refuses a symlink as the file.
16text tcenv "INTERPLANE_SALVAGE_DIR="
17text tcwenv "INTERPLANE_SALVAGE_WORK="
18text tcbad "salvage-collector: INTERPLANE_SALVAGE_DIR and INTERPLANE_SALVAGE_WORK must be absolute paths ending in /, the second outside the first\n"
19note tcenvroot: the value of the variable whose name with = is t, as the store root or the scratch root
20fn tcenvroot t view uchar * work bool to bool
21b = new uchar 1024 0
22for i ulong ulong envcnt bound 4096
23n = envread i b 0 1024
24if ge n long len t
25same = true
26for j ulong len t
27if ne get b j get t j
28same = false
29end
30end
31if same
32if work
33ret slwroot view part b len t sub ulong n len t
34end
35ret slroot view part b len t sub ulong n len t
36end
37end
38end
39ret false
40end
41note tcapart: the scratch root is not the store and not inside it
42fn tcapart to bool
43n = get glrootn 0
44if lt get glwrootn 0 n
45ret true
46end
47for i ulong n bound 512
48if ne get glwroot i get glroot i
49ret true
50end
51end
52ret false
53end
54note tckey: the receipt key the server created, read and never written here
55fn tckey to bool
56b = new uchar 32 0
57p = new uchar 1024 0
58slpath tlempty tlkey
59n = slpget p
60r = slread view part p 0 n b
61if ne r 32
62ret false
63end
64for i ulong 32
65put glkey i get b i
66end
67ret true
68end
69fn tcboot to bool
70if not tcenvroot tcenv false
71ret false
72end
73if not tcenvroot tcwenv true
74ret false
75end
76ret tcapart
77end
78fn main to int
79if not tcboot
80r = write 2 tcbad 0 len tcbad
81ret 1
82end
83once = gt argcnt 1
84while true bound 9223372036854775807
85if tckey
86c = slcollect
87if once
88ret int c
89end
90else
91if once
92ret 3
93end
94end
95z = sleepns 300000000
96end
97ret 0
98end