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/omega-mv/blob/main/seed/net/README.md # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / net / README.md` 303 lines ยท 20338 bytes Raw Blame History Rendered 1 # seed/net: HTTP/1.1 in seeded Omega 2 3 `http.om` is a bounded HTTP/1.1 server and client written in seeded Omega (OM-2 profile), 4 compiled by `seed/out/omc`. It covers strict message parsing, Content-Length, chunked and 5 close-delimited bodies, keep-alive, pipelining, `Expect: 100-continue`, deadlines and 6 server-sent events (SSE) in both directions. TLS is not included; see "Transport boundary". 7 8 Status: IMPLEMENTED and EXERCISED on a Linux AArch64 host with `seed/out/omc` sha256 9 ``befb8199`...8a1d` (`tests/check.py` PASS; the run log is attached to the integration PR). Host 10 only: no hardware or deployment claim. 11 12 ## Files 13 14 | Path | What it is | 15 |---|---| 16 | `http.om` | The library unit. No `om2` line, no `fn main`, no globals. | 17 | `notls.om` | The three transport hooks for a program without TLS (every one returns `HENOSUP`). Composed after `http.om`. | 18 | `https.om` | The same three hooks implemented with the om/tls TLS 1.3 client, plus `htlsinit` / `htlsconn` / `htlsend`. Composed after the om/tls units and `http.om`. | 19 | `examples/sse_server.om` | An embeddable server: `/health`, `/events` (SSE), `/echo` (body up to 1 MiB). | 20 | `examples/sse_client.om` | An incremental SSE client that prints one line per event. | 21 | `tests/parse.om` | Memory-mode parser driver for the corpus. | 22 | `tests/live.om` | Loopback socket tests: bodies, keep-alive, pipelining, SSE, malformed requests, deadlines, descriptor leaks. | 23 | `tests/https.om` | HTTPS GET through `https.om`: `https HOST PORT STOREFILE PATH [CONNECTHOST [IDLEMS [TOTALMS [IOSPARE]]]]`, body to stdout, `status N` / `HTTPSERR r` / `TLSDETAIL d` to stderr. | 24 | `tests/nosup.om` | A program without TLS must refuse every byte on a non-TCP transport. | 25 | `tests/check.py` | Host referee: builds everything, runs the corpus, the mutants, `live.om` and the curl / http.client end-to-end check. | 26 27 ## Building a program 28 29 The library has no `om2` line, so the application build adds one line in front of the 30 concatenated units: 31 32 ```sh 33 { printf 'om2\n'; cat seed/net/http.om seed/net/notls.om app.om; } | seed/out/omc > app 34 ``` 35 36 A program that speaks HTTPS composes the om/tls units and `https.om` instead of `notls.om` 37 (exactly one of the two, after `http.om`): 38 39 ```sh 40 { printf 'om2\n' 41 for u in sha2 hkdf drbg x25519 sha3 mlkem chacha aesgcm ec ecdh rsa x509 rev fips tls; do cat om/tls/$u.om; done 42 cat seed/net/http.om seed/net/https.om app.om; } | seed/out/omc > app 43 ``` 44 45 A program that also parses JSON adds `seed/json/json.om` in the same `cat`. Names in 46 `http.om` are functions `h*`, constants `H*` and texts `h*`; an application must not reuse 47 them. `big`, `out`, `part`, `at`, `field` and the other OM-2 words cannot be names. 48 49 ## Ownership and state 50 51 All state belongs to the caller. A connection is two arrays, normally locals of the function 52 that owns the connection: 53 54 ``` 55 cs = new ulong HCSLEN 0 state: descriptor, cursors, deadlines, framing, header index 56 io = new uchar 131072 0 bytes: read region | write region | transport region 57 ``` 58 59 `hinit cs io fd role` splits `io` into a read region (`io[0, HRCAP)`), a write region 60 (`io[HWB, HWB + HWCAP)`, a quarter of `io`, 256 to 65536 bytes, changeable with `hsetw`) and an 61 empty transport region. Role 1 is a server, 0 a client. `hinit` takes ownership of `fd`: 62 `hclose cs` closes it exactly once, and `hinit` with `fd < 0` selects memory mode (no I/O, 63 `hmemld` loads a whole message; used by the corpus). 64 65 Offsets stored in `cs` (method, target, header names and values) are absolute offsets into `io` 66 and stay valid until the next `hreqrd` / `hrsprd` on the same `cs`. Copy what must outlive that. 67 Several connections are several `cs`/`io` pairs; nothing is shared between them. Because omc 68 refuses globals as arguments and two parts of one array in one call (error 19), the library uses 69 no global, so there is no single-state limitation: a server may hold as many connections as it 70 has arrays for, and a forked worker gets its own copy. 71 72 Bounded epochs: every loop in the library has a bound derived from a buffer size; a connection 73 carries at most `HMAXMSG` messages (default 1000, set with `put cs HMAXMSG n`) after which the 74 server answers with `Connection: close`; a server process serves a bounded number of connections 75 per run (the examples take it as an argument) and is restarted by its supervisor. 76 77 ## Limits (all settable with `put cs SLOT v` after `hinit`) 78 79 | Slot | Default | Meaning | 80 |---|---|---| 81 | `HHEADMX` | min(16384, HRCAP / 2) | Bytes of one message head, also one chunk-size or trailer line. Over it: `HEHEAD`. | 82 | `HHMAX` | 64 (`HHSLOTS`, the maximum) | Header fields per message, also trailer fields. Over it: `HEHEAD`. | 83 | `HBCAP` | `1048576` | Decoded body bytes per message. Over it: `HEBIG`. Covers the 300 KiB gateway bodies and the 1 MiB catalog cap. | 84 | `HMAXMSG` | 1000 | Messages per connection. | 85 | `HIDLE` (`hsettmo`) | 30 s | Longest single wait for the socket. | 86 | `HHDLV` (`hsettmo`) | 30 s | Deadline for receiving a whole head, from the start of `hreqrd` / `hrsprd`. | 87 | `HBDLV` (`hsetbdl`) | 60 s | Armed as `HDL` when a head has been read (that message's body reads and, on a server, the response writes) and when `hreqst` starts a request (its writes). 0 = none. | 88 | `HDL` (`hsetdl`) | set from `HBDLV` | Absolute deadline for the following body reads and writes. A long-lived stream (SSE relay) sets its own with `hsetdl` after the head; `hsetdl cs 0` leaves only the idle limit. | 89 | `HFRMAX` | 65536 | Chunked framing allowance: chunk-size lines (with extensions), the CRLF after each chunk and trailer lines may total at most `HFRMAX` + 8 x decoded bytes per message. Over it: `HEBIG`. | 90 91 ## Results 92 93 Every function returns a `long`. Nonnegative is success. Negative values: 94 95 | Value | Name | Meaning (server answers with `hreject`) | 96 |---|---|---| 97 | `-errno` | | Linux error from the socket, e.g. -104, -32 | 98 | -110 | `HETIME` | idle wait or deadline passed (408) | 99 | -400 | `HEBAD` | malformed message (400) | 100 | -413 | `HEBIG` | body over `HBCAP`, or larger than the caller's array in `hbodyall` (413) | 101 | -417 | `HEEXP` | `Expect` other than `100-continue` (417) | 102 | -431 | `HEHEAD` | head, line or field count over its cap (431) | 103 | -499 | `HETRUNC` | the peer closed in the middle of a message (no answer) | 104 | -501 | `HETE` | a transfer coding other than `chunked` (501) | 105 | -505 | `HEVER` | HTTP major version other than 1, or 1.x with x > 1 (505) | 106 | -22, -95 | `HEINVAL`, `HENOSUP` | caller error; unsupported transport | 107 108 ## Parsing rules (RFC 9112) 109 110 - Lines end in CRLF. A bare LF or a CR not followed by LF is `HEBAD`. A server skips empty 111 lines before a request line. 112 - Request line: method = 1..32 tchar, one SP, target = 1..8192 bytes 0x21-0x7e in origin form, 113 `*`, absolute form (`scheme://...`) or, for CONNECT only, authority form; one SP; 114 `HTTP/1.1` or `HTTP/1.0`. Status line: version, SP, three digits 100..599, SP, reason of 115 field-value bytes (the SP is required even when the reason is empty). 116 - Field line: a tchar name, `:` with no whitespace before it, a value of HTAB, SP, VCHAR and 117 obs-text (no NUL, CR, LF or DEL); leading and trailing SP/HTAB are not part of the value. A 118 line that starts with SP or HTAB (obs-fold) is `HEBAD`. 119 - `Content-Length`: 1..19 digits on exactly one field line. A repeated field, even with the 120 same value, or a list is `HEBAD`. 121 - `Transfer-Encoding`: exactly one field line whose value is `chunked` (any case). Any other 122 coding or list is `HETE`; with `Content-Length` or in HTTP/1.0 it is `HEBAD`. 123 - HTTP/1.1 requests need exactly one `Host`. `Connection: close` ends the connection after the 124 message; HTTP/1.0 connections always close (no 1.0 keep-alive). 125 - Response bodies follow RFC 9112 6.3: none for HEAD, 1xx, 204 and 304; chunked; Content-Length; 126 otherwise close-delimited. `hrsprd` skips up to 15 interim 1xx responses and returns 101 as 127 final. 128 - Chunk sizes are 1..15 hex digits, optionally followed directly by `;` and extension bytes 129 (field-value bytes, not otherwise interpreted). Whitespace before `;` is `HEBAD`. Trailer 130 fields are validated like header fields and then discarded. 131 132 ## Server API 133 134 ``` 135 lf = hlisten a backlog a: sockaddr bytes (haddr4 a ip port; port 0 = ephemeral). 136 The bound address is written back: hport a is the port. 137 c = haccept lf tmo wait at most tmo ns (negative = forever); O_NONBLOCK, CLOEXEC 138 r = hinit cs io int c 1 take ownership of c 139 hsettmo cs idle headdl 140 hsetbdl cs iv body/response deadline per message (default 60 s) 141 r = hreqrd cs io 1 head read; 0 peer closed between requests; < 0 error 142 hreject cs io r answer an error result and mark the connection closing 143 hismeth cs io m / hispath cs io p method / path (target before '?') comparisons 144 i = hhfind cs io name header index or -1; value io[hhvoff cs i, + hhvlen cs i) 145 n = hbodyrd cs io d next decoded body bytes into d; 0 at the end 146 n = hbodyall cs io d the whole body (HEBIG when d is too small) 147 hrspst cs io code status line with the standard reason 148 hhname cs io n / hhval cs io v / hhnum cs io v one header field; framing fields refused 149 hhend cs io mode clen 0 Content-Length clen, 1 chunked, 2 close-delimited 150 hput cs io bytes / hputb cs io b body bytes (chunked: one chunk per buffer flush) 151 hflush cs io send what is buffered now 152 hwfin cs io end the body; checks a Content-Length body was clen bytes 153 (hput / hputb already refuse bytes past clen: HEINVAL, 154 nothing buffered, connection closing) 155 hrspempty / hrsperr cs io code a complete empty response (hrsperr also closes) 156 hnext cs io 1 = read the next request on this connection, 0 = close 157 hclose cs 158 ``` 159 160 Responses to HEAD keep their framing fields and drop the body bytes; 1xx, 204 and 304 get no 161 framing field and no body. `put cs HKEEP 0` before `hhend` ends the connection after this 162 response. A request body the handler did not read makes `hnext` return 0. 163 164 ## Client API 165 166 ``` 167 fd = hdial a tmo nonblocking connect bounded by tmo ns 168 r = hinit cs io int fd 0 169 hreqst cs io method / hreqtg cs io target / hhname / hhval / hhend / hput / hwfin 170 st = hrsprd cs io final status (put cs HISHEAD 1 first after a raw HEAD) 171 n = hbodyrd cs io d Content-Length, chunked or close-delimited 172 ``` 173 174 HTTPS (`https.om`): after `hinit` and before any I/O, `htlsinit cs io host` reserves the 175 transport region `io[HTB, HTB + TLCSZ)` (121696 bytes; `io` must hold it plus at least 512 176 bytes of read and write regions) and starts the om/tls client for the TLS name `host` with 177 ALPN `http/1.1`; `htlsconn cs io st` runs the handshake against the trust store `st` 178 (`TLSTSZ` bytes filled by `tls_store` or `tls_storef`); the request and response functions 179 then work unchanged; `htlsend cs io` sends close_notify, wipes the keys and closes the 180 descriptor (`hclose` alone closes the socket without either). A TLS result `e` comes back as 181 `HETLS - e` (-601 .. -632, names in `tls_errname`), a TLS deadline as `HETIME`. A TCP end of 182 stream without close_notify is `HETLS - 4` (truncation), never a clean end of a body. 183 The handshake runs under the same wait policy as every later read: `htlsconn` hands 184 min(now + idle, `HDL`, `HXDL`) to `tls_deadline` before `tls_connect` (with all three 0, 185 tls_connect keeps its own 30 s budget). `htlsdl cs ms` (after `hinit`, before `htlsconn`) sets 186 `HXDL` (cs slot 54), one monotonic deadline `ms` from now over handshake, request write and 187 response read; 0 clears it, and plain TCP ignores it. A certificate refusal (`HETLS - 17`) 188 carries its X.509 reason in `htlsdet cs io` (`X5EEXP` 2 expired, `X5ENYV` 3 not yet valid, 189 `X5ENAME` 4 wrong name, `X5EUNK` 5 unknown issuer), which survives `htlsend`; no request byte is 190 sent before the chain, time and name checks pass. There is no fallback to cleartext. 191 `tests/https.om` is the reference caller. 192 193 ## Server-sent events 194 195 Writing: `hrspsse` sends the 200 head (`text/event-stream`, `Cache-Control: no-cache`, chunked), 196 then per event `hsseevt` (type), `hsseid`, `hsseret` (retry ms), `hssecmt` (comment), `hssedat` 197 (data; CR, LF and CRLF in it become separate `data:` lines), and `hsseend`, which ends the event 198 and flushes it as one chunk. `hwfin` ends the stream. 199 200 Reading (WHATWG HTML 9.2.6): `ss = new ulong HSSLEN 0`, `lb = new uchar N 0` (N >= 256), 201 `hsseinit ss`. Feed any slice of the body with `hssefeed ss lb src`; it returns the bytes it 202 consumed and stops after a dispatching line with `get ss HSRDY` = 1. The event is then: type 203 `lb[0, HSELEN)` (empty means `message`), last event id `lb[64, 64 + HSILEN)`, data 204 `lb[128, 128 + HSDLEN)`, retry `get ss HSRETRY`. Call `hssenext ss` and feed the rest. Lines may 205 end in CR, LF or CRLF and may be split anywhere between calls; a leading BOM is removed. Event 206 type and id are at most 64 bytes, data plus the current line at most N - 128 bytes (`HEHEAD` / 207 `HEBIG` otherwise). A gateway relays an upstream stream incrementally with `hbodyrd` into a 208 small array, `hssefeed`, and `hsseevt`/`hsseid`/`hssedat`/`hsseend` downstream. The default 209 `HBDLV` deadline (60 s) also covers a stream, so after reading each head the relay calls 210 `hsetdl` on both connections with its own stream budget (or 0 to keep only the idle limit). 211 212 A chunk-size or trailer line that arrives over several receives is scanned once: the scan 213 resumes where it stopped (`HBSC`) instead of restarting at the line start. 214 215 ## Transport boundary 216 217 Every byte crosses three functions only: `hrecvio` (into the read region), `hrecvd` (into the 218 caller's body array) and `hsendio` (from the write region), plus `hwait`. Sockets are 219 O_NONBLOCK; a call that would block waits with `waitio` for at most min(idle, deadline - now), 220 so there is no busy wait and no unbounded block. `get cs HXPORT` selects the transport: 0 is 221 plain TCP or Unix sockets; 1 calls the hooks `htlsrecv`, `htlsrecvd` and `htlssend`, which 222 `https.om` implements over om/tls (`tls_read` / `tls_write`, connection state in the transport 223 region `io[HTB, HTB + HTL)`; before each call the http.om wait policy, min(idle, deadline), is 224 handed to `tls_deadline`) and `notls.om` refuses with `HENOSUP`. Because Omega passes one 225 array to a call once, bytes between the TLS state and the read / write regions of the same `io` 226 cross a 16 KiB bounce array (one extra copy per record). `htlssend` refuses an `off` / `n` outside 227 `io` with `HEINVAL` instead of trapping (om/tls interop row `sink`, `test/tls/bigsend.om`). No 228 other function of `http.om` touches the transport. 229 230 ## Host words used 231 232 `socknew bind listen accept connect sockname sockopt send recv waitio fclose monons` 233 (OMEGESE section 10). No new compiler word is needed. Tests also use `fork waitpid sleepns 234 fopen getdnts`. 235 236 ## Checks 237 238 ```sh 239 nice -n 19 ionice -c3 python3 seed/net/tests/check.py [--omc seed/out/omc] [--keep DIR] 240 ``` 241 242 Prints `HTTP-CHECK PASS` and exits 0, `FAIL` (exit 1) or `NOT_RUN` (exit 3, e.g. no curl). 243 Stages: 244 245 1. Corpus: 105 hand cases with written expectations plus 1500 deterministic fuzz cases 246 (seed 788; generated messages, mutations of framing, whitespace, bytes and truncation, and 247 long chunk extensions). The 248 expected line for each comes from an independent Python reference parser written from RFC 249 9112. The reference is itself checked against the hand table and, for responses, against 250 the standard library's `http.client`: a response `http.client` rejects must be rejected, 251 and one both accept must agree on status, version, fields and body. The corpus caps are 252 head 2048 bytes, 16 fields, body 4096 bytes, chunk framing allowance (`HFRMAX`) 1024 bytes. 253 The run fails on any missing output line. 254 2. Mutants: eleven single-word changes to `http.om` (for example `cl te` to `cl cl`, hex base 16 255 to 10, `ge` to `gt` on the field cap, the chunk framing cap removed); each must compile and 256 must change the corpus output. 257 3. `tests/live.om`: forks a loopback server and checks 300 KiB and 1 MiB request bodies 258 (Content-Length and chunked), 300 KiB responses in both framings, HEAD, two pipelined 259 requests, 40 SSE events read 7 bytes at a time, eight malformed requests and their status, 260 `Expect: 100-continue` over the cap, no `100 Continue` after a flushed final response, a 261 200 ms head deadline against a stalled client, a 300 ms body deadline against a client that 262 trickles its body inside the idle limit, a 200 ms idle wait against a silent server, refusal 263 of body bytes past a declared Content-Length before any is buffered (client and server 264 roles), refused connections, and that the process ends with the descriptors it started with. 265 Seven further mutants of `http.om` (head deadline never armed, `hclose` not closing, SSE CR, 266 chunk-size digit, body deadline not armed, Content-Length overrun not refused, `100 Continue` 267 keyed on the write length) must each make `live.om` fail. 268 4. End to end: `examples/sse_server.om` on an ephemeral port, driven by `curl` (SSE bytes, 269 `-i` head bytes, 300 KiB echo with `Expect: 100-continue` and chunked), `http.client` 270 (six requests on one keep-alive connection, the last with `Connection: close`), raw sockets (obs-fold 400, empty connection, 271 HTTP/1.0) and `examples/sse_client.om`; the server's descriptor count must return to its 272 start value after every connection, and the server must exit 0. 273 5. HTTPS (needs `openssl`): a throwaway PKI (root, leaf for `localhost`, leaf for another 274 name, leaf of an unrelated root), three Python `ssl` TLS 1.3 servers and one 275 `openssl s_server -www`, all on 127.0.0.1 ephemeral ports. `tests/nosup.om` (built with 276 `notls.om`) must refuse every byte on `HXPORT 1`, and its stub mutated to return 0 must 277 fail. `tests/https.om` (built with om/tls and `https.om`) runs 25 rows: 6-byte, 278 300 KiB Content-Length, chunked (chunk sizes 1 .. 60000), fragmented (TLS records of 279 1 .. 11 bytes) and close-delimited bodies compared byte for byte; the smallest `io` 280 (`TLCSZ + 512`) passing and one byte less refused with `HEINVAL` before any request; a 281 head over the limit (`HEHEAD`); TCP close without close_notify after a Content-Length 282 head, on a close-delimited body, and inside an incomplete record (each `HETLS - 4`); a 283 silent server and a silent handshake under a 500 ms idle limit, a silent handshake 284 and a 1-byte-per-250 ms body under a total deadline (`HETIME`); a cleartext HTTP server 285 (`HETLS - 5`; it must receive a TLS record, never `GET`); wrong name, untrusted issuer, 286 expired, not yet valid and self-signed leaves (`HETLS - 17` with the X.509 detail, and 287 the server must receive no request); and four `openssl s_server -www` rows (page, wrong 288 name, untrusted issuer, expired). Thirteen mutants (read dispatch gone, head read error 289 or body truncation taken as end of stream, wait policy not handed to TLS, records not 290 written, handshake not armed, `HXDL` ignored, `io` minimum not enforced, detail lost, 291 chain result ignored, validity window or host name not checked) must each fail a row. 292 With `TLS_NET=1` two live read-only GETs (`www.example.com/`, 293 `api.github.com/licenses/mit`) through the system CA bundle must return 200 with the 294 expected text; without it that part is `NOT_RUN`. 295 296 Every socket in the checks is 127.0.0.1 with a port chosen by the kernel. Nothing contacts port 297 18091; outside hosts are contacted only by the two `TLS_NET=1` rows. 298 299 Re-verified 2026-10-26 after refresh onto main ``c5d981041`` with reseeded `seed/out/omc` ``189ada82e00bb440cb41351bd252cc68c54a1b1050051cc42a1df700081c3b54``: `HTTP-CHECK PASS` (same counts). 300 301 Re-verified 2026-10-26 on `integ/omc-batch2` with the batch 2 `seed/out/omc` ``2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f``: `HTTP-CHECK PASS` (same counts; `HTTP-LIVE-MUTANTS PASS killed=7/7`). 302 303 Re-verified 2026-10-27 on `build/omc-batch3-896-897-898-903` with the batch 3 `seed/out/omc` ``397346de169d78e8a5ce53dce6cf9f0ca56a8f527128165bbfb4fb62a335f93e``: `HTTP-CHECK PASS` (`HTTP-LIVE-MUTANTS PASS killed=7/7`).