@replit/river 0.17.4 → 0.18.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 -3
- package/dist/{chunk-7WY3Z5ZN.js → chunk-CLY7AQ25.js} +169 -95
- package/dist/{chunk-4C2OXQJB.js → chunk-TIFNW5GQ.js} +62 -65
- package/dist/{chunk-F3LFO3GU.js → chunk-UEKU6XRG.js} +1 -1
- package/dist/chunk-YITXOAPA.js +72 -0
- package/dist/{chunk-Q7OSVPZ5.js → chunk-ZPPKYJI7.js} +1 -1
- package/dist/{connection-bdbd20da.d.ts → connection-32bf6608.d.ts} +1 -1
- package/dist/{connection-c4a17403.d.ts → connection-df5f32ee.d.ts} +1 -1
- package/dist/{index-9e300e8a.d.ts → index-314e676a.d.ts} +4 -86
- package/dist/index-6118cd48.d.ts +117 -0
- package/dist/logging/index.cjs +63 -27
- package/dist/logging/index.d.cts +2 -34
- package/dist/logging/index.d.ts +2 -34
- package/dist/logging/index.js +7 -7
- package/dist/{procedures-1c0d2eee.d.ts → procedures-74a10937.d.ts} +4 -3
- package/dist/router/index.cjs +63 -66
- package/dist/router/index.d.cts +43 -42
- package/dist/router/index.d.ts +43 -42
- package/dist/router/index.js +2 -2
- package/dist/transport/impls/uds/client.cjs +152 -84
- package/dist/transport/impls/uds/client.d.cts +3 -2
- package/dist/transport/impls/uds/client.d.ts +3 -2
- package/dist/transport/impls/uds/client.js +7 -4
- package/dist/transport/impls/uds/server.cjs +116 -65
- package/dist/transport/impls/uds/server.d.cts +3 -2
- package/dist/transport/impls/uds/server.d.ts +3 -2
- package/dist/transport/impls/uds/server.js +3 -3
- package/dist/transport/impls/ws/client.cjs +156 -87
- package/dist/transport/impls/ws/client.d.cts +3 -2
- package/dist/transport/impls/ws/client.d.ts +3 -2
- package/dist/transport/impls/ws/client.js +11 -7
- package/dist/transport/impls/ws/server.cjs +116 -65
- package/dist/transport/impls/ws/server.d.cts +4 -3
- package/dist/transport/impls/ws/server.d.ts +4 -3
- package/dist/transport/impls/ws/server.js +3 -3
- package/dist/transport/index.cjs +170 -96
- package/dist/transport/index.d.cts +2 -1
- package/dist/transport/index.d.ts +2 -1
- package/dist/transport/index.js +2 -2
- package/dist/util/testHelpers.cjs +48 -17
- package/dist/util/testHelpers.d.cts +4 -3
- package/dist/util/testHelpers.d.ts +4 -3
- package/dist/util/testHelpers.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-H4BYJELI.js +0 -37
package/dist/transport/index.cjs
CHANGED
|
@@ -118,8 +118,8 @@ function isAck(controlFlag) {
|
|
|
118
118
|
return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
// logging/
|
|
122
|
-
var log;
|
|
121
|
+
// logging/log.ts
|
|
122
|
+
var log = void 0;
|
|
123
123
|
|
|
124
124
|
// transport/events.ts
|
|
125
125
|
var ProtocolError = {
|
|
@@ -221,6 +221,14 @@ var Session = class {
|
|
|
221
221
|
options.heartbeatIntervalMs
|
|
222
222
|
);
|
|
223
223
|
}
|
|
224
|
+
get loggingMetadata() {
|
|
225
|
+
return {
|
|
226
|
+
clientId: this.from,
|
|
227
|
+
connectedTo: this.to,
|
|
228
|
+
sessionId: this.id,
|
|
229
|
+
connId: this.connection?.debugId
|
|
230
|
+
};
|
|
231
|
+
}
|
|
224
232
|
/**
|
|
225
233
|
* Sends a message over the session's connection.
|
|
226
234
|
* If the connection is not ready or the message fails to send, the message can be buffered for retry unless skipped.
|
|
@@ -231,26 +239,37 @@ var Session = class {
|
|
|
231
239
|
*/
|
|
232
240
|
send(msg) {
|
|
233
241
|
const fullMsg = this.constructMsg(msg);
|
|
234
|
-
log?.debug(
|
|
242
|
+
log?.debug(`sending msg`, {
|
|
243
|
+
...this.loggingMetadata,
|
|
244
|
+
fullTransportMessage: fullMsg
|
|
245
|
+
});
|
|
235
246
|
if (this.connection) {
|
|
236
247
|
const ok = this.connection.send(this.codec.toBuffer(fullMsg));
|
|
237
248
|
if (ok)
|
|
238
249
|
return fullMsg.id;
|
|
239
250
|
log?.info(
|
|
240
|
-
|
|
251
|
+
`failed to send msg to ${fullMsg.to}, connection is probably dead`,
|
|
252
|
+
{
|
|
253
|
+
...this.loggingMetadata,
|
|
254
|
+
fullTransportMessage: fullMsg
|
|
255
|
+
}
|
|
241
256
|
);
|
|
242
257
|
} else {
|
|
243
258
|
log?.info(
|
|
244
|
-
|
|
259
|
+
`failed to send msg to ${fullMsg.to}, connection not ready yet`,
|
|
260
|
+
{ ...this.loggingMetadata, fullTransportMessage: fullMsg }
|
|
245
261
|
);
|
|
246
262
|
}
|
|
247
263
|
return fullMsg.id;
|
|
248
264
|
}
|
|
249
265
|
sendHeartbeat() {
|
|
250
|
-
|
|
266
|
+
const misses = this.heartbeatMisses;
|
|
267
|
+
const missDuration = misses * this.options.heartbeatIntervalMs;
|
|
268
|
+
if (misses > this.options.heartbeatsUntilDead) {
|
|
251
269
|
if (this.connection) {
|
|
252
270
|
log?.info(
|
|
253
|
-
|
|
271
|
+
`closing connection to ${this.to} due to inactivity (missed ${misses} heartbeats which is ${missDuration}ms)`,
|
|
272
|
+
this.loggingMetadata
|
|
254
273
|
);
|
|
255
274
|
this.closeStaleConnection();
|
|
256
275
|
}
|
|
@@ -272,26 +291,36 @@ var Session = class {
|
|
|
272
291
|
}
|
|
273
292
|
sendBufferedMessages() {
|
|
274
293
|
if (!this.connection) {
|
|
275
|
-
const msg =
|
|
276
|
-
log?.error(msg);
|
|
294
|
+
const msg = `tried sending buffered messages without a connection (if you hit this code path something is seriously wrong)`;
|
|
295
|
+
log?.error(msg, this.loggingMetadata);
|
|
277
296
|
throw new Error(msg);
|
|
278
297
|
}
|
|
279
298
|
log?.info(
|
|
280
|
-
|
|
299
|
+
`resending ${this.sendBuffer.length} buffered messages`,
|
|
300
|
+
this.loggingMetadata
|
|
281
301
|
);
|
|
282
302
|
for (const msg of this.sendBuffer) {
|
|
283
|
-
log?.debug(
|
|
303
|
+
log?.debug(`resending msg`, {
|
|
304
|
+
...this.loggingMetadata,
|
|
305
|
+
fullTransportMessage: msg
|
|
306
|
+
});
|
|
284
307
|
const ok = this.connection.send(this.codec.toBuffer(msg));
|
|
285
308
|
if (!ok) {
|
|
286
|
-
const
|
|
287
|
-
log?.error(
|
|
288
|
-
|
|
309
|
+
const errMsg = `failed to send buffered message to ${this.to} (if you hit this code path something is seriously wrong)`;
|
|
310
|
+
log?.error(errMsg, {
|
|
311
|
+
...this.loggingMetadata,
|
|
312
|
+
fullTransportMessage: msg
|
|
313
|
+
});
|
|
314
|
+
throw new Error(errMsg);
|
|
289
315
|
}
|
|
290
316
|
}
|
|
291
317
|
}
|
|
292
318
|
updateBookkeeping(ack, seq) {
|
|
293
319
|
if (seq + 1 < this.ack) {
|
|
294
|
-
log?.error(
|
|
320
|
+
log?.error(
|
|
321
|
+
`received stale seq ${seq} + 1 < ${this.ack}`,
|
|
322
|
+
this.loggingMetadata
|
|
323
|
+
);
|
|
295
324
|
return;
|
|
296
325
|
}
|
|
297
326
|
this.sendBuffer = this.sendBuffer.filter((unacked) => unacked.seq >= ack);
|
|
@@ -301,7 +330,8 @@ var Session = class {
|
|
|
301
330
|
if (this.connection === void 0 || this.connection === conn)
|
|
302
331
|
return;
|
|
303
332
|
log?.info(
|
|
304
|
-
|
|
333
|
+
`closing old inner connection from session to ${this.to}`,
|
|
334
|
+
this.loggingMetadata
|
|
305
335
|
);
|
|
306
336
|
this.connection.close();
|
|
307
337
|
this.connection = void 0;
|
|
@@ -313,7 +343,8 @@ var Session = class {
|
|
|
313
343
|
}
|
|
314
344
|
beginGrace(cb) {
|
|
315
345
|
log?.info(
|
|
316
|
-
|
|
346
|
+
`starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
|
|
347
|
+
this.loggingMetadata
|
|
317
348
|
);
|
|
318
349
|
this.disconnectionGrace = setTimeout(() => {
|
|
319
350
|
this.close();
|
|
@@ -568,7 +599,8 @@ var Transport = class {
|
|
|
568
599
|
let oldSession = this.sessions.get(connectedTo);
|
|
569
600
|
if (oldSession?.advertisedSessionId && oldSession.advertisedSessionId !== advertisedSessionId) {
|
|
570
601
|
log?.warn(
|
|
571
|
-
|
|
602
|
+
`connection from ${connectedTo} is a different session (id: ${advertisedSessionId}, last connected to: ${oldSession.advertisedSessionId}), killing old session and starting a new one`,
|
|
603
|
+
oldSession.loggingMetadata
|
|
572
604
|
);
|
|
573
605
|
this.deleteSession(oldSession);
|
|
574
606
|
oldSession = void 0;
|
|
@@ -577,16 +609,18 @@ var Transport = class {
|
|
|
577
609
|
const newSession = this.createSession(connectedTo, conn);
|
|
578
610
|
newSession.advertisedSessionId = advertisedSessionId;
|
|
579
611
|
log?.info(
|
|
580
|
-
|
|
612
|
+
`new connection for new session to ${connectedTo}`,
|
|
613
|
+
newSession.loggingMetadata
|
|
581
614
|
);
|
|
582
615
|
return newSession;
|
|
583
616
|
}
|
|
584
|
-
log?.info(
|
|
585
|
-
`${this.clientId} -- new connection (id: ${conn.debugId}) for existing session (id: ${oldSession.id}) to ${connectedTo}`
|
|
586
|
-
);
|
|
587
617
|
oldSession.replaceWithNewConnection(conn);
|
|
588
618
|
oldSession.sendBufferedMessages();
|
|
589
619
|
oldSession.advertisedSessionId = advertisedSessionId;
|
|
620
|
+
log?.info(
|
|
621
|
+
`new connection for existing session to ${connectedTo}`,
|
|
622
|
+
oldSession.loggingMetadata
|
|
623
|
+
);
|
|
590
624
|
return oldSession;
|
|
591
625
|
}
|
|
592
626
|
createSession(to, conn) {
|
|
@@ -608,7 +642,8 @@ var Transport = class {
|
|
|
608
642
|
if (!session) {
|
|
609
643
|
session = this.createSession(to, conn);
|
|
610
644
|
log?.info(
|
|
611
|
-
|
|
645
|
+
`no session for ${to}, created a new one`,
|
|
646
|
+
session.loggingMetadata
|
|
612
647
|
);
|
|
613
648
|
}
|
|
614
649
|
return session;
|
|
@@ -617,7 +652,8 @@ var Transport = class {
|
|
|
617
652
|
session.close();
|
|
618
653
|
this.sessions.delete(session.to);
|
|
619
654
|
log?.info(
|
|
620
|
-
|
|
655
|
+
`session ${session.id} disconnect from ${session.to}`,
|
|
656
|
+
session.loggingMetadata
|
|
621
657
|
);
|
|
622
658
|
this.eventDispatcher.dispatchEvent("sessionStatus", {
|
|
623
659
|
status: "disconnect",
|
|
@@ -646,17 +682,15 @@ var Transport = class {
|
|
|
646
682
|
const parsedMsg = this.codec.fromBuffer(msg);
|
|
647
683
|
if (parsedMsg === null) {
|
|
648
684
|
const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
|
|
649
|
-
log?.error(
|
|
650
|
-
|
|
651
|
-
);
|
|
685
|
+
log?.error(`received malformed msg, killing conn: ${decodedBuffer}`, {
|
|
686
|
+
clientId: this.clientId
|
|
687
|
+
});
|
|
652
688
|
return null;
|
|
653
689
|
}
|
|
654
690
|
if (!import_value.Value.Check(OpaqueTransportMessageSchema, parsedMsg)) {
|
|
655
|
-
log?.error(
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
)}`
|
|
659
|
-
);
|
|
691
|
+
log?.error(`received invalid msg: ${JSON.stringify(parsedMsg)}`, {
|
|
692
|
+
clientId: this.clientId
|
|
693
|
+
});
|
|
660
694
|
return null;
|
|
661
695
|
}
|
|
662
696
|
return parsedMsg;
|
|
@@ -671,26 +705,29 @@ var Transport = class {
|
|
|
671
705
|
return;
|
|
672
706
|
const session = this.sessions.get(msg.from);
|
|
673
707
|
if (!session) {
|
|
674
|
-
|
|
675
|
-
|
|
708
|
+
log?.error(`(invariant violation) no existing session for ${msg.from}`, {
|
|
709
|
+
clientId: this.clientId,
|
|
710
|
+
fullTransportMessage: msg
|
|
711
|
+
});
|
|
676
712
|
return;
|
|
677
713
|
}
|
|
678
714
|
session.cancelGrace();
|
|
679
|
-
log?.debug(
|
|
715
|
+
log?.debug(`received msg`, {
|
|
716
|
+
clientId: this.clientId,
|
|
717
|
+
fullTransportMessage: msg
|
|
718
|
+
});
|
|
680
719
|
if (msg.seq !== session.nextExpectedSeq) {
|
|
681
720
|
if (msg.seq < session.nextExpectedSeq) {
|
|
682
721
|
log?.debug(
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
)}`
|
|
722
|
+
`received duplicate msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq}), discarding`,
|
|
723
|
+
{ clientId: this.clientId, fullTransportMessage: msg }
|
|
686
724
|
);
|
|
687
725
|
} else {
|
|
688
726
|
const errMsg = `received out-of-order msg (got seq: ${msg.seq}, wanted seq: ${session.nextExpectedSeq})`;
|
|
689
|
-
log?.error(
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
);
|
|
727
|
+
log?.error(`${errMsg}, marking connection as dead`, {
|
|
728
|
+
clientId: this.clientId,
|
|
729
|
+
fullTransportMessage: msg
|
|
730
|
+
});
|
|
694
731
|
this.protocolError(ProtocolError.MessageOrderingViolated, errMsg);
|
|
695
732
|
session.close();
|
|
696
733
|
}
|
|
@@ -700,7 +737,10 @@ var Transport = class {
|
|
|
700
737
|
if (!isAck(msg.controlFlags)) {
|
|
701
738
|
this.eventDispatcher.dispatchEvent("message", msg);
|
|
702
739
|
} else {
|
|
703
|
-
log?.debug(
|
|
740
|
+
log?.debug(`discarding msg (ack bit set)`, {
|
|
741
|
+
clientId: this.clientId,
|
|
742
|
+
fullTransportMessage: msg
|
|
743
|
+
});
|
|
704
744
|
}
|
|
705
745
|
}
|
|
706
746
|
/**
|
|
@@ -728,15 +768,17 @@ var Transport = class {
|
|
|
728
768
|
send(to, msg) {
|
|
729
769
|
if (this.state === "destroyed") {
|
|
730
770
|
const err = "transport is destroyed, cant send";
|
|
731
|
-
log?.error(
|
|
771
|
+
log?.error(err, {
|
|
772
|
+
clientId: this.clientId,
|
|
773
|
+
partialTransportMessage: msg
|
|
774
|
+
});
|
|
732
775
|
this.protocolError(ProtocolError.UseAfterDestroy, err);
|
|
733
776
|
return void 0;
|
|
734
777
|
} else if (this.state === "closed") {
|
|
735
|
-
log?.info(
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
);
|
|
778
|
+
log?.info(`transport closed when sending, discarding`, {
|
|
779
|
+
clientId: this.clientId,
|
|
780
|
+
partialTransportMessage: msg
|
|
781
|
+
});
|
|
740
782
|
return void 0;
|
|
741
783
|
}
|
|
742
784
|
return this.getOrCreateSession(to).send(msg);
|
|
@@ -764,7 +806,7 @@ var Transport = class {
|
|
|
764
806
|
for (const session of this.sessions.values()) {
|
|
765
807
|
this.deleteSession(session);
|
|
766
808
|
}
|
|
767
|
-
log?.info(
|
|
809
|
+
log?.info(`manually closed transport`, { clientId: this.clientId });
|
|
768
810
|
}
|
|
769
811
|
/**
|
|
770
812
|
* Default destroy implementation for transports. You should override this in the downstream
|
|
@@ -776,7 +818,7 @@ var Transport = class {
|
|
|
776
818
|
for (const session of this.sessions.values()) {
|
|
777
819
|
this.deleteSession(session);
|
|
778
820
|
}
|
|
779
|
-
log?.info(
|
|
821
|
+
log?.info(`manually destroyed transport`, { clientId: this.clientId });
|
|
780
822
|
}
|
|
781
823
|
};
|
|
782
824
|
var ClientTransport = class extends Transport {
|
|
@@ -832,18 +874,22 @@ var ClientTransport = class extends Transport {
|
|
|
832
874
|
if (session) {
|
|
833
875
|
this.onDisconnect(conn, session);
|
|
834
876
|
}
|
|
835
|
-
log?.info(
|
|
836
|
-
|
|
837
|
-
|
|
877
|
+
log?.info(`connection to ${to} disconnected`, {
|
|
878
|
+
...session?.loggingMetadata,
|
|
879
|
+
clientId: this.clientId,
|
|
880
|
+
connectedTo: to
|
|
881
|
+
});
|
|
838
882
|
this.inflightConnectionPromises.delete(to);
|
|
839
883
|
if (this.reconnectOnConnectionDrop) {
|
|
840
884
|
void this.connect(to);
|
|
841
885
|
}
|
|
842
886
|
});
|
|
843
887
|
conn.addErrorListener((err) => {
|
|
844
|
-
log?.warn(
|
|
845
|
-
|
|
846
|
-
|
|
888
|
+
log?.warn(`error in connection to ${to}: ${coerceErrorString(err)}`, {
|
|
889
|
+
...session?.loggingMetadata,
|
|
890
|
+
clientId: this.clientId,
|
|
891
|
+
connectedTo: to
|
|
892
|
+
});
|
|
847
893
|
});
|
|
848
894
|
}
|
|
849
895
|
receiveHandshakeResponseMessage(data, conn) {
|
|
@@ -856,11 +902,11 @@ var ClientTransport = class extends Transport {
|
|
|
856
902
|
return false;
|
|
857
903
|
}
|
|
858
904
|
if (!import_value.Value.Check(ControlMessageHandshakeResponseSchema, parsed.payload)) {
|
|
859
|
-
log?.warn(
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
);
|
|
905
|
+
log?.warn(`received invalid handshake resp`, {
|
|
906
|
+
clientId: this.clientId,
|
|
907
|
+
connectedTo: parsed.from,
|
|
908
|
+
fullTransportMessage: parsed
|
|
909
|
+
});
|
|
864
910
|
this.protocolError(
|
|
865
911
|
ProtocolError.HandshakeFailed,
|
|
866
912
|
"invalid handshake resp"
|
|
@@ -868,18 +914,22 @@ var ClientTransport = class extends Transport {
|
|
|
868
914
|
return false;
|
|
869
915
|
}
|
|
870
916
|
if (!parsed.payload.status.ok) {
|
|
871
|
-
log?.warn(
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
);
|
|
917
|
+
log?.warn(`received invalid handshake resp`, {
|
|
918
|
+
clientId: this.clientId,
|
|
919
|
+
connectedTo: parsed.from,
|
|
920
|
+
fullTransportMessage: parsed
|
|
921
|
+
});
|
|
876
922
|
this.protocolError(
|
|
877
923
|
ProtocolError.HandshakeFailed,
|
|
878
924
|
parsed.payload.status.reason
|
|
879
925
|
);
|
|
880
926
|
return false;
|
|
881
927
|
}
|
|
882
|
-
log?.debug(
|
|
928
|
+
log?.debug(`handshake from ${parsed.from} ok`, {
|
|
929
|
+
clientId: this.clientId,
|
|
930
|
+
connectedTo: parsed.from,
|
|
931
|
+
fullTransportMessage: parsed
|
|
932
|
+
});
|
|
883
933
|
const session = this.onConnect(
|
|
884
934
|
conn,
|
|
885
935
|
parsed.from,
|
|
@@ -896,7 +946,8 @@ var ClientTransport = class extends Transport {
|
|
|
896
946
|
const canProceedWithConnection = () => this.state === "open";
|
|
897
947
|
if (!canProceedWithConnection()) {
|
|
898
948
|
log?.info(
|
|
899
|
-
|
|
949
|
+
`transport state is no longer open, cancelling attempt to connect to ${to}`,
|
|
950
|
+
{ clientId: this.clientId, connectedTo: to }
|
|
900
951
|
);
|
|
901
952
|
return;
|
|
902
953
|
}
|
|
@@ -905,7 +956,7 @@ var ClientTransport = class extends Transport {
|
|
|
905
956
|
const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
|
|
906
957
|
if (!this.retryBudget.hasBudget(to)) {
|
|
907
958
|
const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
|
|
908
|
-
log?.warn(
|
|
959
|
+
log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
|
|
909
960
|
this.protocolError(ProtocolError.RetriesExceeded, errMsg);
|
|
910
961
|
return;
|
|
911
962
|
}
|
|
@@ -914,9 +965,10 @@ var ClientTransport = class extends Transport {
|
|
|
914
965
|
if (backoffMs > 0) {
|
|
915
966
|
sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
916
967
|
}
|
|
917
|
-
log?.info(
|
|
918
|
-
|
|
919
|
-
|
|
968
|
+
log?.info(`attempting connection to ${to} (${backoffMs}ms backoff)`, {
|
|
969
|
+
clientId: this.clientId,
|
|
970
|
+
connectedTo: to
|
|
971
|
+
});
|
|
920
972
|
this.retryBudget.consumeBudget(to);
|
|
921
973
|
reconnectPromise = sleep.then(() => {
|
|
922
974
|
if (!canProceedWithConnection()) {
|
|
@@ -925,7 +977,12 @@ var ClientTransport = class extends Transport {
|
|
|
925
977
|
}).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
|
|
926
978
|
if (!canProceedWithConnection()) {
|
|
927
979
|
log?.info(
|
|
928
|
-
|
|
980
|
+
`transport state is no longer open, closing pre-handshake connection to ${to}`,
|
|
981
|
+
{
|
|
982
|
+
clientId: this.clientId,
|
|
983
|
+
connectedTo: to,
|
|
984
|
+
connId: conn.debugId
|
|
985
|
+
}
|
|
929
986
|
);
|
|
930
987
|
conn.close();
|
|
931
988
|
throw new Error("transport state is no longer open");
|
|
@@ -935,9 +992,10 @@ var ClientTransport = class extends Transport {
|
|
|
935
992
|
});
|
|
936
993
|
this.inflightConnectionPromises.set(to, reconnectPromise);
|
|
937
994
|
} else {
|
|
938
|
-
log?.info(
|
|
939
|
-
|
|
940
|
-
|
|
995
|
+
log?.info(`attempting connection to ${to} (reusing previous attempt)`, {
|
|
996
|
+
clientId: this.clientId,
|
|
997
|
+
connectedTo: to
|
|
998
|
+
});
|
|
941
999
|
}
|
|
942
1000
|
try {
|
|
943
1001
|
await reconnectPromise;
|
|
@@ -945,11 +1003,15 @@ var ClientTransport = class extends Transport {
|
|
|
945
1003
|
this.inflightConnectionPromises.delete(to);
|
|
946
1004
|
const errStr = coerceErrorString(error);
|
|
947
1005
|
if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
|
|
948
|
-
log?.warn(
|
|
1006
|
+
log?.warn(`connection to ${to} failed (${errStr})`, {
|
|
1007
|
+
clientId: this.clientId,
|
|
1008
|
+
connectedTo: to
|
|
1009
|
+
});
|
|
949
1010
|
} else {
|
|
950
|
-
log?.warn(
|
|
951
|
-
|
|
952
|
-
|
|
1011
|
+
log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
|
|
1012
|
+
clientId: this.clientId,
|
|
1013
|
+
connectedTo: to
|
|
1014
|
+
});
|
|
953
1015
|
return this.connect(to);
|
|
954
1016
|
}
|
|
955
1017
|
}
|
|
@@ -961,7 +1023,10 @@ var ClientTransport = class extends Transport {
|
|
|
961
1023
|
sendHandshake(to, conn) {
|
|
962
1024
|
const session = this.getOrCreateSession(to, conn);
|
|
963
1025
|
const requestMsg = handshakeRequestMessage(this.clientId, to, session.id);
|
|
964
|
-
log?.debug(
|
|
1026
|
+
log?.debug(`sending handshake request to ${to}`, {
|
|
1027
|
+
clientId: this.clientId,
|
|
1028
|
+
connectedTo: to
|
|
1029
|
+
});
|
|
965
1030
|
conn.send(this.codec.toBuffer(requestMsg));
|
|
966
1031
|
}
|
|
967
1032
|
close() {
|
|
@@ -972,16 +1037,18 @@ var ClientTransport = class extends Transport {
|
|
|
972
1037
|
var ServerTransport = class extends Transport {
|
|
973
1038
|
constructor(clientId, providedOptions) {
|
|
974
1039
|
super(clientId, providedOptions);
|
|
975
|
-
log?.info(
|
|
976
|
-
|
|
977
|
-
|
|
1040
|
+
log?.info(`initiated server transport`, {
|
|
1041
|
+
clientId: this.clientId,
|
|
1042
|
+
protocolVersion: PROTOCOL_VERSION
|
|
1043
|
+
});
|
|
978
1044
|
}
|
|
979
1045
|
handleConnection(conn) {
|
|
980
1046
|
if (this.state !== "open")
|
|
981
1047
|
return;
|
|
982
|
-
log?.info(
|
|
983
|
-
|
|
984
|
-
|
|
1048
|
+
log?.info(`new incoming connection`, {
|
|
1049
|
+
clientId: this.clientId,
|
|
1050
|
+
connId: conn.debugId
|
|
1051
|
+
});
|
|
985
1052
|
let session = void 0;
|
|
986
1053
|
const client = () => session?.to ?? "unknown";
|
|
987
1054
|
const handshakeHandler = (data) => {
|
|
@@ -1006,16 +1073,18 @@ var ServerTransport = class extends Transport {
|
|
|
1006
1073
|
conn.addCloseListener(() => {
|
|
1007
1074
|
if (!session)
|
|
1008
1075
|
return;
|
|
1009
|
-
log?.info(
|
|
1010
|
-
|
|
1011
|
-
|
|
1076
|
+
log?.info(`connection to ${client()} disconnected`, {
|
|
1077
|
+
clientId: this.clientId,
|
|
1078
|
+
connId: conn.debugId
|
|
1079
|
+
});
|
|
1012
1080
|
this.onDisconnect(conn, session);
|
|
1013
1081
|
});
|
|
1014
1082
|
conn.addErrorListener((err) => {
|
|
1015
1083
|
if (!session)
|
|
1016
1084
|
return;
|
|
1017
1085
|
log?.warn(
|
|
1018
|
-
|
|
1086
|
+
`connection to ${client()} got an error: ${coerceErrorString(err)}`,
|
|
1087
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
1019
1088
|
);
|
|
1020
1089
|
});
|
|
1021
1090
|
}
|
|
@@ -1035,7 +1104,10 @@ var ServerTransport = class extends Transport {
|
|
|
1035
1104
|
reason
|
|
1036
1105
|
});
|
|
1037
1106
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
1038
|
-
log?.warn(`${
|
|
1107
|
+
log?.warn(`${reason}: ${JSON.stringify(parsed)}`, {
|
|
1108
|
+
clientId: this.clientId,
|
|
1109
|
+
connId: conn.debugId
|
|
1110
|
+
});
|
|
1039
1111
|
this.protocolError(
|
|
1040
1112
|
ProtocolError.HandshakeFailed,
|
|
1041
1113
|
"invalid handshake request"
|
|
@@ -1051,14 +1123,16 @@ var ServerTransport = class extends Transport {
|
|
|
1051
1123
|
});
|
|
1052
1124
|
conn.send(this.codec.toBuffer(responseMsg2));
|
|
1053
1125
|
log?.warn(
|
|
1054
|
-
|
|
1126
|
+
`received handshake msg with incompatible protocol version (got: ${gotVersion}, expected: ${PROTOCOL_VERSION})`,
|
|
1127
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
1055
1128
|
);
|
|
1056
1129
|
this.protocolError(ProtocolError.HandshakeFailed, reason);
|
|
1057
1130
|
return false;
|
|
1058
1131
|
}
|
|
1059
1132
|
const session = this.getOrCreateSession(parsed.from, conn);
|
|
1060
1133
|
log?.debug(
|
|
1061
|
-
|
|
1134
|
+
`handshake from ${parsed.from} ok, responding with handshake success`,
|
|
1135
|
+
{ clientId: this.clientId, connId: conn.debugId }
|
|
1062
1136
|
);
|
|
1063
1137
|
const responseMsg = handshakeResponseMessage(this.clientId, parsed.from, {
|
|
1064
1138
|
ok: true,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { b as ClientTransport,
|
|
1
|
+
export { b as ClientTransport, P as ClientTransportOptions, C as Connection, g as EventHandler, E as EventMap, f as EventTypes, h as ProtocolError, i as ProtocolErrorType, c as ServerTransport, a as Session, T as Transport, d as TransportOptions, e as TransportStatus } from '../index-314e676a.js';
|
|
2
|
+
export { O as OpaqueTransportMessage, c as OpaqueTransportMessageSchema, T as TransportClientId, a as TransportMessage, b as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../index-6118cd48.js';
|
|
2
3
|
import '../types-3e5768ec.js';
|
|
3
4
|
import '@sinclair/typebox';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { b as ClientTransport,
|
|
1
|
+
export { b as ClientTransport, P as ClientTransportOptions, C as Connection, g as EventHandler, E as EventMap, f as EventTypes, h as ProtocolError, i as ProtocolErrorType, c as ServerTransport, a as Session, T as Transport, d as TransportOptions, e as TransportStatus } from '../index-314e676a.js';
|
|
2
|
+
export { O as OpaqueTransportMessage, c as OpaqueTransportMessageSchema, T as TransportClientId, a as TransportMessage, b as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../index-6118cd48.js';
|
|
2
3
|
import '../types-3e5768ec.js';
|
|
3
4
|
import '@sinclair/typebox';
|
package/dist/transport/index.js
CHANGED
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
ServerTransport,
|
|
7
7
|
Session,
|
|
8
8
|
Transport
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-CLY7AQ25.js";
|
|
10
10
|
import {
|
|
11
11
|
OpaqueTransportMessageSchema,
|
|
12
12
|
TransportMessageSchema
|
|
13
13
|
} from "../chunk-VH3NGOXQ.js";
|
|
14
|
-
import "../chunk-
|
|
14
|
+
import "../chunk-YITXOAPA.js";
|
|
15
15
|
import "../chunk-GZ7HCLLM.js";
|
|
16
16
|
export {
|
|
17
17
|
ClientTransport,
|