@replit/river 0.12.5 → 0.13.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 +4 -1
- package/dist/{builder-c593de11.d.ts → builder-169fbf7f.d.ts} +16 -7
- package/dist/{chunk-AFLZ6INU.js → chunk-CBRQM65K.js} +29 -10
- package/dist/{chunk-IIBVKYDB.js → chunk-CDH7QSB4.js} +39 -1
- package/dist/{chunk-XFFS4UOD.js → chunk-MGGIUH5O.js} +7 -7
- package/dist/{chunk-6OAKPO5R.js → chunk-NPXAAD7M.js} +1 -1
- package/dist/{chunk-2PKONGC3.js → chunk-R2IMXRVU.js} +160 -135
- package/dist/{connection-4a839b9a.d.ts → connection-ab681c08.d.ts} +1 -1
- package/dist/{messageFraming-b200ef25.d.ts → connection-dd789651.d.ts} +17 -2
- package/dist/{index-1afc5580.d.ts → index-21c1b21d.d.ts} +32 -18
- package/dist/router/index.cjs +31 -13
- package/dist/router/index.d.cts +5 -5
- package/dist/router/index.d.ts +5 -5
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +153 -140
- package/dist/transport/impls/uds/client.d.cts +2 -3
- package/dist/transport/impls/uds/client.d.ts +2 -3
- package/dist/transport/impls/uds/client.js +5 -6
- package/dist/transport/impls/uds/server.cjs +161 -146
- package/dist/transport/impls/uds/server.d.cts +2 -3
- package/dist/transport/impls/uds/server.d.ts +2 -3
- package/dist/transport/impls/uds/server.js +4 -5
- package/dist/transport/impls/ws/client.cjs +157 -142
- package/dist/transport/impls/ws/client.d.cts +4 -4
- package/dist/transport/impls/ws/client.d.ts +4 -4
- package/dist/transport/impls/ws/client.js +7 -7
- package/dist/transport/impls/ws/server.cjs +161 -146
- package/dist/transport/impls/ws/server.d.cts +2 -2
- package/dist/transport/impls/ws/server.d.ts +2 -2
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +212 -186
- package/dist/transport/index.d.cts +1 -1
- package/dist/transport/index.d.ts +1 -1
- package/dist/transport/index.js +3 -3
- package/dist/util/testHelpers.cjs +294 -16
- package/dist/util/testHelpers.d.cts +2 -2
- package/dist/util/testHelpers.d.ts +2 -2
- package/dist/util/testHelpers.js +30 -8
- package/package.json +1 -9
- package/dist/chunk-7J66WOIC.js +0 -44
- package/dist/chunk-H4QR2K3T.js +0 -47
- package/dist/connection-64b9e0ff.d.ts +0 -17
- package/dist/connection-a6cc48e8.d.ts +0 -18
- package/dist/transport/impls/stdio/client.cjs +0 -913
- package/dist/transport/impls/stdio/client.d.cts +0 -27
- package/dist/transport/impls/stdio/client.d.ts +0 -27
- package/dist/transport/impls/stdio/client.js +0 -42
- package/dist/transport/impls/stdio/server.cjs +0 -888
- package/dist/transport/impls/stdio/server.d.cts +0 -25
- package/dist/transport/impls/stdio/server.d.ts +0 -25
- package/dist/transport/impls/stdio/server.js +0 -33
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
2
|
-
import { U as UdsConnection } from '../../../connection-
|
|
1
|
+
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
|
|
2
|
+
import { U as UdsConnection } from '../../../connection-dd789651.js';
|
|
3
3
|
import '../../../types-3e5768ec.js';
|
|
4
4
|
import '@sinclair/typebox';
|
|
5
5
|
import 'node:net';
|
|
6
|
-
import '../../../messageFraming-b200ef25.js';
|
|
7
6
|
import 'node:stream';
|
|
8
7
|
|
|
9
8
|
declare class UnixDomainSocketClientTransport extends ClientTransport<UdsConnection> {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-IIBVKYDB.js";
|
|
3
|
+
} from "../../../chunk-CDH7QSB4.js";
|
|
5
4
|
import {
|
|
6
5
|
ClientTransport
|
|
7
|
-
} from "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
9
|
-
import "../../../chunk-XFFS4UOD.js";
|
|
6
|
+
} from "../../../chunk-R2IMXRVU.js";
|
|
7
|
+
import "../../../chunk-MGGIUH5O.js";
|
|
10
8
|
import {
|
|
11
9
|
log
|
|
12
10
|
} from "../../../chunk-H4BYJELI.js";
|
|
11
|
+
import "../../../chunk-GZ7HCLLM.js";
|
|
13
12
|
|
|
14
13
|
// transport/impls/uds/client.ts
|
|
15
14
|
import { Socket } from "node:net";
|
|
@@ -17,7 +16,7 @@ var UnixDomainSocketClientTransport = class extends ClientTransport {
|
|
|
17
16
|
path;
|
|
18
17
|
serverId;
|
|
19
18
|
constructor(socketPath, clientId, serverId, providedOptions) {
|
|
20
|
-
super(clientId, providedOptions);
|
|
19
|
+
super(clientId, serverId, providedOptions);
|
|
21
20
|
this.path = socketPath;
|
|
22
21
|
this.serverId = serverId;
|
|
23
22
|
void this.connect(serverId);
|
|
@@ -39,8 +39,8 @@ var TransportMessageSchema = (t) => import_typebox.Type.Object({
|
|
|
39
39
|
to: import_typebox.Type.String(),
|
|
40
40
|
seq: import_typebox.Type.Integer(),
|
|
41
41
|
ack: import_typebox.Type.Integer(),
|
|
42
|
-
serviceName: import_typebox.Type.Optional(import_typebox.Type.
|
|
43
|
-
procedureName: import_typebox.Type.Optional(import_typebox.Type.
|
|
42
|
+
serviceName: import_typebox.Type.Optional(import_typebox.Type.String()),
|
|
43
|
+
procedureName: import_typebox.Type.Optional(import_typebox.Type.String()),
|
|
44
44
|
streamId: import_typebox.Type.String(),
|
|
45
45
|
controlFlags: import_typebox.Type.Integer(),
|
|
46
46
|
payload: t
|
|
@@ -54,7 +54,7 @@ var ControlMessageCloseSchema = import_typebox.Type.Object({
|
|
|
54
54
|
var PROTOCOL_VERSION = "v1";
|
|
55
55
|
var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
|
|
56
56
|
type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
|
|
57
|
-
protocolVersion: import_typebox.Type.
|
|
57
|
+
protocolVersion: import_typebox.Type.String(),
|
|
58
58
|
instanceId: import_typebox.Type.String()
|
|
59
59
|
});
|
|
60
60
|
var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
|
|
@@ -79,7 +79,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
|
|
|
79
79
|
var OpaqueTransportMessageSchema = TransportMessageSchema(
|
|
80
80
|
import_typebox.Type.Unknown()
|
|
81
81
|
);
|
|
82
|
-
function
|
|
82
|
+
function handshakeResponseMessage(from, instanceId, to, ok) {
|
|
83
83
|
return {
|
|
84
84
|
id: (0, import_nanoid.nanoid)(),
|
|
85
85
|
from,
|
|
@@ -137,6 +137,60 @@ var EventDispatcher = class {
|
|
|
137
137
|
|
|
138
138
|
// transport/session.ts
|
|
139
139
|
var import_nanoid2 = require("nanoid");
|
|
140
|
+
|
|
141
|
+
// codec/json.ts
|
|
142
|
+
var encoder = new TextEncoder();
|
|
143
|
+
var decoder = new TextDecoder();
|
|
144
|
+
function uint8ArrayToBase64(uint8Array) {
|
|
145
|
+
let binary = "";
|
|
146
|
+
uint8Array.forEach((byte) => {
|
|
147
|
+
binary += String.fromCharCode(byte);
|
|
148
|
+
});
|
|
149
|
+
return btoa(binary);
|
|
150
|
+
}
|
|
151
|
+
function base64ToUint8Array(base64) {
|
|
152
|
+
const binaryString = atob(base64);
|
|
153
|
+
const uint8Array = new Uint8Array(binaryString.length);
|
|
154
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
155
|
+
uint8Array[i] = binaryString.charCodeAt(i);
|
|
156
|
+
}
|
|
157
|
+
return uint8Array;
|
|
158
|
+
}
|
|
159
|
+
var NaiveJsonCodec = {
|
|
160
|
+
toBuffer: (obj) => {
|
|
161
|
+
return encoder.encode(
|
|
162
|
+
JSON.stringify(obj, function replacer(key) {
|
|
163
|
+
const val = this[key];
|
|
164
|
+
if (val instanceof Uint8Array) {
|
|
165
|
+
return { $t: uint8ArrayToBase64(val) };
|
|
166
|
+
} else {
|
|
167
|
+
return val;
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
},
|
|
172
|
+
fromBuffer: (buff) => {
|
|
173
|
+
try {
|
|
174
|
+
const parsed = JSON.parse(
|
|
175
|
+
decoder.decode(buff),
|
|
176
|
+
function reviver(_key, val) {
|
|
177
|
+
if (val?.$t) {
|
|
178
|
+
return base64ToUint8Array(val.$t);
|
|
179
|
+
} else {
|
|
180
|
+
return val;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
);
|
|
184
|
+
if (typeof parsed === "object")
|
|
185
|
+
return parsed;
|
|
186
|
+
return null;
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// transport/session.ts
|
|
140
194
|
var nanoid2 = (0, import_nanoid2.customAlphabet)("1234567890abcdefghijklmnopqrstuvxyz", 6);
|
|
141
195
|
var unsafeId = () => nanoid2();
|
|
142
196
|
var Connection = class {
|
|
@@ -148,8 +202,15 @@ var Connection = class {
|
|
|
148
202
|
var HEARTBEAT_INTERVAL_MS = 1e3;
|
|
149
203
|
var HEARTBEATS_TILL_DEAD = 2;
|
|
150
204
|
var SESSION_DISCONNECT_GRACE_MS = 5e3;
|
|
205
|
+
var defaultSessionOptions = {
|
|
206
|
+
heartbeatIntervalMs: HEARTBEAT_INTERVAL_MS,
|
|
207
|
+
heartbeatsUntilDead: HEARTBEATS_TILL_DEAD,
|
|
208
|
+
sessionDisconnectGraceMs: SESSION_DISCONNECT_GRACE_MS,
|
|
209
|
+
codec: NaiveJsonCodec
|
|
210
|
+
};
|
|
151
211
|
var Session = class {
|
|
152
212
|
codec;
|
|
213
|
+
options;
|
|
153
214
|
/**
|
|
154
215
|
* The buffer of messages that have been sent but not yet acknowledged.
|
|
155
216
|
*/
|
|
@@ -185,16 +246,17 @@ var Session = class {
|
|
|
185
246
|
* The interval for sending heartbeats.
|
|
186
247
|
*/
|
|
187
248
|
heartbeat;
|
|
188
|
-
constructor(
|
|
249
|
+
constructor(from, connectedTo, conn, options) {
|
|
250
|
+
this.options = options;
|
|
189
251
|
this.debugId = `sess-${unsafeId()}`;
|
|
190
252
|
this.from = from;
|
|
191
253
|
this.to = connectedTo;
|
|
192
254
|
this.connection = conn;
|
|
193
|
-
this.codec = codec;
|
|
255
|
+
this.codec = options.codec;
|
|
194
256
|
this.heartbeatMisses = 0;
|
|
195
257
|
this.heartbeat = setInterval(
|
|
196
258
|
() => this.sendHeartbeat(),
|
|
197
|
-
|
|
259
|
+
options.heartbeatIntervalMs
|
|
198
260
|
);
|
|
199
261
|
}
|
|
200
262
|
/**
|
|
@@ -230,7 +292,7 @@ var Session = class {
|
|
|
230
292
|
return fullMsg.id;
|
|
231
293
|
}
|
|
232
294
|
sendHeartbeat() {
|
|
233
|
-
if (this.heartbeatMisses >=
|
|
295
|
+
if (this.heartbeatMisses >= this.options.heartbeatsUntilDead) {
|
|
234
296
|
if (this.connection) {
|
|
235
297
|
log?.info(
|
|
236
298
|
`${this.from} -- closing connection (id: ${this.connection.debugId}) to ${this.to} due to inactivity`
|
|
@@ -296,13 +358,11 @@ var Session = class {
|
|
|
296
358
|
this.cancelGrace();
|
|
297
359
|
this.connection = newConn;
|
|
298
360
|
}
|
|
299
|
-
graceCb;
|
|
300
361
|
beginGrace(cb) {
|
|
301
|
-
this.graceCb = cb;
|
|
302
362
|
this.disconnectionGrace = setTimeout(() => {
|
|
303
363
|
this.close();
|
|
304
364
|
cb();
|
|
305
|
-
},
|
|
365
|
+
}, this.options.sessionDisconnectGraceMs);
|
|
306
366
|
}
|
|
307
367
|
// called on reconnect of the underlying session
|
|
308
368
|
cancelGrace() {
|
|
@@ -314,8 +374,8 @@ var Session = class {
|
|
|
314
374
|
close() {
|
|
315
375
|
this.closeStaleConnection(this.connection);
|
|
316
376
|
this.cancelGrace();
|
|
317
|
-
clearInterval(this.heartbeat);
|
|
318
377
|
this.resetBufferedMessages();
|
|
378
|
+
clearInterval(this.heartbeat);
|
|
319
379
|
}
|
|
320
380
|
get connected() {
|
|
321
381
|
return this.connection !== void 0;
|
|
@@ -340,58 +400,6 @@ var Session = class {
|
|
|
340
400
|
}
|
|
341
401
|
};
|
|
342
402
|
|
|
343
|
-
// codec/json.ts
|
|
344
|
-
var encoder = new TextEncoder();
|
|
345
|
-
var decoder = new TextDecoder();
|
|
346
|
-
function uint8ArrayToBase64(uint8Array) {
|
|
347
|
-
let binary = "";
|
|
348
|
-
uint8Array.forEach((byte) => {
|
|
349
|
-
binary += String.fromCharCode(byte);
|
|
350
|
-
});
|
|
351
|
-
return btoa(binary);
|
|
352
|
-
}
|
|
353
|
-
function base64ToUint8Array(base64) {
|
|
354
|
-
const binaryString = atob(base64);
|
|
355
|
-
const uint8Array = new Uint8Array(binaryString.length);
|
|
356
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
357
|
-
uint8Array[i] = binaryString.charCodeAt(i);
|
|
358
|
-
}
|
|
359
|
-
return uint8Array;
|
|
360
|
-
}
|
|
361
|
-
var NaiveJsonCodec = {
|
|
362
|
-
toBuffer: (obj) => {
|
|
363
|
-
return encoder.encode(
|
|
364
|
-
JSON.stringify(obj, function replacer(key) {
|
|
365
|
-
const val = this[key];
|
|
366
|
-
if (val instanceof Uint8Array) {
|
|
367
|
-
return { $t: uint8ArrayToBase64(val) };
|
|
368
|
-
} else {
|
|
369
|
-
return val;
|
|
370
|
-
}
|
|
371
|
-
})
|
|
372
|
-
);
|
|
373
|
-
},
|
|
374
|
-
fromBuffer: (buff) => {
|
|
375
|
-
try {
|
|
376
|
-
const parsed = JSON.parse(
|
|
377
|
-
decoder.decode(buff),
|
|
378
|
-
function reviver(_key, val) {
|
|
379
|
-
if (val?.$t) {
|
|
380
|
-
return base64ToUint8Array(val.$t);
|
|
381
|
-
} else {
|
|
382
|
-
return val;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
);
|
|
386
|
-
if (typeof parsed === "object")
|
|
387
|
-
return parsed;
|
|
388
|
-
return null;
|
|
389
|
-
} catch {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
};
|
|
394
|
-
|
|
395
403
|
// transport/transport.ts
|
|
396
404
|
var import_nanoid3 = require("nanoid");
|
|
397
405
|
|
|
@@ -404,13 +412,13 @@ function coerceErrorString(err) {
|
|
|
404
412
|
}
|
|
405
413
|
|
|
406
414
|
// transport/transport.ts
|
|
407
|
-
var
|
|
408
|
-
var
|
|
415
|
+
var RECONNECT_JITTER_MAX_MS = 500;
|
|
416
|
+
var RECONNECT_INTERVAL_MS = 250;
|
|
409
417
|
var defaultTransportOptions = {
|
|
410
|
-
retryIntervalMs:
|
|
411
|
-
retryJitterMs:
|
|
418
|
+
retryIntervalMs: RECONNECT_INTERVAL_MS,
|
|
419
|
+
retryJitterMs: RECONNECT_JITTER_MAX_MS,
|
|
412
420
|
retryAttemptsMax: 5,
|
|
413
|
-
|
|
421
|
+
...defaultSessionOptions
|
|
414
422
|
};
|
|
415
423
|
var Transport = class {
|
|
416
424
|
/**
|
|
@@ -467,15 +475,6 @@ var Transport = class {
|
|
|
467
475
|
this.clientId = clientId;
|
|
468
476
|
this.state = "open";
|
|
469
477
|
}
|
|
470
|
-
sessionByClientId(clientId) {
|
|
471
|
-
const session = this.sessions.get(clientId);
|
|
472
|
-
if (!session) {
|
|
473
|
-
const err = `${this.clientId} -- (invariant violation) no existing session for ${clientId}`;
|
|
474
|
-
log?.error(err);
|
|
475
|
-
throw new Error(err);
|
|
476
|
-
}
|
|
477
|
-
return session;
|
|
478
|
-
}
|
|
479
478
|
/**
|
|
480
479
|
* Called when a new connection is established
|
|
481
480
|
* and we know the identity of the connected client.
|
|
@@ -490,7 +489,7 @@ var Transport = class {
|
|
|
490
489
|
const lastInstanceId = this.connectedInstanceIds.get(connectedTo);
|
|
491
490
|
if (oldSession && lastInstanceId !== void 0 && lastInstanceId !== instanceId) {
|
|
492
491
|
log?.warn(
|
|
493
|
-
`${this.clientId} --
|
|
492
|
+
`${this.clientId} -- connection from ${connectedTo} is a different instance (got: ${instanceId}, last connected to: ${lastInstanceId}), starting a new session`
|
|
494
493
|
);
|
|
495
494
|
oldSession.close();
|
|
496
495
|
this.deleteSession(oldSession);
|
|
@@ -513,10 +512,10 @@ var Transport = class {
|
|
|
513
512
|
}
|
|
514
513
|
createSession(connectedTo, conn) {
|
|
515
514
|
const session = new Session(
|
|
516
|
-
this.codec,
|
|
517
515
|
this.clientId,
|
|
518
516
|
connectedTo,
|
|
519
|
-
conn
|
|
517
|
+
conn,
|
|
518
|
+
this.options
|
|
520
519
|
);
|
|
521
520
|
this.sessions.set(session.to, session);
|
|
522
521
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
@@ -545,13 +544,10 @@ var Transport = class {
|
|
|
545
544
|
status: "disconnect",
|
|
546
545
|
conn
|
|
547
546
|
});
|
|
548
|
-
|
|
547
|
+
const session = this.sessions.get(connectedTo);
|
|
548
|
+
if (!session)
|
|
549
549
|
return;
|
|
550
|
-
|
|
551
|
-
log?.info(
|
|
552
|
-
`${this.clientId} -- connection (id: ${conn.debugId}) disconnect from ${connectedTo}, ${SESSION_DISCONNECT_GRACE_MS}ms until session (id: ${session.debugId}) disconnect`
|
|
553
|
-
);
|
|
554
|
-
session.closeStaleConnection(conn);
|
|
550
|
+
session.connection = void 0;
|
|
555
551
|
session.beginGrace(() => this.deleteSession(session));
|
|
556
552
|
}
|
|
557
553
|
/**
|
|
@@ -562,7 +558,7 @@ var Transport = class {
|
|
|
562
558
|
parseMsg(msg) {
|
|
563
559
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
564
560
|
if (parsedMsg === null) {
|
|
565
|
-
const decodedBuffer = new TextDecoder().decode(msg);
|
|
561
|
+
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
566
562
|
log?.error(
|
|
567
563
|
`${this.clientId} -- received malformed msg, killing conn: ${decodedBuffer}`
|
|
568
564
|
);
|
|
@@ -576,11 +572,7 @@ var Transport = class {
|
|
|
576
572
|
);
|
|
577
573
|
return null;
|
|
578
574
|
}
|
|
579
|
-
return
|
|
580
|
-
...parsedMsg,
|
|
581
|
-
serviceName: parsedMsg.serviceName === null ? void 0 : parsedMsg.serviceName,
|
|
582
|
-
procedureName: parsedMsg.procedureName === null ? void 0 : parsedMsg.procedureName
|
|
583
|
-
};
|
|
575
|
+
return parsedMsg;
|
|
584
576
|
}
|
|
585
577
|
/**
|
|
586
578
|
* Called when a message is received by this transport.
|
|
@@ -590,15 +582,27 @@ var Transport = class {
|
|
|
590
582
|
handleMsg(msg) {
|
|
591
583
|
if (this.state !== "open")
|
|
592
584
|
return;
|
|
593
|
-
const session = this.
|
|
585
|
+
const session = this.sessions.get(msg.from);
|
|
586
|
+
if (!session) {
|
|
587
|
+
const err = `${this.clientId} -- (invariant violation) no existing session for ${msg.from}`;
|
|
588
|
+
log?.error(err);
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
594
591
|
session.cancelGrace();
|
|
595
592
|
log?.debug(`${this.clientId} -- received msg: ${JSON.stringify(msg)}`);
|
|
596
593
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
msg
|
|
600
|
-
|
|
601
|
-
|
|
594
|
+
if (msg.seq < session.nextExpectedSeq) {
|
|
595
|
+
log?.debug(
|
|
596
|
+
`${this.clientId} -- received duplicate msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), discarding: ${JSON.stringify(
|
|
597
|
+
msg
|
|
598
|
+
)}`
|
|
599
|
+
);
|
|
600
|
+
} else {
|
|
601
|
+
log?.error(
|
|
602
|
+
`${this.clientId} -- received out-of-order msg (got: ${msg.seq}, wanted: ${session.nextExpectedSeq}), marking connection as dead: ${JSON.stringify(msg)}`
|
|
603
|
+
);
|
|
604
|
+
session.closeStaleConnection(session.connection);
|
|
605
|
+
}
|
|
602
606
|
return;
|
|
603
607
|
}
|
|
604
608
|
if (!isAck(msg.controlFlags)) {
|
|
@@ -616,7 +620,7 @@ var Transport = class {
|
|
|
616
620
|
}
|
|
617
621
|
/**
|
|
618
622
|
* Removes a listener from this transport.
|
|
619
|
-
* @param the type of event to
|
|
623
|
+
* @param the type of event to un-listen on
|
|
620
624
|
* @param handler The message handler to remove.
|
|
621
625
|
*/
|
|
622
626
|
removeEventListener(type, handler) {
|
|
@@ -697,22 +701,24 @@ var ServerTransport = class extends Transport {
|
|
|
697
701
|
handleConnection(conn) {
|
|
698
702
|
let session = void 0;
|
|
699
703
|
const client = () => session?.to ?? "unknown";
|
|
700
|
-
const
|
|
701
|
-
conn
|
|
702
|
-
(
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
conn.addDataListener((data) => {
|
|
706
|
-
const parsed = this.parseMsg(data);
|
|
707
|
-
if (!parsed) {
|
|
708
|
-
conn.close();
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
|
-
this.handleMsg(parsed);
|
|
712
|
-
});
|
|
704
|
+
const handshakeHandler = (data) => {
|
|
705
|
+
const handshake = this.receiveHandshakeRequestMessage(data, conn);
|
|
706
|
+
if (!handshake) {
|
|
707
|
+
conn.close();
|
|
708
|
+
return;
|
|
713
709
|
}
|
|
714
|
-
|
|
715
|
-
|
|
710
|
+
session = this.onConnect(conn, handshake.from, handshake.instanceId);
|
|
711
|
+
conn.removeDataListener(handshakeHandler);
|
|
712
|
+
conn.addDataListener((data2) => {
|
|
713
|
+
const parsed = this.parseMsg(data2);
|
|
714
|
+
if (!parsed) {
|
|
715
|
+
conn.close();
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
this.handleMsg(parsed);
|
|
719
|
+
});
|
|
720
|
+
};
|
|
721
|
+
conn.addDataListener(handshakeHandler);
|
|
716
722
|
conn.addCloseListener(() => {
|
|
717
723
|
if (!session)
|
|
718
724
|
return;
|
|
@@ -729,42 +735,51 @@ var ServerTransport = class extends Transport {
|
|
|
729
735
|
);
|
|
730
736
|
});
|
|
731
737
|
}
|
|
732
|
-
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
this.instanceId,
|
|
743
|
-
parsed.from,
|
|
744
|
-
false
|
|
745
|
-
);
|
|
746
|
-
conn.send(this.codec.toBuffer(responseMsg2));
|
|
747
|
-
log?.warn(
|
|
748
|
-
`${this.clientId} -- received invalid handshake msg: ${JSON.stringify(
|
|
749
|
-
parsed
|
|
750
|
-
)}`
|
|
751
|
-
);
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
const instanceId = parsed.payload.instanceId;
|
|
755
|
-
log?.debug(
|
|
756
|
-
`${this.clientId} -- handshake from ${parsed.from} ok (instance id: ${instanceId}), responding with handshake success`
|
|
738
|
+
receiveHandshakeRequestMessage(data, conn) {
|
|
739
|
+
const parsed = this.parseMsg(data);
|
|
740
|
+
if (!parsed)
|
|
741
|
+
return false;
|
|
742
|
+
if (!import_value.Value.Check(ControlMessageHandshakeRequestSchema, parsed.payload)) {
|
|
743
|
+
const responseMsg2 = handshakeResponseMessage(
|
|
744
|
+
this.clientId,
|
|
745
|
+
this.instanceId,
|
|
746
|
+
parsed.from,
|
|
747
|
+
false
|
|
757
748
|
);
|
|
758
|
-
|
|
749
|
+
conn.send(this.codec.toBuffer(responseMsg2));
|
|
750
|
+
log?.warn(
|
|
751
|
+
`${this.clientId} -- received invalid handshake msg: ${JSON.stringify(
|
|
752
|
+
parsed
|
|
753
|
+
)}`
|
|
754
|
+
);
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
const gotVersion = parsed.payload.protocolVersion;
|
|
758
|
+
if (gotVersion !== PROTOCOL_VERSION) {
|
|
759
|
+
const responseMsg2 = handshakeResponseMessage(
|
|
759
760
|
this.clientId,
|
|
760
761
|
this.instanceId,
|
|
761
762
|
parsed.from,
|
|
762
|
-
|
|
763
|
+
false
|
|
763
764
|
);
|
|
764
|
-
conn.send(this.codec.toBuffer(
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
765
|
+
conn.send(this.codec.toBuffer(responseMsg2));
|
|
766
|
+
log?.warn(
|
|
767
|
+
`${this.clientId} -- received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`
|
|
768
|
+
);
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
const instanceId = parsed.payload.instanceId;
|
|
772
|
+
log?.debug(
|
|
773
|
+
`${this.clientId} -- handshake from ${parsed.from} ok (instance id: ${instanceId}), responding with handshake success`
|
|
774
|
+
);
|
|
775
|
+
const responseMsg = handshakeResponseMessage(
|
|
776
|
+
this.clientId,
|
|
777
|
+
this.instanceId,
|
|
778
|
+
parsed.from,
|
|
779
|
+
true
|
|
780
|
+
);
|
|
781
|
+
conn.send(this.codec.toBuffer(responseMsg));
|
|
782
|
+
return { instanceId, from: parsed.from };
|
|
768
783
|
}
|
|
769
784
|
};
|
|
770
785
|
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-dd789651.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
|
-
import '../../../messageFraming-b200ef25.js';
|
|
7
6
|
import 'node:stream';
|
|
8
7
|
|
|
9
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Server, Socket } from 'node:net';
|
|
2
|
-
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-
|
|
3
|
-
import { U as UdsConnection } from '../../../connection-
|
|
2
|
+
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js';
|
|
3
|
+
import { U as UdsConnection } from '../../../connection-dd789651.js';
|
|
4
4
|
import '../../../types-3e5768ec.js';
|
|
5
5
|
import '@sinclair/typebox';
|
|
6
|
-
import '../../../messageFraming-b200ef25.js';
|
|
7
6
|
import 'node:stream';
|
|
8
7
|
|
|
9
8
|
declare class UnixDomainSocketServerTransport extends ServerTransport<UdsConnection> {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UdsConnection
|
|
3
|
-
} from "../../../chunk-
|
|
4
|
-
import "../../../chunk-IIBVKYDB.js";
|
|
3
|
+
} from "../../../chunk-CDH7QSB4.js";
|
|
5
4
|
import {
|
|
6
5
|
ServerTransport
|
|
7
|
-
} from "../../../chunk-
|
|
8
|
-
import "../../../chunk-
|
|
9
|
-
import "../../../chunk-XFFS4UOD.js";
|
|
6
|
+
} from "../../../chunk-R2IMXRVU.js";
|
|
7
|
+
import "../../../chunk-MGGIUH5O.js";
|
|
10
8
|
import {
|
|
11
9
|
log
|
|
12
10
|
} from "../../../chunk-H4BYJELI.js";
|
|
11
|
+
import "../../../chunk-GZ7HCLLM.js";
|
|
13
12
|
|
|
14
13
|
// transport/impls/uds/server.ts
|
|
15
14
|
var UnixDomainSocketServerTransport = class extends ServerTransport {
|