interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / community / 20api.om

380 lines · 6472 bytes Raw Blame History
1note community/20api.om -- the four message kinds, in the order of checks:
2note size, form, key, clock, signature, deny list, replay, then volume counting (per key and in all;
3note alarms only, nothing is refused for volume), then the kind. Counters move only after the
4note signature and the replay check, so nobody can inflate another key's count.
5
6const cmcagr ulong 25
7const cmcsnd ulong 26
8text cmtnone "next"
9text cmlok "ok"
10text cmjlf "job "
11text cmtsl "/"
12text cmplf "part "
13text cmclf "compiler "
14
15fn cm_api to long
16put cmgv cmchub 0
17put cmgv cmcsec 0
18if not cm_on
19ret cm_refuse cmeoff
20end
21if ne get fmeth 0 3
22ret 405
23end
24if not cm_lock
25ret cm_refuse cmeio
26end
27r = cm_handle
28cm_unlock
29ret r
30end
31
32fn cm_handle to long
33e = cm_parse
34if ne e 0
35ret cm_refuse e
36end
37cm_msha
38k = get cmgv cmkind
39if eq k 1
40e = cm_regkey
41else
42e = cm_kload
43end
44if ne e 0
45ret cm_refuse e
46end
47t = cm_fnum cmftime
48now = cm_now
49if or gt t add now cmskew lt add t cmskew now
50ret cm_refuse cmeclk
51end
52if not cm_verify
53ret cm_refuse cmesig
54end
55if cm_kdeny
56ret cm_refuse cmeden
57end
58cm_msgp
59if cm_exists
60ret cm_refuse cmedup
61end
62cm_tkey
63cm_tally cmtall cmaall cmtamsg
64if eq k 1
65ret cm_doreg
66end
67if eq k 2
68ret cm_donext
69end
70if eq k 3
71ret cm_dores
72end
73ret cm_doleave
74end
75
76fn cm_kdeny to bool
77k = new uchar 64 0
78for i ulong 64
79put k i get cmkid i
80end
81ret cm_denied cmdkey k
82end
83
84fn cm_tkey to void
85k = new uchar 64 0
86for i ulong 64
87put k i get cmkid i
88end
89cm_tally k cmakey cmtamsg
90end
91
92fn cm_doreg to long
93r = cm_fnum cmfthird
94if eq r 18446744073709551615
95ret cm_refuse cmemal
96end
97if not cm_kwrite cmlj r
98ret cm_refuse cmeio
99end
100if not cm_store
101ret cm_refuse cmedup
102end
103x = cm_ledger cmtreg false cmlok
104ret cm_rok cmkreg
105end
106
107fn cm_doleave to long
108if not cm_kwrite cmll cm_krate
109ret cm_refuse cmeio
110end
111if not cm_store
112ret cm_refuse cmedup
113end
114x = cm_ledger cmtlv false cmlok
115ret cm_rok cmkleft
116end
117
118note cm_donext: the newest published part this key has not run yet, as a new job
119fn cm_donext to long
120if not cm_store
121ret cm_refuse cmedup
122end
123if not cm_pickjob
124x = cm_ledger cmtnext false cmlnone
125ret cm_rok cmknone
126end
127j = new uchar 16 0
128jh = new uchar 32 0
129d = new uchar 256 0
130r = random j 0 16 0
131if ne r 16
132ret cm_refuse cmeio
133end
134cm_tohex j jh
135k = cm_jline d
136cm_p0
137cm_pa cmtjobs
138cm_pa jh
139if not cm_wnew part d 0 k
140ret cm_refuse cmeio
141end
142x = cm_ledger cmtnext false cmlok
143z = cm_reply 200
144fput cmrok
145fput cmkjob
146fput cmjlf
147fput jh
148fput cmnl
149fput cmplf
150cm_putpick
151fput cmnl
152fput cmclf
153fput tlpin
154fput cmnl
155ret 200
156end
157
158fn cm_putpick to void
159p = new uchar 64 0
160for i ulong 64
161put p i get cmpick i
162end
163fput p
164end
165
166note cm_jline: "<key> <part> <compiler> <issued>\n" for the job file
167fn cm_jline d edit uchar * to ulong
168k = cm_khex d 0
169k = cm_cp d k cmsp
170for i ulong 64
171put d add k i get cmpick i
172end
173k = add k 64
174k = cm_cp d k cmsp
175k = cm_cp d k tlpin
176k = cm_cp d k cmsp
177k = cm_decput d k cm_now
178ret cm_cp d k cmnl
179end
180
181note cm_pickjob: newest first through the salvage index
182fn cm_pickjob to bool
183id = new uchar 64 0
184n = get glidxn 0
185for ix ulong n bound 1000000
186pos = sub sub n ix 1
187for i ulong 64
188put id i get glidx add mul pos 65 i
189end
190if cm_pickok id
191for i ulong 64
192put cmpick i get id i
193end
194ret true
195end
196end
197ret false
198end
199
200note cm_pickok: a published part with a passing receipt from the pinned compiler, not denied,
201note and not already run by this key
202fn cm_pickok id view uchar * to bool
203if not slpublic id
204ret false
205end
206if ne get glrec 8 2
207ret false
208end
209for i ulong 64
210if ne get glrcpt add 193 i get tlpin i
211ret false
212end
213end
214if cm_denied cmdpart id
215ret false
216end
217cm_kpath id
218ret not cm_exists
219end
220
221note cm_kpath: cmpth = <root>parts/<id>/k/<key>
222fn cm_kpath id view uchar * to void
223cm_p0
224cm_pa cmtparts
225cm_pa id
226cm_pa cmtk
227cm_pkid
228end
229
230note cm_dores: the result must answer a job issued to this key less than an hour ago, for the same
231note part and compiler, used once
232fn cm_dores to long
233b = new uchar 512 0
234j = new uchar 32 0
235p = new uchar 64 0
236if not and cm_fget cmfjob j cm_fget cmfpart p
237ret cm_refuse cmemal
238end
239cm_p0
240cm_pa cmtjobs
241cm_pa j
242r = cm_rd b
243if ne r 206
244ret cm_refuse cmejob
245end
246e = cm_jobok part b 0 206
247if ne e 0
248ret cm_refuse e
249end
250if cm_denied cmdpart p
251ret cm_refuse cmeden
252end
253cm_p0
254cm_pa cmtused
255cm_pa j
256if not cm_wnew part b 0 0
257ret cm_refuse cmedup
258end
259if not cm_store
260ret cm_refuse cmedup
261end
262ret cm_count1 p
263end
264
265note cm_jobok: the job file is "<key> <part> <compiler> <issued>\n" (206 bytes with a 10-digit time)
266fn cm_jobok b view uchar * to ulong
267f = new uchar 64 0
268for i ulong 64
269if ne get b i get cmkid i
270ret cmejob
271end
272end
273iss = cm_dec part b 195 10
274now = cm_now
275if or gt iss now ge sub now iss cmjlife
276ret cmejob
277end
278if not cm_fget cmfpart f
279ret cmemal
280end
281if not cm_eq part b 65 64 f
282ret cmemis
283end
284if not cm_fget cmfcomp f
285ret cmemal
286end
287if not cm_eq part b 130 64 f
288ret cmemis
289end
290ret 0
291end
292
293note cm_count1: record the counted result (the first for this key and part), or answer duplicate
294fn cm_count1 p view uchar * to long
295d = new uchar 256 0
296if cm_iscell
297x = cm_ledger cmtres true cmlcell
298ret cm_rok cmkstor
299end
300cm_p0
301cm_pa cmtparts
302cm_pa p
303x = cm_mkdir
304cm_pa cmtk
305x = cm_mkdir
306cm_pkid
307k = cm_triple d
308k = cm_cp d k cmsp
309k = cm_decput d k cm_fnum cmftime
310k = cm_cp d k cmsp
311k = cm_shex d k
312k = cm_cp d k cmnl
313if not cm_wnew part d 0 k
314x = cm_ledger cmtres true cmldup
315ret cm_refuse cmedup
316end
317if not cm_group p
318ret cm_refuse cmeio
319end
320x = cm_ledger cmtres true cmlcnt
321ret cm_rok cmkcnt
322end
323
324fn cm_iscell to bool
325n = get cmfn cmfexit
326if lt n len cmxcell
327ret false
328end
329ret cm_bodyis get cmfo cmfexit cmxcell
330end
331
332note cm_triple: "<binary> <stdout> <exit>" from the message into d; its length
333fn cm_triple d edit uchar * to ulong
334b = new uchar 64 0
335e = new uchar 32 0
336x = cm_fget cmfbin b
337k = cm_cp d 0 b
338k = cm_cp d k cmsp
339x = cm_fget cmfout b
340k = cm_cp d k b
341k = cm_cp d k cmsp
342n = get cmfn cmfexit
343o = get cmfo cmfexit
344for i ulong n bound 32
345put d add k i get fbody add o i
346end
347ret add k n
348end
349
350note cm_group: parts/<p>/g/<hash of the triple>.v holds the triple, and the directory
351note parts/<p>/g/<hash>/ holds one empty file per key with that triple
352fn cm_group p view uchar * to bool
353d = new uchar 256 0
354h = new uchar 32 0
355x = new uchar 64 0
356k = cm_triple d
357cm_sha part d 0 k h
358cm_tohex h x
359put d k 10
360cm_p0
361cm_pa cmtparts
362cm_pa p
363cm_pa cmtg
364y = cm_mkdir
365cm_pa x
366cm_pa cmtv
367y = cm_wnew part d 0 add k 1
368cm_p0
369cm_pa cmtparts
370cm_pa p
371cm_pa cmtg
372cm_pa x
373if not cm_mkdir
374ret false
375end
376cm_pa cmtsl
377cm_pkid
378e = new uchar 1 0
379ret cm_wnew part e 0 0
380end