@dxos/network-manager 0.1.58-main.f5feb2a → 0.1.58-main.f69fa2f
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/dist/lib/browser/{chunk-CNQ55TFQ.mjs → chunk-3KLH55NB.mjs} +144 -81
- package/dist/lib/browser/chunk-3KLH55NB.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -148
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/index.cjs +598 -423
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +931 -889
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +2 -2
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +2 -2
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/index.d.ts +1 -0
- package/dist/types/src/transport/index.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +12 -0
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
- package/package.json +18 -17
- package/src/swarm/connection.test.ts +1 -1
- package/src/swarm/connection.ts +4 -3
- package/src/swarm/peer.ts +7 -2
- package/src/swarm/swarm-mapper.ts +4 -7
- package/src/swarm/swarm.test.ts +3 -3
- package/src/swarm/swarm.ts +3 -3
- package/src/testing/test-builder.ts +1 -1
- package/src/tests/basic-test-suite.ts +1 -1
- package/src/tests/memory-transport.test.ts +2 -2
- package/src/tests/tcp-transport.test.ts +2 -2
- package/src/tests/webrtc-transport.test.ts +1 -1
- package/src/topology/star-topology.ts +1 -4
- package/src/transport/index.ts +1 -0
- package/src/transport/simplepeer-transport-proxy.ts +25 -24
- package/src/transport/simplepeer-transport-service.ts +9 -5
- package/src/transport/simplepeer-transport.ts +8 -5
- package/src/transport/tcp-transport.browser.ts +28 -0
- package/dist/lib/browser/chunk-CNQ55TFQ.mjs.map +0 -7
|
@@ -520,29 +520,141 @@ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
|
|
|
520
520
|
var import_rpc = require("@dxos/rpc");
|
|
521
521
|
var import_util11 = require("@dxos/util");
|
|
522
522
|
|
|
523
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
524
|
+
var import_async = require("@dxos/async");
|
|
525
|
+
var import_keys = require("@dxos/keys");
|
|
526
|
+
var import_log = require("@dxos/log");
|
|
527
|
+
var import_teleport2 = require("@dxos/teleport");
|
|
528
|
+
var import_util = require("@dxos/util");
|
|
529
|
+
|
|
530
|
+
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
531
|
+
var import_teleport = require("@dxos/teleport");
|
|
532
|
+
var createTeleportProtocolFactory = (onConnection) => {
|
|
533
|
+
return (params) => {
|
|
534
|
+
const teleport = new import_teleport.Teleport(params);
|
|
535
|
+
return {
|
|
536
|
+
stream: teleport.stream,
|
|
537
|
+
open: async () => {
|
|
538
|
+
await teleport.open();
|
|
539
|
+
await onConnection(teleport);
|
|
540
|
+
},
|
|
541
|
+
close: async () => {
|
|
542
|
+
await teleport.close();
|
|
543
|
+
},
|
|
544
|
+
abort: async () => {
|
|
545
|
+
await teleport.abort();
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
};
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
552
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
553
|
+
var TestWireProtocol = class {
|
|
554
|
+
constructor(peerId, _extensionFactory = () => []) {
|
|
555
|
+
this.peerId = peerId;
|
|
556
|
+
this._extensionFactory = _extensionFactory;
|
|
557
|
+
this.connections = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
558
|
+
this.streamConnections = new import_util.ComplexMap(import_keys.PublicKey.hash);
|
|
559
|
+
this.connected = new import_async.Event();
|
|
560
|
+
this.disconnected = new import_async.Event();
|
|
561
|
+
this.otherConnections = new import_util.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
|
|
562
|
+
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
563
|
+
(0, import_log.log)("create", {
|
|
564
|
+
remotePeerId: teleport.remotePeerId
|
|
565
|
+
}, {
|
|
566
|
+
F: __dxlog_file,
|
|
567
|
+
L: 38,
|
|
568
|
+
S: this,
|
|
569
|
+
C: (f, a) => f(...a)
|
|
570
|
+
});
|
|
571
|
+
const extension = new import_teleport2.TestExtension({
|
|
572
|
+
onClose: async () => {
|
|
573
|
+
this.connections.delete(teleport.remotePeerId);
|
|
574
|
+
this.disconnected.emit(teleport.remotePeerId);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
this.connections.set(teleport.remotePeerId, extension);
|
|
578
|
+
teleport.addExtension("test", extension);
|
|
579
|
+
this.connected.emit(teleport.remotePeerId);
|
|
580
|
+
const streamExtension = new import_teleport2.TestExtensionWithStreams({
|
|
581
|
+
onClose: async () => {
|
|
582
|
+
this.streamConnections.delete(teleport.remotePeerId);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
this.streamConnections.set(teleport.remotePeerId, streamExtension);
|
|
586
|
+
teleport.addExtension("test-stream", streamExtension);
|
|
587
|
+
for (const { name, extension: extension2 } of this._extensionFactory()) {
|
|
588
|
+
this.otherConnections.set({
|
|
589
|
+
remotePeerId: teleport.remotePeerId,
|
|
590
|
+
extension: name
|
|
591
|
+
}, extension2);
|
|
592
|
+
teleport.addExtension(name, extension2);
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
async waitForConnection(peerId) {
|
|
597
|
+
if (this.connections.has(peerId)) {
|
|
598
|
+
return this.connections.get(peerId);
|
|
599
|
+
}
|
|
600
|
+
(0, import_log.log)("waitForConnection", {
|
|
601
|
+
peerId
|
|
602
|
+
}, {
|
|
603
|
+
F: __dxlog_file,
|
|
604
|
+
L: 67,
|
|
605
|
+
S: this,
|
|
606
|
+
C: (f, a) => f(...a)
|
|
607
|
+
});
|
|
608
|
+
await (0, import_async.asyncTimeout)(
|
|
609
|
+
this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
|
|
610
|
+
// TODO(nf): Make this configurable.
|
|
611
|
+
1e4
|
|
612
|
+
);
|
|
613
|
+
return this.connections.get(peerId);
|
|
614
|
+
}
|
|
615
|
+
async testConnection(peerId, message) {
|
|
616
|
+
const connection = await this.waitForConnection(peerId);
|
|
617
|
+
await connection.test(message);
|
|
618
|
+
}
|
|
619
|
+
async openStream(peerId, streamTag, streamLoadInterval, streamLoadChunkSize) {
|
|
620
|
+
if (!this.streamConnections.has(peerId)) {
|
|
621
|
+
throw new Error("Connection does not exist.");
|
|
622
|
+
}
|
|
623
|
+
const connection = this.streamConnections.get(peerId);
|
|
624
|
+
return connection.addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag);
|
|
625
|
+
}
|
|
626
|
+
async closeStream(peerId, streamTag) {
|
|
627
|
+
if (!this.streamConnections.has(peerId)) {
|
|
628
|
+
throw new Error("Connection does not exist.");
|
|
629
|
+
}
|
|
630
|
+
const connection = this.streamConnections.get(peerId);
|
|
631
|
+
return connection.closeStream(streamTag);
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
|
|
523
635
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
524
|
-
var
|
|
636
|
+
var import_async8 = require("@dxos/async");
|
|
525
637
|
var import_invariant6 = require("@dxos/invariant");
|
|
526
|
-
var
|
|
527
|
-
var
|
|
638
|
+
var import_keys9 = require("@dxos/keys");
|
|
639
|
+
var import_log8 = require("@dxos/log");
|
|
528
640
|
var import_messaging = require("@dxos/messaging");
|
|
529
641
|
var import_protocols6 = require("@dxos/protocols");
|
|
530
642
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
531
|
-
var
|
|
643
|
+
var import_util7 = require("@dxos/util");
|
|
532
644
|
|
|
533
645
|
// packages/core/mesh/network-manager/src/connection-log.ts
|
|
534
|
-
var
|
|
646
|
+
var import_async7 = require("@dxos/async");
|
|
535
647
|
var import_debug3 = require("@dxos/debug");
|
|
536
|
-
var
|
|
537
|
-
var
|
|
648
|
+
var import_keys8 = require("@dxos/keys");
|
|
649
|
+
var import_util6 = require("@dxos/util");
|
|
538
650
|
|
|
539
651
|
// packages/core/mesh/network-manager/src/swarm/connection.ts
|
|
540
|
-
var
|
|
652
|
+
var import_async2 = require("@dxos/async");
|
|
541
653
|
var import_context = require("@dxos/context");
|
|
542
654
|
var import_debug = require("@dxos/debug");
|
|
543
655
|
var import_invariant = require("@dxos/invariant");
|
|
544
|
-
var
|
|
545
|
-
var
|
|
656
|
+
var import_keys2 = require("@dxos/keys");
|
|
657
|
+
var import_log2 = require("@dxos/log");
|
|
546
658
|
var import_protocols = require("@dxos/protocols");
|
|
547
659
|
function _ts_decorate(decorators, target, key, desc) {
|
|
548
660
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -554,7 +666,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
554
666
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
555
667
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
556
668
|
}
|
|
557
|
-
var
|
|
669
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts";
|
|
558
670
|
var STARTING_SIGNALLING_DELAY = 10;
|
|
559
671
|
var MAX_SIGNALLING_DELAY = 300;
|
|
560
672
|
var ConnectionState;
|
|
@@ -614,21 +726,21 @@ var Connection = class {
|
|
|
614
726
|
this._state = ConnectionState.CREATED;
|
|
615
727
|
this._incomingSignalBuffer = [];
|
|
616
728
|
this._outgoingSignalBuffer = [];
|
|
617
|
-
this.stateChanged = new
|
|
729
|
+
this.stateChanged = new import_async2.Event();
|
|
618
730
|
this.errors = new import_debug.ErrorStream();
|
|
619
|
-
this._instanceId =
|
|
620
|
-
this._signalSendTask = new
|
|
731
|
+
this._instanceId = import_keys2.PublicKey.random().toHex();
|
|
732
|
+
this._signalSendTask = new import_async2.DeferredTask(this._ctx, async () => {
|
|
621
733
|
await this._flushSignalBuffer();
|
|
622
734
|
});
|
|
623
735
|
this._signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
624
|
-
|
|
736
|
+
import_log2.log.trace("dxos.mesh.connection.construct", {
|
|
625
737
|
sessionId: this.sessionId,
|
|
626
738
|
topic: this.topic,
|
|
627
739
|
localPeerId: this.ownId,
|
|
628
740
|
remotePeerId: this.remoteId,
|
|
629
741
|
initiator: this.initiator
|
|
630
742
|
}, {
|
|
631
|
-
F:
|
|
743
|
+
F: __dxlog_file2,
|
|
632
744
|
L: 123,
|
|
633
745
|
S: this,
|
|
634
746
|
C: (f, a) => f(...a)
|
|
@@ -648,7 +760,7 @@ var Connection = class {
|
|
|
648
760
|
*/
|
|
649
761
|
async openConnection() {
|
|
650
762
|
(0, import_invariant.invariant)(this._state === ConnectionState.INITIAL, "Invalid state.", {
|
|
651
|
-
F:
|
|
763
|
+
F: __dxlog_file2,
|
|
652
764
|
L: 148,
|
|
653
765
|
S: this,
|
|
654
766
|
A: [
|
|
@@ -656,22 +768,22 @@ var Connection = class {
|
|
|
656
768
|
"'Invalid state.'"
|
|
657
769
|
]
|
|
658
770
|
});
|
|
659
|
-
|
|
771
|
+
import_log2.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.begin({
|
|
660
772
|
id: this._instanceId
|
|
661
773
|
}), {
|
|
662
|
-
F:
|
|
774
|
+
F: __dxlog_file2,
|
|
663
775
|
L: 149,
|
|
664
776
|
S: this,
|
|
665
777
|
C: (f, a) => f(...a)
|
|
666
778
|
});
|
|
667
|
-
|
|
779
|
+
import_log2.log.trace("dxos.mesh.connection.open", {
|
|
668
780
|
sessionId: this.sessionId,
|
|
669
781
|
topic: this.topic,
|
|
670
782
|
localPeerId: this.ownId,
|
|
671
783
|
remotePeerId: this.remoteId,
|
|
672
784
|
initiator: this.initiator
|
|
673
785
|
}, {
|
|
674
|
-
F:
|
|
786
|
+
F: __dxlog_file2,
|
|
675
787
|
L: 150,
|
|
676
788
|
S: this,
|
|
677
789
|
C: (f, a) => f(...a)
|
|
@@ -681,8 +793,8 @@ var Connection = class {
|
|
|
681
793
|
this.errors.raise(err);
|
|
682
794
|
});
|
|
683
795
|
this._protocol.stream.on("close", () => {
|
|
684
|
-
(0,
|
|
685
|
-
F:
|
|
796
|
+
(0, import_log2.log)("protocol stream closed", void 0, {
|
|
797
|
+
F: __dxlog_file2,
|
|
686
798
|
L: 167,
|
|
687
799
|
S: this,
|
|
688
800
|
C: (f, a) => f(...a)
|
|
@@ -690,7 +802,7 @@ var Connection = class {
|
|
|
690
802
|
this.close(new import_protocols.ProtocolError("protocol stream closed")).catch((err) => this.errors.raise(err));
|
|
691
803
|
});
|
|
692
804
|
(0, import_invariant.invariant)(!this._transport, void 0, {
|
|
693
|
-
F:
|
|
805
|
+
F: __dxlog_file2,
|
|
694
806
|
L: 171,
|
|
695
807
|
S: this,
|
|
696
808
|
A: [
|
|
@@ -709,8 +821,8 @@ var Connection = class {
|
|
|
709
821
|
});
|
|
710
822
|
this._transport.closed.once(() => {
|
|
711
823
|
this._transport = void 0;
|
|
712
|
-
(0,
|
|
713
|
-
F:
|
|
824
|
+
(0, import_log2.log)("abort triggered by transport close", void 0, {
|
|
825
|
+
F: __dxlog_file2,
|
|
714
826
|
L: 185,
|
|
715
827
|
S: this,
|
|
716
828
|
C: (f, a) => f(...a)
|
|
@@ -718,10 +830,10 @@ var Connection = class {
|
|
|
718
830
|
this.abort().catch((err) => this.errors.raise(err));
|
|
719
831
|
});
|
|
720
832
|
this._transport.errors.handle((err) => {
|
|
721
|
-
(0,
|
|
833
|
+
(0, import_log2.log)("transport error:", {
|
|
722
834
|
err
|
|
723
835
|
}, {
|
|
724
|
-
F:
|
|
836
|
+
F: __dxlog_file2,
|
|
725
837
|
L: 190,
|
|
726
838
|
S: this,
|
|
727
839
|
C: (f, a) => f(...a)
|
|
@@ -730,26 +842,26 @@ var Connection = class {
|
|
|
730
842
|
this.closeReason = err?.message;
|
|
731
843
|
}
|
|
732
844
|
if (err instanceof import_protocols.ConnectionResetError) {
|
|
733
|
-
|
|
734
|
-
F:
|
|
845
|
+
import_log2.log.warn("aborting due to transport ConnectionResetError", void 0, {
|
|
846
|
+
F: __dxlog_file2,
|
|
735
847
|
L: 197,
|
|
736
848
|
S: this,
|
|
737
849
|
C: (f, a) => f(...a)
|
|
738
850
|
});
|
|
739
851
|
this.abort().catch((err2) => this.errors.raise(err2));
|
|
740
852
|
} else if (err instanceof import_protocols.ConnectivityError) {
|
|
741
|
-
|
|
742
|
-
F:
|
|
853
|
+
import_log2.log.warn("aborting due to transport ConnectivityError", void 0, {
|
|
854
|
+
F: __dxlog_file2,
|
|
743
855
|
L: 200,
|
|
744
856
|
S: this,
|
|
745
857
|
C: (f, a) => f(...a)
|
|
746
858
|
});
|
|
747
859
|
this.abort().catch((err2) => this.errors.raise(err2));
|
|
748
860
|
} else if (err instanceof import_protocols.UnknownProtocolError) {
|
|
749
|
-
|
|
861
|
+
import_log2.log.warn("unsure what to do with UnknownProtocolError, will keep on truckin", {
|
|
750
862
|
err
|
|
751
863
|
}, {
|
|
752
|
-
F:
|
|
864
|
+
F: __dxlog_file2,
|
|
753
865
|
L: 203,
|
|
754
866
|
S: this,
|
|
755
867
|
C: (f, a) => f(...a)
|
|
@@ -763,28 +875,28 @@ var Connection = class {
|
|
|
763
875
|
void this._transport.signal(signal);
|
|
764
876
|
}
|
|
765
877
|
this._incomingSignalBuffer = [];
|
|
766
|
-
|
|
878
|
+
import_log2.log.trace("dxos.mesh.connection.open-connection", import_protocols.trace.end({
|
|
767
879
|
id: this._instanceId
|
|
768
880
|
}), {
|
|
769
|
-
F:
|
|
881
|
+
F: __dxlog_file2,
|
|
770
882
|
L: 218,
|
|
771
883
|
S: this,
|
|
772
884
|
C: (f, a) => f(...a)
|
|
773
885
|
});
|
|
774
886
|
}
|
|
775
887
|
async abort(err) {
|
|
776
|
-
(0,
|
|
888
|
+
(0, import_log2.log)("aborting...", {
|
|
777
889
|
err
|
|
778
890
|
}, {
|
|
779
|
-
F:
|
|
780
|
-
L:
|
|
891
|
+
F: __dxlog_file2,
|
|
892
|
+
L: 225,
|
|
781
893
|
S: this,
|
|
782
894
|
C: (f, a) => f(...a)
|
|
783
895
|
});
|
|
784
896
|
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
|
|
785
|
-
(0,
|
|
786
|
-
F:
|
|
787
|
-
L:
|
|
897
|
+
(0, import_log2.log)(`abort ignored: already ${this._state}`, this.closeReason, {
|
|
898
|
+
F: __dxlog_file2,
|
|
899
|
+
L: 227,
|
|
788
900
|
S: this,
|
|
789
901
|
C: (f, a) => f(...a)
|
|
790
902
|
});
|
|
@@ -796,19 +908,19 @@ var Connection = class {
|
|
|
796
908
|
}
|
|
797
909
|
await this._ctx.dispose();
|
|
798
910
|
try {
|
|
799
|
-
(0,
|
|
911
|
+
(0, import_log2.log)("aborting protocol... ", {
|
|
800
912
|
proto: this._protocol
|
|
801
913
|
}, {
|
|
802
|
-
F:
|
|
803
|
-
L:
|
|
914
|
+
F: __dxlog_file2,
|
|
915
|
+
L: 240,
|
|
804
916
|
S: this,
|
|
805
917
|
C: (f, a) => f(...a)
|
|
806
918
|
});
|
|
807
919
|
await this._protocol.abort();
|
|
808
920
|
} catch (err2) {
|
|
809
|
-
|
|
810
|
-
F:
|
|
811
|
-
L:
|
|
921
|
+
import_log2.log.catch(err2, void 0, {
|
|
922
|
+
F: __dxlog_file2,
|
|
923
|
+
L: 243,
|
|
812
924
|
S: this,
|
|
813
925
|
C: (f, a) => f(...a)
|
|
814
926
|
});
|
|
@@ -816,9 +928,9 @@ var Connection = class {
|
|
|
816
928
|
try {
|
|
817
929
|
await this._transport?.destroy();
|
|
818
930
|
} catch (err2) {
|
|
819
|
-
|
|
820
|
-
F:
|
|
821
|
-
L:
|
|
931
|
+
import_log2.log.catch(err2, void 0, {
|
|
932
|
+
F: __dxlog_file2,
|
|
933
|
+
L: 250,
|
|
822
934
|
S: this,
|
|
823
935
|
C: (f, a) => f(...a)
|
|
824
936
|
});
|
|
@@ -826,9 +938,9 @@ var Connection = class {
|
|
|
826
938
|
try {
|
|
827
939
|
this._callbacks?.onClosed?.(err);
|
|
828
940
|
} catch (err2) {
|
|
829
|
-
|
|
830
|
-
F:
|
|
831
|
-
L:
|
|
941
|
+
import_log2.log.catch(err2, void 0, {
|
|
942
|
+
F: __dxlog_file2,
|
|
943
|
+
L: 256,
|
|
832
944
|
S: this,
|
|
833
945
|
C: (f, a) => f(...a)
|
|
834
946
|
});
|
|
@@ -845,11 +957,11 @@ var Connection = class {
|
|
|
845
957
|
const lastState = this._state;
|
|
846
958
|
this._changeState(ConnectionState.CLOSING);
|
|
847
959
|
await this._ctx.dispose();
|
|
848
|
-
(0,
|
|
960
|
+
(0, import_log2.log)("closing...", {
|
|
849
961
|
peerId: this.ownId
|
|
850
962
|
}, {
|
|
851
|
-
F:
|
|
852
|
-
L:
|
|
963
|
+
F: __dxlog_file2,
|
|
964
|
+
L: 278,
|
|
853
965
|
S: this,
|
|
854
966
|
C: (f, a) => f(...a)
|
|
855
967
|
});
|
|
@@ -857,9 +969,9 @@ var Connection = class {
|
|
|
857
969
|
try {
|
|
858
970
|
await this._protocol.close();
|
|
859
971
|
} catch (err2) {
|
|
860
|
-
|
|
861
|
-
F:
|
|
862
|
-
L:
|
|
972
|
+
import_log2.log.catch(err2, void 0, {
|
|
973
|
+
F: __dxlog_file2,
|
|
974
|
+
L: 285,
|
|
863
975
|
S: this,
|
|
864
976
|
C: (f, a) => f(...a)
|
|
865
977
|
});
|
|
@@ -867,19 +979,19 @@ var Connection = class {
|
|
|
867
979
|
try {
|
|
868
980
|
await this._transport?.destroy();
|
|
869
981
|
} catch (err2) {
|
|
870
|
-
|
|
871
|
-
F:
|
|
872
|
-
L:
|
|
982
|
+
import_log2.log.catch(err2, void 0, {
|
|
983
|
+
F: __dxlog_file2,
|
|
984
|
+
L: 292,
|
|
873
985
|
S: this,
|
|
874
986
|
C: (f, a) => f(...a)
|
|
875
987
|
});
|
|
876
988
|
}
|
|
877
989
|
}
|
|
878
|
-
(0,
|
|
990
|
+
(0, import_log2.log)("closed", {
|
|
879
991
|
peerId: this.ownId
|
|
880
992
|
}, {
|
|
881
|
-
F:
|
|
882
|
-
L:
|
|
993
|
+
F: __dxlog_file2,
|
|
994
|
+
L: 296,
|
|
883
995
|
S: this,
|
|
884
996
|
C: (f, a) => f(...a)
|
|
885
997
|
});
|
|
@@ -896,7 +1008,7 @@ var Connection = class {
|
|
|
896
1008
|
}
|
|
897
1009
|
try {
|
|
898
1010
|
if (process.env.NODE_ENV !== "test") {
|
|
899
|
-
await (0, import_context.cancelWithContext)(this._ctx, (0,
|
|
1011
|
+
await (0, import_context.cancelWithContext)(this._ctx, (0, import_async2.sleep)(this._signallingDelay));
|
|
900
1012
|
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
901
1013
|
}
|
|
902
1014
|
const signals = [
|
|
@@ -918,11 +1030,11 @@ var Connection = class {
|
|
|
918
1030
|
if (err instanceof import_protocols.CancelledError) {
|
|
919
1031
|
return;
|
|
920
1032
|
}
|
|
921
|
-
|
|
1033
|
+
import_log2.log.warn("signal failed", {
|
|
922
1034
|
err
|
|
923
1035
|
}, {
|
|
924
|
-
F:
|
|
925
|
-
L:
|
|
1036
|
+
F: __dxlog_file2,
|
|
1037
|
+
L: 333,
|
|
926
1038
|
S: this,
|
|
927
1039
|
C: (f, a) => f(...a)
|
|
928
1040
|
});
|
|
@@ -934,8 +1046,8 @@ var Connection = class {
|
|
|
934
1046
|
*/
|
|
935
1047
|
async signal(msg) {
|
|
936
1048
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
937
|
-
F:
|
|
938
|
-
L:
|
|
1049
|
+
F: __dxlog_file2,
|
|
1050
|
+
L: 342,
|
|
939
1051
|
S: this,
|
|
940
1052
|
A: [
|
|
941
1053
|
"msg.sessionId",
|
|
@@ -943,17 +1055,17 @@ var Connection = class {
|
|
|
943
1055
|
]
|
|
944
1056
|
});
|
|
945
1057
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
946
|
-
(0,
|
|
947
|
-
F:
|
|
948
|
-
L:
|
|
1058
|
+
(0, import_log2.log)("dropping signal for incorrect session id", void 0, {
|
|
1059
|
+
F: __dxlog_file2,
|
|
1060
|
+
L: 344,
|
|
949
1061
|
S: this,
|
|
950
1062
|
C: (f, a) => f(...a)
|
|
951
1063
|
});
|
|
952
1064
|
return;
|
|
953
1065
|
}
|
|
954
1066
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
955
|
-
F:
|
|
956
|
-
L:
|
|
1067
|
+
F: __dxlog_file2,
|
|
1068
|
+
L: 347,
|
|
957
1069
|
S: this,
|
|
958
1070
|
A: [
|
|
959
1071
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -961,8 +1073,8 @@ var Connection = class {
|
|
|
961
1073
|
]
|
|
962
1074
|
});
|
|
963
1075
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
964
|
-
F:
|
|
965
|
-
L:
|
|
1076
|
+
F: __dxlog_file2,
|
|
1077
|
+
L: 348,
|
|
966
1078
|
S: this,
|
|
967
1079
|
A: [
|
|
968
1080
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -970,8 +1082,8 @@ var Connection = class {
|
|
|
970
1082
|
]
|
|
971
1083
|
});
|
|
972
1084
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
973
|
-
F:
|
|
974
|
-
L:
|
|
1085
|
+
F: __dxlog_file2,
|
|
1086
|
+
L: 349,
|
|
975
1087
|
S: this,
|
|
976
1088
|
A: [
|
|
977
1089
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -989,34 +1101,34 @@ var Connection = class {
|
|
|
989
1101
|
ConnectionState.CREATED,
|
|
990
1102
|
ConnectionState.INITIAL
|
|
991
1103
|
].includes(this.state)) {
|
|
992
|
-
(0,
|
|
1104
|
+
(0, import_log2.log)("buffered signal", {
|
|
993
1105
|
peerId: this.ownId,
|
|
994
1106
|
remoteId: this.remoteId,
|
|
995
1107
|
msg: msg.data
|
|
996
1108
|
}, {
|
|
997
|
-
F:
|
|
998
|
-
L:
|
|
1109
|
+
F: __dxlog_file2,
|
|
1110
|
+
L: 358,
|
|
999
1111
|
S: this,
|
|
1000
1112
|
C: (f, a) => f(...a)
|
|
1001
1113
|
});
|
|
1002
1114
|
this._incomingSignalBuffer.push(signal);
|
|
1003
1115
|
} else {
|
|
1004
1116
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
1005
|
-
F:
|
|
1006
|
-
L:
|
|
1117
|
+
F: __dxlog_file2,
|
|
1118
|
+
L: 361,
|
|
1007
1119
|
S: this,
|
|
1008
1120
|
A: [
|
|
1009
1121
|
"this._transport",
|
|
1010
1122
|
"'Connection not ready to accept signals.'"
|
|
1011
1123
|
]
|
|
1012
1124
|
});
|
|
1013
|
-
(0,
|
|
1125
|
+
(0, import_log2.log)("received signal", {
|
|
1014
1126
|
peerId: this.ownId,
|
|
1015
1127
|
remoteId: this.remoteId,
|
|
1016
1128
|
msg: msg.data
|
|
1017
1129
|
}, {
|
|
1018
|
-
F:
|
|
1019
|
-
L:
|
|
1130
|
+
F: __dxlog_file2,
|
|
1131
|
+
L: 362,
|
|
1020
1132
|
S: this,
|
|
1021
1133
|
C: (f, a) => f(...a)
|
|
1022
1134
|
});
|
|
@@ -1028,19 +1140,19 @@ var Connection = class {
|
|
|
1028
1140
|
this._changeState(ConnectionState.INITIAL);
|
|
1029
1141
|
}
|
|
1030
1142
|
_changeState(state) {
|
|
1031
|
-
(0,
|
|
1143
|
+
(0, import_log2.log)("stateChanged", {
|
|
1032
1144
|
from: this._state,
|
|
1033
1145
|
to: state,
|
|
1034
1146
|
peerId: this.ownId
|
|
1035
1147
|
}, {
|
|
1036
|
-
F:
|
|
1037
|
-
L:
|
|
1148
|
+
F: __dxlog_file2,
|
|
1149
|
+
L: 373,
|
|
1038
1150
|
S: this,
|
|
1039
1151
|
C: (f, a) => f(...a)
|
|
1040
1152
|
});
|
|
1041
1153
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
1042
|
-
F:
|
|
1043
|
-
L:
|
|
1154
|
+
F: __dxlog_file2,
|
|
1155
|
+
L: 374,
|
|
1044
1156
|
S: this,
|
|
1045
1157
|
A: [
|
|
1046
1158
|
"state !== this._state",
|
|
@@ -1052,301 +1164,83 @@ var Connection = class {
|
|
|
1052
1164
|
}
|
|
1053
1165
|
};
|
|
1054
1166
|
_ts_decorate([
|
|
1055
|
-
|
|
1167
|
+
import_async2.synchronized
|
|
1056
1168
|
], Connection.prototype, "abort", null);
|
|
1057
1169
|
_ts_decorate([
|
|
1058
|
-
|
|
1170
|
+
import_async2.synchronized
|
|
1059
1171
|
], Connection.prototype, "close", null);
|
|
1060
1172
|
|
|
1061
1173
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
1062
|
-
var
|
|
1174
|
+
var import_async4 = require("@dxos/async");
|
|
1063
1175
|
var import_context4 = require("@dxos/context");
|
|
1064
1176
|
var import_debug2 = require("@dxos/debug");
|
|
1065
1177
|
var import_invariant4 = require("@dxos/invariant");
|
|
1066
|
-
var
|
|
1067
|
-
var
|
|
1178
|
+
var import_keys5 = require("@dxos/keys");
|
|
1179
|
+
var import_log5 = require("@dxos/log");
|
|
1068
1180
|
var import_protocols4 = require("@dxos/protocols");
|
|
1069
|
-
var
|
|
1181
|
+
var import_util3 = require("@dxos/util");
|
|
1070
1182
|
|
|
1071
|
-
// packages/core/mesh/network-manager/src/
|
|
1183
|
+
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
1184
|
+
var import_async3 = require("@dxos/async");
|
|
1072
1185
|
var import_context2 = require("@dxos/context");
|
|
1073
1186
|
var import_invariant2 = require("@dxos/invariant");
|
|
1074
|
-
var
|
|
1075
|
-
var
|
|
1187
|
+
var import_keys3 = require("@dxos/keys");
|
|
1188
|
+
var import_log3 = require("@dxos/log");
|
|
1076
1189
|
var import_protocols2 = require("@dxos/protocols");
|
|
1077
|
-
|
|
1078
|
-
var
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1190
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
1191
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1192
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1193
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1194
|
+
else
|
|
1195
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1196
|
+
if (d = decorators[i])
|
|
1197
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1198
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1199
|
+
}
|
|
1200
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
1201
|
+
var ConnectionDisplacedError = class extends import_protocols2.SystemError {
|
|
1202
|
+
constructor() {
|
|
1203
|
+
super("Connection displaced by remote initiator.");
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
1207
|
+
var Peer = class {
|
|
1208
|
+
// TODO(burdon): Convert to map?
|
|
1209
|
+
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
1210
|
+
this.id = id;
|
|
1211
|
+
this.topic = topic;
|
|
1212
|
+
this.localPeerId = localPeerId;
|
|
1213
|
+
this._signalMessaging = _signalMessaging;
|
|
1214
|
+
this._protocolProvider = _protocolProvider;
|
|
1215
|
+
this._transportFactory = _transportFactory;
|
|
1216
|
+
this._connectionLimiter = _connectionLimiter;
|
|
1217
|
+
this._callbacks = _callbacks;
|
|
1218
|
+
this._availableAfter = 0;
|
|
1219
|
+
this.availableToConnect = true;
|
|
1082
1220
|
this._ctx = new import_context2.Context();
|
|
1083
|
-
this.
|
|
1084
|
-
this.
|
|
1085
|
-
this.
|
|
1086
|
-
this._onOffer = onOffer;
|
|
1087
|
-
this._topic = topic;
|
|
1221
|
+
this.advertizing = false;
|
|
1222
|
+
this.initiating = false;
|
|
1223
|
+
this.connectionDisplaced = new import_async3.Event();
|
|
1088
1224
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
const
|
|
1094
|
-
if (
|
|
1095
|
-
|
|
1225
|
+
/**
|
|
1226
|
+
* Respond to remote offer.
|
|
1227
|
+
*/
|
|
1228
|
+
async onOffer(message) {
|
|
1229
|
+
const remoteId = message.author;
|
|
1230
|
+
if (this.connection && ![
|
|
1231
|
+
ConnectionState.CREATED,
|
|
1232
|
+
ConnectionState.INITIAL
|
|
1233
|
+
].includes(this.connection.state)) {
|
|
1234
|
+
import_log3.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
1235
|
+
F: __dxlog_file3,
|
|
1236
|
+
L: 112,
|
|
1237
|
+
S: this,
|
|
1238
|
+
C: (f, a) => f(...a)
|
|
1239
|
+
});
|
|
1240
|
+
return {
|
|
1241
|
+
accept: false
|
|
1242
|
+
};
|
|
1096
1243
|
}
|
|
1097
|
-
(0, import_log2.log)("received", {
|
|
1098
|
-
from: author,
|
|
1099
|
-
to: recipient,
|
|
1100
|
-
msg: message
|
|
1101
|
-
}, {
|
|
1102
|
-
F: __dxlog_file2,
|
|
1103
|
-
L: 69,
|
|
1104
|
-
S: this,
|
|
1105
|
-
C: (f, a) => f(...a)
|
|
1106
|
-
});
|
|
1107
|
-
if (message.data?.offer) {
|
|
1108
|
-
await this._handleOffer({
|
|
1109
|
-
author,
|
|
1110
|
-
recipient,
|
|
1111
|
-
message
|
|
1112
|
-
});
|
|
1113
|
-
} else if (message.data?.answer) {
|
|
1114
|
-
await this._resolveAnswers(message);
|
|
1115
|
-
} else if (message.data?.signal) {
|
|
1116
|
-
await this._handleSignal({
|
|
1117
|
-
author,
|
|
1118
|
-
recipient,
|
|
1119
|
-
message
|
|
1120
|
-
});
|
|
1121
|
-
} else if (message.data?.signalBatch) {
|
|
1122
|
-
await this._handleSignal({
|
|
1123
|
-
author,
|
|
1124
|
-
recipient,
|
|
1125
|
-
message
|
|
1126
|
-
});
|
|
1127
|
-
} else {
|
|
1128
|
-
import_log2.log.warn("unknown message", {
|
|
1129
|
-
message
|
|
1130
|
-
}, {
|
|
1131
|
-
F: __dxlog_file2,
|
|
1132
|
-
L: 80,
|
|
1133
|
-
S: this,
|
|
1134
|
-
C: (f, a) => f(...a)
|
|
1135
|
-
});
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
async signal(message) {
|
|
1139
|
-
(0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
1140
|
-
F: __dxlog_file2,
|
|
1141
|
-
L: 85,
|
|
1142
|
-
S: this,
|
|
1143
|
-
A: [
|
|
1144
|
-
"message.data?.signal || message.data?.signalBatch",
|
|
1145
|
-
"'Invalid message'"
|
|
1146
|
-
]
|
|
1147
|
-
});
|
|
1148
|
-
await this._sendReliableMessage({
|
|
1149
|
-
author: message.author,
|
|
1150
|
-
recipient: message.recipient,
|
|
1151
|
-
message
|
|
1152
|
-
});
|
|
1153
|
-
}
|
|
1154
|
-
async offer(message) {
|
|
1155
|
-
const networkMessage = {
|
|
1156
|
-
...message,
|
|
1157
|
-
messageId: import_keys2.PublicKey.random()
|
|
1158
|
-
};
|
|
1159
|
-
return new Promise((resolve, reject) => {
|
|
1160
|
-
this._offerRecords.set(networkMessage.messageId, {
|
|
1161
|
-
resolve
|
|
1162
|
-
});
|
|
1163
|
-
this._sendReliableMessage({
|
|
1164
|
-
author: message.author,
|
|
1165
|
-
recipient: message.recipient,
|
|
1166
|
-
message: networkMessage
|
|
1167
|
-
}).catch((err) => reject(err));
|
|
1168
|
-
});
|
|
1169
|
-
}
|
|
1170
|
-
async _sendReliableMessage({ author, recipient, message }) {
|
|
1171
|
-
const networkMessage = {
|
|
1172
|
-
...message,
|
|
1173
|
-
// Setting unique message_id if it not specified yet.
|
|
1174
|
-
messageId: message.messageId ?? import_keys2.PublicKey.random()
|
|
1175
|
-
};
|
|
1176
|
-
(0, import_log2.log)("sending", {
|
|
1177
|
-
from: author,
|
|
1178
|
-
to: recipient,
|
|
1179
|
-
msg: networkMessage
|
|
1180
|
-
}, {
|
|
1181
|
-
F: __dxlog_file2,
|
|
1182
|
-
L: 123,
|
|
1183
|
-
S: this,
|
|
1184
|
-
C: (f, a) => f(...a)
|
|
1185
|
-
});
|
|
1186
|
-
await this._sendMessage({
|
|
1187
|
-
author,
|
|
1188
|
-
recipient,
|
|
1189
|
-
payload: {
|
|
1190
|
-
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
1191
|
-
value: SwarmMessage.encode(networkMessage)
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
|
-
async _resolveAnswers(message) {
|
|
1196
|
-
(0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
1197
|
-
F: __dxlog_file2,
|
|
1198
|
-
L: 135,
|
|
1199
|
-
S: this,
|
|
1200
|
-
A: [
|
|
1201
|
-
"message.data?.answer?.offerMessageId",
|
|
1202
|
-
"'No offerMessageId'"
|
|
1203
|
-
]
|
|
1204
|
-
});
|
|
1205
|
-
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
1206
|
-
if (offerRecord) {
|
|
1207
|
-
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
1208
|
-
(0, import_invariant2.invariant)(message.data?.answer, "No answer", {
|
|
1209
|
-
F: __dxlog_file2,
|
|
1210
|
-
L: 139,
|
|
1211
|
-
S: this,
|
|
1212
|
-
A: [
|
|
1213
|
-
"message.data?.answer",
|
|
1214
|
-
"'No answer'"
|
|
1215
|
-
]
|
|
1216
|
-
});
|
|
1217
|
-
(0, import_log2.log)("resolving", {
|
|
1218
|
-
answer: message.data.answer
|
|
1219
|
-
}, {
|
|
1220
|
-
F: __dxlog_file2,
|
|
1221
|
-
L: 140,
|
|
1222
|
-
S: this,
|
|
1223
|
-
C: (f, a) => f(...a)
|
|
1224
|
-
});
|
|
1225
|
-
offerRecord.resolve(message.data.answer);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
async _handleOffer({ author, recipient, message }) {
|
|
1229
|
-
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
1230
|
-
F: __dxlog_file2,
|
|
1231
|
-
L: 154,
|
|
1232
|
-
S: this,
|
|
1233
|
-
A: [
|
|
1234
|
-
"message.data.offer",
|
|
1235
|
-
"'No offer'"
|
|
1236
|
-
]
|
|
1237
|
-
});
|
|
1238
|
-
const offerMessage = {
|
|
1239
|
-
author,
|
|
1240
|
-
recipient,
|
|
1241
|
-
...message,
|
|
1242
|
-
data: {
|
|
1243
|
-
offer: message.data.offer
|
|
1244
|
-
}
|
|
1245
|
-
};
|
|
1246
|
-
const answer = await this._onOffer(offerMessage);
|
|
1247
|
-
answer.offerMessageId = message.messageId;
|
|
1248
|
-
try {
|
|
1249
|
-
await this._sendReliableMessage({
|
|
1250
|
-
author: recipient,
|
|
1251
|
-
recipient: author,
|
|
1252
|
-
message: {
|
|
1253
|
-
topic: message.topic,
|
|
1254
|
-
sessionId: message.sessionId,
|
|
1255
|
-
data: {
|
|
1256
|
-
answer
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
});
|
|
1260
|
-
} catch (err) {
|
|
1261
|
-
import_log2.log.warn("error sending answer", {
|
|
1262
|
-
err
|
|
1263
|
-
}, {
|
|
1264
|
-
F: __dxlog_file2,
|
|
1265
|
-
L: 174,
|
|
1266
|
-
S: this,
|
|
1267
|
-
C: (f, a) => f(...a)
|
|
1268
|
-
});
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
async _handleSignal({ author, recipient, message }) {
|
|
1272
|
-
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
1273
|
-
F: __dxlog_file2,
|
|
1274
|
-
L: 187,
|
|
1275
|
-
S: this,
|
|
1276
|
-
A: [
|
|
1277
|
-
"message.messageId",
|
|
1278
|
-
""
|
|
1279
|
-
]
|
|
1280
|
-
});
|
|
1281
|
-
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
1282
|
-
F: __dxlog_file2,
|
|
1283
|
-
L: 188,
|
|
1284
|
-
S: this,
|
|
1285
|
-
A: [
|
|
1286
|
-
"message.data.signal || message.data.signalBatch",
|
|
1287
|
-
"'Invalid message'"
|
|
1288
|
-
]
|
|
1289
|
-
});
|
|
1290
|
-
const signalMessage = {
|
|
1291
|
-
author,
|
|
1292
|
-
recipient,
|
|
1293
|
-
...message,
|
|
1294
|
-
data: {
|
|
1295
|
-
signal: message.data.signal,
|
|
1296
|
-
signalBatch: message.data.signalBatch
|
|
1297
|
-
}
|
|
1298
|
-
};
|
|
1299
|
-
await this._onSignal(signalMessage);
|
|
1300
|
-
}
|
|
1301
|
-
};
|
|
1302
|
-
|
|
1303
|
-
// packages/core/mesh/network-manager/src/swarm/peer.ts
|
|
1304
|
-
var import_async2 = require("@dxos/async");
|
|
1305
|
-
var import_context3 = require("@dxos/context");
|
|
1306
|
-
var import_invariant3 = require("@dxos/invariant");
|
|
1307
|
-
var import_keys3 = require("@dxos/keys");
|
|
1308
|
-
var import_log3 = require("@dxos/log");
|
|
1309
|
-
var import_protocols3 = require("@dxos/protocols");
|
|
1310
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
1311
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1312
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1313
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
1314
|
-
else
|
|
1315
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1316
|
-
if (d = decorators[i])
|
|
1317
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1318
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1319
|
-
}
|
|
1320
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
1321
|
-
var ConnectionDisplacedError = class extends import_protocols3.SystemError {
|
|
1322
|
-
constructor() {
|
|
1323
|
-
super("Connection displaced by remote initiator.");
|
|
1324
|
-
}
|
|
1325
|
-
};
|
|
1326
|
-
var CONNECTION_COUNTS_STABLE_AFTER = 5e3;
|
|
1327
|
-
var Peer = class {
|
|
1328
|
-
// TODO(burdon): Convert to map?
|
|
1329
|
-
constructor(id, topic, localPeerId, _signalMessaging, _protocolProvider, _transportFactory, _connectionLimiter, _callbacks) {
|
|
1330
|
-
this.id = id;
|
|
1331
|
-
this.topic = topic;
|
|
1332
|
-
this.localPeerId = localPeerId;
|
|
1333
|
-
this._signalMessaging = _signalMessaging;
|
|
1334
|
-
this._protocolProvider = _protocolProvider;
|
|
1335
|
-
this._transportFactory = _transportFactory;
|
|
1336
|
-
this._connectionLimiter = _connectionLimiter;
|
|
1337
|
-
this._callbacks = _callbacks;
|
|
1338
|
-
this._availableAfter = 0;
|
|
1339
|
-
this.availableToConnect = true;
|
|
1340
|
-
this._ctx = new import_context3.Context();
|
|
1341
|
-
this.advertizing = false;
|
|
1342
|
-
this.initiating = false;
|
|
1343
|
-
this.connectionDisplaced = new import_async2.Event();
|
|
1344
|
-
}
|
|
1345
|
-
/**
|
|
1346
|
-
* Respond to remote offer.
|
|
1347
|
-
*/
|
|
1348
|
-
async onOffer(message) {
|
|
1349
|
-
const remoteId = message.author;
|
|
1350
1244
|
if (this.connection || this.initiating) {
|
|
1351
1245
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
1352
1246
|
(0, import_log3.log)("close local connection", {
|
|
@@ -1356,7 +1250,7 @@ var Peer = class {
|
|
|
1356
1250
|
sessionId: this.connection?.sessionId
|
|
1357
1251
|
}, {
|
|
1358
1252
|
F: __dxlog_file3,
|
|
1359
|
-
L:
|
|
1253
|
+
L: 121,
|
|
1360
1254
|
S: this,
|
|
1361
1255
|
C: (f, a) => f(...a)
|
|
1362
1256
|
});
|
|
@@ -1371,9 +1265,9 @@ var Peer = class {
|
|
|
1371
1265
|
}
|
|
1372
1266
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
1373
1267
|
if (!this.connection) {
|
|
1374
|
-
(0,
|
|
1268
|
+
(0, import_invariant2.invariant)(message.sessionId, void 0, {
|
|
1375
1269
|
F: __dxlog_file3,
|
|
1376
|
-
L:
|
|
1270
|
+
L: 141,
|
|
1377
1271
|
S: this,
|
|
1378
1272
|
A: [
|
|
1379
1273
|
"message.sessionId",
|
|
@@ -1386,7 +1280,7 @@ var Peer = class {
|
|
|
1386
1280
|
connection.initiate();
|
|
1387
1281
|
await connection.openConnection();
|
|
1388
1282
|
} catch (err) {
|
|
1389
|
-
if (!(err instanceof
|
|
1283
|
+
if (!(err instanceof import_protocols2.CancelledError)) {
|
|
1390
1284
|
import_log3.log.warn("connection error", {
|
|
1391
1285
|
topic: this.topic,
|
|
1392
1286
|
peerId: this.localPeerId,
|
|
@@ -1394,7 +1288,7 @@ var Peer = class {
|
|
|
1394
1288
|
err
|
|
1395
1289
|
}, {
|
|
1396
1290
|
F: __dxlog_file3,
|
|
1397
|
-
L:
|
|
1291
|
+
L: 151,
|
|
1398
1292
|
S: this,
|
|
1399
1293
|
C: (f, a) => f(...a)
|
|
1400
1294
|
});
|
|
@@ -1414,18 +1308,18 @@ var Peer = class {
|
|
|
1414
1308
|
* Initiate a connection to the remote peer.
|
|
1415
1309
|
*/
|
|
1416
1310
|
async initiateConnection() {
|
|
1417
|
-
(0,
|
|
1311
|
+
(0, import_invariant2.invariant)(!this.initiating, "Initiation in progress.", {
|
|
1418
1312
|
F: __dxlog_file3,
|
|
1419
|
-
L:
|
|
1313
|
+
L: 168,
|
|
1420
1314
|
S: this,
|
|
1421
1315
|
A: [
|
|
1422
1316
|
"!this.initiating",
|
|
1423
1317
|
"'Initiation in progress.'"
|
|
1424
1318
|
]
|
|
1425
1319
|
});
|
|
1426
|
-
(0,
|
|
1320
|
+
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1427
1321
|
F: __dxlog_file3,
|
|
1428
|
-
L:
|
|
1322
|
+
L: 169,
|
|
1429
1323
|
S: this,
|
|
1430
1324
|
A: [
|
|
1431
1325
|
"!this.connection",
|
|
@@ -1440,7 +1334,7 @@ var Peer = class {
|
|
|
1440
1334
|
sessionId
|
|
1441
1335
|
}, {
|
|
1442
1336
|
F: __dxlog_file3,
|
|
1443
|
-
L:
|
|
1337
|
+
L: 171,
|
|
1444
1338
|
S: this,
|
|
1445
1339
|
C: (f, a) => f(...a)
|
|
1446
1340
|
});
|
|
@@ -1465,14 +1359,14 @@ var Peer = class {
|
|
|
1465
1359
|
remoteId: this.id
|
|
1466
1360
|
}, {
|
|
1467
1361
|
F: __dxlog_file3,
|
|
1468
|
-
L:
|
|
1362
|
+
L: 187,
|
|
1469
1363
|
S: this,
|
|
1470
1364
|
C: (f, a) => f(...a)
|
|
1471
1365
|
});
|
|
1472
1366
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1473
1367
|
(0, import_log3.log)("ignoring response", void 0, {
|
|
1474
1368
|
F: __dxlog_file3,
|
|
1475
|
-
L:
|
|
1369
|
+
L: 189,
|
|
1476
1370
|
S: this,
|
|
1477
1371
|
C: (f, a) => f(...a)
|
|
1478
1372
|
});
|
|
@@ -1492,11 +1386,17 @@ var Peer = class {
|
|
|
1492
1386
|
remoteId: this.id
|
|
1493
1387
|
}, {
|
|
1494
1388
|
F: __dxlog_file3,
|
|
1495
|
-
L:
|
|
1389
|
+
L: 200,
|
|
1496
1390
|
S: this,
|
|
1497
1391
|
C: (f, a) => f(...a)
|
|
1498
1392
|
});
|
|
1499
|
-
if (err instanceof
|
|
1393
|
+
if (err instanceof import_protocols2.TimeoutError) {
|
|
1394
|
+
import_log3.log.warn("aborting connection due to signalling failure", void 0, {
|
|
1395
|
+
F: __dxlog_file3,
|
|
1396
|
+
L: 202,
|
|
1397
|
+
S: this,
|
|
1398
|
+
C: (f, a) => f(...a)
|
|
1399
|
+
});
|
|
1500
1400
|
await connection.abort(err);
|
|
1501
1401
|
}
|
|
1502
1402
|
await this.closeConnection(err);
|
|
@@ -1518,13 +1418,13 @@ var Peer = class {
|
|
|
1518
1418
|
sessionId
|
|
1519
1419
|
}, {
|
|
1520
1420
|
F: __dxlog_file3,
|
|
1521
|
-
L:
|
|
1421
|
+
L: 218,
|
|
1522
1422
|
S: this,
|
|
1523
1423
|
C: (f, a) => f(...a)
|
|
1524
1424
|
});
|
|
1525
|
-
(0,
|
|
1425
|
+
(0, import_invariant2.invariant)(!this.connection, "Already connected.", {
|
|
1526
1426
|
F: __dxlog_file3,
|
|
1527
|
-
L:
|
|
1427
|
+
L: 225,
|
|
1528
1428
|
S: this,
|
|
1529
1429
|
A: [
|
|
1530
1430
|
"!this.connection",
|
|
@@ -1560,7 +1460,7 @@ var Peer = class {
|
|
|
1560
1460
|
initiator
|
|
1561
1461
|
}, {
|
|
1562
1462
|
F: __dxlog_file3,
|
|
1563
|
-
L:
|
|
1463
|
+
L: 244,
|
|
1564
1464
|
S: this,
|
|
1565
1465
|
C: (f, a) => f(...a)
|
|
1566
1466
|
});
|
|
@@ -1573,14 +1473,14 @@ var Peer = class {
|
|
|
1573
1473
|
initiator
|
|
1574
1474
|
}, {
|
|
1575
1475
|
F: __dxlog_file3,
|
|
1576
|
-
L:
|
|
1476
|
+
L: 253,
|
|
1577
1477
|
S: this,
|
|
1578
1478
|
C: (f, a) => f(...a)
|
|
1579
1479
|
});
|
|
1580
1480
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1581
|
-
(0,
|
|
1481
|
+
(0, import_invariant2.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1582
1482
|
F: __dxlog_file3,
|
|
1583
|
-
L:
|
|
1483
|
+
L: 258,
|
|
1584
1484
|
S: this,
|
|
1585
1485
|
A: [
|
|
1586
1486
|
"this.connection === connection",
|
|
@@ -1595,7 +1495,7 @@ var Peer = class {
|
|
|
1595
1495
|
initiator
|
|
1596
1496
|
}, {
|
|
1597
1497
|
F: __dxlog_file3,
|
|
1598
|
-
L:
|
|
1498
|
+
L: 260,
|
|
1599
1499
|
S: this,
|
|
1600
1500
|
C: (f, a) => f(...a)
|
|
1601
1501
|
});
|
|
@@ -1609,7 +1509,7 @@ var Peer = class {
|
|
|
1609
1509
|
this._availableAfter = increaseInterval(this._availableAfter);
|
|
1610
1510
|
}
|
|
1611
1511
|
this._callbacks.onDisconnected();
|
|
1612
|
-
(0,
|
|
1512
|
+
(0, import_async3.scheduleTask)(this._connectionCtx, () => {
|
|
1613
1513
|
this.availableToConnect = true;
|
|
1614
1514
|
this._callbacks.onPeerAvailable();
|
|
1615
1515
|
}, this._availableAfter);
|
|
@@ -1630,95 +1530,327 @@ var Peer = class {
|
|
|
1630
1530
|
err
|
|
1631
1531
|
}, {
|
|
1632
1532
|
F: __dxlog_file3,
|
|
1633
|
-
L:
|
|
1533
|
+
L: 300,
|
|
1534
|
+
S: this,
|
|
1535
|
+
C: (f, a) => f(...a)
|
|
1536
|
+
});
|
|
1537
|
+
import_log3.log.trace("dxos.mesh.connection.error", {
|
|
1538
|
+
topic: this.topic,
|
|
1539
|
+
localPeerId: this.localPeerId,
|
|
1540
|
+
remotePeerId: this.id,
|
|
1541
|
+
sessionId,
|
|
1542
|
+
initiator,
|
|
1543
|
+
err
|
|
1544
|
+
}, {
|
|
1545
|
+
F: __dxlog_file3,
|
|
1546
|
+
L: 301,
|
|
1547
|
+
S: this,
|
|
1548
|
+
C: (f, a) => f(...a)
|
|
1549
|
+
});
|
|
1550
|
+
void this.closeConnection(err);
|
|
1551
|
+
});
|
|
1552
|
+
this.connection = connection;
|
|
1553
|
+
return connection;
|
|
1554
|
+
}
|
|
1555
|
+
async closeConnection(err) {
|
|
1556
|
+
if (!this.connection) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const connection = this.connection;
|
|
1560
|
+
(0, import_log3.log)("closing...", {
|
|
1561
|
+
peerId: this.id,
|
|
1562
|
+
sessionId: connection.sessionId
|
|
1563
|
+
}, {
|
|
1564
|
+
F: __dxlog_file3,
|
|
1565
|
+
L: 326,
|
|
1566
|
+
S: this,
|
|
1567
|
+
C: (f, a) => f(...a)
|
|
1568
|
+
});
|
|
1569
|
+
await connection.close(err);
|
|
1570
|
+
(0, import_log3.log)("closed", {
|
|
1571
|
+
peerId: this.id,
|
|
1572
|
+
sessionId: connection.sessionId
|
|
1573
|
+
}, {
|
|
1574
|
+
F: __dxlog_file3,
|
|
1575
|
+
L: 332,
|
|
1576
|
+
S: this,
|
|
1577
|
+
C: (f, a) => f(...a)
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
async onSignal(message) {
|
|
1581
|
+
if (!this.connection) {
|
|
1582
|
+
(0, import_log3.log)("dropping signal message for non-existent connection", {
|
|
1583
|
+
message
|
|
1584
|
+
}, {
|
|
1585
|
+
F: __dxlog_file3,
|
|
1586
|
+
L: 337,
|
|
1587
|
+
S: this,
|
|
1588
|
+
C: (f, a) => f(...a)
|
|
1589
|
+
});
|
|
1590
|
+
return;
|
|
1591
|
+
}
|
|
1592
|
+
await this.connection.signal(message);
|
|
1593
|
+
}
|
|
1594
|
+
async destroy() {
|
|
1595
|
+
await this._ctx.dispose();
|
|
1596
|
+
(0, import_log3.log)("Destroying peer", {
|
|
1597
|
+
peerId: this.id,
|
|
1598
|
+
topic: this.topic
|
|
1599
|
+
}, {
|
|
1600
|
+
F: __dxlog_file3,
|
|
1601
|
+
L: 347,
|
|
1602
|
+
S: this,
|
|
1603
|
+
C: (f, a) => f(...a)
|
|
1604
|
+
});
|
|
1605
|
+
await this?.connection?.close();
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
_ts_decorate2([
|
|
1609
|
+
import_async3.synchronized
|
|
1610
|
+
], Peer.prototype, "destroy", null);
|
|
1611
|
+
var increaseInterval = (interval) => {
|
|
1612
|
+
if (interval === 0) {
|
|
1613
|
+
return 50;
|
|
1614
|
+
} else if (interval < 500) {
|
|
1615
|
+
return 500;
|
|
1616
|
+
} else if (interval < 1e3) {
|
|
1617
|
+
return 1e3;
|
|
1618
|
+
} else if (interval < 5e3) {
|
|
1619
|
+
return 5e3;
|
|
1620
|
+
}
|
|
1621
|
+
return 1e4;
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
// packages/core/mesh/network-manager/src/signal/swarm-messenger.ts
|
|
1625
|
+
var import_context3 = require("@dxos/context");
|
|
1626
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
1627
|
+
var import_keys4 = require("@dxos/keys");
|
|
1628
|
+
var import_log4 = require("@dxos/log");
|
|
1629
|
+
var import_protocols3 = require("@dxos/protocols");
|
|
1630
|
+
var import_util2 = require("@dxos/util");
|
|
1631
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
1632
|
+
var SwarmMessage = import_protocols3.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
1633
|
+
var SwarmMessenger = class {
|
|
1634
|
+
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
1635
|
+
this._ctx = new import_context3.Context();
|
|
1636
|
+
this._offerRecords = new import_util2.ComplexMap((key) => key.toHex());
|
|
1637
|
+
this._sendMessage = sendMessage;
|
|
1638
|
+
this._onSignal = onSignal;
|
|
1639
|
+
this._onOffer = onOffer;
|
|
1640
|
+
this._topic = topic;
|
|
1641
|
+
}
|
|
1642
|
+
async receiveMessage({ author, recipient, payload }) {
|
|
1643
|
+
if (payload.type_url !== "dxos.mesh.swarm.SwarmMessage") {
|
|
1644
|
+
return;
|
|
1645
|
+
}
|
|
1646
|
+
const message = SwarmMessage.decode(payload.value);
|
|
1647
|
+
if (!this._topic.equals(message.topic)) {
|
|
1648
|
+
return;
|
|
1649
|
+
}
|
|
1650
|
+
(0, import_log4.log)("received", {
|
|
1651
|
+
from: author,
|
|
1652
|
+
to: recipient,
|
|
1653
|
+
msg: message
|
|
1654
|
+
}, {
|
|
1655
|
+
F: __dxlog_file4,
|
|
1656
|
+
L: 69,
|
|
1657
|
+
S: this,
|
|
1658
|
+
C: (f, a) => f(...a)
|
|
1659
|
+
});
|
|
1660
|
+
if (message.data?.offer) {
|
|
1661
|
+
await this._handleOffer({
|
|
1662
|
+
author,
|
|
1663
|
+
recipient,
|
|
1664
|
+
message
|
|
1665
|
+
});
|
|
1666
|
+
} else if (message.data?.answer) {
|
|
1667
|
+
await this._resolveAnswers(message);
|
|
1668
|
+
} else if (message.data?.signal) {
|
|
1669
|
+
await this._handleSignal({
|
|
1670
|
+
author,
|
|
1671
|
+
recipient,
|
|
1672
|
+
message
|
|
1673
|
+
});
|
|
1674
|
+
} else if (message.data?.signalBatch) {
|
|
1675
|
+
await this._handleSignal({
|
|
1676
|
+
author,
|
|
1677
|
+
recipient,
|
|
1678
|
+
message
|
|
1679
|
+
});
|
|
1680
|
+
} else {
|
|
1681
|
+
import_log4.log.warn("unknown message", {
|
|
1682
|
+
message
|
|
1683
|
+
}, {
|
|
1684
|
+
F: __dxlog_file4,
|
|
1685
|
+
L: 80,
|
|
1686
|
+
S: this,
|
|
1687
|
+
C: (f, a) => f(...a)
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
async signal(message) {
|
|
1692
|
+
(0, import_invariant3.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
1693
|
+
F: __dxlog_file4,
|
|
1694
|
+
L: 85,
|
|
1695
|
+
S: this,
|
|
1696
|
+
A: [
|
|
1697
|
+
"message.data?.signal || message.data?.signalBatch",
|
|
1698
|
+
"'Invalid message'"
|
|
1699
|
+
]
|
|
1700
|
+
});
|
|
1701
|
+
await this._sendReliableMessage({
|
|
1702
|
+
author: message.author,
|
|
1703
|
+
recipient: message.recipient,
|
|
1704
|
+
message
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
async offer(message) {
|
|
1708
|
+
const networkMessage = {
|
|
1709
|
+
...message,
|
|
1710
|
+
messageId: import_keys4.PublicKey.random()
|
|
1711
|
+
};
|
|
1712
|
+
return new Promise((resolve, reject) => {
|
|
1713
|
+
this._offerRecords.set(networkMessage.messageId, {
|
|
1714
|
+
resolve
|
|
1715
|
+
});
|
|
1716
|
+
this._sendReliableMessage({
|
|
1717
|
+
author: message.author,
|
|
1718
|
+
recipient: message.recipient,
|
|
1719
|
+
message: networkMessage
|
|
1720
|
+
}).catch((err) => reject(err));
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
async _sendReliableMessage({ author, recipient, message }) {
|
|
1724
|
+
const networkMessage = {
|
|
1725
|
+
...message,
|
|
1726
|
+
// Setting unique message_id if it not specified yet.
|
|
1727
|
+
messageId: message.messageId ?? import_keys4.PublicKey.random()
|
|
1728
|
+
};
|
|
1729
|
+
(0, import_log4.log)("sending", {
|
|
1730
|
+
from: author,
|
|
1731
|
+
to: recipient,
|
|
1732
|
+
msg: networkMessage
|
|
1733
|
+
}, {
|
|
1734
|
+
F: __dxlog_file4,
|
|
1735
|
+
L: 123,
|
|
1736
|
+
S: this,
|
|
1737
|
+
C: (f, a) => f(...a)
|
|
1738
|
+
});
|
|
1739
|
+
await this._sendMessage({
|
|
1740
|
+
author,
|
|
1741
|
+
recipient,
|
|
1742
|
+
payload: {
|
|
1743
|
+
type_url: "dxos.mesh.swarm.SwarmMessage",
|
|
1744
|
+
value: SwarmMessage.encode(networkMessage)
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
async _resolveAnswers(message) {
|
|
1749
|
+
(0, import_invariant3.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
1750
|
+
F: __dxlog_file4,
|
|
1751
|
+
L: 135,
|
|
1752
|
+
S: this,
|
|
1753
|
+
A: [
|
|
1754
|
+
"message.data?.answer?.offerMessageId",
|
|
1755
|
+
"'No offerMessageId'"
|
|
1756
|
+
]
|
|
1757
|
+
});
|
|
1758
|
+
const offerRecord = this._offerRecords.get(message.data.answer.offerMessageId);
|
|
1759
|
+
if (offerRecord) {
|
|
1760
|
+
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
1761
|
+
(0, import_invariant3.invariant)(message.data?.answer, "No answer", {
|
|
1762
|
+
F: __dxlog_file4,
|
|
1763
|
+
L: 139,
|
|
1634
1764
|
S: this,
|
|
1635
|
-
|
|
1765
|
+
A: [
|
|
1766
|
+
"message.data?.answer",
|
|
1767
|
+
"'No answer'"
|
|
1768
|
+
]
|
|
1636
1769
|
});
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
localPeerId: this.localPeerId,
|
|
1640
|
-
remotePeerId: this.id,
|
|
1641
|
-
sessionId,
|
|
1642
|
-
initiator,
|
|
1643
|
-
err
|
|
1770
|
+
(0, import_log4.log)("resolving", {
|
|
1771
|
+
answer: message.data.answer
|
|
1644
1772
|
}, {
|
|
1645
|
-
F:
|
|
1646
|
-
L:
|
|
1773
|
+
F: __dxlog_file4,
|
|
1774
|
+
L: 140,
|
|
1647
1775
|
S: this,
|
|
1648
1776
|
C: (f, a) => f(...a)
|
|
1649
1777
|
});
|
|
1650
|
-
|
|
1651
|
-
});
|
|
1652
|
-
this.connection = connection;
|
|
1653
|
-
return connection;
|
|
1654
|
-
}
|
|
1655
|
-
async closeConnection(err) {
|
|
1656
|
-
if (!this.connection) {
|
|
1657
|
-
return;
|
|
1778
|
+
offerRecord.resolve(message.data.answer);
|
|
1658
1779
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
F: __dxlog_file3,
|
|
1665
|
-
L: 321,
|
|
1666
|
-
S: this,
|
|
1667
|
-
C: (f, a) => f(...a)
|
|
1668
|
-
});
|
|
1669
|
-
await connection.close(err);
|
|
1670
|
-
(0, import_log3.log)("closed", {
|
|
1671
|
-
peerId: this.id,
|
|
1672
|
-
sessionId: connection.sessionId
|
|
1673
|
-
}, {
|
|
1674
|
-
F: __dxlog_file3,
|
|
1675
|
-
L: 327,
|
|
1780
|
+
}
|
|
1781
|
+
async _handleOffer({ author, recipient, message }) {
|
|
1782
|
+
(0, import_invariant3.invariant)(message.data.offer, "No offer", {
|
|
1783
|
+
F: __dxlog_file4,
|
|
1784
|
+
L: 154,
|
|
1676
1785
|
S: this,
|
|
1677
|
-
|
|
1786
|
+
A: [
|
|
1787
|
+
"message.data.offer",
|
|
1788
|
+
"'No offer'"
|
|
1789
|
+
]
|
|
1678
1790
|
});
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1791
|
+
const offerMessage = {
|
|
1792
|
+
author,
|
|
1793
|
+
recipient,
|
|
1794
|
+
...message,
|
|
1795
|
+
data: {
|
|
1796
|
+
offer: message.data.offer
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
const answer = await this._onOffer(offerMessage);
|
|
1800
|
+
answer.offerMessageId = message.messageId;
|
|
1801
|
+
try {
|
|
1802
|
+
await this._sendReliableMessage({
|
|
1803
|
+
author: recipient,
|
|
1804
|
+
recipient: author,
|
|
1805
|
+
message: {
|
|
1806
|
+
topic: message.topic,
|
|
1807
|
+
sessionId: message.sessionId,
|
|
1808
|
+
data: {
|
|
1809
|
+
answer
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
});
|
|
1813
|
+
} catch (err) {
|
|
1814
|
+
import_log4.log.warn("error sending answer", {
|
|
1815
|
+
err
|
|
1684
1816
|
}, {
|
|
1685
|
-
F:
|
|
1686
|
-
L:
|
|
1817
|
+
F: __dxlog_file4,
|
|
1818
|
+
L: 174,
|
|
1687
1819
|
S: this,
|
|
1688
1820
|
C: (f, a) => f(...a)
|
|
1689
1821
|
});
|
|
1690
|
-
return;
|
|
1691
1822
|
}
|
|
1692
|
-
await this.connection.signal(message);
|
|
1693
1823
|
}
|
|
1694
|
-
async
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
topic: this.topic
|
|
1699
|
-
}, {
|
|
1700
|
-
F: __dxlog_file3,
|
|
1701
|
-
L: 342,
|
|
1824
|
+
async _handleSignal({ author, recipient, message }) {
|
|
1825
|
+
(0, import_invariant3.invariant)(message.messageId, void 0, {
|
|
1826
|
+
F: __dxlog_file4,
|
|
1827
|
+
L: 187,
|
|
1702
1828
|
S: this,
|
|
1703
|
-
|
|
1829
|
+
A: [
|
|
1830
|
+
"message.messageId",
|
|
1831
|
+
""
|
|
1832
|
+
]
|
|
1704
1833
|
});
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1834
|
+
(0, import_invariant3.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
1835
|
+
F: __dxlog_file4,
|
|
1836
|
+
L: 188,
|
|
1837
|
+
S: this,
|
|
1838
|
+
A: [
|
|
1839
|
+
"message.data.signal || message.data.signalBatch",
|
|
1840
|
+
"'Invalid message'"
|
|
1841
|
+
]
|
|
1842
|
+
});
|
|
1843
|
+
const signalMessage = {
|
|
1844
|
+
author,
|
|
1845
|
+
recipient,
|
|
1846
|
+
...message,
|
|
1847
|
+
data: {
|
|
1848
|
+
signal: message.data.signal,
|
|
1849
|
+
signalBatch: message.data.signalBatch
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
await this._onSignal(signalMessage);
|
|
1720
1853
|
}
|
|
1721
|
-
return 1e4;
|
|
1722
1854
|
};
|
|
1723
1855
|
|
|
1724
1856
|
// packages/core/mesh/network-manager/src/swarm/swarm.ts
|
|
@@ -1732,7 +1864,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1732
1864
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1733
1865
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1734
1866
|
}
|
|
1735
|
-
var
|
|
1867
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1736
1868
|
var INITIATION_DELAY = 100;
|
|
1737
1869
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1738
1870
|
var Swarm = class {
|
|
@@ -1750,28 +1882,28 @@ var Swarm = class {
|
|
|
1750
1882
|
this._initiationDelay = _initiationDelay;
|
|
1751
1883
|
this._ctx = new import_context4.Context();
|
|
1752
1884
|
this._listeningHandle = void 0;
|
|
1753
|
-
this._peers = new
|
|
1754
|
-
this._instanceId =
|
|
1755
|
-
this.connectionAdded = new
|
|
1756
|
-
this.disconnected = new
|
|
1757
|
-
this.connected = new
|
|
1885
|
+
this._peers = new import_util3.ComplexMap(import_keys5.PublicKey.hash);
|
|
1886
|
+
this._instanceId = import_keys5.PublicKey.random().toHex();
|
|
1887
|
+
this.connectionAdded = new import_async4.Event();
|
|
1888
|
+
this.disconnected = new import_async4.Event();
|
|
1889
|
+
this.connected = new import_async4.Event();
|
|
1758
1890
|
this.errors = new import_debug2.ErrorStream();
|
|
1759
|
-
|
|
1891
|
+
import_log5.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.begin({
|
|
1760
1892
|
id: this._instanceId,
|
|
1761
1893
|
data: {
|
|
1762
1894
|
topic: this._topic.toHex(),
|
|
1763
1895
|
peerId: this._ownPeerId.toHex()
|
|
1764
1896
|
}
|
|
1765
1897
|
}), {
|
|
1766
|
-
F:
|
|
1898
|
+
F: __dxlog_file5,
|
|
1767
1899
|
L: 88,
|
|
1768
1900
|
S: this,
|
|
1769
1901
|
C: (f, a) => f(...a)
|
|
1770
1902
|
});
|
|
1771
|
-
(0,
|
|
1903
|
+
(0, import_log5.log)("creating swarm", {
|
|
1772
1904
|
peerId: _ownPeerId
|
|
1773
1905
|
}, {
|
|
1774
|
-
F:
|
|
1906
|
+
F: __dxlog_file5,
|
|
1775
1907
|
L: 92,
|
|
1776
1908
|
S: this,
|
|
1777
1909
|
C: (f, a) => f(...a)
|
|
@@ -1783,17 +1915,17 @@ var Swarm = class {
|
|
|
1783
1915
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
1784
1916
|
topic: this._topic
|
|
1785
1917
|
});
|
|
1786
|
-
|
|
1918
|
+
import_log5.log.trace("dxos.mesh.swarm.constructor", import_protocols4.trace.end({
|
|
1787
1919
|
id: this._instanceId
|
|
1788
1920
|
}), {
|
|
1789
|
-
F:
|
|
1921
|
+
F: __dxlog_file5,
|
|
1790
1922
|
L: 101,
|
|
1791
1923
|
S: this,
|
|
1792
1924
|
C: (f, a) => f(...a)
|
|
1793
1925
|
});
|
|
1794
1926
|
}
|
|
1795
1927
|
get connections() {
|
|
1796
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
1928
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(import_util3.isNotNullOrUndefined);
|
|
1797
1929
|
}
|
|
1798
1930
|
get ownPeerId() {
|
|
1799
1931
|
return this._ownPeerId;
|
|
@@ -1809,7 +1941,7 @@ var Swarm = class {
|
|
|
1809
1941
|
}
|
|
1810
1942
|
async open() {
|
|
1811
1943
|
(0, import_invariant4.invariant)(!this._listeningHandle, void 0, {
|
|
1812
|
-
F:
|
|
1944
|
+
F: __dxlog_file5,
|
|
1813
1945
|
L: 128,
|
|
1814
1946
|
S: this,
|
|
1815
1947
|
A: [
|
|
@@ -1821,10 +1953,10 @@ var Swarm = class {
|
|
|
1821
1953
|
peerId: this._ownPeerId,
|
|
1822
1954
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1823
1955
|
onMessage: async (message) => {
|
|
1824
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1956
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log5.log.warn("Error while receiving message", {
|
|
1825
1957
|
err
|
|
1826
1958
|
}, {
|
|
1827
|
-
F:
|
|
1959
|
+
F: __dxlog_file5,
|
|
1828
1960
|
L: 135,
|
|
1829
1961
|
S: this,
|
|
1830
1962
|
C: (f, a) => f(...a)
|
|
@@ -1833,8 +1965,8 @@ var Swarm = class {
|
|
|
1833
1965
|
});
|
|
1834
1966
|
}
|
|
1835
1967
|
async destroy() {
|
|
1836
|
-
(0,
|
|
1837
|
-
F:
|
|
1968
|
+
(0, import_log5.log)("destroying...", void 0, {
|
|
1969
|
+
F: __dxlog_file5,
|
|
1838
1970
|
L: 141,
|
|
1839
1971
|
S: this,
|
|
1840
1972
|
C: (f, a) => f(...a)
|
|
@@ -1844,8 +1976,8 @@ var Swarm = class {
|
|
|
1844
1976
|
await this._ctx.dispose();
|
|
1845
1977
|
await this._topology.destroy();
|
|
1846
1978
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
1847
|
-
(0,
|
|
1848
|
-
F:
|
|
1979
|
+
(0, import_log5.log)("destroyed", void 0, {
|
|
1980
|
+
F: __dxlog_file5,
|
|
1849
1981
|
L: 148,
|
|
1850
1982
|
S: this,
|
|
1851
1983
|
C: (f, a) => f(...a)
|
|
@@ -1853,7 +1985,7 @@ var Swarm = class {
|
|
|
1853
1985
|
}
|
|
1854
1986
|
async setTopology(topology) {
|
|
1855
1987
|
(0, import_invariant4.invariant)(!this._ctx.disposed, "Swarm is offline", {
|
|
1856
|
-
F:
|
|
1988
|
+
F: __dxlog_file5,
|
|
1857
1989
|
L: 152,
|
|
1858
1990
|
S: this,
|
|
1859
1991
|
A: [
|
|
@@ -1864,11 +1996,11 @@ var Swarm = class {
|
|
|
1864
1996
|
if (topology === this._topology) {
|
|
1865
1997
|
return;
|
|
1866
1998
|
}
|
|
1867
|
-
(0,
|
|
1999
|
+
(0, import_log5.log)("setting topology", {
|
|
1868
2000
|
previous: getClassName(this._topology),
|
|
1869
2001
|
topology: getClassName(topology)
|
|
1870
2002
|
}, {
|
|
1871
|
-
F:
|
|
2003
|
+
F: __dxlog_file5,
|
|
1872
2004
|
L: 156,
|
|
1873
2005
|
S: this,
|
|
1874
2006
|
C: (f, a) => f(...a)
|
|
@@ -1879,17 +2011,17 @@ var Swarm = class {
|
|
|
1879
2011
|
this._topology.update();
|
|
1880
2012
|
}
|
|
1881
2013
|
onSwarmEvent(swarmEvent) {
|
|
1882
|
-
(0,
|
|
2014
|
+
(0, import_log5.log)("swarm event", {
|
|
1883
2015
|
swarmEvent
|
|
1884
2016
|
}, {
|
|
1885
|
-
F:
|
|
2017
|
+
F: __dxlog_file5,
|
|
1886
2018
|
L: 169,
|
|
1887
2019
|
S: this,
|
|
1888
2020
|
C: (f, a) => f(...a)
|
|
1889
2021
|
});
|
|
1890
2022
|
if (this._ctx.disposed) {
|
|
1891
|
-
(0,
|
|
1892
|
-
F:
|
|
2023
|
+
(0, import_log5.log)("swarm event ignored for disposed swarm", void 0, {
|
|
2024
|
+
F: __dxlog_file5,
|
|
1893
2025
|
L: 172,
|
|
1894
2026
|
S: this,
|
|
1895
2027
|
C: (f, a) => f(...a)
|
|
@@ -1897,11 +2029,11 @@ var Swarm = class {
|
|
|
1897
2029
|
return;
|
|
1898
2030
|
}
|
|
1899
2031
|
if (swarmEvent.peerAvailable) {
|
|
1900
|
-
const peerId =
|
|
1901
|
-
(0,
|
|
2032
|
+
const peerId = import_keys5.PublicKey.from(swarmEvent.peerAvailable.peer);
|
|
2033
|
+
(0, import_log5.log)("new peer", {
|
|
1902
2034
|
peerId
|
|
1903
2035
|
}, {
|
|
1904
|
-
F:
|
|
2036
|
+
F: __dxlog_file5,
|
|
1905
2037
|
L: 178,
|
|
1906
2038
|
S: this,
|
|
1907
2039
|
C: (f, a) => f(...a)
|
|
@@ -1911,12 +2043,12 @@ var Swarm = class {
|
|
|
1911
2043
|
peer.advertizing = true;
|
|
1912
2044
|
}
|
|
1913
2045
|
} else if (swarmEvent.peerLeft) {
|
|
1914
|
-
const peer = this._peers.get(
|
|
2046
|
+
const peer = this._peers.get(import_keys5.PublicKey.from(swarmEvent.peerLeft.peer));
|
|
1915
2047
|
if (peer) {
|
|
1916
2048
|
peer.advertizing = false;
|
|
1917
2049
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1918
|
-
void this._destroyPeer(peer.id).catch((err) =>
|
|
1919
|
-
F:
|
|
2050
|
+
void this._destroyPeer(peer.id).catch((err) => import_log5.log.catch(err, void 0, {
|
|
2051
|
+
F: __dxlog_file5,
|
|
1920
2052
|
L: 189,
|
|
1921
2053
|
S: this,
|
|
1922
2054
|
C: (f, a) => f(...a)
|
|
@@ -1927,17 +2059,17 @@ var Swarm = class {
|
|
|
1927
2059
|
this._topology.update();
|
|
1928
2060
|
}
|
|
1929
2061
|
async onOffer(message) {
|
|
1930
|
-
(0,
|
|
2062
|
+
(0, import_log5.log)("offer", {
|
|
1931
2063
|
message
|
|
1932
2064
|
}, {
|
|
1933
|
-
F:
|
|
2065
|
+
F: __dxlog_file5,
|
|
1934
2066
|
L: 199,
|
|
1935
2067
|
S: this,
|
|
1936
2068
|
C: (f, a) => f(...a)
|
|
1937
2069
|
});
|
|
1938
2070
|
if (this._ctx.disposed) {
|
|
1939
|
-
(0,
|
|
1940
|
-
F:
|
|
2071
|
+
(0, import_log5.log)("ignored for disposed swarm", void 0, {
|
|
2072
|
+
F: __dxlog_file5,
|
|
1941
2073
|
L: 201,
|
|
1942
2074
|
S: this,
|
|
1943
2075
|
C: (f, a) => f(...a)
|
|
@@ -1947,7 +2079,7 @@ var Swarm = class {
|
|
|
1947
2079
|
};
|
|
1948
2080
|
}
|
|
1949
2081
|
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
1950
|
-
F:
|
|
2082
|
+
F: __dxlog_file5,
|
|
1951
2083
|
L: 206,
|
|
1952
2084
|
S: this,
|
|
1953
2085
|
A: [
|
|
@@ -1956,10 +2088,10 @@ var Swarm = class {
|
|
|
1956
2088
|
]
|
|
1957
2089
|
});
|
|
1958
2090
|
if (!message.recipient?.equals(this._ownPeerId)) {
|
|
1959
|
-
(0,
|
|
2091
|
+
(0, import_log5.log)("rejecting offer with incorrect peerId", {
|
|
1960
2092
|
message
|
|
1961
2093
|
}, {
|
|
1962
|
-
F:
|
|
2094
|
+
F: __dxlog_file5,
|
|
1963
2095
|
L: 208,
|
|
1964
2096
|
S: this,
|
|
1965
2097
|
C: (f, a) => f(...a)
|
|
@@ -1969,10 +2101,10 @@ var Swarm = class {
|
|
|
1969
2101
|
};
|
|
1970
2102
|
}
|
|
1971
2103
|
if (!message.topic?.equals(this._topic)) {
|
|
1972
|
-
(0,
|
|
2104
|
+
(0, import_log5.log)("rejecting offer with incorrect topic", {
|
|
1973
2105
|
message
|
|
1974
2106
|
}, {
|
|
1975
|
-
F:
|
|
2107
|
+
F: __dxlog_file5,
|
|
1976
2108
|
L: 212,
|
|
1977
2109
|
S: this,
|
|
1978
2110
|
C: (f, a) => f(...a)
|
|
@@ -1987,17 +2119,17 @@ var Swarm = class {
|
|
|
1987
2119
|
return answer;
|
|
1988
2120
|
}
|
|
1989
2121
|
async onSignal(message) {
|
|
1990
|
-
(0,
|
|
2122
|
+
(0, import_log5.log)("signal", {
|
|
1991
2123
|
message
|
|
1992
2124
|
}, {
|
|
1993
|
-
F:
|
|
2125
|
+
F: __dxlog_file5,
|
|
1994
2126
|
L: 223,
|
|
1995
2127
|
S: this,
|
|
1996
2128
|
C: (f, a) => f(...a)
|
|
1997
2129
|
});
|
|
1998
2130
|
if (this._ctx.disposed) {
|
|
1999
|
-
|
|
2000
|
-
F:
|
|
2131
|
+
import_log5.log.info("ignored for offline swarm", void 0, {
|
|
2132
|
+
F: __dxlog_file5,
|
|
2001
2133
|
L: 225,
|
|
2002
2134
|
S: this,
|
|
2003
2135
|
C: (f, a) => f(...a)
|
|
@@ -2005,7 +2137,7 @@ var Swarm = class {
|
|
|
2005
2137
|
return;
|
|
2006
2138
|
}
|
|
2007
2139
|
(0, import_invariant4.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
2008
|
-
F:
|
|
2140
|
+
F: __dxlog_file5,
|
|
2009
2141
|
L: 228,
|
|
2010
2142
|
S: this,
|
|
2011
2143
|
A: [
|
|
@@ -2014,7 +2146,7 @@ var Swarm = class {
|
|
|
2014
2146
|
]
|
|
2015
2147
|
});
|
|
2016
2148
|
(0, import_invariant4.invariant)(message.topic?.equals(this._topic), void 0, {
|
|
2017
|
-
F:
|
|
2149
|
+
F: __dxlog_file5,
|
|
2018
2150
|
L: 232,
|
|
2019
2151
|
S: this,
|
|
2020
2152
|
A: [
|
|
@@ -2023,7 +2155,7 @@ var Swarm = class {
|
|
|
2023
2155
|
]
|
|
2024
2156
|
});
|
|
2025
2157
|
(0, import_invariant4.invariant)(message.author, void 0, {
|
|
2026
|
-
F:
|
|
2158
|
+
F: __dxlog_file5,
|
|
2027
2159
|
L: 233,
|
|
2028
2160
|
S: this,
|
|
2029
2161
|
A: [
|
|
@@ -2083,7 +2215,7 @@ var Swarm = class {
|
|
|
2083
2215
|
}
|
|
2084
2216
|
async _destroyPeer(peerId) {
|
|
2085
2217
|
(0, import_invariant4.invariant)(this._peers.has(peerId), void 0, {
|
|
2086
|
-
F:
|
|
2218
|
+
F: __dxlog_file5,
|
|
2087
2219
|
L: 303,
|
|
2088
2220
|
S: this,
|
|
2089
2221
|
A: [
|
|
@@ -2105,12 +2237,12 @@ var Swarm = class {
|
|
|
2105
2237
|
if (this._ctx.disposed) {
|
|
2106
2238
|
return;
|
|
2107
2239
|
}
|
|
2108
|
-
(0,
|
|
2240
|
+
(0, import_async4.scheduleTask)(this._ctx, async () => {
|
|
2109
2241
|
try {
|
|
2110
2242
|
await this._initiateConnection(peer);
|
|
2111
2243
|
} catch (err) {
|
|
2112
|
-
(0,
|
|
2113
|
-
F:
|
|
2244
|
+
(0, import_log5.log)("initiation error", err, {
|
|
2245
|
+
F: __dxlog_file5,
|
|
2114
2246
|
L: 329,
|
|
2115
2247
|
S: this,
|
|
2116
2248
|
C: (f, a) => f(...a)
|
|
@@ -2122,7 +2254,7 @@ var Swarm = class {
|
|
|
2122
2254
|
if (this._ctx.disposed) {
|
|
2123
2255
|
return;
|
|
2124
2256
|
}
|
|
2125
|
-
(0,
|
|
2257
|
+
(0, import_async4.scheduleTask)(this._ctx, async () => {
|
|
2126
2258
|
await this._closeConnection(peer);
|
|
2127
2259
|
this._topology.update();
|
|
2128
2260
|
});
|
|
@@ -2135,15 +2267,15 @@ var Swarm = class {
|
|
|
2135
2267
|
async _initiateConnection(remoteId) {
|
|
2136
2268
|
const ctx = this._ctx;
|
|
2137
2269
|
if (remoteId.toHex() < this._ownPeerId.toHex()) {
|
|
2138
|
-
(0,
|
|
2270
|
+
(0, import_log5.log)("initiation delay", {
|
|
2139
2271
|
remoteId
|
|
2140
2272
|
}, {
|
|
2141
|
-
F:
|
|
2273
|
+
F: __dxlog_file5,
|
|
2142
2274
|
L: 356,
|
|
2143
2275
|
S: this,
|
|
2144
2276
|
C: (f, a) => f(...a)
|
|
2145
2277
|
});
|
|
2146
|
-
await (0,
|
|
2278
|
+
await (0, import_async4.sleep)(this._initiationDelay);
|
|
2147
2279
|
}
|
|
2148
2280
|
if (ctx.disposed) {
|
|
2149
2281
|
return;
|
|
@@ -2152,20 +2284,20 @@ var Swarm = class {
|
|
|
2152
2284
|
if (peer.connection) {
|
|
2153
2285
|
return;
|
|
2154
2286
|
}
|
|
2155
|
-
(0,
|
|
2287
|
+
(0, import_log5.log)("initiating connection...", {
|
|
2156
2288
|
remoteId
|
|
2157
2289
|
}, {
|
|
2158
|
-
F:
|
|
2290
|
+
F: __dxlog_file5,
|
|
2159
2291
|
L: 370,
|
|
2160
2292
|
S: this,
|
|
2161
2293
|
C: (f, a) => f(...a)
|
|
2162
2294
|
});
|
|
2163
2295
|
await peer.initiateConnection();
|
|
2164
2296
|
this._topology.update();
|
|
2165
|
-
(0,
|
|
2297
|
+
(0, import_log5.log)("initiated", {
|
|
2166
2298
|
remoteId
|
|
2167
2299
|
}, {
|
|
2168
|
-
F:
|
|
2300
|
+
F: __dxlog_file5,
|
|
2169
2301
|
L: 373,
|
|
2170
2302
|
S: this,
|
|
2171
2303
|
C: (f, a) => f(...a)
|
|
@@ -2180,44 +2312,43 @@ var Swarm = class {
|
|
|
2180
2312
|
}
|
|
2181
2313
|
};
|
|
2182
2314
|
_ts_decorate3([
|
|
2183
|
-
|
|
2315
|
+
import_log5.logInfo
|
|
2184
2316
|
], Swarm.prototype, "_instanceId", void 0);
|
|
2185
2317
|
_ts_decorate3([
|
|
2186
|
-
|
|
2318
|
+
import_log5.logInfo
|
|
2187
2319
|
], Swarm.prototype, "ownPeerId", null);
|
|
2188
2320
|
_ts_decorate3([
|
|
2189
|
-
|
|
2321
|
+
import_log5.logInfo
|
|
2190
2322
|
], Swarm.prototype, "topic", null);
|
|
2191
2323
|
_ts_decorate3([
|
|
2192
|
-
|
|
2324
|
+
import_async4.synchronized
|
|
2193
2325
|
], Swarm.prototype, "onSwarmEvent", null);
|
|
2194
2326
|
_ts_decorate3([
|
|
2195
|
-
|
|
2327
|
+
import_async4.synchronized
|
|
2196
2328
|
], Swarm.prototype, "onOffer", null);
|
|
2197
2329
|
_ts_decorate3([
|
|
2198
|
-
|
|
2330
|
+
import_async4.synchronized
|
|
2199
2331
|
], Swarm.prototype, "goOffline", null);
|
|
2200
2332
|
_ts_decorate3([
|
|
2201
|
-
|
|
2333
|
+
import_async4.synchronized
|
|
2202
2334
|
], Swarm.prototype, "goOnline", null);
|
|
2203
2335
|
|
|
2204
2336
|
// packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts
|
|
2205
|
-
var
|
|
2206
|
-
var
|
|
2207
|
-
var
|
|
2208
|
-
var
|
|
2209
|
-
var
|
|
2337
|
+
var import_async5 = require("@dxos/async");
|
|
2338
|
+
var import_keys6 = require("@dxos/keys");
|
|
2339
|
+
var import_log6 = require("@dxos/log");
|
|
2340
|
+
var import_util4 = require("@dxos/util");
|
|
2341
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
2210
2342
|
var SwarmMapper = class {
|
|
2211
2343
|
get peers() {
|
|
2212
2344
|
return Array.from(this._peers.values());
|
|
2213
2345
|
}
|
|
2214
|
-
// prettier-ignore
|
|
2215
2346
|
constructor(_swarm) {
|
|
2216
2347
|
this._swarm = _swarm;
|
|
2217
|
-
this._subscriptions = new
|
|
2218
|
-
this._connectionSubscriptions = new
|
|
2219
|
-
this._peers = new
|
|
2220
|
-
this.mapUpdated = new
|
|
2348
|
+
this._subscriptions = new import_async5.EventSubscriptions();
|
|
2349
|
+
this._connectionSubscriptions = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
|
|
2350
|
+
this._peers = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
|
|
2351
|
+
this.mapUpdated = new import_async5.Event();
|
|
2221
2352
|
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
2222
2353
|
this._update();
|
|
2223
2354
|
this._connectionSubscriptions.set(connection.remoteId, connection.stateChanged.on(() => {
|
|
@@ -2232,9 +2363,9 @@ var SwarmMapper = class {
|
|
|
2232
2363
|
this._update();
|
|
2233
2364
|
}
|
|
2234
2365
|
_update() {
|
|
2235
|
-
(0,
|
|
2236
|
-
F:
|
|
2237
|
-
L:
|
|
2366
|
+
(0, import_log6.log)("updating swarm", void 0, {
|
|
2367
|
+
F: __dxlog_file6,
|
|
2368
|
+
L: 72,
|
|
2238
2369
|
S: this,
|
|
2239
2370
|
C: (f, a) => f(...a)
|
|
2240
2371
|
});
|
|
@@ -2253,12 +2384,12 @@ var SwarmMapper = class {
|
|
|
2253
2384
|
]
|
|
2254
2385
|
});
|
|
2255
2386
|
}
|
|
2256
|
-
(0,
|
|
2387
|
+
(0, import_log6.log)("graph changed", {
|
|
2257
2388
|
directConnections: this._swarm.connections.length,
|
|
2258
2389
|
totalPeersInSwarm: this._peers.size
|
|
2259
2390
|
}, {
|
|
2260
|
-
F:
|
|
2261
|
-
L:
|
|
2391
|
+
F: __dxlog_file6,
|
|
2392
|
+
L: 113,
|
|
2262
2393
|
S: this,
|
|
2263
2394
|
C: (f, a) => f(...a)
|
|
2264
2395
|
});
|
|
@@ -2272,14 +2403,14 @@ var SwarmMapper = class {
|
|
|
2272
2403
|
};
|
|
2273
2404
|
|
|
2274
2405
|
// packages/core/mesh/network-manager/src/swarm/connection-limiter.ts
|
|
2275
|
-
var
|
|
2406
|
+
var import_async6 = require("@dxos/async");
|
|
2276
2407
|
var import_context5 = require("@dxos/context");
|
|
2277
2408
|
var import_invariant5 = require("@dxos/invariant");
|
|
2278
|
-
var
|
|
2279
|
-
var
|
|
2409
|
+
var import_keys7 = require("@dxos/keys");
|
|
2410
|
+
var import_log7 = require("@dxos/log");
|
|
2280
2411
|
var import_protocols5 = require("@dxos/protocols");
|
|
2281
|
-
var
|
|
2282
|
-
var
|
|
2412
|
+
var import_util5 = require("@dxos/util");
|
|
2413
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2283
2414
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2284
2415
|
var ConnectionLimiter = class {
|
|
2285
2416
|
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
@@ -2287,8 +2418,8 @@ var ConnectionLimiter = class {
|
|
|
2287
2418
|
/**
|
|
2288
2419
|
* Queue of promises to resolve when initiating connections amount is below the limit.
|
|
2289
2420
|
*/
|
|
2290
|
-
this._waitingPromises = new
|
|
2291
|
-
this.resolveWaitingPromises = new
|
|
2421
|
+
this._waitingPromises = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
|
|
2422
|
+
this.resolveWaitingPromises = new import_async6.DeferredTask(this._ctx, async () => {
|
|
2292
2423
|
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2293
2424
|
resolve();
|
|
2294
2425
|
});
|
|
@@ -2300,7 +2431,7 @@ var ConnectionLimiter = class {
|
|
|
2300
2431
|
*/
|
|
2301
2432
|
async connecting(sessionId) {
|
|
2302
2433
|
(0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2303
|
-
F:
|
|
2434
|
+
F: __dxlog_file7,
|
|
2304
2435
|
L: 48,
|
|
2305
2436
|
S: this,
|
|
2306
2437
|
A: [
|
|
@@ -2308,10 +2439,10 @@ var ConnectionLimiter = class {
|
|
|
2308
2439
|
"'Peer is already waiting for connection'"
|
|
2309
2440
|
]
|
|
2310
2441
|
});
|
|
2311
|
-
(0,
|
|
2442
|
+
(0, import_log7.log)("waiting", {
|
|
2312
2443
|
sessionId
|
|
2313
2444
|
}, {
|
|
2314
|
-
F:
|
|
2445
|
+
F: __dxlog_file7,
|
|
2315
2446
|
L: 49,
|
|
2316
2447
|
S: this,
|
|
2317
2448
|
C: (f, a) => f(...a)
|
|
@@ -2323,10 +2454,10 @@ var ConnectionLimiter = class {
|
|
|
2323
2454
|
});
|
|
2324
2455
|
this.resolveWaitingPromises.schedule();
|
|
2325
2456
|
});
|
|
2326
|
-
(0,
|
|
2457
|
+
(0, import_log7.log)("allow", {
|
|
2327
2458
|
sessionId
|
|
2328
2459
|
}, {
|
|
2329
|
-
F:
|
|
2460
|
+
F: __dxlog_file7,
|
|
2330
2461
|
L: 57,
|
|
2331
2462
|
S: this,
|
|
2332
2463
|
C: (f, a) => f(...a)
|
|
@@ -2336,10 +2467,10 @@ var ConnectionLimiter = class {
|
|
|
2336
2467
|
* Rejects promise returned by `connecting` method.
|
|
2337
2468
|
*/
|
|
2338
2469
|
doneConnecting(sessionId) {
|
|
2339
|
-
(0,
|
|
2470
|
+
(0, import_log7.log)("done", {
|
|
2340
2471
|
sessionId
|
|
2341
2472
|
}, {
|
|
2342
|
-
F:
|
|
2473
|
+
F: __dxlog_file7,
|
|
2343
2474
|
L: 64,
|
|
2344
2475
|
S: this,
|
|
2345
2476
|
C: (f, a) => f(...a)
|
|
@@ -2367,8 +2498,8 @@ var ConnectionLog = class {
|
|
|
2367
2498
|
/**
|
|
2368
2499
|
* SwarmId => info
|
|
2369
2500
|
*/
|
|
2370
|
-
this._swarms = new
|
|
2371
|
-
this.update = new
|
|
2501
|
+
this._swarms = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
|
|
2502
|
+
this.update = new import_async7.Event();
|
|
2372
2503
|
}
|
|
2373
2504
|
getSwarmInfo(swarmId) {
|
|
2374
2505
|
return this._swarms.get(swarmId) ?? (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
|
|
@@ -2378,13 +2509,13 @@ var ConnectionLog = class {
|
|
|
2378
2509
|
}
|
|
2379
2510
|
joinedSwarm(swarm) {
|
|
2380
2511
|
const info = {
|
|
2381
|
-
id:
|
|
2512
|
+
id: import_keys8.PublicKey.from(swarm._instanceId),
|
|
2382
2513
|
topic: swarm.topic,
|
|
2383
2514
|
isActive: true,
|
|
2384
2515
|
label: swarm.label,
|
|
2385
2516
|
connections: []
|
|
2386
2517
|
};
|
|
2387
|
-
this._swarms.set(
|
|
2518
|
+
this._swarms.set(import_keys8.PublicKey.from(swarm._instanceId), info);
|
|
2388
2519
|
this.update.emit();
|
|
2389
2520
|
swarm.connectionAdded.on((connection) => {
|
|
2390
2521
|
const connectionInfo = {
|
|
@@ -2414,24 +2545,24 @@ var ConnectionLog = class {
|
|
|
2414
2545
|
});
|
|
2415
2546
|
}
|
|
2416
2547
|
leftSwarm(swarm) {
|
|
2417
|
-
this.getSwarmInfo(
|
|
2548
|
+
this.getSwarmInfo(import_keys8.PublicKey.from(swarm._instanceId)).isActive = false;
|
|
2418
2549
|
this.update.emit();
|
|
2419
2550
|
}
|
|
2420
2551
|
};
|
|
2421
2552
|
|
|
2422
2553
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
2423
|
-
var
|
|
2554
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2424
2555
|
var NetworkManager = class {
|
|
2425
2556
|
constructor({ transportFactory, signalManager, log: log1 }) {
|
|
2426
2557
|
/**
|
|
2427
2558
|
* @internal
|
|
2428
2559
|
*/
|
|
2429
|
-
this._swarms = new
|
|
2430
|
-
this._mappers = new
|
|
2560
|
+
this._swarms = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
2561
|
+
this._mappers = new import_util7.ComplexMap(import_keys9.PublicKey.hash);
|
|
2431
2562
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
2432
|
-
this.connectionStateChanged = new
|
|
2433
|
-
this.topicsUpdated = new
|
|
2434
|
-
this._instanceId =
|
|
2563
|
+
this.connectionStateChanged = new import_async8.Event();
|
|
2564
|
+
this.topicsUpdated = new import_async8.Event();
|
|
2565
|
+
this._instanceId = import_keys9.PublicKey.random().toHex();
|
|
2435
2566
|
this._transportFactory = transportFactory;
|
|
2436
2567
|
this._signalManager = signalManager;
|
|
2437
2568
|
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
|
|
@@ -2465,20 +2596,20 @@ var NetworkManager = class {
|
|
|
2465
2596
|
return this._swarms.get(topic);
|
|
2466
2597
|
}
|
|
2467
2598
|
async open() {
|
|
2468
|
-
|
|
2599
|
+
import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
|
|
2469
2600
|
id: this._instanceId
|
|
2470
2601
|
}), {
|
|
2471
|
-
F:
|
|
2602
|
+
F: __dxlog_file8,
|
|
2472
2603
|
L: 130,
|
|
2473
2604
|
S: this,
|
|
2474
2605
|
C: (f, a) => f(...a)
|
|
2475
2606
|
});
|
|
2476
2607
|
await this._messenger.open();
|
|
2477
2608
|
await this._signalManager.open();
|
|
2478
|
-
|
|
2609
|
+
import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
|
|
2479
2610
|
id: this._instanceId
|
|
2480
2611
|
}), {
|
|
2481
|
-
F:
|
|
2612
|
+
F: __dxlog_file8,
|
|
2482
2613
|
L: 133,
|
|
2483
2614
|
S: this,
|
|
2484
2615
|
C: (f, a) => f(...a)
|
|
@@ -2487,8 +2618,8 @@ var NetworkManager = class {
|
|
|
2487
2618
|
async close() {
|
|
2488
2619
|
for (const topic of this._swarms.keys()) {
|
|
2489
2620
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2490
|
-
(0,
|
|
2491
|
-
F:
|
|
2621
|
+
(0, import_log8.log)(err, void 0, {
|
|
2622
|
+
F: __dxlog_file8,
|
|
2492
2623
|
L: 139,
|
|
2493
2624
|
S: this,
|
|
2494
2625
|
C: (f, a) => f(...a)
|
|
@@ -2502,8 +2633,8 @@ var NetworkManager = class {
|
|
|
2502
2633
|
* Join the swarm.
|
|
2503
2634
|
*/
|
|
2504
2635
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
2505
|
-
(0, import_invariant6.invariant)(
|
|
2506
|
-
F:
|
|
2636
|
+
(0, import_invariant6.invariant)(import_keys9.PublicKey.isPublicKey(topic), void 0, {
|
|
2637
|
+
F: __dxlog_file8,
|
|
2507
2638
|
L: 157,
|
|
2508
2639
|
S: this,
|
|
2509
2640
|
A: [
|
|
@@ -2511,8 +2642,8 @@ var NetworkManager = class {
|
|
|
2511
2642
|
""
|
|
2512
2643
|
]
|
|
2513
2644
|
});
|
|
2514
|
-
(0, import_invariant6.invariant)(
|
|
2515
|
-
F:
|
|
2645
|
+
(0, import_invariant6.invariant)(import_keys9.PublicKey.isPublicKey(peerId), void 0, {
|
|
2646
|
+
F: __dxlog_file8,
|
|
2516
2647
|
L: 158,
|
|
2517
2648
|
S: this,
|
|
2518
2649
|
A: [
|
|
@@ -2521,7 +2652,7 @@ var NetworkManager = class {
|
|
|
2521
2652
|
]
|
|
2522
2653
|
});
|
|
2523
2654
|
(0, import_invariant6.invariant)(topology, void 0, {
|
|
2524
|
-
F:
|
|
2655
|
+
F: __dxlog_file8,
|
|
2525
2656
|
L: 159,
|
|
2526
2657
|
S: this,
|
|
2527
2658
|
A: [
|
|
@@ -2530,7 +2661,7 @@ var NetworkManager = class {
|
|
|
2530
2661
|
]
|
|
2531
2662
|
});
|
|
2532
2663
|
(0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
|
|
2533
|
-
F:
|
|
2664
|
+
F: __dxlog_file8,
|
|
2534
2665
|
L: 160,
|
|
2535
2666
|
S: this,
|
|
2536
2667
|
A: [
|
|
@@ -2539,24 +2670,24 @@ var NetworkManager = class {
|
|
|
2539
2670
|
]
|
|
2540
2671
|
});
|
|
2541
2672
|
if (this._swarms.has(topic)) {
|
|
2542
|
-
throw new Error(`Already connected to swarm: ${
|
|
2673
|
+
throw new Error(`Already connected to swarm: ${import_keys9.PublicKey.from(topic)}`);
|
|
2543
2674
|
}
|
|
2544
|
-
(0,
|
|
2545
|
-
topic:
|
|
2675
|
+
(0, import_log8.log)("joining", {
|
|
2676
|
+
topic: import_keys9.PublicKey.from(topic),
|
|
2546
2677
|
peerId,
|
|
2547
2678
|
topology: topology.toString()
|
|
2548
2679
|
}, {
|
|
2549
|
-
F:
|
|
2680
|
+
F: __dxlog_file8,
|
|
2550
2681
|
L: 165,
|
|
2551
2682
|
S: this,
|
|
2552
2683
|
C: (f, a) => f(...a)
|
|
2553
2684
|
});
|
|
2554
2685
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2555
2686
|
swarm.errors.handle((error) => {
|
|
2556
|
-
(0,
|
|
2687
|
+
(0, import_log8.log)("swarm error", {
|
|
2557
2688
|
error
|
|
2558
2689
|
}, {
|
|
2559
|
-
F:
|
|
2690
|
+
F: __dxlog_file8,
|
|
2560
2691
|
L: 178,
|
|
2561
2692
|
S: this,
|
|
2562
2693
|
C: (f, a) => f(...a)
|
|
@@ -2568,19 +2699,19 @@ var NetworkManager = class {
|
|
|
2568
2699
|
this._signalConnection.join({
|
|
2569
2700
|
topic,
|
|
2570
2701
|
peerId
|
|
2571
|
-
}).catch((error) =>
|
|
2572
|
-
F:
|
|
2702
|
+
}).catch((error) => import_log8.log.catch(error, void 0, {
|
|
2703
|
+
F: __dxlog_file8,
|
|
2573
2704
|
L: 187,
|
|
2574
2705
|
S: this,
|
|
2575
2706
|
C: (f, a) => f(...a)
|
|
2576
2707
|
}));
|
|
2577
2708
|
this.topicsUpdated.emit();
|
|
2578
2709
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2579
|
-
(0,
|
|
2580
|
-
topic:
|
|
2710
|
+
(0, import_log8.log)("joined", {
|
|
2711
|
+
topic: import_keys9.PublicKey.from(topic),
|
|
2581
2712
|
count: this._swarms.size
|
|
2582
2713
|
}, {
|
|
2583
|
-
F:
|
|
2714
|
+
F: __dxlog_file8,
|
|
2584
2715
|
L: 191,
|
|
2585
2716
|
S: this,
|
|
2586
2717
|
C: (f, a) => f(...a)
|
|
@@ -2596,10 +2727,10 @@ var NetworkManager = class {
|
|
|
2596
2727
|
if (!this._swarms.has(topic)) {
|
|
2597
2728
|
return;
|
|
2598
2729
|
}
|
|
2599
|
-
(0,
|
|
2600
|
-
topic:
|
|
2730
|
+
(0, import_log8.log)("leaving", {
|
|
2731
|
+
topic: import_keys9.PublicKey.from(topic)
|
|
2601
2732
|
}, {
|
|
2602
|
-
F:
|
|
2733
|
+
F: __dxlog_file8,
|
|
2603
2734
|
L: 207,
|
|
2604
2735
|
S: this,
|
|
2605
2736
|
C: (f, a) => f(...a)
|
|
@@ -2616,11 +2747,11 @@ var NetworkManager = class {
|
|
|
2616
2747
|
await swarm.destroy();
|
|
2617
2748
|
this._swarms.delete(topic);
|
|
2618
2749
|
await this.topicsUpdated.emit();
|
|
2619
|
-
(0,
|
|
2620
|
-
topic:
|
|
2750
|
+
(0, import_log8.log)("left", {
|
|
2751
|
+
topic: import_keys9.PublicKey.from(topic),
|
|
2621
2752
|
count: this._swarms.size
|
|
2622
2753
|
}, {
|
|
2623
|
-
F:
|
|
2754
|
+
F: __dxlog_file8,
|
|
2624
2755
|
L: 221,
|
|
2625
2756
|
S: this,
|
|
2626
2757
|
C: (f, a) => f(...a)
|
|
@@ -2656,14 +2787,14 @@ var NetworkManager = class {
|
|
|
2656
2787
|
|
|
2657
2788
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
2658
2789
|
var import_invariant7 = require("@dxos/invariant");
|
|
2659
|
-
var
|
|
2790
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2660
2791
|
var FullyConnectedTopology = class {
|
|
2661
2792
|
toString() {
|
|
2662
2793
|
return "FullyConnectedTopology";
|
|
2663
2794
|
}
|
|
2664
2795
|
init(controller) {
|
|
2665
2796
|
(0, import_invariant7.invariant)(!this._controller, "Already initialized", {
|
|
2666
|
-
F:
|
|
2797
|
+
F: __dxlog_file9,
|
|
2667
2798
|
L: 18,
|
|
2668
2799
|
S: this,
|
|
2669
2800
|
A: [
|
|
@@ -2675,7 +2806,7 @@ var FullyConnectedTopology = class {
|
|
|
2675
2806
|
}
|
|
2676
2807
|
update() {
|
|
2677
2808
|
(0, import_invariant7.invariant)(this._controller, "Not initialized", {
|
|
2678
|
-
F:
|
|
2809
|
+
F: __dxlog_file9,
|
|
2679
2810
|
L: 23,
|
|
2680
2811
|
S: this,
|
|
2681
2812
|
A: [
|
|
@@ -2698,20 +2829,20 @@ var FullyConnectedTopology = class {
|
|
|
2698
2829
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
2699
2830
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
2700
2831
|
var import_invariant8 = require("@dxos/invariant");
|
|
2701
|
-
var
|
|
2832
|
+
var import_log9 = require("@dxos/log");
|
|
2702
2833
|
|
|
2703
2834
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
2704
2835
|
var import_invariant9 = require("@dxos/invariant");
|
|
2705
|
-
var
|
|
2836
|
+
var import_log10 = require("@dxos/log");
|
|
2706
2837
|
|
|
2707
2838
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
2708
2839
|
var import_node_stream = require("node:stream");
|
|
2709
|
-
var
|
|
2840
|
+
var import_async9 = require("@dxos/async");
|
|
2710
2841
|
var import_debug4 = require("@dxos/debug");
|
|
2711
2842
|
var import_invariant10 = require("@dxos/invariant");
|
|
2712
|
-
var
|
|
2713
|
-
var
|
|
2714
|
-
var
|
|
2843
|
+
var import_keys10 = require("@dxos/keys");
|
|
2844
|
+
var import_log11 = require("@dxos/log");
|
|
2845
|
+
var import_util8 = require("@dxos/util");
|
|
2715
2846
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
2716
2847
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2717
2848
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2722,7 +2853,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2722
2853
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2723
2854
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2724
2855
|
}
|
|
2725
|
-
var
|
|
2856
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2726
2857
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2727
2858
|
var createStreamDelay = (delay) => {
|
|
2728
2859
|
return new import_node_stream.Transform({
|
|
@@ -2738,26 +2869,26 @@ var MemoryTransportFactory = {
|
|
|
2738
2869
|
var MemoryTransport = class _MemoryTransport {
|
|
2739
2870
|
static {
|
|
2740
2871
|
// TODO(burdon): Remove static properties (inject context into constructor).
|
|
2741
|
-
this._connections = new
|
|
2872
|
+
this._connections = new import_util8.ComplexMap(import_keys10.PublicKey.hash);
|
|
2742
2873
|
}
|
|
2743
2874
|
constructor(options) {
|
|
2744
2875
|
this.options = options;
|
|
2745
|
-
this.closed = new
|
|
2746
|
-
this.connected = new
|
|
2876
|
+
this.closed = new import_async9.Event();
|
|
2877
|
+
this.connected = new import_async9.Event();
|
|
2747
2878
|
this.errors = new import_debug4.ErrorStream();
|
|
2748
|
-
this._instanceId =
|
|
2749
|
-
this._remote = new
|
|
2879
|
+
this._instanceId = import_keys10.PublicKey.random();
|
|
2880
|
+
this._remote = new import_async9.Trigger();
|
|
2750
2881
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2751
2882
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2752
2883
|
this._destroyed = false;
|
|
2753
|
-
(0,
|
|
2754
|
-
F:
|
|
2884
|
+
(0, import_log11.log)("creating", void 0, {
|
|
2885
|
+
F: __dxlog_file10,
|
|
2755
2886
|
L: 64,
|
|
2756
2887
|
S: this,
|
|
2757
2888
|
C: (f, a) => f(...a)
|
|
2758
2889
|
});
|
|
2759
2890
|
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2760
|
-
F:
|
|
2891
|
+
F: __dxlog_file10,
|
|
2761
2892
|
L: 66,
|
|
2762
2893
|
S: this,
|
|
2763
2894
|
A: [
|
|
@@ -2768,8 +2899,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2768
2899
|
_MemoryTransport._connections.set(this._instanceId, this);
|
|
2769
2900
|
if (this.options.initiator) {
|
|
2770
2901
|
setTimeout(async () => {
|
|
2771
|
-
(0,
|
|
2772
|
-
F:
|
|
2902
|
+
(0, import_log11.log)("sending signal", void 0, {
|
|
2903
|
+
F: __dxlog_file10,
|
|
2773
2904
|
L: 73,
|
|
2774
2905
|
S: this,
|
|
2775
2906
|
C: (f, a) => f(...a)
|
|
@@ -2799,7 +2930,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2799
2930
|
return;
|
|
2800
2931
|
}
|
|
2801
2932
|
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2802
|
-
F:
|
|
2933
|
+
F: __dxlog_file10,
|
|
2803
2934
|
L: 99,
|
|
2804
2935
|
S: this,
|
|
2805
2936
|
A: [
|
|
@@ -2809,8 +2940,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2809
2940
|
});
|
|
2810
2941
|
this._remoteConnection._remoteConnection = this;
|
|
2811
2942
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2812
|
-
(0,
|
|
2813
|
-
F:
|
|
2943
|
+
(0, import_log11.log)("connected", void 0, {
|
|
2944
|
+
F: __dxlog_file10,
|
|
2814
2945
|
L: 103,
|
|
2815
2946
|
S: this,
|
|
2816
2947
|
C: (f, a) => f(...a)
|
|
@@ -2827,8 +2958,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2827
2958
|
}
|
|
2828
2959
|
}
|
|
2829
2960
|
async destroy() {
|
|
2830
|
-
(0,
|
|
2831
|
-
F:
|
|
2961
|
+
(0, import_log11.log)("closing", void 0, {
|
|
2962
|
+
F: __dxlog_file10,
|
|
2832
2963
|
L: 124,
|
|
2833
2964
|
S: this,
|
|
2834
2965
|
C: (f, a) => f(...a)
|
|
@@ -2836,8 +2967,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2836
2967
|
this._destroyed = true;
|
|
2837
2968
|
_MemoryTransport._connections.delete(this._instanceId);
|
|
2838
2969
|
if (this._remoteConnection) {
|
|
2839
|
-
(0,
|
|
2840
|
-
F:
|
|
2970
|
+
(0, import_log11.log)("closing", void 0, {
|
|
2971
|
+
F: __dxlog_file10,
|
|
2841
2972
|
L: 129,
|
|
2842
2973
|
S: this,
|
|
2843
2974
|
C: (f, a) => f(...a)
|
|
@@ -2849,26 +2980,26 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2849
2980
|
this._remoteConnection.closed.emit();
|
|
2850
2981
|
this._remoteConnection._remoteConnection = void 0;
|
|
2851
2982
|
this._remoteConnection = void 0;
|
|
2852
|
-
(0,
|
|
2853
|
-
F:
|
|
2983
|
+
(0, import_log11.log)("closed", void 0, {
|
|
2984
|
+
F: __dxlog_file10,
|
|
2854
2985
|
L: 147,
|
|
2855
2986
|
S: this,
|
|
2856
2987
|
C: (f, a) => f(...a)
|
|
2857
2988
|
});
|
|
2858
2989
|
}
|
|
2859
2990
|
this.closed.emit();
|
|
2860
|
-
(0,
|
|
2861
|
-
F:
|
|
2991
|
+
(0, import_log11.log)("closed", void 0, {
|
|
2992
|
+
F: __dxlog_file10,
|
|
2862
2993
|
L: 151,
|
|
2863
2994
|
S: this,
|
|
2864
2995
|
C: (f, a) => f(...a)
|
|
2865
2996
|
});
|
|
2866
2997
|
}
|
|
2867
2998
|
signal({ payload }) {
|
|
2868
|
-
(0,
|
|
2999
|
+
(0, import_log11.log)("received signal", {
|
|
2869
3000
|
payload
|
|
2870
3001
|
}, {
|
|
2871
|
-
F:
|
|
3002
|
+
F: __dxlog_file10,
|
|
2872
3003
|
L: 155,
|
|
2873
3004
|
S: this,
|
|
2874
3005
|
C: (f, a) => f(...a)
|
|
@@ -2878,16 +3009,16 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2878
3009
|
}
|
|
2879
3010
|
const transportId = payload.transportId;
|
|
2880
3011
|
if (transportId) {
|
|
2881
|
-
const remoteId =
|
|
3012
|
+
const remoteId = import_keys10.PublicKey.fromHex(transportId);
|
|
2882
3013
|
this._remote.wake(remoteId);
|
|
2883
3014
|
}
|
|
2884
3015
|
}
|
|
2885
3016
|
};
|
|
2886
3017
|
_ts_decorate4([
|
|
2887
|
-
|
|
3018
|
+
import_log11.logInfo
|
|
2888
3019
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
2889
3020
|
_ts_decorate4([
|
|
2890
|
-
|
|
3021
|
+
import_log11.logInfo
|
|
2891
3022
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
2892
3023
|
|
|
2893
3024
|
// packages/core/mesh/network-manager/src/transport/transport.ts
|
|
@@ -2903,10 +3034,10 @@ var TransportKind;
|
|
|
2903
3034
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
|
|
2904
3035
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
2905
3036
|
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
2906
|
-
var
|
|
3037
|
+
var import_async10 = require("@dxos/async");
|
|
2907
3038
|
var import_debug5 = require("@dxos/debug");
|
|
2908
|
-
var
|
|
2909
|
-
var
|
|
3039
|
+
var import_keys11 = require("@dxos/keys");
|
|
3040
|
+
var import_log12 = require("@dxos/log");
|
|
2910
3041
|
var import_protocols7 = require("@dxos/protocols");
|
|
2911
3042
|
|
|
2912
3043
|
// packages/core/mesh/network-manager/src/transport/webrtc.ts
|
|
@@ -2917,25 +3048,25 @@ try {
|
|
|
2917
3048
|
}
|
|
2918
3049
|
|
|
2919
3050
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts
|
|
2920
|
-
var
|
|
3051
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2921
3052
|
var SimplePeerTransport = class {
|
|
2922
3053
|
constructor(params) {
|
|
2923
3054
|
this.params = params;
|
|
2924
3055
|
this._closed = false;
|
|
2925
|
-
this.closed = new
|
|
2926
|
-
this.connected = new
|
|
3056
|
+
this.closed = new import_async10.Event();
|
|
3057
|
+
this.connected = new import_async10.Event();
|
|
2927
3058
|
this.errors = new import_debug5.ErrorStream();
|
|
2928
|
-
this._instanceId =
|
|
2929
|
-
|
|
3059
|
+
this._instanceId = import_keys11.PublicKey.random().toHex();
|
|
3060
|
+
import_log12.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.begin({
|
|
2930
3061
|
id: this._instanceId
|
|
2931
3062
|
}), {
|
|
2932
|
-
F:
|
|
3063
|
+
F: __dxlog_file11,
|
|
2933
3064
|
L: 40,
|
|
2934
3065
|
S: this,
|
|
2935
3066
|
C: (f, a) => f(...a)
|
|
2936
3067
|
});
|
|
2937
|
-
(0,
|
|
2938
|
-
F:
|
|
3068
|
+
(0, import_log12.log)("created connection", params, {
|
|
3069
|
+
F: __dxlog_file11,
|
|
2939
3070
|
L: 41,
|
|
2940
3071
|
S: this,
|
|
2941
3072
|
C: (f, a) => f(...a)
|
|
@@ -2947,8 +3078,8 @@ var SimplePeerTransport = class {
|
|
|
2947
3078
|
config: this.params.webrtcConfig
|
|
2948
3079
|
});
|
|
2949
3080
|
this._peer.on("signal", async (data) => {
|
|
2950
|
-
(0,
|
|
2951
|
-
F:
|
|
3081
|
+
(0, import_log12.log)("signal", data, {
|
|
3082
|
+
F: __dxlog_file11,
|
|
2952
3083
|
L: 50,
|
|
2953
3084
|
S: this,
|
|
2954
3085
|
C: (f, a) => f(...a)
|
|
@@ -2960,8 +3091,8 @@ var SimplePeerTransport = class {
|
|
|
2960
3091
|
});
|
|
2961
3092
|
});
|
|
2962
3093
|
this._peer.on("connect", () => {
|
|
2963
|
-
(0,
|
|
2964
|
-
F:
|
|
3094
|
+
(0, import_log12.log)("connected", void 0, {
|
|
3095
|
+
F: __dxlog_file11,
|
|
2965
3096
|
L: 55,
|
|
2966
3097
|
S: this,
|
|
2967
3098
|
C: (f, a) => f(...a)
|
|
@@ -2970,8 +3101,8 @@ var SimplePeerTransport = class {
|
|
|
2970
3101
|
this.connected.emit();
|
|
2971
3102
|
});
|
|
2972
3103
|
this._peer.on("close", async () => {
|
|
2973
|
-
(0,
|
|
2974
|
-
F:
|
|
3104
|
+
(0, import_log12.log)("closed", void 0, {
|
|
3105
|
+
F: __dxlog_file11,
|
|
2975
3106
|
L: 61,
|
|
2976
3107
|
S: this,
|
|
2977
3108
|
C: (f, a) => f(...a)
|
|
@@ -2986,66 +3117,80 @@ var SimplePeerTransport = class {
|
|
|
2986
3117
|
} else {
|
|
2987
3118
|
this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
|
|
2988
3119
|
}
|
|
2989
|
-
} else if (err.name === "InvalidStateError") {
|
|
2990
|
-
this.errors.raise(new import_protocols7.ConnectionResetError("safari WebRTC error", err));
|
|
2991
3120
|
} else if ("code" in err) {
|
|
3121
|
+
import_log12.log.info("simple-peer error", err, {
|
|
3122
|
+
F: __dxlog_file11,
|
|
3123
|
+
L: 77,
|
|
3124
|
+
S: this,
|
|
3125
|
+
C: (f, a) => f(...a)
|
|
3126
|
+
});
|
|
2992
3127
|
switch (err.code) {
|
|
2993
3128
|
case "ERR_WEBRTC_SUPPORT":
|
|
2994
3129
|
this.errors.raise(new import_protocols7.ProtocolError("WebRTC not supported", err));
|
|
3130
|
+
break;
|
|
2995
3131
|
case "ERR_ICE_CONNECTION_FAILURE":
|
|
2996
3132
|
case "ERR_DATA_CHANNEL":
|
|
2997
3133
|
case "ERR_CONNECTION_FAILURE":
|
|
2998
3134
|
case "ERR_SIGNALING":
|
|
2999
3135
|
this.errors.raise(new import_protocols7.ConnectivityError("unknown communication failure", err));
|
|
3136
|
+
break;
|
|
3000
3137
|
case "ERR_CREATE_OFFER":
|
|
3001
3138
|
case "ERR_CREATE_ANSWER":
|
|
3002
3139
|
case "ERR_SET_LOCAL_DESCRIPTION":
|
|
3003
3140
|
case "ERR_SET_REMOTE_DESCRIPTION":
|
|
3004
3141
|
case "ERR_ADD_ICE_CANDIDATE":
|
|
3005
3142
|
this.errors.raise(new import_protocols7.UnknownProtocolError("unknown simple-peer library failure", err));
|
|
3143
|
+
break;
|
|
3006
3144
|
default:
|
|
3007
3145
|
this.errors.raise(new Error("unknown simple-peer error"));
|
|
3146
|
+
break;
|
|
3008
3147
|
}
|
|
3009
3148
|
} else {
|
|
3149
|
+
import_log12.log.info("unknown peer connection error", err, {
|
|
3150
|
+
F: __dxlog_file11,
|
|
3151
|
+
L: 101,
|
|
3152
|
+
S: this,
|
|
3153
|
+
C: (f, a) => f(...a)
|
|
3154
|
+
});
|
|
3010
3155
|
this.errors.raise(err);
|
|
3011
3156
|
}
|
|
3012
3157
|
try {
|
|
3013
|
-
if (typeof this._peer?._pc
|
|
3158
|
+
if (typeof this._peer?._pc?.getStats === "function") {
|
|
3014
3159
|
this._peer._pc.getStats().then((stats) => {
|
|
3015
|
-
|
|
3160
|
+
import_log12.log.warn("report after webrtc error", {
|
|
3016
3161
|
config: this.params.webrtcConfig,
|
|
3017
3162
|
stats
|
|
3018
3163
|
}, {
|
|
3019
|
-
F:
|
|
3020
|
-
L:
|
|
3164
|
+
F: __dxlog_file11,
|
|
3165
|
+
L: 109,
|
|
3021
3166
|
S: this,
|
|
3022
3167
|
C: (f, a) => f(...a)
|
|
3023
3168
|
});
|
|
3024
3169
|
});
|
|
3025
3170
|
}
|
|
3026
3171
|
} catch (err2) {
|
|
3027
|
-
|
|
3028
|
-
F:
|
|
3029
|
-
L:
|
|
3172
|
+
import_log12.log.catch(err2, void 0, {
|
|
3173
|
+
F: __dxlog_file11,
|
|
3174
|
+
L: 116,
|
|
3030
3175
|
S: this,
|
|
3031
3176
|
C: (f, a) => f(...a)
|
|
3032
3177
|
});
|
|
3033
3178
|
}
|
|
3034
3179
|
await this.destroy();
|
|
3035
3180
|
});
|
|
3036
|
-
|
|
3181
|
+
import_log12.log.trace("dxos.mesh.webrtc-transport.constructor", import_protocols7.trace.end({
|
|
3037
3182
|
id: this._instanceId
|
|
3038
3183
|
}), {
|
|
3039
|
-
F:
|
|
3040
|
-
L:
|
|
3184
|
+
F: __dxlog_file11,
|
|
3185
|
+
L: 121,
|
|
3041
3186
|
S: this,
|
|
3042
3187
|
C: (f, a) => f(...a)
|
|
3043
3188
|
});
|
|
3044
3189
|
}
|
|
3045
3190
|
async destroy() {
|
|
3046
|
-
(0,
|
|
3047
|
-
F:
|
|
3048
|
-
L:
|
|
3191
|
+
(0, import_log12.log)("closing...", void 0, {
|
|
3192
|
+
F: __dxlog_file11,
|
|
3193
|
+
L: 125,
|
|
3049
3194
|
S: this,
|
|
3050
3195
|
C: (f, a) => f(...a)
|
|
3051
3196
|
});
|
|
@@ -3053,9 +3198,9 @@ var SimplePeerTransport = class {
|
|
|
3053
3198
|
await this._disconnectStreams();
|
|
3054
3199
|
this._peer.destroy();
|
|
3055
3200
|
this.closed.emit();
|
|
3056
|
-
(0,
|
|
3057
|
-
F:
|
|
3058
|
-
L:
|
|
3201
|
+
(0, import_log12.log)("closed", void 0, {
|
|
3202
|
+
F: __dxlog_file11,
|
|
3203
|
+
L: 130,
|
|
3059
3204
|
S: this,
|
|
3060
3205
|
C: (f, a) => f(...a)
|
|
3061
3206
|
});
|
|
@@ -3082,16 +3227,15 @@ var createSimplePeerTransportFactory = (webrtcConfig) => ({
|
|
|
3082
3227
|
var import_node_stream2 = require("node:stream");
|
|
3083
3228
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
3084
3229
|
var import_invariant11 = require("@dxos/invariant");
|
|
3085
|
-
var
|
|
3086
|
-
var
|
|
3230
|
+
var import_keys12 = require("@dxos/keys");
|
|
3231
|
+
var import_log13 = require("@dxos/log");
|
|
3087
3232
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
3088
|
-
var
|
|
3089
|
-
var
|
|
3233
|
+
var import_util9 = require("@dxos/util");
|
|
3234
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
|
|
3090
3235
|
var SimplePeerTransportService = class {
|
|
3091
|
-
// prettier-ignore
|
|
3092
3236
|
constructor(_webrtcConfig) {
|
|
3093
3237
|
this._webrtcConfig = _webrtcConfig;
|
|
3094
|
-
this.transports = new
|
|
3238
|
+
this.transports = new import_util9.ComplexMap(import_keys12.PublicKey.hash);
|
|
3095
3239
|
}
|
|
3096
3240
|
open(request) {
|
|
3097
3241
|
const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
@@ -3158,7 +3302,8 @@ var SimplePeerTransportService = class {
|
|
|
3158
3302
|
const transportState = {
|
|
3159
3303
|
transport,
|
|
3160
3304
|
stream: duplex,
|
|
3161
|
-
writeCallbacks: []
|
|
3305
|
+
writeCallbacks: [],
|
|
3306
|
+
state: "OPEN"
|
|
3162
3307
|
};
|
|
3163
3308
|
ready();
|
|
3164
3309
|
this.transports.set(request.proxyId, transportState);
|
|
@@ -3167,8 +3312,8 @@ var SimplePeerTransportService = class {
|
|
|
3167
3312
|
}
|
|
3168
3313
|
async sendSignal({ proxyId, signal }) {
|
|
3169
3314
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3170
|
-
F:
|
|
3171
|
-
L:
|
|
3315
|
+
F: __dxlog_file12,
|
|
3316
|
+
L: 112,
|
|
3172
3317
|
S: this,
|
|
3173
3318
|
A: [
|
|
3174
3319
|
"this.transports.has(proxyId)",
|
|
@@ -3178,9 +3323,17 @@ var SimplePeerTransportService = class {
|
|
|
3178
3323
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
3179
3324
|
}
|
|
3180
3325
|
async sendData({ proxyId, payload }) {
|
|
3326
|
+
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3327
|
+
import_log13.log.debug("transport is closed", void 0, {
|
|
3328
|
+
F: __dxlog_file12,
|
|
3329
|
+
L: 118,
|
|
3330
|
+
S: this,
|
|
3331
|
+
C: (f, a) => f(...a)
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3181
3334
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3182
|
-
F:
|
|
3183
|
-
L:
|
|
3335
|
+
F: __dxlog_file12,
|
|
3336
|
+
L: 120,
|
|
3184
3337
|
S: this,
|
|
3185
3338
|
A: [
|
|
3186
3339
|
"this.transports.has(proxyId)",
|
|
@@ -3198,10 +3351,12 @@ var SimplePeerTransportService = class {
|
|
|
3198
3351
|
async close({ proxyId }) {
|
|
3199
3352
|
await this.transports.get(proxyId)?.transport.destroy();
|
|
3200
3353
|
await this.transports.get(proxyId)?.stream.end();
|
|
3201
|
-
this.transports.
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3354
|
+
if (this.transports.get(proxyId)) {
|
|
3355
|
+
this.transports.get(proxyId).state = "CLOSED";
|
|
3356
|
+
}
|
|
3357
|
+
(0, import_log13.log)("Closed.", void 0, {
|
|
3358
|
+
F: __dxlog_file12,
|
|
3359
|
+
L: 136,
|
|
3205
3360
|
S: this,
|
|
3206
3361
|
C: (f, a) => f(...a)
|
|
3207
3362
|
});
|
|
@@ -3210,24 +3365,23 @@ var SimplePeerTransportService = class {
|
|
|
3210
3365
|
|
|
3211
3366
|
// packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts
|
|
3212
3367
|
var import_node_stream3 = require("node:stream");
|
|
3213
|
-
var
|
|
3368
|
+
var import_async11 = require("@dxos/async");
|
|
3214
3369
|
var import_context6 = require("@dxos/context");
|
|
3215
3370
|
var import_debug6 = require("@dxos/debug");
|
|
3216
3371
|
var import_invariant12 = require("@dxos/invariant");
|
|
3217
|
-
var
|
|
3218
|
-
var
|
|
3372
|
+
var import_keys13 = require("@dxos/keys");
|
|
3373
|
+
var import_log14 = require("@dxos/log");
|
|
3219
3374
|
var import_protocols8 = require("@dxos/protocols");
|
|
3220
3375
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
3221
|
-
var
|
|
3222
|
-
var
|
|
3376
|
+
var import_util10 = require("@dxos/util");
|
|
3377
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
|
|
3223
3378
|
var SimplePeerTransportProxy = class {
|
|
3224
|
-
// prettier-ignore
|
|
3225
3379
|
constructor(_params) {
|
|
3226
3380
|
this._params = _params;
|
|
3227
|
-
this._proxyId =
|
|
3381
|
+
this._proxyId = import_keys13.PublicKey.random();
|
|
3228
3382
|
this._ctx = new import_context6.Context();
|
|
3229
|
-
this.closed = new
|
|
3230
|
-
this.connected = new
|
|
3383
|
+
this.closed = new import_async11.Event();
|
|
3384
|
+
this.connected = new import_async11.Event();
|
|
3231
3385
|
this.errors = new import_debug6.ErrorStream();
|
|
3232
3386
|
this._closed = false;
|
|
3233
3387
|
this._serviceStream = this._params.bridgeService.open({
|
|
@@ -3236,9 +3390,9 @@ var SimplePeerTransportProxy = class {
|
|
|
3236
3390
|
});
|
|
3237
3391
|
this._serviceStream.waitUntilReady().then(() => {
|
|
3238
3392
|
this._serviceStream.subscribe(async (event) => {
|
|
3239
|
-
(0,
|
|
3240
|
-
F:
|
|
3241
|
-
L:
|
|
3393
|
+
(0, import_log14.log)("SimplePeerTransportProxy: event", event, {
|
|
3394
|
+
F: __dxlog_file13,
|
|
3395
|
+
L: 55,
|
|
3242
3396
|
S: this,
|
|
3243
3397
|
C: (f, a) => f(...a)
|
|
3244
3398
|
});
|
|
@@ -3256,8 +3410,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3256
3410
|
proxyId: this._proxyId,
|
|
3257
3411
|
payload: chunk
|
|
3258
3412
|
}).then(() => callback(), (err) => {
|
|
3259
|
-
|
|
3260
|
-
F:
|
|
3413
|
+
import_log14.log.catch(err, void 0, {
|
|
3414
|
+
F: __dxlog_file13,
|
|
3261
3415
|
L: 76,
|
|
3262
3416
|
S: this,
|
|
3263
3417
|
C: (f, a) => f(...a)
|
|
@@ -3265,9 +3419,9 @@ var SimplePeerTransportProxy = class {
|
|
|
3265
3419
|
});
|
|
3266
3420
|
}
|
|
3267
3421
|
}));
|
|
3268
|
-
}, (error) =>
|
|
3269
|
-
F:
|
|
3270
|
-
L:
|
|
3422
|
+
}, (error) => import_log14.log.catch(error, void 0, {
|
|
3423
|
+
F: __dxlog_file13,
|
|
3424
|
+
L: 83,
|
|
3271
3425
|
S: this,
|
|
3272
3426
|
C: (f, a) => f(...a)
|
|
3273
3427
|
}));
|
|
@@ -3288,7 +3442,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3288
3442
|
}
|
|
3289
3443
|
}
|
|
3290
3444
|
_handleData(dataEvent) {
|
|
3291
|
-
this._params.stream.write((0,
|
|
3445
|
+
this._params.stream.write((0, import_util10.arrayToBuffer)(dataEvent.payload));
|
|
3292
3446
|
}
|
|
3293
3447
|
async _handleSignal(signalEvent) {
|
|
3294
3448
|
await this._params.sendSignal(signalEvent.payload);
|
|
@@ -3311,9 +3465,9 @@ var SimplePeerTransportProxy = class {
|
|
|
3311
3465
|
proxyId: this._proxyId
|
|
3312
3466
|
});
|
|
3313
3467
|
} catch (err) {
|
|
3314
|
-
|
|
3315
|
-
F:
|
|
3316
|
-
L:
|
|
3468
|
+
import_log14.log.catch(err, void 0, {
|
|
3469
|
+
F: __dxlog_file13,
|
|
3470
|
+
L: 134,
|
|
3317
3471
|
S: this,
|
|
3318
3472
|
C: (f, a) => f(...a)
|
|
3319
3473
|
});
|
|
@@ -3348,8 +3502,8 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3348
3502
|
}
|
|
3349
3503
|
createTransport(options) {
|
|
3350
3504
|
(0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3351
|
-
F:
|
|
3352
|
-
L:
|
|
3505
|
+
F: __dxlog_file13,
|
|
3506
|
+
L: 171,
|
|
3353
3507
|
S: this,
|
|
3354
3508
|
A: [
|
|
3355
3509
|
"this._bridgeService",
|
|
@@ -3367,15 +3521,15 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3367
3521
|
};
|
|
3368
3522
|
var decodeError = (err) => {
|
|
3369
3523
|
const message = typeof err === "string" ? err : err.message;
|
|
3370
|
-
if (message.includes("
|
|
3524
|
+
if (message.includes("CONNECTION_RESET")) {
|
|
3371
3525
|
return new import_protocols8.ConnectionResetError(message);
|
|
3372
|
-
} else if (message.includes("
|
|
3526
|
+
} else if (message.includes("TIMEOUT")) {
|
|
3373
3527
|
return new import_protocols8.TimeoutError(message);
|
|
3374
|
-
} else if (message.includes("
|
|
3528
|
+
} else if (message.includes("PROTOCOL_ERROR")) {
|
|
3375
3529
|
return new import_protocols8.ProtocolError(message);
|
|
3376
|
-
} else if (message.includes("
|
|
3530
|
+
} else if (message.includes("CONNECTIVITY_ERROR")) {
|
|
3377
3531
|
return new import_protocols8.ConnectivityError(message);
|
|
3378
|
-
} else if (message.includes("
|
|
3532
|
+
} else if (message.includes("UNKNOWN_PROTOCOL_ERROR")) {
|
|
3379
3533
|
return new import_protocols8.UnknownProtocolError(message);
|
|
3380
3534
|
} else {
|
|
3381
3535
|
return typeof err === "string" ? new Error(err) : err;
|
|
@@ -3387,9 +3541,9 @@ init_datachannel();
|
|
|
3387
3541
|
|
|
3388
3542
|
// packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts
|
|
3389
3543
|
var import_stream = require("stream");
|
|
3390
|
-
var
|
|
3544
|
+
var import_async12 = require("@dxos/async");
|
|
3391
3545
|
var import_debug7 = require("@dxos/debug");
|
|
3392
|
-
var
|
|
3546
|
+
var import_log15 = require("@dxos/log");
|
|
3393
3547
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
3394
3548
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3395
3549
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -3400,7 +3554,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
3400
3554
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3401
3555
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3402
3556
|
}
|
|
3403
|
-
var
|
|
3557
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
|
|
3404
3558
|
var DATACHANNEL_LABEL = "dxos.mesh.transport";
|
|
3405
3559
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3406
3560
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
@@ -3408,11 +3562,11 @@ var LibDataChannelTransport = class {
|
|
|
3408
3562
|
constructor(params) {
|
|
3409
3563
|
this.params = params;
|
|
3410
3564
|
this._closed = false;
|
|
3411
|
-
this.closed = new
|
|
3565
|
+
this.closed = new import_async12.Event();
|
|
3412
3566
|
this._connected = false;
|
|
3413
|
-
this.connected = new
|
|
3567
|
+
this.connected = new import_async12.Event();
|
|
3414
3568
|
this.errors = new import_debug7.ErrorStream();
|
|
3415
|
-
this._readyForCandidates = new
|
|
3569
|
+
this._readyForCandidates = new import_async12.Trigger();
|
|
3416
3570
|
this._writeCallback = null;
|
|
3417
3571
|
this._peer = (async () => {
|
|
3418
3572
|
const { RTCPeerConnection: PeerConnection2 } = await Promise.resolve().then(() => (init_datachannel(), datachannel_exports));
|
|
@@ -3421,32 +3575,32 @@ var LibDataChannelTransport = class {
|
|
|
3421
3575
|
}
|
|
3422
3576
|
const peer = new PeerConnection2(params.webrtcConfig);
|
|
3423
3577
|
peer.onicecandidateerror = (event) => {
|
|
3424
|
-
|
|
3578
|
+
import_log15.log.error("peer.onicecandidateerror", {
|
|
3425
3579
|
event
|
|
3426
3580
|
}, {
|
|
3427
|
-
F:
|
|
3581
|
+
F: __dxlog_file14,
|
|
3428
3582
|
L: 53,
|
|
3429
3583
|
S: this,
|
|
3430
3584
|
C: (f, a) => f(...a)
|
|
3431
3585
|
});
|
|
3432
3586
|
};
|
|
3433
3587
|
peer.onconnectionstatechange = (event) => {
|
|
3434
|
-
|
|
3588
|
+
import_log15.log.debug("peer.onconnectionstatechange", {
|
|
3435
3589
|
event,
|
|
3436
3590
|
peerConnectionState: peer.connectionState,
|
|
3437
3591
|
transportConnectionState: this._connected
|
|
3438
3592
|
}, {
|
|
3439
|
-
F:
|
|
3593
|
+
F: __dxlog_file14,
|
|
3440
3594
|
L: 57,
|
|
3441
3595
|
S: this,
|
|
3442
3596
|
C: (f, a) => f(...a)
|
|
3443
3597
|
});
|
|
3444
3598
|
};
|
|
3445
3599
|
peer.onicecandidate = async (event) => {
|
|
3446
|
-
|
|
3600
|
+
import_log15.log.debug("peer.onicecandidate", {
|
|
3447
3601
|
event
|
|
3448
3602
|
}, {
|
|
3449
|
-
F:
|
|
3603
|
+
F: __dxlog_file14,
|
|
3450
3604
|
L: 66,
|
|
3451
3605
|
S: this,
|
|
3452
3606
|
C: (f, a) => f(...a)
|
|
@@ -3467,10 +3621,10 @@ var LibDataChannelTransport = class {
|
|
|
3467
3621
|
}
|
|
3468
3622
|
});
|
|
3469
3623
|
} catch (err) {
|
|
3470
|
-
|
|
3624
|
+
import_log15.log.warn("signaling errror", {
|
|
3471
3625
|
err
|
|
3472
3626
|
}, {
|
|
3473
|
-
F:
|
|
3627
|
+
F: __dxlog_file14,
|
|
3474
3628
|
L: 83,
|
|
3475
3629
|
S: this,
|
|
3476
3630
|
C: (f, a) => f(...a)
|
|
@@ -3481,20 +3635,20 @@ var LibDataChannelTransport = class {
|
|
|
3481
3635
|
if (params.initiator) {
|
|
3482
3636
|
peer.createOffer().then(async (offer) => {
|
|
3483
3637
|
if (peer.connectionState !== "connecting") {
|
|
3484
|
-
|
|
3638
|
+
import_log15.log.error("i am initiator but peer not in state connecting", {
|
|
3485
3639
|
peer
|
|
3486
3640
|
}, {
|
|
3487
|
-
F:
|
|
3641
|
+
F: __dxlog_file14,
|
|
3488
3642
|
L: 92,
|
|
3489
3643
|
S: this,
|
|
3490
3644
|
C: (f, a) => f(...a)
|
|
3491
3645
|
});
|
|
3492
3646
|
this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
|
|
3493
3647
|
}
|
|
3494
|
-
|
|
3648
|
+
import_log15.log.debug(`im the initiator, creating offer, peer is in state ${peer.connectionState}`, {
|
|
3495
3649
|
offer
|
|
3496
3650
|
}, {
|
|
3497
|
-
F:
|
|
3651
|
+
F: __dxlog_file14,
|
|
3498
3652
|
L: 95,
|
|
3499
3653
|
S: this,
|
|
3500
3654
|
C: (f, a) => f(...a)
|
|
@@ -3513,8 +3667,8 @@ var LibDataChannelTransport = class {
|
|
|
3513
3667
|
this.errors.raise(err);
|
|
3514
3668
|
});
|
|
3515
3669
|
this.handleChannel(peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3516
|
-
|
|
3517
|
-
F:
|
|
3670
|
+
import_log15.log.debug("created data channel", void 0, {
|
|
3671
|
+
F: __dxlog_file14,
|
|
3518
3672
|
L: 104,
|
|
3519
3673
|
S: this,
|
|
3520
3674
|
C: (f, a) => f(...a)
|
|
@@ -3524,10 +3678,10 @@ var LibDataChannelTransport = class {
|
|
|
3524
3678
|
};
|
|
3525
3679
|
} else {
|
|
3526
3680
|
peer.ondatachannel = (event) => {
|
|
3527
|
-
|
|
3681
|
+
import_log15.log.debug("peer.ondatachannel (non-initiator)", {
|
|
3528
3682
|
event
|
|
3529
3683
|
}, {
|
|
3530
|
-
F:
|
|
3684
|
+
F: __dxlog_file14,
|
|
3531
3685
|
L: 110,
|
|
3532
3686
|
S: this,
|
|
3533
3687
|
C: (f, a) => f(...a)
|
|
@@ -3544,8 +3698,8 @@ var LibDataChannelTransport = class {
|
|
|
3544
3698
|
handleChannel(dataChannel) {
|
|
3545
3699
|
this._channel = dataChannel;
|
|
3546
3700
|
this._channel.onopen = () => {
|
|
3547
|
-
|
|
3548
|
-
F:
|
|
3701
|
+
import_log15.log.debug("dataChannel.onopen", void 0, {
|
|
3702
|
+
F: __dxlog_file14,
|
|
3549
3703
|
L: 126,
|
|
3550
3704
|
S: this,
|
|
3551
3705
|
C: (f, a) => f(...a)
|
|
@@ -3560,8 +3714,8 @@ var LibDataChannelTransport = class {
|
|
|
3560
3714
|
dataChannel.send(chunk);
|
|
3561
3715
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3562
3716
|
if (this._writeCallback !== null) {
|
|
3563
|
-
|
|
3564
|
-
F:
|
|
3717
|
+
import_log15.log.error("consumer trying to write before we're ready for more data", void 0, {
|
|
3718
|
+
F: __dxlog_file14,
|
|
3565
3719
|
L: 139,
|
|
3566
3720
|
S: this,
|
|
3567
3721
|
C: (f, a) => f(...a)
|
|
@@ -3583,10 +3737,10 @@ var LibDataChannelTransport = class {
|
|
|
3583
3737
|
await this._close();
|
|
3584
3738
|
};
|
|
3585
3739
|
this._channel.onclose = async (err) => {
|
|
3586
|
-
|
|
3740
|
+
import_log15.log.info("channel onclose", {
|
|
3587
3741
|
err
|
|
3588
3742
|
}, {
|
|
3589
|
-
F:
|
|
3743
|
+
F: __dxlog_file14,
|
|
3590
3744
|
L: 159,
|
|
3591
3745
|
S: this,
|
|
3592
3746
|
C: (f, a) => f(...a)
|
|
@@ -3620,10 +3774,10 @@ var LibDataChannelTransport = class {
|
|
|
3620
3774
|
switch (data.type) {
|
|
3621
3775
|
case "offer": {
|
|
3622
3776
|
if ((await this._peer).connectionState !== "new") {
|
|
3623
|
-
|
|
3777
|
+
import_log15.log.error("received offer but peer not in state new", {
|
|
3624
3778
|
peer
|
|
3625
3779
|
}, {
|
|
3626
|
-
F:
|
|
3780
|
+
F: __dxlog_file14,
|
|
3627
3781
|
L: 194,
|
|
3628
3782
|
S: this,
|
|
3629
3783
|
C: (f, a) => f(...a)
|
|
@@ -3648,10 +3802,10 @@ var LibDataChannelTransport = class {
|
|
|
3648
3802
|
});
|
|
3649
3803
|
this._readyForCandidates.wake();
|
|
3650
3804
|
} catch (err) {
|
|
3651
|
-
|
|
3805
|
+
import_log15.log.error("can't handle offer from signalling server", {
|
|
3652
3806
|
err
|
|
3653
3807
|
}, {
|
|
3654
|
-
F:
|
|
3808
|
+
F: __dxlog_file14,
|
|
3655
3809
|
L: 205,
|
|
3656
3810
|
S: this,
|
|
3657
3811
|
C: (f, a) => f(...a)
|
|
@@ -3668,10 +3822,10 @@ var LibDataChannelTransport = class {
|
|
|
3668
3822
|
});
|
|
3669
3823
|
this._readyForCandidates.wake();
|
|
3670
3824
|
} catch (err) {
|
|
3671
|
-
|
|
3825
|
+
import_log15.log.error("can't handle answer from signalling server", {
|
|
3672
3826
|
err
|
|
3673
3827
|
}, {
|
|
3674
|
-
F:
|
|
3828
|
+
F: __dxlog_file14,
|
|
3675
3829
|
L: 216,
|
|
3676
3830
|
S: this,
|
|
3677
3831
|
C: (f, a) => f(...a)
|
|
@@ -3686,11 +3840,11 @@ var LibDataChannelTransport = class {
|
|
|
3686
3840
|
});
|
|
3687
3841
|
break;
|
|
3688
3842
|
default:
|
|
3689
|
-
|
|
3843
|
+
import_log15.log.error("unhandled signal type", {
|
|
3690
3844
|
type: data.type,
|
|
3691
3845
|
signal
|
|
3692
3846
|
}, {
|
|
3693
|
-
F:
|
|
3847
|
+
F: __dxlog_file14,
|
|
3694
3848
|
L: 227,
|
|
3695
3849
|
S: this,
|
|
3696
3850
|
C: (f, a) => f(...a)
|
|
@@ -3698,8 +3852,8 @@ var LibDataChannelTransport = class {
|
|
|
3698
3852
|
this.errors.raise(new Error(`unhandled signal type ${data.type}`));
|
|
3699
3853
|
}
|
|
3700
3854
|
}).catch((err) => {
|
|
3701
|
-
|
|
3702
|
-
F:
|
|
3855
|
+
import_log15.log.catch(err, void 0, {
|
|
3856
|
+
F: __dxlog_file14,
|
|
3703
3857
|
L: 232,
|
|
3704
3858
|
S: this,
|
|
3705
3859
|
C: (f, a) => f(...a)
|
|
@@ -3715,7 +3869,7 @@ var LibDataChannelTransport = class {
|
|
|
3715
3869
|
}
|
|
3716
3870
|
};
|
|
3717
3871
|
_ts_decorate5([
|
|
3718
|
-
|
|
3872
|
+
import_async12.synchronized
|
|
3719
3873
|
], LibDataChannelTransport.prototype, "_close", null);
|
|
3720
3874
|
var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
3721
3875
|
createTransport: (params) => new LibDataChannelTransport({
|
|
@@ -3726,10 +3880,10 @@ var createLibDataChannelTransportFactory = (webrtcConfig) => ({
|
|
|
3726
3880
|
|
|
3727
3881
|
// packages/core/mesh/network-manager/src/transport/tcp-transport.ts
|
|
3728
3882
|
var import_node_net = require("node:net");
|
|
3729
|
-
var
|
|
3883
|
+
var import_async13 = require("@dxos/async");
|
|
3730
3884
|
var import_debug8 = require("@dxos/debug");
|
|
3731
|
-
var
|
|
3732
|
-
var
|
|
3885
|
+
var import_log16 = require("@dxos/log");
|
|
3886
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
|
|
3733
3887
|
var TcpTransportFactory = {
|
|
3734
3888
|
createTransport: (params) => new TcpTransport(params)
|
|
3735
3889
|
};
|
|
@@ -3738,13 +3892,13 @@ var TcpTransport = class {
|
|
|
3738
3892
|
this.options = options;
|
|
3739
3893
|
this._server = void 0;
|
|
3740
3894
|
this._socket = void 0;
|
|
3741
|
-
this.closed = new
|
|
3742
|
-
this.connected = new
|
|
3895
|
+
this.closed = new import_async13.Event();
|
|
3896
|
+
this.connected = new import_async13.Event();
|
|
3743
3897
|
this.errors = new import_debug8.ErrorStream();
|
|
3744
3898
|
this._destroyed = false;
|
|
3745
3899
|
this._connected = false;
|
|
3746
|
-
(0,
|
|
3747
|
-
F:
|
|
3900
|
+
(0, import_log16.log)("creating", void 0, {
|
|
3901
|
+
F: __dxlog_file15,
|
|
3748
3902
|
L: 34,
|
|
3749
3903
|
S: this,
|
|
3750
3904
|
C: (f, a) => f(...a)
|
|
@@ -3753,8 +3907,8 @@ var TcpTransport = class {
|
|
|
3753
3907
|
setTimeout(async () => {
|
|
3754
3908
|
const { Server } = await import("node:net");
|
|
3755
3909
|
this._server = new Server((socket) => {
|
|
3756
|
-
(0,
|
|
3757
|
-
F:
|
|
3910
|
+
(0, import_log16.log)("new connection", void 0, {
|
|
3911
|
+
F: __dxlog_file15,
|
|
3758
3912
|
L: 42,
|
|
3759
3913
|
S: this,
|
|
3760
3914
|
C: (f, a) => f(...a)
|
|
@@ -3766,10 +3920,10 @@ var TcpTransport = class {
|
|
|
3766
3920
|
});
|
|
3767
3921
|
this._server.on("listening", () => {
|
|
3768
3922
|
const { port: port2 } = this._server.address();
|
|
3769
|
-
(0,
|
|
3923
|
+
(0, import_log16.log)("listening", {
|
|
3770
3924
|
port: port2
|
|
3771
3925
|
}, {
|
|
3772
|
-
F:
|
|
3926
|
+
F: __dxlog_file15,
|
|
3773
3927
|
L: 51,
|
|
3774
3928
|
S: this,
|
|
3775
3929
|
C: (f, a) => f(...a)
|
|
@@ -3792,8 +3946,8 @@ var TcpTransport = class {
|
|
|
3792
3946
|
}
|
|
3793
3947
|
}
|
|
3794
3948
|
async destroy() {
|
|
3795
|
-
(0,
|
|
3796
|
-
F:
|
|
3949
|
+
(0, import_log16.log)("closing", void 0, {
|
|
3950
|
+
F: __dxlog_file15,
|
|
3797
3951
|
L: 72,
|
|
3798
3952
|
S: this,
|
|
3799
3953
|
C: (f, a) => f(...a)
|
|
@@ -3803,10 +3957,10 @@ var TcpTransport = class {
|
|
|
3803
3957
|
this._destroyed = true;
|
|
3804
3958
|
}
|
|
3805
3959
|
signal({ payload }) {
|
|
3806
|
-
(0,
|
|
3960
|
+
(0, import_log16.log)("received signal", {
|
|
3807
3961
|
payload
|
|
3808
3962
|
}, {
|
|
3809
|
-
F:
|
|
3963
|
+
F: __dxlog_file15,
|
|
3810
3964
|
L: 80,
|
|
3811
3965
|
S: this,
|
|
3812
3966
|
C: (f, a) => f(...a)
|
|
@@ -3822,11 +3976,11 @@ var TcpTransport = class {
|
|
|
3822
3976
|
});
|
|
3823
3977
|
}
|
|
3824
3978
|
_handleSocket(socket) {
|
|
3825
|
-
(0,
|
|
3979
|
+
(0, import_log16.log)("handling socket", {
|
|
3826
3980
|
remotePort: socket.remotePort,
|
|
3827
3981
|
localPort: socket.localPort
|
|
3828
3982
|
}, {
|
|
3829
|
-
F:
|
|
3983
|
+
F: __dxlog_file15,
|
|
3830
3984
|
L: 91,
|
|
3831
3985
|
S: this,
|
|
3832
3986
|
C: (f, a) => f(...a)
|
|
@@ -3835,10 +3989,10 @@ var TcpTransport = class {
|
|
|
3835
3989
|
this.connected.emit();
|
|
3836
3990
|
this.options.stream.pipe(this._socket).pipe(this.options.stream);
|
|
3837
3991
|
this._socket.on("connect", () => {
|
|
3838
|
-
(0,
|
|
3992
|
+
(0, import_log16.log)("connected to", {
|
|
3839
3993
|
port: this._socket?.remotePort
|
|
3840
3994
|
}, {
|
|
3841
|
-
F:
|
|
3995
|
+
F: __dxlog_file15,
|
|
3842
3996
|
L: 97,
|
|
3843
3997
|
S: this,
|
|
3844
3998
|
C: (f, a) => f(...a)
|
|
@@ -3854,118 +4008,6 @@ var TcpTransport = class {
|
|
|
3854
4008
|
}
|
|
3855
4009
|
};
|
|
3856
4010
|
|
|
3857
|
-
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
3858
|
-
var import_async13 = require("@dxos/async");
|
|
3859
|
-
var import_keys13 = require("@dxos/keys");
|
|
3860
|
-
var import_log16 = require("@dxos/log");
|
|
3861
|
-
var import_teleport2 = require("@dxos/teleport");
|
|
3862
|
-
var import_util10 = require("@dxos/util");
|
|
3863
|
-
|
|
3864
|
-
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
3865
|
-
var import_teleport = require("@dxos/teleport");
|
|
3866
|
-
var createTeleportProtocolFactory = (onConnection) => {
|
|
3867
|
-
return (params) => {
|
|
3868
|
-
const teleport = new import_teleport.Teleport(params);
|
|
3869
|
-
return {
|
|
3870
|
-
stream: teleport.stream,
|
|
3871
|
-
open: async () => {
|
|
3872
|
-
await teleport.open();
|
|
3873
|
-
await onConnection(teleport);
|
|
3874
|
-
},
|
|
3875
|
-
close: async () => {
|
|
3876
|
-
await teleport.close();
|
|
3877
|
-
},
|
|
3878
|
-
abort: async () => {
|
|
3879
|
-
await teleport.abort();
|
|
3880
|
-
}
|
|
3881
|
-
};
|
|
3882
|
-
};
|
|
3883
|
-
};
|
|
3884
|
-
|
|
3885
|
-
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
3886
|
-
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts";
|
|
3887
|
-
var TestWireProtocol = class {
|
|
3888
|
-
constructor(peerId, _extensionFactory = () => []) {
|
|
3889
|
-
this.peerId = peerId;
|
|
3890
|
-
this._extensionFactory = _extensionFactory;
|
|
3891
|
-
this.connections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
3892
|
-
this.streamConnections = new import_util10.ComplexMap(import_keys13.PublicKey.hash);
|
|
3893
|
-
this.connected = new import_async13.Event();
|
|
3894
|
-
this.disconnected = new import_async13.Event();
|
|
3895
|
-
this.otherConnections = new import_util10.ComplexMap(({ remotePeerId, extension }) => remotePeerId.toHex() + extension);
|
|
3896
|
-
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
3897
|
-
(0, import_log16.log)("create", {
|
|
3898
|
-
remotePeerId: teleport.remotePeerId
|
|
3899
|
-
}, {
|
|
3900
|
-
F: __dxlog_file15,
|
|
3901
|
-
L: 38,
|
|
3902
|
-
S: this,
|
|
3903
|
-
C: (f, a) => f(...a)
|
|
3904
|
-
});
|
|
3905
|
-
const extension = new import_teleport2.TestExtension({
|
|
3906
|
-
onClose: async () => {
|
|
3907
|
-
this.connections.delete(teleport.remotePeerId);
|
|
3908
|
-
this.disconnected.emit(teleport.remotePeerId);
|
|
3909
|
-
}
|
|
3910
|
-
});
|
|
3911
|
-
this.connections.set(teleport.remotePeerId, extension);
|
|
3912
|
-
teleport.addExtension("test", extension);
|
|
3913
|
-
this.connected.emit(teleport.remotePeerId);
|
|
3914
|
-
const streamExtension = new import_teleport2.TestExtensionWithStreams({
|
|
3915
|
-
onClose: async () => {
|
|
3916
|
-
this.streamConnections.delete(teleport.remotePeerId);
|
|
3917
|
-
}
|
|
3918
|
-
});
|
|
3919
|
-
this.streamConnections.set(teleport.remotePeerId, streamExtension);
|
|
3920
|
-
teleport.addExtension("test-stream", streamExtension);
|
|
3921
|
-
for (const { name, extension: extension2 } of this._extensionFactory()) {
|
|
3922
|
-
this.otherConnections.set({
|
|
3923
|
-
remotePeerId: teleport.remotePeerId,
|
|
3924
|
-
extension: name
|
|
3925
|
-
}, extension2);
|
|
3926
|
-
teleport.addExtension(name, extension2);
|
|
3927
|
-
}
|
|
3928
|
-
});
|
|
3929
|
-
}
|
|
3930
|
-
async waitForConnection(peerId) {
|
|
3931
|
-
if (this.connections.has(peerId)) {
|
|
3932
|
-
return this.connections.get(peerId);
|
|
3933
|
-
}
|
|
3934
|
-
(0, import_log16.log)("waitForConnection", {
|
|
3935
|
-
peerId
|
|
3936
|
-
}, {
|
|
3937
|
-
F: __dxlog_file15,
|
|
3938
|
-
L: 67,
|
|
3939
|
-
S: this,
|
|
3940
|
-
C: (f, a) => f(...a)
|
|
3941
|
-
});
|
|
3942
|
-
await (0, import_async13.asyncTimeout)(
|
|
3943
|
-
this.connected.waitFor((connectedId) => connectedId.equals(peerId)),
|
|
3944
|
-
// TODO(nf): Make this configurable.
|
|
3945
|
-
1e4
|
|
3946
|
-
);
|
|
3947
|
-
return this.connections.get(peerId);
|
|
3948
|
-
}
|
|
3949
|
-
async testConnection(peerId, message) {
|
|
3950
|
-
const connection = await this.waitForConnection(peerId);
|
|
3951
|
-
await connection.test(message);
|
|
3952
|
-
}
|
|
3953
|
-
async openStream(peerId, streamTag, streamLoadInterval, streamLoadChunkSize) {
|
|
3954
|
-
if (!this.streamConnections.has(peerId)) {
|
|
3955
|
-
throw new Error("Connection does not exist.");
|
|
3956
|
-
}
|
|
3957
|
-
const connection = this.streamConnections.get(peerId);
|
|
3958
|
-
return connection.addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag);
|
|
3959
|
-
}
|
|
3960
|
-
async closeStream(peerId, streamTag) {
|
|
3961
|
-
if (!this.streamConnections.has(peerId)) {
|
|
3962
|
-
throw new Error("Connection does not exist.");
|
|
3963
|
-
}
|
|
3964
|
-
const connection = this.streamConnections.get(peerId);
|
|
3965
|
-
return connection.closeStream(streamTag);
|
|
3966
|
-
}
|
|
3967
|
-
};
|
|
3968
|
-
|
|
3969
4011
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
3970
4012
|
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-builder.ts";
|
|
3971
4013
|
var port = process.env.SIGNAL_PORT ?? 4e3;
|