@nervur.org/installer-node 0.0.0-stage → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/LICENSE +105 -0
  2. package/README.md +158 -2
  3. package/SECURITY.md +8 -0
  4. package/bin/nervur.js +5 -0
  5. package/cargo/emscripten-module.wasm +0 -0
  6. package/cargo/manifest.json +1 -0
  7. package/cargo/sqlite3.wasm +0 -0
  8. package/cargo/table-i-i.wasm +0 -0
  9. package/cargo/table-i-ii.wasm +0 -0
  10. package/cargo/table-i-iii.wasm +0 -0
  11. package/cargo/table-i-iiii.wasm +0 -0
  12. package/cargo/table-i-iiiii.wasm +0 -0
  13. package/cargo/table-i-iiij.wasm +0 -0
  14. package/cargo/table-i-ij.wasm +0 -0
  15. package/cargo/table-v-ii.wasm +0 -0
  16. package/cargo/table-v-iii.wasm +0 -0
  17. package/cargo/worker.js +30756 -0
  18. package/organs/console/node/guard.d.ts +10 -0
  19. package/organs/console/node/guard.js +52 -0
  20. package/organs/console/node/index.d.ts +4 -0
  21. package/organs/console/node/index.js +5 -0
  22. package/organs/console/node/line.d.ts +16 -0
  23. package/organs/console/node/line.js +150 -0
  24. package/organs/console/node/main.js +51 -0
  25. package/organs/console/node/program.d.ts +1 -0
  26. package/organs/console/node/program.js +5 -0
  27. package/organs/console/node/proof.d.ts +15 -0
  28. package/organs/console/node/proof.js +84 -0
  29. package/organs/console/node/socket.d.ts +15 -0
  30. package/organs/console/node/socket.js +99 -0
  31. package/organs/disk/index.d.ts +1 -0
  32. package/organs/disk/index.js +2 -0
  33. package/organs/disk/node/files.js +162 -0
  34. package/organs/disk/node/main.js +20 -0
  35. package/organs/disk/node/program.d.ts +1 -0
  36. package/organs/disk/node/program.js +5 -0
  37. package/organs/disk/organ.d.ts +5 -0
  38. package/organs/disk/organ.js +69 -0
  39. package/organs/network/node/fill.d.ts +21 -0
  40. package/organs/network/node/fill.js +195 -0
  41. package/organs/network/node/flows.js +66 -0
  42. package/organs/network/node/half.js +260 -0
  43. package/organs/network/node/lines.d.ts +29 -0
  44. package/organs/network/node/lines.js +236 -0
  45. package/organs/network/node/link.d.ts +24 -0
  46. package/organs/network/node/link.js +215 -0
  47. package/organs/network/node/main.js +41 -0
  48. package/organs/network/node/moved.d.ts +2 -0
  49. package/organs/network/node/moved.js +20 -0
  50. package/organs/network/node/near.d.ts +63 -0
  51. package/organs/network/node/near.js +263 -0
  52. package/organs/network/node/program.d.ts +1 -0
  53. package/organs/network/node/program.js +5 -0
  54. package/organs/network/node/schemes.d.ts +1 -0
  55. package/organs/network/node/schemes.js +2 -0
  56. package/organs/network/node/sent.d.ts +13 -0
  57. package/organs/network/node/sent.js +101 -0
  58. package/organs/network/node/served.d.ts +19 -0
  59. package/organs/network/node/served.js +237 -0
  60. package/organs/screen/node/client.js +3 -0
  61. package/organs/screen/node/follow.js +266 -0
  62. package/organs/screen/node/frames.js +26 -0
  63. package/organs/screen/node/held.js +27 -0
  64. package/organs/screen/node/http.js +179 -0
  65. package/organs/screen/node/lay.js +116 -0
  66. package/organs/screen/node/leave.js +27 -0
  67. package/organs/screen/node/linked.js +69 -0
  68. package/organs/screen/node/listen.js +61 -0
  69. package/organs/screen/node/look.js +121 -0
  70. package/organs/screen/node/loop.js +154 -0
  71. package/organs/screen/node/main.js +74 -0
  72. package/organs/screen/node/mirror.js +112 -0
  73. package/organs/screen/node/notice.js +44 -0
  74. package/organs/screen/node/presser.js +11 -0
  75. package/organs/screen/node/presses.js +108 -0
  76. package/organs/screen/node/program.d.ts +1 -0
  77. package/organs/screen/node/program.js +5 -0
  78. package/organs/screen/node/shown.js +205 -0
  79. package/organs/screen/node/standing.js +29 -0
  80. package/organs/screen/node/state.js +80 -0
  81. package/organs/screen/node/tell.js +47 -0
  82. package/organs/screen/node/uid.js +65 -0
  83. package/organs/screen/node/worn.js +23 -0
  84. package/organs/shell/index.d.ts +1 -0
  85. package/organs/shell/index.js +2 -0
  86. package/organs/shell/node/main.js +26 -0
  87. package/organs/shell/node/output.js +70 -0
  88. package/organs/shell/node/pressure.js +14 -0
  89. package/organs/shell/node/program.d.ts +1 -0
  90. package/organs/shell/node/program.js +5 -0
  91. package/organs/shell/node/runs.js +220 -0
  92. package/organs/shell/node/told.js +70 -0
  93. package/organs/shell/organ.d.ts +5 -0
  94. package/organs/shell/organ.js +59 -0
  95. package/package.json +43 -4
  96. package/src/command/act.d.ts +31 -0
  97. package/src/command/act.js +256 -0
  98. package/src/command/answers.d.ts +3 -0
  99. package/src/command/answers.js +232 -0
  100. package/src/command/args.d.ts +14 -0
  101. package/src/command/args.js +220 -0
  102. package/src/command/arrive.d.ts +2 -0
  103. package/src/command/arrive.js +21 -0
  104. package/src/command/asked.d.ts +18 -0
  105. package/src/command/asked.js +49 -0
  106. package/src/command/backup.d.ts +18 -0
  107. package/src/command/backup.js +261 -0
  108. package/src/command/before.d.ts +41 -0
  109. package/src/command/before.js +237 -0
  110. package/src/command/born.d.ts +27 -0
  111. package/src/command/born.js +103 -0
  112. package/src/command/bridge.d.ts +19 -0
  113. package/src/command/bridge.js +152 -0
  114. package/src/command/chain.d.ts +9 -0
  115. package/src/command/chain.js +48 -0
  116. package/src/command/channel.d.ts +29 -0
  117. package/src/command/channel.js +263 -0
  118. package/src/command/choices.d.ts +35 -0
  119. package/src/command/choices.js +173 -0
  120. package/src/command/claim.d.ts +12 -0
  121. package/src/command/claim.js +46 -0
  122. package/src/command/commands.d.ts +16 -0
  123. package/src/command/commands.js +257 -0
  124. package/src/command/ends.d.ts +16 -0
  125. package/src/command/ends.js +78 -0
  126. package/src/command/follow.d.ts +12 -0
  127. package/src/command/follow.js +66 -0
  128. package/src/command/given.d.ts +39 -0
  129. package/src/command/given.js +53 -0
  130. package/src/command/held.d.ts +15 -0
  131. package/src/command/held.js +56 -0
  132. package/src/command/index.d.ts +1 -0
  133. package/src/command/index.js +203 -0
  134. package/src/command/jailer.d.ts +28 -0
  135. package/src/command/jailer.js +135 -0
  136. package/src/command/laid.d.ts +6 -0
  137. package/src/command/laid.js +31 -0
  138. package/src/command/left.d.ts +9 -0
  139. package/src/command/left.js +34 -0
  140. package/src/command/line.d.ts +7 -0
  141. package/src/command/line.js +39 -0
  142. package/src/command/link.d.ts +30 -0
  143. package/src/command/link.js +123 -0
  144. package/src/command/lobes.d.ts +1 -0
  145. package/src/command/lobes.js +10 -0
  146. package/src/command/locks.d.ts +17 -0
  147. package/src/command/locks.js +76 -0
  148. package/src/command/mcp/calls.d.ts +27 -0
  149. package/src/command/mcp/calls.js +155 -0
  150. package/src/command/mcp/notices.d.ts +22 -0
  151. package/src/command/mcp/notices.js +203 -0
  152. package/src/command/mcp/resources.d.ts +31 -0
  153. package/src/command/mcp/resources.js +108 -0
  154. package/src/command/mcp/server.d.ts +19 -0
  155. package/src/command/mcp/server.js +149 -0
  156. package/src/command/mcp/tools.d.ts +39 -0
  157. package/src/command/mcp/tools.js +131 -0
  158. package/src/command/mcp.d.ts +8 -0
  159. package/src/command/mcp.js +39 -0
  160. package/src/command/noticed.d.ts +11 -0
  161. package/src/command/noticed.js +55 -0
  162. package/src/command/older.d.ts +11 -0
  163. package/src/command/older.js +45 -0
  164. package/src/command/open.d.ts +24 -0
  165. package/src/command/open.js +107 -0
  166. package/src/command/passphrase.d.ts +6 -0
  167. package/src/command/passphrase.js +82 -0
  168. package/src/command/reclaim.d.ts +7 -0
  169. package/src/command/reclaim.js +47 -0
  170. package/src/command/refused.d.ts +4 -0
  171. package/src/command/refused.js +27 -0
  172. package/src/command/release.d.ts +27 -0
  173. package/src/command/release.js +153 -0
  174. package/src/command/repo.d.ts +31 -0
  175. package/src/command/repo.js +133 -0
  176. package/src/command/rewrap.d.ts +16 -0
  177. package/src/command/rewrap.js +175 -0
  178. package/src/command/runtime.d.ts +25 -0
  179. package/src/command/runtime.js +175 -0
  180. package/src/command/salvage.d.ts +4 -0
  181. package/src/command/salvage.js +42 -0
  182. package/src/command/screen.d.ts +14 -0
  183. package/src/command/screen.js +62 -0
  184. package/src/command/spawn.d.ts +23 -0
  185. package/src/command/spawn.js +213 -0
  186. package/src/command/start.d.ts +34 -0
  187. package/src/command/start.js +246 -0
  188. package/src/command/state.d.ts +5 -0
  189. package/src/command/state.js +39 -0
  190. package/src/command/token.d.ts +1 -0
  191. package/src/command/token.js +9 -0
  192. package/src/command/trial.d.ts +17 -0
  193. package/src/command/trial.js +92 -0
  194. package/src/command/vouch.d.ts +1 -0
  195. package/src/command/vouch.js +15 -0
  196. package/src/command/windows-processes.d.ts +2 -0
  197. package/src/command/windows-processes.js +22 -0
  198. package/src/command/wipe.d.ts +9 -0
  199. package/src/command/wipe.js +105 -0
  200. package/src/command/words.d.ts +5 -0
  201. package/src/command/words.js +53 -0
  202. package/src/door/claim.d.ts +5 -0
  203. package/src/door/claim.js +21 -0
  204. package/src/door/claimed.d.ts +7 -0
  205. package/src/door/claimed.js +110 -0
  206. package/src/door/configuration.d.ts +40 -0
  207. package/src/door/configuration.js +206 -0
  208. package/src/door/design.d.ts +13 -0
  209. package/src/door/design.js +71 -0
  210. package/src/door/digests.d.ts +7 -0
  211. package/src/door/digests.js +36 -0
  212. package/src/door/distribution.d.ts +25 -0
  213. package/src/door/distribution.js +88 -0
  214. package/src/door/door.d.ts +41 -0
  215. package/src/door/door.js +219 -0
  216. package/src/door/dressed.d.ts +34 -0
  217. package/src/door/dressed.js +182 -0
  218. package/src/door/faculties.d.ts +29 -0
  219. package/src/door/faculties.js +88 -0
  220. package/src/door/longest.d.ts +6 -0
  221. package/src/door/longest.js +25 -0
  222. package/src/fills/account-only.d.ts +3 -0
  223. package/src/fills/account-only.js +24 -0
  224. package/src/fills/boot-key.d.ts +21 -0
  225. package/src/fills/boot-key.js +70 -0
  226. package/src/fills/boot-move.d.ts +25 -0
  227. package/src/fills/boot-move.js +86 -0
  228. package/src/fills/bridge.d.ts +13 -0
  229. package/src/fills/bridge.js +86 -0
  230. package/src/fills/chance.d.ts +2 -0
  231. package/src/fills/chance.js +7 -0
  232. package/src/fills/crypto.d.ts +2 -0
  233. package/src/fills/crypto.js +94 -0
  234. package/src/fills/flushed.d.ts +9 -0
  235. package/src/fills/flushed.js +80 -0
  236. package/src/fills/hardware.d.ts +18 -0
  237. package/src/fills/hardware.js +70 -0
  238. package/src/fills/held.d.ts +31 -0
  239. package/src/fills/held.js +171 -0
  240. package/src/fills/keepers.d.ts +23 -0
  241. package/src/fills/keepers.js +151 -0
  242. package/src/fills/keyring.d.ts +19 -0
  243. package/src/fills/keyring.js +131 -0
  244. package/src/fills/pages.d.ts +3 -0
  245. package/src/fills/pages.js +260 -0
  246. package/src/fills/reserve.d.ts +11 -0
  247. package/src/fills/reserve.js +72 -0
  248. package/src/fills/time.d.ts +2 -0
  249. package/src/fills/time.js +29 -0
  250. package/src/fills/unlocker.d.ts +6 -0
  251. package/src/fills/unlocker.js +26 -0
  252. package/src/fills/vitals.d.ts +8 -0
  253. package/src/fills/vitals.js +100 -0
  254. package/src/fills/windows-start.d.ts +2 -0
  255. package/src/fills/windows-start.js +21 -0
  256. package/src/halves/build.d.ts +10 -0
  257. package/src/halves/build.js +219 -0
  258. package/src/halves/end.d.ts +17 -0
  259. package/src/halves/end.js +157 -0
  260. package/src/halves/genome.d.ts +3 -0
  261. package/src/halves/genome.js +21 -0
  262. package/src/halves/handler.d.ts +8 -0
  263. package/src/halves/handler.js +40 -0
  264. package/src/halves/index.d.ts +5 -0
  265. package/src/halves/index.js +6 -0
  266. package/src/halves/laid.d.ts +12 -0
  267. package/src/halves/laid.js +103 -0
  268. package/src/halves/lent.d.ts +6 -0
  269. package/src/halves/lent.js +147 -0
  270. package/src/halves/native.d.ts +12 -0
  271. package/src/halves/native.js +53 -0
  272. package/src/halves/statements.d.ts +23 -0
  273. package/src/halves/statements.js +165 -0
  274. package/src/halves/tokens.d.ts +22 -0
  275. package/src/halves/tokens.js +135 -0
  276. package/src/link/link.d.ts +4 -0
  277. package/src/link/link.js +4 -0
  278. package/src/link/placeholder.d.ts +1 -0
  279. package/src/link/placeholder.js +21 -0
  280. package/src/link/steps.d.ts +52 -0
  281. package/src/link/steps.js +118 -0
  282. package/src/lobes/calls.d.ts +76 -0
  283. package/src/lobes/calls.js +61 -0
  284. package/src/lobes/channel.d.ts +76 -0
  285. package/src/lobes/channel.js +202 -0
  286. package/src/lobes/index.d.ts +1 -0
  287. package/src/lobes/index.js +2 -0
  288. package/src/lobes/lobes.d.ts +15 -0
  289. package/src/lobes/lobes.js +244 -0
  290. package/src/lobes/main.js +107 -0
  291. package/src/lobes/thread.d.ts +22 -0
  292. package/src/lobes/thread.js +270 -0
  293. package/src/organism/act.d.ts +8 -0
  294. package/src/organism/act.js +63 -0
  295. package/src/organism/beat.d.ts +5 -0
  296. package/src/organism/beat.js +45 -0
  297. package/src/organism/compiled.d.ts +2 -0
  298. package/src/organism/compiled.js +24 -0
  299. package/src/organism/folder.d.ts +88 -0
  300. package/src/organism/folder.js +259 -0
  301. package/src/organism/main.d.ts +1 -0
  302. package/src/organism/main.js +11 -0
  303. package/src/organism/organism.d.ts +1 -0
  304. package/src/organism/organism.js +219 -0
  305. package/src/organism/said.d.ts +12 -0
  306. package/src/organism/said.js +30 -0
  307. package/src/organism/told.d.ts +5 -0
  308. package/src/organism/told.js +110 -0
  309. package/src/organism/unlock.d.ts +8 -0
  310. package/src/organism/unlock.js +95 -0
  311. package/src/organism/upgrade.d.ts +24 -0
  312. package/src/organism/upgrade.js +145 -0
  313. package/src/organism/via.d.ts +7 -0
  314. package/src/organism/via.js +20 -0
  315. package/src/service/body.d.ts +8 -0
  316. package/src/service/body.js +34 -0
  317. package/src/service/handler.d.ts +20 -0
  318. package/src/service/handler.js +128 -0
  319. package/src/service/index.d.ts +4 -0
  320. package/src/service/index.js +16 -0
  321. package/src/service/manager.d.ts +18 -0
  322. package/src/service/manager.js +185 -0
  323. package/src/service/service.d.ts +24 -0
  324. package/src/service/service.js +200 -0
  325. package/src/service/swap.d.ts +12 -0
  326. package/src/service/swap.js +74 -0
  327. package/src/service/watchdog.d.ts +6 -0
  328. package/src/service/watchdog.js +31 -0
  329. package/src/tcp/crowd.d.ts +18 -0
  330. package/src/tcp/crowd.js +85 -0
  331. package/src/tcp/dial.d.ts +23 -0
  332. package/src/tcp/dial.js +102 -0
  333. package/src/tcp/frame.d.ts +23 -0
  334. package/src/tcp/frame.js +159 -0
  335. package/src/tcp/listen.d.ts +50 -0
  336. package/src/tcp/listen.js +207 -0
  337. package/src/tcp/source.d.ts +2 -0
  338. package/src/tcp/source.js +26 -0
  339. package/src/version/index.d.ts +1 -0
  340. package/src/version/index.js +2 -0
  341. package/src/version/version.d.ts +1 -0
  342. package/src/version/version.js +2 -0
  343. package/src/work/first.d.ts +11 -0
  344. package/src/work/first.js +91 -0
  345. package/src/work/index.d.ts +2 -0
  346. package/src/work/index.js +15 -0
  347. package/src/work/work.d.ts +20 -0
  348. package/src/work/work.js +136 -0
  349. package/src/ws/dial.d.ts +7 -0
  350. package/src/ws/dial.js +252 -0
  351. package/src/ws/dialing.d.ts +50 -0
  352. package/src/ws/dialing.js +72 -0
  353. package/src/ws/frame.d.ts +32 -0
  354. package/src/ws/frame.js +124 -0
  355. package/src/ws/handshake.d.ts +4 -0
  356. package/src/ws/handshake.js +27 -0
  357. package/src/ws/line.d.ts +45 -0
  358. package/src/ws/line.js +250 -0
  359. package/src/ws/listen.d.ts +42 -0
  360. package/src/ws/listen.js +272 -0
  361. package/src/ws/rfc6455.d.ts +18 -0
  362. package/src/ws/rfc6455.js +187 -0
@@ -0,0 +1,207 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { createServer, } from 'node:net';
3
+ import { networkInterfaces, totalmem } from 'node:os';
4
+ import { BOX_SIZE, LOBE_MEMORY, queueOf, } from '@nervur.org/genome/seams';
5
+ import { hex } from '@nervur.org/genome/standard';
6
+ import { addressAt, DROPPED, frameOf, reader } from './frame.js';
7
+ import { admitted, carried, crowdOf, left, working, } from './crowd.js';
8
+ import { SOURCE_V6, sourceOf } from './source.js';
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ export const shareOf = (total ) => Math.max(1, Math.ceil(total / 8));
21
+
22
+ export const carriedOf = (memory ) =>
23
+ Math.max(1, Math.floor(Math.min(memory / 8, 256 * BOX_SIZE) / BOX_SIZE));
24
+
25
+ const CONNECTIONS = carriedOf(totalmem());
26
+ export const BOUNDS = {
27
+ connections: CONNECTIONS,
28
+ 'connections.share': shareOf(CONNECTIONS),
29
+ 'source.v6': SOURCE_V6,
30
+ flight: queueOf(LOBE_MEMORY).queue.ceiling,
31
+ idle: 60_000,
32
+ wait: 60_000,
33
+ dropped: DROPPED,
34
+ };
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ export const LONGEST_SPAN = 2 ** 31 - 1;
44
+
45
+ export const moved = (
46
+ bounds ,
47
+ words ,
48
+ ) => {
49
+ const named = Object.fromEntries(Object.entries(words).filter(([name]) => Object.hasOwn(bounds, name)));
50
+ const next = { ...bounds, ...named };
51
+ return {
52
+ ...next,
53
+ idle: Math.min(next.idle, LONGEST_SPAN),
54
+ wait: Math.min(next.wait, LONGEST_SPAN),
55
+ };
56
+ };
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+ export const listeningOf = (bounds = BOUNDS, counted = () => undefined) => ({
75
+ defaults: bounds,
76
+ bounds,
77
+ waiting: new Map(),
78
+ servers: [],
79
+ sockets: new Set(),
80
+ crowd: crowdOf((socket) => socket.destroy()),
81
+ next: 1,
82
+ accepted: 0,
83
+ unreplied: 0,
84
+ counted,
85
+ });
86
+
87
+ export const boundedBy = (listening , words ) => {
88
+ const { connections } = words;
89
+ const share = connections === undefined ? {} : { 'connections.share': shareOf(connections) };
90
+ listening.bounds = moved(listening.defaults, { ...share, ...words });
91
+ };
92
+
93
+ const freed = (listening , exchange ) => {
94
+ const held = listening.waiting.get(exchange);
95
+ if (held === undefined) return undefined;
96
+ listening.waiting.delete(exchange);
97
+ held.flight.delete(exchange);
98
+ clearTimeout(held.timer);
99
+ if (held.flight.size === 0) working(listening.crowd, held.socket, false);
100
+ return held;
101
+ };
102
+
103
+ const unreplied = (listening , exchange ) => {
104
+ if (freed(listening, exchange) === undefined) return;
105
+ listening.unreplied += 1;
106
+ listening.counted();
107
+ };
108
+
109
+ export const hostsOf = (host ) =>
110
+ host === '0.0.0.0' || host === '::'
111
+ ? Object.values(networkInterfaces())
112
+ .flat()
113
+ .flatMap((one) =>
114
+ one !== undefined && (one.family === 'IPv4' || (host === '::' && one.scopeid === 0)) ? [one.address] : [],
115
+ )
116
+ : [host];
117
+
118
+ const connected = (
119
+ listening ,
120
+ arrived ,
121
+ socket ,
122
+ ) => {
123
+ listening.accepted += 1;
124
+ const { connections, 'connections.share': share, flight: most, idle, wait, dropped } = listening.bounds;
125
+ const source = sourceOf(socket.remoteAddress, listening.accepted, listening.bounds['source.v6']);
126
+ if (!admitted(listening.crowd, socket, source, connections, share)) {
127
+ socket.destroy();
128
+ return;
129
+ }
130
+ const flight = new Set ();
131
+ const feed = reader(
132
+ (frame) => {
133
+ if (frame.kind !== 'ask' || socket.destroyed) return;
134
+ if (flight.size >= most) {
135
+ socket.destroy();
136
+ return;
137
+ }
138
+ const exchange = listening.next++;
139
+ const timer = setTimeout(() => unreplied(listening, exchange), wait);
140
+ flight.add(exchange);
141
+ working(listening.crowd, socket, true);
142
+ listening.waiting.set(exchange, { socket, id: frame.id, flight, timer });
143
+ arrived(exchange, frame.box, hex(frame.ward), source);
144
+ },
145
+ () => socket.destroy(),
146
+ dropped,
147
+ );
148
+ listening.sockets.add(socket);
149
+ socket.setTimeout(idle);
150
+ socket.on('timeout', () => {
151
+ if (flight.size === 0) socket.destroy();
152
+ else socket.setTimeout(idle);
153
+ });
154
+ socket.on('close', () => {
155
+ listening.sockets.delete(socket);
156
+ left(listening.crowd, socket);
157
+ for (const exchange of flight) freed(listening, exchange);
158
+ });
159
+ socket.on('data', (chunk) => feed(new Uint8Array(chunk)));
160
+ socket.on('error', () => socket.destroy());
161
+ };
162
+
163
+ export const whyNot = (failed , port ) => {
164
+ if (failed.code === 'EADDRINUSE') return `port ${port} is taken by another program on this machine`;
165
+ if (failed.code === 'EACCES') return `port ${port} needs an administrator on this machine`;
166
+ return failed.message;
167
+ };
168
+
169
+ export const listenOf =
170
+ (listening , announced ) =>
171
+ (endpoint, arrived) => {
172
+ const found = /^tcp:\/\/(\[[0-9A-Fa-f:.]+\]|[^\s/?#@[\]:]+):(\d{1,5})$/i.exec(endpoint);
173
+ if (found?.[1] === undefined || found[2] === undefined || Number(found[2]) > 65_535)
174
+ return Promise.resolve({ why: `${endpoint} is no tcp endpoint` });
175
+ const host = found[1].replace(/^\[|\]$/g, '');
176
+ const server = createServer((socket) => connected(listening, arrived, socket));
177
+ return new Promise((done) => {
178
+ server.once('error', (failed ) => done({ why: whyNot(failed, Number(found[2])) }));
179
+ server.listen(Number(found[2]), host === '::' ? undefined : host, () => {
180
+ listening.servers.push(server);
181
+ const where = server.address();
182
+ const port = typeof where === 'object' && where !== null ? where.port : 0;
183
+ const addresses = (announced === null ? hostsOf(host) : [announced]).flatMap((one) => {
184
+ const address = addressAt(one, port);
185
+ return address === null ? [] : [address];
186
+ });
187
+ done({ addresses });
188
+ });
189
+ });
190
+ };
191
+
192
+ export const openedOf =
193
+ (listening ) =>
194
+ (exchange) => {
195
+ const held = listening.waiting.get(exchange);
196
+ if (held !== undefined) carried(listening.crowd, held.socket);
197
+ };
198
+
199
+ export const replyOf =
200
+ (listening ) =>
201
+ (exchange, bytes) => {
202
+ const held = freed(listening, exchange);
203
+ if (held === undefined || held.socket.destroyed) return;
204
+ held.socket.write(
205
+ frameOf(bytes === null ? { kind: 'nothing', id: held.id } : { kind: 'reply', id: held.id, box: bytes }),
206
+ );
207
+ };
@@ -0,0 +1,2 @@
1
+ export declare const SOURCE_V6 = 56;
2
+ export declare const sourceOf: (address: string | undefined, connection: number, prefix?: number) => string;
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+
3
+ export const SOURCE_V6 = 56;
4
+
5
+ const networkOf = (address , prefix ) => {
6
+ const [head = '', tail] = address.split('::');
7
+ const groups = head === '' ? [] : head.split(':');
8
+ const after = tail === undefined || tail === '' ? [] : tail.split(':');
9
+ const missing = tail === undefined ? 0 : 8 - groups.length - after.length;
10
+ const whole = [...groups, ...Array.from({ length: missing }, () => '0'), ...after];
11
+ const bits = Math.max(0, Math.min(128, prefix));
12
+ return whole
13
+ .map((group, at) => {
14
+ const kept = Math.max(0, Math.min(16, bits - at * 16));
15
+ const mask = kept === 0 ? 0 : (0xffff << (16 - kept)) & 0xffff;
16
+ return (Number.parseInt(group === '' ? '0' : group, 16) & mask).toString(16);
17
+ })
18
+ .join(':')
19
+ .concat(`/${bits}`);
20
+ };
21
+
22
+ export const sourceOf = (address , connection , prefix = SOURCE_V6) => {
23
+ const plain = address?.replace(/^::ffff:/i, '');
24
+ if (plain === undefined || plain === '::1' || plain.startsWith('127.')) return `connection ${connection}`;
25
+ return plain.includes(':') ? networkOf(plain.replace(/%.*$/, ''), prefix) : plain;
26
+ };
@@ -0,0 +1 @@
1
+ export { INSTALLER_VERSION } from './version.js';
@@ -0,0 +1,2 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ export { INSTALLER_VERSION } from './version.js';
@@ -0,0 +1 @@
1
+ export declare const INSTALLER_VERSION: string;
@@ -0,0 +1,2 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ export const INSTALLER_VERSION = '0.37.1';
@@ -0,0 +1,11 @@
1
+ import { type Fields } from '@nervur.org/genome/standard';
2
+ import type { Program } from '../fills/bridge.js';
3
+ import type { Laid } from '../organism/folder.js';
4
+ type Why = {
5
+ readonly why: string;
6
+ };
7
+ export declare const firstFrameOf: (program: Program, span: number) => Promise<{
8
+ readonly frame: Fields;
9
+ } | Why>;
10
+ export declare const networkStarts: (home: string, laid: Pick<Laid, 'publicHost' | 'ws' | 'wss' | 'work'>) => Promise<null | Why>;
11
+ export {};
@@ -0,0 +1,91 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { spawn } from 'node:child_process';
3
+ import { NETWORK_BLUEPRINT } from '@nervur.org/genome';
4
+ import { genomeCodec } from '@nervur.org/genome/cage';
5
+ import { FRAME_SIZE, LONGEST_TIMEOUT } from '../door/longest.js';
6
+ import { dataText, isFields, utf8Text, } from '@nervur.org/genome/standard';
7
+
8
+ import { NETWORK, networkOf } from '../door/configuration.js';
9
+ import { halvesOf, programOf } from '../halves/index.js';
10
+
11
+ import { workHalvesOf } from './work.js';
12
+
13
+
14
+
15
+ const NEWLINE = 0x0a;
16
+
17
+ const FIRST_WITHIN = LONGEST_TIMEOUT;
18
+
19
+ const firstLine = (chunks ) => {
20
+ const bytes = Buffer.concat(chunks);
21
+ const at = bytes.indexOf(NEWLINE);
22
+ if (at === -1) return bytes.length > FRAME_SIZE ? null : undefined;
23
+ return at > FRAME_SIZE ? null : new Uint8Array(bytes.subarray(0, at));
24
+ };
25
+
26
+ export const firstFrameOf = (program , span ) =>
27
+ new Promise((done) => {
28
+ const child = spawn(program.command, [...program.args], { stdio: ['pipe', 'pipe', 'pipe'] });
29
+ const out = [];
30
+ let said = '';
31
+ let settled = false;
32
+ const settle = (answer ) => {
33
+ if (settled) return;
34
+ settled = true;
35
+ done(answer);
36
+ child.stdin.end();
37
+ if (child.exitCode === null) timer.refresh();
38
+ };
39
+ const timer = setTimeout(() => {
40
+ settle({ why: `it wrote no first frame within ${span} ms` });
41
+ child.kill();
42
+ }, span);
43
+ child.stdin.on('error', () => undefined);
44
+ child.stderr.on('data', (chunk ) => (said += chunk.toString('utf8')));
45
+ child.stdout.on('data', (chunk ) => {
46
+ out.push(new Uint8Array(chunk));
47
+ const line = firstLine(out);
48
+ if (line === undefined) return;
49
+ const text = line === null ? null : utf8Text(line);
50
+ const read = text === null ? null : genomeCodec.read(text);
51
+ settle(
52
+ read !== null && 'data' in read && isFields(read.data)
53
+ ? { frame: read.data }
54
+ : { why: 'its first line is no frame' },
55
+ );
56
+ });
57
+ child.on('error', (failed) => settle({ why: failed.message }));
58
+ child.on('close', (code) => {
59
+ clearTimeout(timer);
60
+ const told = said.trim();
61
+ settle({
62
+ why: `it ended, ${code ?? 'stopped'}, with no first frame${told === '' ? '' : `: ${told}`}`,
63
+ });
64
+ });
65
+ });
66
+
67
+ export const networkStarts = async (
68
+ home ,
69
+ laid ,
70
+ ) => {
71
+ const { reach, half } = networkOf(laid);
72
+ const program = programOf(
73
+ halvesOf(home),
74
+ [],
75
+ workHalvesOf(home),
76
+ )(NETWORK, {
77
+ ...half,
78
+ reach,
79
+ code: null,
80
+ });
81
+ const account = isFields(reach) && typeof reach['account'] === 'string' ? reach['account'] : 'its account';
82
+ const fails = (why ) => ({
83
+ why: `network's half does not start as ${account}: ${why}; the organism runs on as it was`,
84
+ });
85
+ if ('why' in program) return fails(program.why);
86
+ const first = await firstFrameOf(program, FIRST_WITHIN);
87
+ if ('why' in first) return fails(first.why);
88
+ return dataText(first.frame) === dataText({ blueprint: NETWORK_BLUEPRINT })
89
+ ? null
90
+ : fails(`its first frame is not network's blueprint: ${dataText(first.frame).slice(0, 200)}`);
91
+ };
@@ -0,0 +1,2 @@
1
+ export { asWork, baseClosed, costOf, homeOpened, recoveryCostOf, layWorkHalves, readableAs, runsNode, workHalvesOf, workOf, type Work, } from './work.js';
2
+ export { firstFrameOf, networkStarts } from './first.js';
@@ -0,0 +1,15 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ export {
3
+ asWork,
4
+ baseClosed,
5
+ costOf,
6
+ homeOpened,
7
+ recoveryCostOf,
8
+ layWorkHalves,
9
+ readableAs,
10
+ runsNode,
11
+ workHalvesOf,
12
+ workOf,
13
+
14
+ } from './work.js';
15
+ export { firstFrameOf, networkStarts } from './first.js';
@@ -0,0 +1,20 @@
1
+ import type { Program } from '../fills/bridge.js';
2
+ import { type Built } from '../halves/native.js';
3
+ export type Work = {
4
+ readonly account: string;
5
+ readonly home: string;
6
+ };
7
+ type Why = {
8
+ readonly why: string;
9
+ };
10
+ export declare const asWork: (work: Pick<Work, 'account'>, program: Program) => Program;
11
+ export declare const runsNode: (node: string, account: string, started?: (program: Program) => Program) => null | Why;
12
+ export declare const workOf: (account: string, platform?: NodeJS.Platform, node?: string) => Work | Why;
13
+ export declare const workHalvesOf: (organism: string) => string;
14
+ export declare const homeOpened: (organism: string, home?: string) => void;
15
+ export declare const baseClosed: (organism: string, home?: string) => void;
16
+ export declare const layWorkHalves: (organism: string, halves: Iterable<Built>) => readonly string[];
17
+ export declare const readableAs: (work: Work, organism: string, digest: string) => null | Why;
18
+ export declare const costOf: (work: Pick<Work, 'account'> | undefined, root?: boolean) => string;
19
+ export declare const recoveryCostOf: (delay: number) => string;
20
+ export {};
@@ -0,0 +1,136 @@
1
+ // SPDX-License-Identifier: FSL-1.1-ALv2
2
+ import { execFileSync } from 'node:child_process';
3
+ import { chmodSync, existsSync, mkdirSync, renameSync, statSync, writeFileSync } from 'node:fs';
4
+ import { userInfo } from 'node:os';
5
+ import { dirname, join } from 'node:path';
6
+
7
+ import { digestOf, } from '../halves/native.js';
8
+
9
+
10
+
11
+
12
+
13
+ const ACCOUNT = /^[a-z_][a-z0-9_-]{0,31}$/;
14
+
15
+ export const asWork = (work , program ) => ({
16
+ command: 'sudo',
17
+ args: ['-n', '-u', work.account, '-H', '--', program.command, ...program.args],
18
+ });
19
+
20
+ const roadTo = (file ) =>
21
+ dirname(file) === file ? [file] : [...roadTo(dirname(file)), file];
22
+
23
+ const BLOCKED = 'for one in "$@"; do [ -x "$one" ] || { printf %s "$one"; exit 1; }; done';
24
+
25
+ export const runsNode = (
26
+ node ,
27
+ account ,
28
+ started = (program) => program,
29
+ ) => {
30
+ const { command, args } = started({ command: 'sh', args: ['-c', BLOCKED, 'sh', ...roadTo(node)] });
31
+ try {
32
+ execFileSync(command, [...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
33
+ return null;
34
+ } catch (failed) {
35
+ const blocked = failed instanceof Error && 'stdout' in failed ? String(failed.stdout) : '';
36
+ if (!blocked.startsWith('/')) return { why: `${account} could not be asked whether it runs ${node}` };
37
+ return {
38
+ why:
39
+ blocked === node
40
+ ? `${account} may not run ${node}, the Node the body runs on: it lacks the mode that lets every account run it`
41
+ : `${account} cannot run ${node}, the Node the body runs on: it does not pass ${blocked}; a root lets it, as chmod 711 on that folder does`,
42
+ };
43
+ }
44
+ };
45
+
46
+ export const workOf = (
47
+ account ,
48
+ platform = process.platform,
49
+ node = process.execPath,
50
+ ) => {
51
+ if (platform === 'win32') return { why: 'a work account has no road on Windows yet: install without --work' };
52
+ if (!ACCOUNT.test(account)) return { why: `--work is an account's name, not ${account}` };
53
+ const rule = `a root lays the account, with no login and no password, and the rule ${process.env['USER'] ?? 'nervur'} ALL=(${account}) NOPASSWD: ALL`;
54
+ let home ;
55
+ try {
56
+ home = execFileSync('sudo', ['-n', '-u', account, '-H', '--', 'sh', '-c', 'printf %s "$HOME"'], {
57
+ encoding: 'utf8',
58
+ stdio: ['ignore', 'pipe', 'pipe'],
59
+ });
60
+ } catch {
61
+ return { why: `sudo starts nothing as ${account} without a password: ${rule}` };
62
+ }
63
+ if (!home.startsWith('/')) return { why: `${account} has no home: ${rule}` };
64
+ return runsNode(node, account, (program) => asWork({ account }, program)) ?? { account, home };
65
+ };
66
+
67
+ export const workHalvesOf = (organism ) => join(dirname(organism), 'work');
68
+
69
+ const fileOf = (folder , digest ) => join(folder, `${digest}.mjs`);
70
+
71
+ export const homeOpened = (organism , home = userInfo().homedir) => {
72
+ if (organism !== join(home, '.nervur', 'organism')) return;
73
+ try {
74
+ chmodSync(home, statSync(home).mode | 0o711);
75
+ } catch {
76
+ }
77
+ };
78
+
79
+ const closed = (base ) => {
80
+ chmodSync(base, 0o711);
81
+ const installer = join(base, 'installer');
82
+ if (existsSync(installer)) chmodSync(installer, 0o700);
83
+ };
84
+
85
+ export const baseClosed = (organism , home = userInfo().homedir) => {
86
+ if (organism !== join(home, '.nervur', 'organism')) return;
87
+ try {
88
+ chmodSync(dirname(organism), 0o700);
89
+ const installer = join(dirname(organism), 'installer');
90
+ if (existsSync(installer)) chmodSync(installer, 0o700);
91
+ } catch {
92
+ }
93
+ };
94
+
95
+ export const layWorkHalves = (organism , halves ) => {
96
+ const folder = workHalvesOf(organism);
97
+ homeOpened(organism);
98
+ closed(dirname(folder));
99
+ mkdirSync(folder, { recursive: true, mode: 0o711 });
100
+ chmodSync(folder, 0o711);
101
+ const laid = [];
102
+ for (const { text, digest } of halves) {
103
+ const file = fileOf(folder, digest);
104
+ if (existsSync(file) && digestOf(file) === digest) continue;
105
+ const writing = `${file}.${process.pid}.writing`;
106
+ writeFileSync(writing, text, { mode: 0o644 });
107
+ chmodSync(writing, 0o644);
108
+ renameSync(writing, file);
109
+ laid.push(digest);
110
+ }
111
+ return laid;
112
+ };
113
+
114
+ export const readableAs = (work , organism , digest ) => {
115
+ const file = fileOf(workHalvesOf(organism), digest);
116
+ try {
117
+ execFileSync('sudo', ['-n', '-u', work.account, '--', 'test', '-r', file], { stdio: 'ignore' });
118
+ return null;
119
+ } catch {
120
+ return {
121
+ why: `${work.account} cannot read ${file}: a root lets it pass the homes above it, as chmod 711 on the account's home does`,
122
+ };
123
+ }
124
+ };
125
+
126
+ const ROOT_SAID =
127
+ ' This account is root, which holds the whole machine, so the organism holds it too: a machine with other people on it gives each an account of their own.';
128
+
129
+ export const costOf = (work , root = process.getuid?.() === 0) =>
130
+ (work === undefined
131
+ ? "The body, shell, disk and network, runs as this account: any program shell starts may read the organism's folder, its store and its boot key."
132
+ : `The body, shell, disk and network, runs as ${work.account}: any program shell starts may stop network's half or take its ports while it restarts, and never reads the organism's folder, its store, its boot key or its memory.`) +
133
+ (root ? ROOT_SAID : '');
134
+
135
+ export const recoveryCostOf = (delay ) =>
136
+ `A recovery key, one for each owner who keeps one, set as a set with ask brain recoveryKeys, reclaims the organism if its owners lose it; a set replacing another holds ${delay / 86_400_000} days after it is set, while the set it replaces still reclaims and every owner is told.`;
@@ -0,0 +1,7 @@
1
+ import { type Proven } from '@nervur.org/genome/seams';
2
+ import { replyOf, type Answer } from './line.js';
3
+ import { type Dialing, type Wanted } from './dialing.js';
4
+ export declare const holdOf: (dialing: Dialing) => (lines: readonly Wanted[]) => readonly string[];
5
+ export declare const provedOf: (dialing: Dialing) => (address: string, nonce: Uint8Array, proven: readonly Proven[]) => void;
6
+ export declare const replyOn: (dialing: Dialing) => ReturnType<typeof replyOf>;
7
+ export declare const sendOf: (dialing: Dialing) => (address: string, bytes: Uint8Array, wait: number, wardText: string) => Promise<Answer>;