interplane.Get Omega
Read in your language

spark-connector

aien-dev/spark-connector

Brought by drakestapleton

branch main Branches Tags History

spark-connector / docs / PROTOCOL.md

158 lines · 7778 bytes Raw Blame History Rendered
1# Interplane community runner protocol, version 1 (ipcc1)
2
3This is the wire contract between the runner (`runner/`, this repository) and the hub (the
4`community/` slice of interplane-forge, served at https://interplane.io/community/). Both sides
5are seeded Omega. Every message is plain ASCII text. There is no JSON, no cookie and no account.
6
7## Keys and signatures
8
9- A runner key is an ECDSA key on NIST P-256. The public key travels as 130 lowercase hex
10 characters: the 65-byte SEC1 uncompressed point `04 || X || Y`.
11- The key id is the lowercase hex SHA-256 of those 65 bytes (64 characters).
12- A signature is ECDSA over P-256 with SHA-256: the digest is SHA-256 of the signed bytes, and the
13 signature travels as 128 lowercase hex characters, `r || s`, each 32 bytes big-endian.
14 The hub verifies with `ecdsa_verify_raw` from omega-mv `om/tls/ec.om`; the runner signs with
15 `runner/20key.om` and checks its own signature with the same verifier before it sends anything.
16
17## Message form (runner to hub)
18
19Each message is the body of one `POST` to `https://interplane.io/community/api`, at most 4096
20bytes, `Content-Type: text/plain`. It is a sequence of lines, each `name SP value LF`, in the
21fixed order shown, with no other bytes: no carriage return, no trailing space, no blank line,
22no repeated or extra field. The first line names the protocol and the kind. The last line is
23`sig <128 hex>`. The signed bytes are every byte before `sig `.
24
25`time` is Unix seconds in decimal without leading zeros. The hub refuses a message whose time is
26more than 300 seconds away from its own clock.
27
28### register
29
30```
31ipcc1 register
32pub <130 hex>
33time <decimal>
34rate <decimal: checks per hour, the volunteer's own setting (0 = paused)>
35sig <128 hex>
36```
37
38The signature proves the sender holds the private key. The hub stores the registration. A key
39that registers again updates its `rate`; a key that left may register again.
40
41### next (ask for work)
42
43```
44ipcc1 next
45key <64 hex key id>
46time <decimal>
47nonce <32 hex>
48sig <128 hex>
49```
50
51### result
52
53```
54ipcc1 result
55key <64 hex key id>
56job <32 hex>
57part <64 hex revision: the salvage record id>
58compiler <64 hex sha256 of the compiler that built the part>
59binary <64 hex sha256 of the compiled binary, 64 zeros when the compiler refused>
60stdout <64 hex sha256 of the bytes the declared example wrote to stdout>
61exit <outcome>
62time <decimal>
63sig <128 hex>
64```
65
66`<outcome>` is one of: a decimal exit status `0`..`255` of the program; `signal<N>` (N 1..127) when
67a signal ended it (the cell's CPU limit is `signal24`); `timeout` when the runner's 3 s wall clock
68ended it; for the compile stage, `omc<K>` when the compiler exited with status K, `omcsignal<N>`
69or `omctimeout` (in those three cases `binary` is 64 zeros and `stdout` is the SHA-256 of no
70bytes); `cell<E>` when the cell itself could not start (E the errno), so the machine cannot run
71jobs. A `cell` result is stored and listed in the ledger but never counted.
72
73### leave
74
75```
76ipcc1 leave
77key <64 hex key id>
78time <decimal>
79sig <128 hex>
80```
81
82## Replies (hub to runner)
83
84Every reply is `text/plain`. The first line is `ipcc1 ok <kind>` or `ipcc1 refused <reason>`,
85where `<reason>` is one lowercase word from the table below. The HTTP status is 200 for ok,
86400 for a malformed message, 403 for a refusal by rule, 409 for a duplicate, 413 for size and 503 when the
87community service is off. The hub refuses nothing for volume: it counts signed messages (after the signature and replay checks) per key
88and in all, and refusals, per hour, and writes one line to `<hub>/community/alarms` naming the key (or
89"all", "refused") and the count when a count first passes its threshold (150 per key, 3600 in all,
903600 refusals). The public edge limits request rate per address (HTTP 429 from nginx); the runner
91backs off on any error.
92
93A job reply to `next`:
94
95```
96ipcc1 ok job
97job <32 hex>
98part <64 hex>
99compiler <64 hex>
100```
101
102The runner fetches the record from `<hub>/salvage/<part>/record`.
103
104No work: `ipcc1 ok none` then `retry <seconds>`. Other replies: `ipcc1 ok registered`,
105`ipcc1 ok counted` (a result that counts), `ipcc1 ok stored` (a `cell` result), `ipcc1 ok left`.
106A refused body is answered with `ipcc1 refused <reason>`; every refusal and every accepted
107message is public: `<hub>/community/refused`, `<hub>/community/ledger`,
108`<hub>/community/msg/<message id>`, `<hub>/community/key/<key id>`.
109
110| reason | when |
111|---|---|
112| `malformed` | the body does not have the exact form above |
113| `size` | the body is longer than 4096 bytes |
114| `clock` | `time` is more than 300 s from the hub clock |
115| `signature` | the signature does not verify for the key |
116| `unregistered` | the key id is not registered, or it has left |
117| `denied` | the key or the part is on the hub deny list |
118| `job` | the job id was not issued to this key, or it expired (3600 s) |
119| `mismatch` | `part` or `compiler` differ from what the job named |
120| `duplicate` | this key already has a counted result for this part (stored, not counted) |
121| `off` | the community service is switched off on this hub |
122| `store` | the hub could not write its store (try again later) |
123
124Every refusal is appended to the hub's refusal log with its reason and, when known, the key id and the message id. The message id is the SHA-256 of the signed bytes (everything before the `sig` line): it names the stored message and is the replay key, so the other valid encoding of the same signature ((r, n - s)) is a replay too. The ledger and the refusal log are set aside as `ledger.<seconds>` and `refused.<seconds>` when they reach 4 MiB; all parts stay public.
125
126## The job class in version 1
127
128A job names a published salvage part (a record id, which is the SHA-256 of the record bytes) and
129the compiler SHA-256 the hub's own check used. The runner:
130
1311. refuses the job unless `compiler` equals the one compiler it carries
132 (omc `3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194`, omega-mv f4df8239,
133 the salvage pin), whose file it hashes again before every job;
1342. fetches the record over HTTPS, refuses it unless its SHA-256 equals `part` and it parses as a
135 part record (`IPSLV001`, kind 2), and takes the source and the declared stdin from it;
1363. compiles the source with that compiler inside the cell, then runs the binary inside the cell
137 with the declared stdin;
1384. hashes the binary and the stdout bytes, signs the result and posts it.
139
140The cell is omega-mv `execpure` for both stages (the compiler too): Landlock allows only reading
141and executing the one program, `PR_SET_NO_NEW_PRIVS`, seccomp allows only `read` on descriptor 0,
142`write` on descriptors 1 and 2, `exit` and `execveat` of that program, and prlimit sets CPU 1 s
143soft / 2 s hard, file size 1 MiB, stack 8 MiB, no core, no new processes, 4 descriptors and
144128 MiB address space, with an empty environment. The runner adds a 3 s wall clock per stage.
145Brought code never runs outside the cell. There is no GPU work in version 1.
146
147## Counting rule (the hub page)
148
149- Only results that passed every check above count. Each key counts at most once per part
150 revision: the first accepted result of that key for that revision; later ones are stored as
151 `duplicate` and never counted.
152- N is the number of keys counted for the revision. Results agree when `binary`, `stdout` and
153 `exit` are all equal. K is the size of the largest agreeing group; the rest disagree.
154 When two groups tie for largest, K is reported for each and no group is called the agreement.
155- The page says "ran again by N community runners: K agree" and, when any disagree,
156 "D disagree" and that the part is not shown as reproduced.
157- Keys are free, so N unknown keys agreeing is not called verified and never changes what the
158 hub's own tick means.