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 / seed / node / op.om

210 lines · 4231 bytes Raw Blame History
1note seed/node/op.om -- omnode-op, the operator's client of the Omega Node
2note view (DRA-291, seed/node/view.om). OM-2; compose after seed/net/http.om
3note and seed/net/notls.om.
4note omnode-op PORT view [SINCE INC] GET /view, the body on stdout
5note omnode-op PORT cmd ID OP TARGET INC VER [A [B [C [D]]]]
6note POST /cmd, the acknowledgement
7note omnode-op PORT health GET /health (the model server's
8note probe, DRA-292), the body on stdout
9note PORT is on 127.0.0.1 (never 18091). Exit 0 for 200, 1 for 409 (stale),
10note 400 (invalid) or 500 (refused), 3 for 503 (busy) or 504 (pending: post
11note again with the same ID), 4 no connection or no response in 10 s, 5
12note other statuses, 2 usage.
13text opview "view"
14text opcmd "cmd"
15text ophlth "health"
16text opph "/health"
17text opget "GET"
18text oppost "POST"
19text ophost "Host"
20text ophostv "127.0.0.1"
21text oppv "/view"
22text oppc "/cmd"
23text opks "?since="
24text opki "&inc="
25text opnames "?id=,&op=,&target=,&inc=,&ver=,&a=,&b=,&c=,&d=,"
26text opnl "\n"
27
28note The decimal argument i, or all ones when it is not 1..19 digits.
29fn op_num i ulong to ulong
30b = new uchar 32 0
31n = argread i b 0 32
32if or lt n 1 gt n 19
33ret not ulong 0
34end
35v = ulong 0
36for j ulong ulong n
37c = ulong get b j
38if or lt c 48 gt c 57
39ret not ulong 0
40end
41v = add mul v 10 sub c 48
42end
43ret v
44end
45
46note Append a to o at p; past 1000 bytes the result is 2000 (overflow), and
47note an overflowed p stays overflowed.
48fn op_cat o edit uchar 1024 p ulong a view uchar * to ulong
49if gt add p len a 1000
50ret 2000
51end
52for i ulong len a
53put o add p i get a i
54end
55ret add p len a
56end
57
58fn op_dec o edit uchar 1024 p ulong v ulong to ulong
59d = new uchar 20 0
60k = ulong 20
61x = v
62for it ulong 20
63k = sub k 1
64put d k uchar add rem x 10 48
65x = div x 10
66if eq x 0
67break
68end
69end
70ret op_cat o p view part d k sub 20 k
71end
72
73note The request target into t; its length, or 0 on a usage error.
74fn op_target t edit uchar 1024 to ulong
75w = new uchar 8 0
76n = argread 2 w 0 8
77c = ulong argcnt
78if heq view part w 0 ulong n opview
79p = op_cat t 0 oppv
80if eq c 3
81ret p
82end
83if ne c 5
84ret 0
85end
86p = op_cat t p opks
87p = op_arg t p 3
88p = op_cat t p opki
89ret op_arg t p 4
90end
91if heq view part w 0 ulong n ophlth
92if ne c 3
93ret 0
94end
95ret op_cat t 0 opph
96end
97if not heq view part w 0 ulong n opcmd
98ret 0
99end
100if or lt c 8 gt c 12
101ret 0
102end
103p = op_cat t 0 oppc
104for i ulong sub c 3
105p = op_qn t p i
106p = op_arg t p add i 3
107end
108ret p
109end
110
111note Append the i-th comma-terminated name of opnames.
112fn op_qn t edit uchar 1024 p ulong i ulong to ulong
113s = ulong 0
114m = ulong 0
115for j ulong len opnames
116if eq get opnames j 44
117if eq m i
118ret op_cat t p view part opnames s sub j s
119end
120m = add m 1
121s = add j 1
122end
123end
124ret p
125end
126
127note Decimal argument i at t[p]; p past the end when it is not a number.
128fn op_arg t edit uchar 1024 p ulong i ulong to ulong
129v = op_num i
130if eq v not ulong 0
131ret 2000
132end
133ret op_dec t p v
134end
135
136fn op_main to int
137cs = new ulong 320 0
138io = new uchar 131072 0
139t = new uchar 1024 0
140a = new uchar 16 0
141bd = new uchar 65536 0
142if lt argcnt 3
143ret 2
144end
145po = op_num 1
146if or or eq po 0 gt po 65535 eq po 18091
147ret 2
148end
149tn = op_target t
150if or eq tn 0 gt tn 1000
151ret 2
152end
153r = haddr4 a 2130706433 po
154fd = hdial a 5000000000
155if lt fd 0
156ret 4
157end
158r = hinit cs io int fd 0
159hsettmo cs 10000000000 10000000000
160hsetbdl cs 10000000000
161st = op_req cs io view part t 0 tn
162if lt st 0
163x = hclose cs
164ret 4
165end
166n = hbodyall cs io bd
167x = hclose cs
168if gt n 0
169x = write 1 bd 0 ulong n
170end
171x = write 1 opnl 0 1
172ret op_exit st
173end
174
175note Send the request (POST with no body for /cmd, GET for /view and
176note /health); the response status, or negative.
177fn op_req cs edit ulong 320 io edit uchar 131072 t view uchar * to long
178r = long 0
179if eq get t 1 99
180r = hreqst cs io oppost
181else
182r = hreqst cs io opget
183end
184r = hfe r hreqtg cs io t
185r = hfe r hhname cs io ophost
186r = hfe r hhval cs io ophostv
187r = hfe r hhend cs io 0 0
188r = hfe r hwfin cs io
189if lt r 0
190ret r
191end
192ret hrsprd cs io
193end
194
195fn op_exit st long to int
196if eq st 200
197ret 0
198end
199if or or eq st 409 eq st 400 eq st 500
200ret 1
201end
202if or eq st 503 eq st 504
203ret 3
204end
205ret 5
206end
207
208fn main to int
209ret op_main
210end