@ai-ecoverse/slicc-kernel 1.149.0 → 1.150.0
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.
- package/README.md +3 -2
- package/dist/index.js +4 -1
- package/dist/index.js.map +2 -2
- package/dist/kernel-worker.js +79 -44
- package/dist/kernel-worker.js.map +3 -3
- package/dist/node-process-worker.js +1 -1
- package/dist/node.js +79 -44
- package/dist/node.js.map +3 -3
- package/dist/process-worker.js +1 -1
- package/dist/types/kernel/socket.d.ts +1 -1
- package/package.json +3 -3
package/dist/kernel-worker.js
CHANGED
|
@@ -5100,12 +5100,12 @@ var KernelPipe = class {
|
|
|
5100
5100
|
await this.changed(signal);
|
|
5101
5101
|
}
|
|
5102
5102
|
const out = new Uint8Array(Math.min(max, this.size));
|
|
5103
|
-
let
|
|
5103
|
+
let filled2 = 0;
|
|
5104
5104
|
for (const chunk2 of this.chunks) {
|
|
5105
|
-
if (
|
|
5106
|
-
const count2 = Math.min(chunk2.length, out.length -
|
|
5107
|
-
out.set(chunk2.subarray(0, count2),
|
|
5108
|
-
|
|
5105
|
+
if (filled2 === out.length) break;
|
|
5106
|
+
const count2 = Math.min(chunk2.length, out.length - filled2);
|
|
5107
|
+
out.set(chunk2.subarray(0, count2), filled2);
|
|
5108
|
+
filled2 += count2;
|
|
5109
5109
|
}
|
|
5110
5110
|
return out;
|
|
5111
5111
|
}
|
|
@@ -5133,12 +5133,12 @@ var KernelPipe = class {
|
|
|
5133
5133
|
}
|
|
5134
5134
|
take(n) {
|
|
5135
5135
|
const out = new Uint8Array(n);
|
|
5136
|
-
let
|
|
5137
|
-
while (
|
|
5136
|
+
let filled2 = 0;
|
|
5137
|
+
while (filled2 < n) {
|
|
5138
5138
|
const head = this.chunks[0];
|
|
5139
|
-
const count2 = Math.min(head.length, n -
|
|
5140
|
-
out.set(head.subarray(0, count2),
|
|
5141
|
-
|
|
5139
|
+
const count2 = Math.min(head.length, n - filled2);
|
|
5140
|
+
out.set(head.subarray(0, count2), filled2);
|
|
5141
|
+
filled2 += count2;
|
|
5142
5142
|
if (count2 === head.length) this.chunks.shift();
|
|
5143
5143
|
else this.chunks[0] = head.subarray(count2);
|
|
5144
5144
|
}
|
|
@@ -5903,8 +5903,8 @@ var DIAL_ERRORS = [
|
|
|
5903
5903
|
"ETIMEDOUT",
|
|
5904
5904
|
"ECONNRESET"
|
|
5905
5905
|
];
|
|
5906
|
-
function dialError(e,
|
|
5907
|
-
if (
|
|
5906
|
+
function dialError(e, timedOut2, closed) {
|
|
5907
|
+
if (timedOut2) return new KernelError("ETIMEDOUT");
|
|
5908
5908
|
if (closed) return new KernelError("ECONNABORTED");
|
|
5909
5909
|
const code = e?.code;
|
|
5910
5910
|
const known = DIAL_ERRORS.find((errno3) => errno3 === code);
|
|
@@ -6159,7 +6159,7 @@ var KernelSocket = class _KernelSocket {
|
|
|
6159
6159
|
get loopbackLinked() {
|
|
6160
6160
|
return this.state === "connected" && !this.switch;
|
|
6161
6161
|
}
|
|
6162
|
-
async secureLink(make, signal = NEVER_ABORTED) {
|
|
6162
|
+
async secureLink(make, signal = NEVER_ABORTED, keeps = () => false) {
|
|
6163
6163
|
const raw2 = this.connection();
|
|
6164
6164
|
if (this.switch || this.served || this.writeShut || this.readShut)
|
|
6165
6165
|
throw new KernelError("EINVAL");
|
|
@@ -6181,14 +6181,18 @@ var KernelSocket = class _KernelSocket {
|
|
|
6181
6181
|
}
|
|
6182
6182
|
};
|
|
6183
6183
|
let made2;
|
|
6184
|
-
const abandon = () =>
|
|
6184
|
+
const abandon = () => {
|
|
6185
|
+
if (!keeps(signal.reason)) view2.close();
|
|
6186
|
+
};
|
|
6185
6187
|
signal.addEventListener("abort", abandon, { once: true });
|
|
6186
6188
|
try {
|
|
6187
6189
|
made2 = await make(view2);
|
|
6188
6190
|
} catch (err) {
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6191
|
+
if (!(signal.aborted && keeps(signal.reason))) {
|
|
6192
|
+
view2.close();
|
|
6193
|
+
this.readShut = true;
|
|
6194
|
+
this.writeShut = true;
|
|
6195
|
+
}
|
|
6192
6196
|
this.changes.wake();
|
|
6193
6197
|
throw signal.aborted ? signal.reason : err;
|
|
6194
6198
|
} finally {
|
|
@@ -6212,9 +6216,9 @@ var KernelSocket = class _KernelSocket {
|
|
|
6212
6216
|
this.state = "connecting";
|
|
6213
6217
|
const abort = new AbortController();
|
|
6214
6218
|
this.dialing = abort;
|
|
6215
|
-
let
|
|
6219
|
+
let timedOut2 = false;
|
|
6216
6220
|
const timer = setTimeout(() => {
|
|
6217
|
-
|
|
6221
|
+
timedOut2 = true;
|
|
6218
6222
|
abort.abort(new KernelError("ETIMEDOUT"));
|
|
6219
6223
|
}, route2.timeoutMs ?? DIAL_TIMEOUT_MS);
|
|
6220
6224
|
const abandoned = new Promise((_, reject) => {
|
|
@@ -6230,7 +6234,7 @@ var KernelSocket = class _KernelSocket {
|
|
|
6230
6234
|
);
|
|
6231
6235
|
return Promise.race([dialled, abandoned]).then(
|
|
6232
6236
|
async (raw2) => {
|
|
6233
|
-
if (abort.signal.aborted) throw dialError(abort.signal.reason,
|
|
6237
|
+
if (abort.signal.aborted) throw dialError(abort.signal.reason, timedOut2, true);
|
|
6234
6238
|
const conn = new SwitchConn(raw2);
|
|
6235
6239
|
if (secure2) {
|
|
6236
6240
|
clearTimeout(timer);
|
|
@@ -6256,7 +6260,7 @@ var KernelSocket = class _KernelSocket {
|
|
|
6256
6260
|
);
|
|
6257
6261
|
},
|
|
6258
6262
|
(e) => {
|
|
6259
|
-
throw this.dialFailed(abort, dialError(e,
|
|
6263
|
+
throw this.dialFailed(abort, dialError(e, timedOut2, abort.signal.aborted));
|
|
6260
6264
|
}
|
|
6261
6265
|
).finally(() => clearTimeout(timer));
|
|
6262
6266
|
}
|
|
@@ -6837,10 +6841,11 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS2 } = {})
|
|
|
6837
6841
|
const flow = {
|
|
6838
6842
|
inflight: 0,
|
|
6839
6843
|
closing: false,
|
|
6844
|
+
dropped: false,
|
|
6840
6845
|
deadline: () => AbortSignal.timeout(closeWaitMs).addEventListener("abort", late, { once: true })
|
|
6841
6846
|
};
|
|
6842
6847
|
credit.set(nid, flow);
|
|
6843
|
-
const
|
|
6848
|
+
const timedOut2 = { code: 1006, reason: "the far end did not answer the close" };
|
|
6844
6849
|
let oversize = false;
|
|
6845
6850
|
try {
|
|
6846
6851
|
const messages = socket.messages[Symbol.asyncIterator]();
|
|
@@ -6848,7 +6853,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS2 } = {})
|
|
|
6848
6853
|
const next3 = await Promise.race([messages.next(), unanswered]);
|
|
6849
6854
|
if (next3 === "late" || next3.done) break;
|
|
6850
6855
|
const data = next3.value;
|
|
6851
|
-
if (flow.
|
|
6856
|
+
if (flow.dropped) continue;
|
|
6852
6857
|
if (payloadSize(data) > MESSAGE_LIMIT) {
|
|
6853
6858
|
oversize = true;
|
|
6854
6859
|
break;
|
|
@@ -6866,7 +6871,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS2 } = {})
|
|
|
6866
6871
|
}
|
|
6867
6872
|
}
|
|
6868
6873
|
if (oversize) socket.close(1e3, "a message is too big");
|
|
6869
|
-
ending = oversize ? { code: 1009, reason: `a message is over ${MESSAGE_LIMIT} bytes` } : await Promise.race([socket.closed, unanswered.then(() =>
|
|
6874
|
+
ending = oversize ? { code: 1009, reason: `a message is over ${MESSAGE_LIMIT} bytes` } : await Promise.race([socket.closed, unanswered.then(() => timedOut2)]);
|
|
6870
6875
|
} catch (e) {
|
|
6871
6876
|
socket.close(1e3, "the relay failed");
|
|
6872
6877
|
ending = { code: 1011, reason: e instanceof Error ? e.message : String(e) };
|
|
@@ -6902,6 +6907,8 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS2 } = {})
|
|
|
6902
6907
|
};
|
|
6903
6908
|
const drop = (nid) => {
|
|
6904
6909
|
sockets.get(nid)?.close(1e3, "cancelled");
|
|
6910
|
+
const flow = credit.get(nid);
|
|
6911
|
+
if (flow) flow.dropped = true;
|
|
6905
6912
|
refill(nid, 0, true);
|
|
6906
6913
|
const entry = open2.get(nid);
|
|
6907
6914
|
open2.delete(nid);
|
|
@@ -7908,7 +7915,7 @@ function satisfies(version, range2) {
|
|
|
7908
7915
|
}
|
|
7909
7916
|
|
|
7910
7917
|
// src/version.ts
|
|
7911
|
-
var KERNEL_VERSION = true ? "1.
|
|
7918
|
+
var KERNEL_VERSION = true ? "1.150.0" : "0.0.0-dev";
|
|
7912
7919
|
var OS_RELEASE = "6.0.0-slicc";
|
|
7913
7920
|
function procVersion() {
|
|
7914
7921
|
return `Linux version ${OS_RELEASE} (slicc-kernel ${KERNEL_VERSION}) #1 SMP PREEMPT_DYNAMIC
|
|
@@ -17708,8 +17715,8 @@ var HttpHandles = class {
|
|
|
17708
17715
|
else entry.left = next3.value;
|
|
17709
17716
|
} catch (e) {
|
|
17710
17717
|
entry.done = true;
|
|
17711
|
-
const
|
|
17712
|
-
return { ok: false, errno:
|
|
17718
|
+
const timedOut2 = e?.code === "ETIMEDOUT";
|
|
17719
|
+
return { ok: false, errno: timedOut2 ? "ETIMEDOUT" : "EIO", message: message2(e) };
|
|
17713
17720
|
}
|
|
17714
17721
|
}
|
|
17715
17722
|
const bytes = entry.left.subarray(0, Math.max(0, max));
|
|
@@ -18875,15 +18882,22 @@ async function tlsClient(conn, o, taken = new Uint8Array(0)) {
|
|
|
18875
18882
|
throw err;
|
|
18876
18883
|
}
|
|
18877
18884
|
}
|
|
18878
|
-
|
|
18885
|
+
var HTTP_REQUEST = /^[A-Z]{3,10} [!-~]/;
|
|
18886
|
+
function serverRefusal(err, session, first) {
|
|
18887
|
+
const opening2 = first ? new TextDecoder("latin1").decode(first.subarray(0, 16)) : "";
|
|
18888
|
+
if (HTTP_REQUEST.test(opening2))
|
|
18889
|
+
return new KernelError("EPROTO", "ERR_SSL_HTTP_REQUEST: http request");
|
|
18890
|
+
const text = err instanceof TlsError ? err.message : String(err);
|
|
18891
|
+
return new KernelError("EPROTO", `ERR_SSL_HANDSHAKE_FAILURE: ${text}${alertOf(session)}`);
|
|
18892
|
+
}
|
|
18893
|
+
async function serverHandshake(conn, session, inbox, first) {
|
|
18879
18894
|
for (; ; ) {
|
|
18880
18895
|
let done5;
|
|
18881
18896
|
try {
|
|
18882
18897
|
done5 = session.handshake();
|
|
18883
18898
|
} catch (err) {
|
|
18884
18899
|
await send(conn, session).catch(() => void 0);
|
|
18885
|
-
|
|
18886
|
-
throw new KernelError("EPROTO", `ERR_SSL_HANDSHAKE_FAILURE: ${text}${alertOf(session)}`);
|
|
18900
|
+
throw serverRefusal(err, session, first());
|
|
18887
18901
|
}
|
|
18888
18902
|
await send(conn, session);
|
|
18889
18903
|
if (done5) return;
|
|
@@ -18896,9 +18910,18 @@ async function serverHandshake(conn, session, inbox) {
|
|
|
18896
18910
|
}
|
|
18897
18911
|
}
|
|
18898
18912
|
async function tlsServer(conn, session, clientCerts) {
|
|
18899
|
-
|
|
18913
|
+
let first;
|
|
18914
|
+
const watched = {
|
|
18915
|
+
...conn,
|
|
18916
|
+
read: async () => {
|
|
18917
|
+
const bytes = await conn.read();
|
|
18918
|
+
first ??= bytes ?? void 0;
|
|
18919
|
+
return bytes;
|
|
18920
|
+
}
|
|
18921
|
+
};
|
|
18922
|
+
const inbox = new Ciphertext(watched, session);
|
|
18900
18923
|
try {
|
|
18901
|
-
await serverHandshake(conn, session, inbox);
|
|
18924
|
+
await serverHandshake(conn, session, inbox, () => first);
|
|
18902
18925
|
const chain2 = session.peerChain();
|
|
18903
18926
|
const code = clientCerts ? verifyCode(session.verifyResult) : void 0;
|
|
18904
18927
|
const info = {
|
|
@@ -19368,6 +19391,7 @@ var RANK = {
|
|
|
19368
19391
|
var CR2 = 13;
|
|
19369
19392
|
var LF2 = 10;
|
|
19370
19393
|
var EMPTY4 = new Uint8Array(0);
|
|
19394
|
+
var FILLER = 42;
|
|
19371
19395
|
function register(automaton, sources, ids, bytes, source) {
|
|
19372
19396
|
const key = Array.from(bytes).join(",");
|
|
19373
19397
|
let id2 = ids.get(key);
|
|
@@ -19378,7 +19402,7 @@ function register(automaton, sources, ids, bytes, source) {
|
|
|
19378
19402
|
}
|
|
19379
19403
|
sources[id2].push(source);
|
|
19380
19404
|
}
|
|
19381
|
-
function prepare(secrets) {
|
|
19405
|
+
function prepare(secrets, sameLength) {
|
|
19382
19406
|
const main = new Automaton();
|
|
19383
19407
|
const wrap = new Automaton();
|
|
19384
19408
|
const sources = [];
|
|
@@ -19402,7 +19426,19 @@ function prepare(secrets) {
|
|
|
19402
19426
|
utf82(secret.placeholder),
|
|
19403
19427
|
utf82(`[redacted:${secret.name}]`)
|
|
19404
19428
|
]);
|
|
19405
|
-
return { secrets, values, main, wrap, sources, wrapSources, replacements };
|
|
19429
|
+
return { secrets, values, main, wrap, sources, wrapSources, replacements, sameLength };
|
|
19430
|
+
}
|
|
19431
|
+
function filled(input, start2, end) {
|
|
19432
|
+
const out = new Uint8Array(end - start2);
|
|
19433
|
+
for (let i = start2; i < end; i++) {
|
|
19434
|
+
const byte = input[i];
|
|
19435
|
+
out[i - start2] = byte === CR2 || byte === LF2 ? byte : FILLER;
|
|
19436
|
+
}
|
|
19437
|
+
return out;
|
|
19438
|
+
}
|
|
19439
|
+
function replacement(c, input, candidate) {
|
|
19440
|
+
if (c.sameLength) return filled(input, candidate.start, candidate.end);
|
|
19441
|
+
return c.replacements[candidate.secret][candidate.form === "raw" ? 0 : 1];
|
|
19406
19442
|
}
|
|
19407
19443
|
function better(a, b) {
|
|
19408
19444
|
if (!b) return true;
|
|
@@ -19511,10 +19547,7 @@ function pass(c, input, final) {
|
|
|
19511
19547
|
break;
|
|
19512
19548
|
}
|
|
19513
19549
|
const candidate = best.get(next3);
|
|
19514
|
-
parts2.push(
|
|
19515
|
-
input.subarray(pos, next3),
|
|
19516
|
-
c.replacements[candidate.secret][candidate.form === "raw" ? 0 : 1]
|
|
19517
|
-
);
|
|
19550
|
+
parts2.push(input.subarray(pos, next3), replacement(c, input, candidate));
|
|
19518
19551
|
count(c, hits, candidate);
|
|
19519
19552
|
pos = candidate.end;
|
|
19520
19553
|
}
|
|
@@ -19529,7 +19562,10 @@ function merge(into, from) {
|
|
|
19529
19562
|
}
|
|
19530
19563
|
}
|
|
19531
19564
|
function compile(secrets, options = {}) {
|
|
19532
|
-
const c = prepare(
|
|
19565
|
+
const c = prepare(
|
|
19566
|
+
secrets.map((secret) => ({ ...secret })),
|
|
19567
|
+
options.sameLength === true
|
|
19568
|
+
);
|
|
19533
19569
|
const decoder4 = new TextDecoder();
|
|
19534
19570
|
const idleMs = options.idleMs ?? 250;
|
|
19535
19571
|
const scrubBytes = (input) => {
|
|
@@ -22102,12 +22138,10 @@ function timeoutOf(req) {
|
|
|
22102
22138
|
);
|
|
22103
22139
|
return ms;
|
|
22104
22140
|
}
|
|
22141
|
+
var timedOut = new KernelError("EPROTO", "ERR_TLS_HANDSHAKE_TIMEOUT: TLS handshake timeout");
|
|
22105
22142
|
function handshakeSignal(proc, ms) {
|
|
22106
22143
|
const timer = new AbortController();
|
|
22107
|
-
const id2 = setTimeout(
|
|
22108
|
-
() => timer.abort(new KernelError("EPROTO", "ERR_TLS_HANDSHAKE_TIMEOUT: TLS handshake timeout")),
|
|
22109
|
-
ms
|
|
22110
|
-
);
|
|
22144
|
+
const id2 = setTimeout(() => timer.abort(timedOut), ms);
|
|
22111
22145
|
return {
|
|
22112
22146
|
signal: AbortSignal.any([handshakeAbort(proc), timer.signal]),
|
|
22113
22147
|
done: () => clearTimeout(id2)
|
|
@@ -22165,7 +22199,8 @@ async function serveSecure(proc, socket, req) {
|
|
|
22165
22199
|
const limit = handshakeSignal(proc, server.timeoutMs);
|
|
22166
22200
|
const info = await socket.secureLink(
|
|
22167
22201
|
(raw2) => tlsServer(raw2, engine.serverSession(leaf, alpn, store, flags2), flags2 !== 0),
|
|
22168
|
-
limit.signal
|
|
22202
|
+
limit.signal,
|
|
22203
|
+
(reason) => !shared && reason === timedOut
|
|
22169
22204
|
).finally(limit.done);
|
|
22170
22205
|
return {
|
|
22171
22206
|
path: "kernel",
|