Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-sovereign-core-mv/blob/main/om/golden/fake.om # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / golden / fake.om` 329 lines ยท 5584 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note om/golden/fake.om: TEST ONLY fake HTTP responder for om/golden/check.sh. It is not an engine and 3 note never produces a REAL record: check.sh records against it with label FAKE. 4 note fake PORTFILE CANNED CAPTURE N 5 note Binds 127.0.0.1 on a kernel-chosen port, writes "PORT\n" to PORTFILE (created, never overwritten), 6 note then serves exactly N connections in order: connection k reads one HTTP/1.1 request (headers up to 7 note 65536 bytes, body by Content-Length), stores the raw request bytes as CAPTURE/k.http and answers 8 note with the bytes of CANNED/k.http verbatim. Exit 0 after N connections; 10 usage, 11 socket, 9 note 12 file, 13 malformed request. 10 11 const FQCAP ulong `1048576` 12 const FHCAP ulong 65536 13 14 global fa uchar 8192 15 global fas ulong 8 16 global fal ulong 8 17 global fp uchar 4200 18 global fq uchar `1048576` 19 global fr uchar `1048576` 20 global fb uchar 64 21 global fst uchar 128 22 23 text tfpre "fake: exit " 24 text tfsuf ".http" 25 text tfcl "content-length:" 26 27 fn fx code int to void 28 d = new uchar 3 0 29 w = write 2 tfpre 0 len tfpre 30 put d 0 uchar add 48 div code 10 31 put d 1 uchar add 48 rem code 10 32 put d 2 10 33 w = write 2 d 0 3 34 exit code 35 end 36 37 note fpath: fp = argument a, a slash, decimal k, .http; returns the length 38 fn fpath a ulong k ulong to ulong 39 n = get fal a 40 if or eq n 0 gt n 4096 41 fx 10 42 end 43 o = get fas a 44 for i ulong n 45 put fp i get fa add o i 46 end 47 put fp n 47 48 n = add n 1 49 if ge k 100 50 put fp n uchar add 48 div k 100 51 n = add n 1 52 end 53 if ge k 10 54 put fp n uchar add 48 rem div k 10 10 55 n = add n 1 56 end 57 put fp n uchar add 48 rem k 10 58 n = add n 1 59 for j ulong len tfsuf 60 put fp add n j get tfsuf j 61 end 62 ret add n len tfsuf 63 end 64 65 note fcreate: write fq[0..n) to the new file fp[0..pn) (O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC, 0600) 66 fn fcreate pn ulong n ulong to void 67 fd = int fopen fp 0 pn 557249 384 68 if lt fd 0 69 fx 12 70 end 71 o = ulong 0 72 while lt o n bound 999999 73 r = write fd fq o sub n o 74 if le r 0 75 fx 12 76 end 77 o = add o ulong r 78 end 79 if ne fclose fd 0 80 fx 12 81 end 82 end 83 84 fn fle64 o ulong to ulong 85 v = ulong 0 86 for i ulong 8 87 v = or v shl ulong get fst add o i mul 8 i 88 end 89 ret v 90 end 91 92 note fload: read the regular file fp[0..pn) into fr (O_RDONLY|O_CLOEXEC|O_NOFOLLOW); returns its size 93 fn fload pn ulong to ulong 94 fd = int fopen fp 0 pn 557056 0 95 if lt fd 0 96 fx 12 97 end 98 if ne fstat fd fst 0 128 0 99 fx 12 100 end 101 sz = fle64 48 102 if gt sz FQCAP 103 fx 12 104 end 105 o = ulong 0 106 while lt o sz bound 999999 107 q = pread fd fr o sub sz o long o 108 if le q 0 109 fx 12 110 end 111 o = add o ulong q 112 end 113 if ne fclose fd 0 114 fx 12 115 end 116 ret sz 117 end 118 119 fn fcrlf i ulong to bool 120 ret and eq get fq i 13 eq get fq add i 1 10 121 end 122 123 note fhend: the offset just past the first CR LF CR LF in fq[0..n), or 0 124 fn fhend n ulong to ulong 125 if lt n 4 126 ret 0 127 end 128 for i ulong sub n 3 129 if and fcrlf i fcrlf add i 2 130 ret add i 4 131 end 132 end 133 ret 0 134 end 135 136 fn flow c uchar to uchar 137 if and ge c 65 le c 90 138 ret uchar add c 32 139 end 140 ret c 141 end 142 143 fn fiscl p ulong h ulong to bool 144 if gt add p len tfcl h 145 ret false 146 end 147 for i ulong len tfcl 148 if ne flow get fq add p i get tfcl i 149 ret false 150 end 151 end 152 ret true 153 end 154 155 fn fblank q ulong to bool 156 ret or eq get fq q 32 eq get fq q 9 157 end 158 159 fn fdig q ulong to bool 160 ret and ge get fq q 48 le get fq q 57 161 end 162 163 note fcval: the decimal after optional blanks at p; 13 on a missing or oversized value 164 fn fcval p ulong h ulong to ulong 165 q = p 166 while and lt q h fblank q bound 65536 167 q = add q 1 168 end 169 v = ulong 0 170 d = ulong 0 171 while and lt q h fdig q bound 65536 172 v = add mul v 10 ulong sub get fq q 48 173 if gt v FQCAP 174 fx 13 175 end 176 d = add d 1 177 q = add q 1 178 end 179 if eq d 0 180 fx 13 181 end 182 ret v 183 end 184 185 note fclen: Content-Length of the header block fq[0..h), 0 when absent 186 fn fclen h ulong to ulong 187 p = ulong 0 188 while lt p h bound 65536 189 if fiscl p h 190 ret fcval add p len tfcl h 191 end 192 while and lt p h ne get fq p 10 bound 65536 193 p = add p 1 194 end 195 p = add p 1 196 end 197 ret 0 198 end 199 200 note frdreq: read one request from connection a into fq; returns its byte count 201 fn frdreq a int to ulong 202 n = ulong 0 203 h = ulong 0 204 while eq h 0 bound 65536 205 if ge n FHCAP 206 fx 13 207 end 208 r = recv a fq n sub FHCAP n 0 209 if le r 0 210 fx 13 211 end 212 n = add n ulong r 213 h = fhend n 214 end 215 t = add h fclen h 216 if gt t FQCAP 217 fx 13 218 end 219 while lt n t bound 999999 220 r = recv a fq n sub t n 0 221 if le r 0 222 fx 13 223 end 224 n = add n ulong r 225 end 226 if ne n t 227 fx 13 228 end 229 ret t 230 end 231 232 fn fsendall a int n ulong to void 233 o = ulong 0 234 while lt o n bound 999999 235 r = send a fr o sub n o 0 236 if le r 0 237 fx 11 238 end 239 o = add o ulong r 240 end 241 end 242 243 fn fserve s int k ulong to void 244 a = int accept s 0 245 if lt a 0 246 fx 11 247 end 248 t = frdreq a 249 fcreate fpath 3 k t 250 fsendall a fload fpath 2 k 251 if ne fclose a 0 252 fx 11 253 end 254 end 255 256 note fport: bind 127.0.0.1:0, listen, write the chosen port to argument 1; returns the socket 257 fn fport to int 258 s = int socknew 2 1 0 259 if lt s 0 260 fx 11 261 end 262 put fb 0 2 263 put fb 4 127 264 put fb 7 1 265 if ne bind s fb 0 16 0 266 fx 11 267 end 268 if ne listen s 16 0 269 fx 11 270 end 271 if ne sockname s fb 0 64 16 272 fx 11 273 end 274 v = add mul ulong get fb 2 256 ulong get fb 3 275 note the port digits go through fq, which holds no request yet 276 k = ulong 0 277 x = v 278 while gt x 0 bound 6 279 x = div x 10 280 k = add k 1 281 end 282 x = v 283 for i ulong k 284 put fq sub sub k 1 i uchar add 48 rem x 10 285 x = div x 10 286 end 287 put fq k 10 288 n = get fal 1 289 o = get fas 1 290 for i ulong n 291 put fp i get fa add o i 292 end 293 fcreate n add k 1 294 ret s 295 end 296 297 fn main to int 298 c = argcnt 299 if ne c 5 300 fx 10 301 end 302 o = ulong 0 303 for i ulong ulong c 304 r = argread i fa o sub len fa o 305 if lt r 0 306 fx 10 307 end 308 put fas i o 309 put fal i ulong r 310 o = add o ulong r 311 end 312 nn = ulong 0 313 o = get fas 4 314 for i ulong get fal 4 315 x = get fa add o i 316 if or lt x 48 gt x 57 317 fx 10 318 end 319 nn = add mul nn 10 ulong sub x 48 320 if gt nn 999 321 fx 10 322 end 323 end 324 s = fport 325 for k ulong nn 326 fserve s k 327 end 328 ret 0 329 end