@dxos/network-manager 0.6.5 → 0.6.6-staging.582ce24
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-3UBXH53L.mjs → chunk-ZT4NXID2.mjs} +519 -452
- package/dist/lib/browser/chunk-ZT4NXID2.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-VXLEPDWN.cjs → chunk-DZJ3BJOK.cjs} +603 -537
- package/dist/lib/node/chunk-DZJ3BJOK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +29 -27
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +18 -18
- package/dist/types/src/signal/ice.d.ts +6 -0
- package/dist/types/src/signal/ice.d.ts.map +1 -0
- package/dist/types/src/signal/ice.test.d.ts +2 -0
- package/dist/types/src/signal/ice.test.d.ts.map +1 -0
- package/dist/types/src/signal/index.d.ts +1 -0
- package/dist/types/src/signal/index.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +5 -3
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +19 -17
- package/src/signal/ice.test.ts +42 -0
- package/src/signal/ice.ts +38 -0
- package/src/signal/index.ts +1 -0
- package/src/swarm/connection.ts +6 -2
- package/src/transport/libdatachannel-transport.ts +23 -7
- package/src/transport/simplepeer-transport-service.ts +6 -1
- package/src/transport/simplepeer-transport.ts +94 -70
- package/dist/lib/browser/chunk-3UBXH53L.mjs.map +0 -7
- package/dist/lib/node/chunk-VXLEPDWN.cjs.map +0 -7
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_DZJ3BJOK_exports = {};
|
|
30
|
+
__export(chunk_DZJ3BJOK_exports, {
|
|
31
31
|
Connection: () => Connection,
|
|
32
32
|
ConnectionLimiter: () => ConnectionLimiter,
|
|
33
33
|
ConnectionLog: () => ConnectionLog,
|
|
@@ -51,11 +51,12 @@ __export(chunk_VXLEPDWN_exports, {
|
|
|
51
51
|
TcpTransport: () => TcpTransport,
|
|
52
52
|
TcpTransportFactory: () => TcpTransportFactory,
|
|
53
53
|
TransportKind: () => TransportKind,
|
|
54
|
+
createIceProvider: () => createIceProvider,
|
|
54
55
|
createLibDataChannelTransportFactory: () => createLibDataChannelTransportFactory,
|
|
55
56
|
createSimplePeerTransportFactory: () => createSimplePeerTransportFactory,
|
|
56
57
|
createTeleportProtocolFactory: () => createTeleportProtocolFactory
|
|
57
58
|
});
|
|
58
|
-
module.exports = __toCommonJS(
|
|
59
|
+
module.exports = __toCommonJS(chunk_DZJ3BJOK_exports);
|
|
59
60
|
var import_async = require("@dxos/async");
|
|
60
61
|
var import_context = require("@dxos/context");
|
|
61
62
|
var import_debug = require("@dxos/debug");
|
|
@@ -63,95 +64,98 @@ var import_invariant = require("@dxos/invariant");
|
|
|
63
64
|
var import_keys = require("@dxos/keys");
|
|
64
65
|
var import_log = require("@dxos/log");
|
|
65
66
|
var import_protocols = require("@dxos/protocols");
|
|
67
|
+
var import_async2 = require("@dxos/async");
|
|
68
|
+
var import_log2 = require("@dxos/log");
|
|
69
|
+
var import_util = require("@dxos/util");
|
|
66
70
|
var import_context2 = require("@dxos/context");
|
|
67
71
|
var import_invariant2 = require("@dxos/invariant");
|
|
68
72
|
var import_keys2 = require("@dxos/keys");
|
|
69
|
-
var
|
|
73
|
+
var import_log3 = require("@dxos/log");
|
|
70
74
|
var import_protocols2 = require("@dxos/protocols");
|
|
71
|
-
var
|
|
72
|
-
var
|
|
75
|
+
var import_util2 = require("@dxos/util");
|
|
76
|
+
var import_async3 = require("@dxos/async");
|
|
73
77
|
var import_context3 = require("@dxos/context");
|
|
74
78
|
var import_debug2 = require("@dxos/debug");
|
|
75
79
|
var import_invariant3 = require("@dxos/invariant");
|
|
76
80
|
var import_keys3 = require("@dxos/keys");
|
|
77
|
-
var
|
|
81
|
+
var import_log4 = require("@dxos/log");
|
|
78
82
|
var import_protocols3 = require("@dxos/protocols");
|
|
79
|
-
var
|
|
80
|
-
var
|
|
83
|
+
var import_util3 = require("@dxos/util");
|
|
84
|
+
var import_async4 = require("@dxos/async");
|
|
81
85
|
var import_context4 = require("@dxos/context");
|
|
82
86
|
var import_invariant4 = require("@dxos/invariant");
|
|
83
87
|
var import_keys4 = require("@dxos/keys");
|
|
84
|
-
var import_log4 = require("@dxos/log");
|
|
85
|
-
var import_protocols4 = require("@dxos/protocols");
|
|
86
|
-
var import_async4 = require("@dxos/async");
|
|
87
|
-
var import_keys5 = require("@dxos/keys");
|
|
88
88
|
var import_log5 = require("@dxos/log");
|
|
89
|
-
var
|
|
89
|
+
var import_protocols4 = require("@dxos/protocols");
|
|
90
90
|
var import_async5 = require("@dxos/async");
|
|
91
|
+
var import_keys5 = require("@dxos/keys");
|
|
92
|
+
var import_log6 = require("@dxos/log");
|
|
93
|
+
var import_util4 = require("@dxos/util");
|
|
94
|
+
var import_async6 = require("@dxos/async");
|
|
91
95
|
var import_context5 = require("@dxos/context");
|
|
92
96
|
var import_invariant5 = require("@dxos/invariant");
|
|
93
97
|
var import_keys6 = require("@dxos/keys");
|
|
94
|
-
var
|
|
98
|
+
var import_log7 = require("@dxos/log");
|
|
95
99
|
var import_protocols5 = require("@dxos/protocols");
|
|
96
|
-
var import_util4 = require("@dxos/util");
|
|
97
|
-
var import_async6 = require("@dxos/async");
|
|
98
|
-
var import_debug3 = require("@dxos/debug");
|
|
99
|
-
var import_keys7 = require("@dxos/keys");
|
|
100
100
|
var import_util5 = require("@dxos/util");
|
|
101
101
|
var import_async7 = require("@dxos/async");
|
|
102
|
+
var import_debug3 = require("@dxos/debug");
|
|
103
|
+
var import_keys7 = require("@dxos/keys");
|
|
104
|
+
var import_util6 = require("@dxos/util");
|
|
105
|
+
var import_async8 = require("@dxos/async");
|
|
102
106
|
var import_invariant6 = require("@dxos/invariant");
|
|
103
107
|
var import_keys8 = require("@dxos/keys");
|
|
104
|
-
var
|
|
108
|
+
var import_log8 = require("@dxos/log");
|
|
105
109
|
var import_messaging = require("@dxos/messaging");
|
|
106
110
|
var import_protocols6 = require("@dxos/protocols");
|
|
107
111
|
var import_services = require("@dxos/protocols/proto/dxos/client/services");
|
|
108
|
-
var
|
|
112
|
+
var import_util7 = require("@dxos/util");
|
|
109
113
|
var import_invariant7 = require("@dxos/invariant");
|
|
110
114
|
var import_xor_distance = __toESM(require("xor-distance"));
|
|
111
115
|
var import_invariant8 = require("@dxos/invariant");
|
|
112
|
-
var import_log8 = require("@dxos/log");
|
|
113
|
-
var import_invariant9 = require("@dxos/invariant");
|
|
114
116
|
var import_log9 = require("@dxos/log");
|
|
117
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
118
|
+
var import_log10 = require("@dxos/log");
|
|
115
119
|
var import_node_stream = require("node:stream");
|
|
116
|
-
var
|
|
120
|
+
var import_async9 = require("@dxos/async");
|
|
117
121
|
var import_debug4 = require("@dxos/debug");
|
|
118
122
|
var import_invariant10 = require("@dxos/invariant");
|
|
119
123
|
var import_keys9 = require("@dxos/keys");
|
|
120
|
-
var
|
|
121
|
-
var
|
|
124
|
+
var import_log11 = require("@dxos/log");
|
|
125
|
+
var import_util8 = require("@dxos/util");
|
|
122
126
|
var import_simple_peer = __toESM(require("simple-peer"));
|
|
123
127
|
var import_tiny_invariant = __toESM(require("tiny-invariant"));
|
|
124
|
-
var
|
|
128
|
+
var import_async10 = require("@dxos/async");
|
|
125
129
|
var import_debug5 = require("@dxos/debug");
|
|
126
130
|
var import_keys10 = require("@dxos/keys");
|
|
127
|
-
var
|
|
131
|
+
var import_log12 = require("@dxos/log");
|
|
128
132
|
var import_protocols7 = require("@dxos/protocols");
|
|
129
133
|
var import_node_stream2 = require("node:stream");
|
|
130
134
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
131
135
|
var import_invariant11 = require("@dxos/invariant");
|
|
132
136
|
var import_keys11 = require("@dxos/keys");
|
|
133
|
-
var
|
|
137
|
+
var import_log13 = require("@dxos/log");
|
|
134
138
|
var import_bridge = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
135
|
-
var
|
|
139
|
+
var import_util9 = require("@dxos/util");
|
|
136
140
|
var import_node_stream3 = require("node:stream");
|
|
137
|
-
var
|
|
141
|
+
var import_async11 = require("@dxos/async");
|
|
138
142
|
var import_context6 = require("@dxos/context");
|
|
139
143
|
var import_debug6 = require("@dxos/debug");
|
|
140
144
|
var import_invariant12 = require("@dxos/invariant");
|
|
141
145
|
var import_keys12 = require("@dxos/keys");
|
|
142
|
-
var
|
|
146
|
+
var import_log14 = require("@dxos/log");
|
|
143
147
|
var import_protocols8 = require("@dxos/protocols");
|
|
144
148
|
var import_bridge2 = require("@dxos/protocols/proto/dxos/mesh/bridge");
|
|
145
|
-
var
|
|
149
|
+
var import_util10 = require("@dxos/util");
|
|
146
150
|
var import_stream = require("stream");
|
|
147
|
-
var
|
|
151
|
+
var import_async12 = require("@dxos/async");
|
|
148
152
|
var import_debug7 = require("@dxos/debug");
|
|
149
153
|
var import_invariant13 = require("@dxos/invariant");
|
|
150
|
-
var
|
|
154
|
+
var import_log15 = require("@dxos/log");
|
|
151
155
|
var import_node_net = require("node:net");
|
|
152
|
-
var
|
|
156
|
+
var import_async13 = require("@dxos/async");
|
|
153
157
|
var import_debug8 = require("@dxos/debug");
|
|
154
|
-
var
|
|
158
|
+
var import_log16 = require("@dxos/log");
|
|
155
159
|
var import_teleport = require("@dxos/teleport");
|
|
156
160
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
157
161
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -575,14 +579,14 @@ var Connection = class {
|
|
|
575
579
|
}
|
|
576
580
|
});
|
|
577
581
|
} catch (err) {
|
|
578
|
-
if (err instanceof import_protocols.CancelledError || err instanceof Error && err.message?.includes("CANCELLED")) {
|
|
582
|
+
if (err instanceof import_protocols.CancelledError || err instanceof import_context.ContextDisposedError || err instanceof Error && err.message?.includes("CANCELLED")) {
|
|
579
583
|
return;
|
|
580
584
|
}
|
|
581
585
|
import_log.log.info("signal message failed to deliver", {
|
|
582
586
|
err
|
|
583
587
|
}, {
|
|
584
588
|
F: __dxlog_file,
|
|
585
|
-
L:
|
|
589
|
+
L: 393,
|
|
586
590
|
S: this,
|
|
587
591
|
C: (f, a) => f(...a)
|
|
588
592
|
});
|
|
@@ -595,7 +599,7 @@ var Connection = class {
|
|
|
595
599
|
async signal(msg) {
|
|
596
600
|
(0, import_invariant.invariant)(msg.sessionId, void 0, {
|
|
597
601
|
F: __dxlog_file,
|
|
598
|
-
L:
|
|
602
|
+
L: 402,
|
|
599
603
|
S: this,
|
|
600
604
|
A: [
|
|
601
605
|
"msg.sessionId",
|
|
@@ -605,7 +609,7 @@ var Connection = class {
|
|
|
605
609
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
606
610
|
(0, import_log.log)("dropping signal for incorrect session id", void 0, {
|
|
607
611
|
F: __dxlog_file,
|
|
608
|
-
L:
|
|
612
|
+
L: 404,
|
|
609
613
|
S: this,
|
|
610
614
|
C: (f, a) => f(...a)
|
|
611
615
|
});
|
|
@@ -613,7 +617,7 @@ var Connection = class {
|
|
|
613
617
|
}
|
|
614
618
|
(0, import_invariant.invariant)(msg.data.signal || msg.data.signalBatch, void 0, {
|
|
615
619
|
F: __dxlog_file,
|
|
616
|
-
L:
|
|
620
|
+
L: 407,
|
|
617
621
|
S: this,
|
|
618
622
|
A: [
|
|
619
623
|
"msg.data.signal || msg.data.signalBatch",
|
|
@@ -622,7 +626,7 @@ var Connection = class {
|
|
|
622
626
|
});
|
|
623
627
|
(0, import_invariant.invariant)(msg.author?.equals(this.remoteId), void 0, {
|
|
624
628
|
F: __dxlog_file,
|
|
625
|
-
L:
|
|
629
|
+
L: 408,
|
|
626
630
|
S: this,
|
|
627
631
|
A: [
|
|
628
632
|
"msg.author?.equals(this.remoteId)",
|
|
@@ -631,7 +635,7 @@ var Connection = class {
|
|
|
631
635
|
});
|
|
632
636
|
(0, import_invariant.invariant)(msg.recipient?.equals(this.ownId), void 0, {
|
|
633
637
|
F: __dxlog_file,
|
|
634
|
-
L:
|
|
638
|
+
L: 409,
|
|
635
639
|
S: this,
|
|
636
640
|
A: [
|
|
637
641
|
"msg.recipient?.equals(this.ownId)",
|
|
@@ -655,7 +659,7 @@ var Connection = class {
|
|
|
655
659
|
msg: msg.data
|
|
656
660
|
}, {
|
|
657
661
|
F: __dxlog_file,
|
|
658
|
-
L:
|
|
662
|
+
L: 418,
|
|
659
663
|
S: this,
|
|
660
664
|
C: (f, a) => f(...a)
|
|
661
665
|
});
|
|
@@ -663,7 +667,7 @@ var Connection = class {
|
|
|
663
667
|
} else {
|
|
664
668
|
(0, import_invariant.invariant)(this._transport, "Connection not ready to accept signals.", {
|
|
665
669
|
F: __dxlog_file,
|
|
666
|
-
L:
|
|
670
|
+
L: 421,
|
|
667
671
|
S: this,
|
|
668
672
|
A: [
|
|
669
673
|
"this._transport",
|
|
@@ -676,7 +680,7 @@ var Connection = class {
|
|
|
676
680
|
msg: msg.data
|
|
677
681
|
}, {
|
|
678
682
|
F: __dxlog_file,
|
|
679
|
-
L:
|
|
683
|
+
L: 422,
|
|
680
684
|
S: this,
|
|
681
685
|
C: (f, a) => f(...a)
|
|
682
686
|
});
|
|
@@ -694,13 +698,13 @@ var Connection = class {
|
|
|
694
698
|
peerId: this.ownId
|
|
695
699
|
}, {
|
|
696
700
|
F: __dxlog_file,
|
|
697
|
-
L:
|
|
701
|
+
L: 433,
|
|
698
702
|
S: this,
|
|
699
703
|
C: (f, a) => f(...a)
|
|
700
704
|
});
|
|
701
705
|
(0, import_invariant.invariant)(state !== this._state, "Already in this state.", {
|
|
702
706
|
F: __dxlog_file,
|
|
703
|
-
L:
|
|
707
|
+
L: 434,
|
|
704
708
|
S: this,
|
|
705
709
|
A: [
|
|
706
710
|
"state !== this._state",
|
|
@@ -726,15 +730,38 @@ _ts_decorate([
|
|
|
726
730
|
_ts_decorate([
|
|
727
731
|
import_async.synchronized
|
|
728
732
|
], Connection.prototype, "close", null);
|
|
729
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/
|
|
733
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/ice.ts";
|
|
734
|
+
var createIceProvider = (iceProviders) => {
|
|
735
|
+
let cachedIceServers;
|
|
736
|
+
return {
|
|
737
|
+
getIceServers: async () => {
|
|
738
|
+
if (cachedIceServers) {
|
|
739
|
+
return cachedIceServers;
|
|
740
|
+
}
|
|
741
|
+
cachedIceServers = (await Promise.all(iceProviders.map(({ urls }) => (0, import_async2.asyncTimeout)(fetch(urls, {
|
|
742
|
+
method: "GET"
|
|
743
|
+
}), 1e4).then((response) => response.json()).catch((err) => import_log2.log.error("Failed to fetch ICE servers from provider", {
|
|
744
|
+
urls,
|
|
745
|
+
err
|
|
746
|
+
}, {
|
|
747
|
+
F: __dxlog_file2,
|
|
748
|
+
L: 27,
|
|
749
|
+
S: void 0,
|
|
750
|
+
C: (f, a) => f(...a)
|
|
751
|
+
}))))).filter(import_util.isNotNullOrUndefined).map(({ iceServers }) => iceServers).flat();
|
|
752
|
+
return cachedIceServers;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
};
|
|
756
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/signal/swarm-messenger.ts";
|
|
730
757
|
var SwarmMessage = import_protocols2.schema.getCodecForType("dxos.mesh.swarm.SwarmMessage");
|
|
731
758
|
var SwarmMessenger = class {
|
|
732
759
|
constructor({ sendMessage, onSignal, onOffer, topic }) {
|
|
733
760
|
this._ctx = new import_context2.Context(void 0, {
|
|
734
|
-
F:
|
|
761
|
+
F: __dxlog_file3,
|
|
735
762
|
L: 33
|
|
736
763
|
});
|
|
737
|
-
this._offerRecords = new
|
|
764
|
+
this._offerRecords = new import_util2.ComplexMap((key) => key.toHex());
|
|
738
765
|
this._sendMessage = sendMessage;
|
|
739
766
|
this._onSignal = onSignal;
|
|
740
767
|
this._onOffer = onOffer;
|
|
@@ -748,12 +775,12 @@ var SwarmMessenger = class {
|
|
|
748
775
|
if (!this._topic.equals(message.topic)) {
|
|
749
776
|
return;
|
|
750
777
|
}
|
|
751
|
-
(0,
|
|
778
|
+
(0, import_log3.log)("received", {
|
|
752
779
|
from: author,
|
|
753
780
|
to: recipient,
|
|
754
781
|
msg: message
|
|
755
782
|
}, {
|
|
756
|
-
F:
|
|
783
|
+
F: __dxlog_file3,
|
|
757
784
|
L: 69,
|
|
758
785
|
S: this,
|
|
759
786
|
C: (f, a) => f(...a)
|
|
@@ -779,10 +806,10 @@ var SwarmMessenger = class {
|
|
|
779
806
|
message
|
|
780
807
|
});
|
|
781
808
|
} else {
|
|
782
|
-
|
|
809
|
+
import_log3.log.warn("unknown message", {
|
|
783
810
|
message
|
|
784
811
|
}, {
|
|
785
|
-
F:
|
|
812
|
+
F: __dxlog_file3,
|
|
786
813
|
L: 80,
|
|
787
814
|
S: this,
|
|
788
815
|
C: (f, a) => f(...a)
|
|
@@ -791,7 +818,7 @@ var SwarmMessenger = class {
|
|
|
791
818
|
}
|
|
792
819
|
async signal(message) {
|
|
793
820
|
(0, import_invariant2.invariant)(message.data?.signal || message.data?.signalBatch, "Invalid message", {
|
|
794
|
-
F:
|
|
821
|
+
F: __dxlog_file3,
|
|
795
822
|
L: 85,
|
|
796
823
|
S: this,
|
|
797
824
|
A: [
|
|
@@ -827,12 +854,12 @@ var SwarmMessenger = class {
|
|
|
827
854
|
// Setting unique message_id if it not specified yet.
|
|
828
855
|
messageId: message.messageId ?? import_keys2.PublicKey.random()
|
|
829
856
|
};
|
|
830
|
-
(0,
|
|
857
|
+
(0, import_log3.log)("sending", {
|
|
831
858
|
from: author,
|
|
832
859
|
to: recipient,
|
|
833
860
|
msg: networkMessage
|
|
834
861
|
}, {
|
|
835
|
-
F:
|
|
862
|
+
F: __dxlog_file3,
|
|
836
863
|
L: 123,
|
|
837
864
|
S: this,
|
|
838
865
|
C: (f, a) => f(...a)
|
|
@@ -848,7 +875,7 @@ var SwarmMessenger = class {
|
|
|
848
875
|
}
|
|
849
876
|
async _resolveAnswers(message) {
|
|
850
877
|
(0, import_invariant2.invariant)(message.data?.answer?.offerMessageId, "No offerMessageId", {
|
|
851
|
-
F:
|
|
878
|
+
F: __dxlog_file3,
|
|
852
879
|
L: 135,
|
|
853
880
|
S: this,
|
|
854
881
|
A: [
|
|
@@ -860,7 +887,7 @@ var SwarmMessenger = class {
|
|
|
860
887
|
if (offerRecord) {
|
|
861
888
|
this._offerRecords.delete(message.data.answer.offerMessageId);
|
|
862
889
|
(0, import_invariant2.invariant)(message.data?.answer, "No answer", {
|
|
863
|
-
F:
|
|
890
|
+
F: __dxlog_file3,
|
|
864
891
|
L: 139,
|
|
865
892
|
S: this,
|
|
866
893
|
A: [
|
|
@@ -868,10 +895,10 @@ var SwarmMessenger = class {
|
|
|
868
895
|
"'No answer'"
|
|
869
896
|
]
|
|
870
897
|
});
|
|
871
|
-
(0,
|
|
898
|
+
(0, import_log3.log)("resolving", {
|
|
872
899
|
answer: message.data.answer
|
|
873
900
|
}, {
|
|
874
|
-
F:
|
|
901
|
+
F: __dxlog_file3,
|
|
875
902
|
L: 140,
|
|
876
903
|
S: this,
|
|
877
904
|
C: (f, a) => f(...a)
|
|
@@ -881,7 +908,7 @@ var SwarmMessenger = class {
|
|
|
881
908
|
}
|
|
882
909
|
async _handleOffer({ author, recipient, message }) {
|
|
883
910
|
(0, import_invariant2.invariant)(message.data.offer, "No offer", {
|
|
884
|
-
F:
|
|
911
|
+
F: __dxlog_file3,
|
|
885
912
|
L: 154,
|
|
886
913
|
S: this,
|
|
887
914
|
A: [
|
|
@@ -913,19 +940,19 @@ var SwarmMessenger = class {
|
|
|
913
940
|
});
|
|
914
941
|
} catch (err) {
|
|
915
942
|
if (err instanceof import_protocols2.TimeoutError) {
|
|
916
|
-
|
|
943
|
+
import_log3.log.info("timeout sending answer to offer", {
|
|
917
944
|
err
|
|
918
945
|
}, {
|
|
919
|
-
F:
|
|
946
|
+
F: __dxlog_file3,
|
|
920
947
|
L: 175,
|
|
921
948
|
S: this,
|
|
922
949
|
C: (f, a) => f(...a)
|
|
923
950
|
});
|
|
924
951
|
} else {
|
|
925
|
-
|
|
952
|
+
import_log3.log.info("error sending answer to offer", {
|
|
926
953
|
err
|
|
927
954
|
}, {
|
|
928
|
-
F:
|
|
955
|
+
F: __dxlog_file3,
|
|
929
956
|
L: 177,
|
|
930
957
|
S: this,
|
|
931
958
|
C: (f, a) => f(...a)
|
|
@@ -935,7 +962,7 @@ var SwarmMessenger = class {
|
|
|
935
962
|
}
|
|
936
963
|
async _handleSignal({ author, recipient, message }) {
|
|
937
964
|
(0, import_invariant2.invariant)(message.messageId, void 0, {
|
|
938
|
-
F:
|
|
965
|
+
F: __dxlog_file3,
|
|
939
966
|
L: 191,
|
|
940
967
|
S: this,
|
|
941
968
|
A: [
|
|
@@ -944,7 +971,7 @@ var SwarmMessenger = class {
|
|
|
944
971
|
]
|
|
945
972
|
});
|
|
946
973
|
(0, import_invariant2.invariant)(message.data.signal || message.data.signalBatch, "Invalid message", {
|
|
947
|
-
F:
|
|
974
|
+
F: __dxlog_file3,
|
|
948
975
|
L: 192,
|
|
949
976
|
S: this,
|
|
950
977
|
A: [
|
|
@@ -974,7 +1001,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
974
1001
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
975
1002
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
976
1003
|
}
|
|
977
|
-
var
|
|
1004
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts";
|
|
978
1005
|
var ConnectionDisplacedError = class extends import_protocols4.SystemError {
|
|
979
1006
|
constructor() {
|
|
980
1007
|
super("Connection displaced by remote initiator.");
|
|
@@ -994,12 +1021,12 @@ var Peer = class {
|
|
|
994
1021
|
this._availableAfter = 0;
|
|
995
1022
|
this.availableToConnect = true;
|
|
996
1023
|
this._ctx = new import_context4.Context(void 0, {
|
|
997
|
-
F:
|
|
1024
|
+
F: __dxlog_file4,
|
|
998
1025
|
L: 79
|
|
999
1026
|
});
|
|
1000
1027
|
this.advertizing = false;
|
|
1001
1028
|
this.initiating = false;
|
|
1002
|
-
this.connectionDisplaced = new
|
|
1029
|
+
this.connectionDisplaced = new import_async4.Event();
|
|
1003
1030
|
}
|
|
1004
1031
|
/**
|
|
1005
1032
|
* Respond to remote offer.
|
|
@@ -1011,8 +1038,8 @@ var Peer = class {
|
|
|
1011
1038
|
ConnectionState.INITIAL,
|
|
1012
1039
|
ConnectionState.CONNECTING
|
|
1013
1040
|
].includes(this.connection.state)) {
|
|
1014
|
-
|
|
1015
|
-
F:
|
|
1041
|
+
import_log5.log.info(`received offer when connection already in ${this.connection.state} state`, void 0, {
|
|
1042
|
+
F: __dxlog_file4,
|
|
1016
1043
|
L: 114,
|
|
1017
1044
|
S: this,
|
|
1018
1045
|
C: (f, a) => f(...a)
|
|
@@ -1023,13 +1050,13 @@ var Peer = class {
|
|
|
1023
1050
|
}
|
|
1024
1051
|
if (this.connection || this.initiating) {
|
|
1025
1052
|
if (remoteId.toHex() < this.localPeerId.toHex()) {
|
|
1026
|
-
(0,
|
|
1053
|
+
(0, import_log5.log)("close local connection", {
|
|
1027
1054
|
localPeerId: this.id,
|
|
1028
1055
|
topic: this.topic,
|
|
1029
1056
|
remotePeerId: this.localPeerId,
|
|
1030
1057
|
sessionId: this.connection?.sessionId
|
|
1031
1058
|
}, {
|
|
1032
|
-
F:
|
|
1059
|
+
F: __dxlog_file4,
|
|
1033
1060
|
L: 123,
|
|
1034
1061
|
S: this,
|
|
1035
1062
|
C: (f, a) => f(...a)
|
|
@@ -1046,7 +1073,7 @@ var Peer = class {
|
|
|
1046
1073
|
if (await this._callbacks.onOffer(remoteId)) {
|
|
1047
1074
|
if (!this.connection) {
|
|
1048
1075
|
(0, import_invariant4.invariant)(message.sessionId, void 0, {
|
|
1049
|
-
F:
|
|
1076
|
+
F: __dxlog_file4,
|
|
1050
1077
|
L: 143,
|
|
1051
1078
|
S: this,
|
|
1052
1079
|
A: [
|
|
@@ -1061,13 +1088,13 @@ var Peer = class {
|
|
|
1061
1088
|
await connection.openConnection();
|
|
1062
1089
|
} catch (err) {
|
|
1063
1090
|
if (!(err instanceof import_protocols4.CancelledError)) {
|
|
1064
|
-
|
|
1091
|
+
import_log5.log.info("connection error", {
|
|
1065
1092
|
topic: this.topic,
|
|
1066
1093
|
peerId: this.localPeerId,
|
|
1067
1094
|
remoteId: this.id,
|
|
1068
1095
|
err
|
|
1069
1096
|
}, {
|
|
1070
|
-
F:
|
|
1097
|
+
F: __dxlog_file4,
|
|
1071
1098
|
L: 153,
|
|
1072
1099
|
S: this,
|
|
1073
1100
|
C: (f, a) => f(...a)
|
|
@@ -1089,7 +1116,7 @@ var Peer = class {
|
|
|
1089
1116
|
*/
|
|
1090
1117
|
async initiateConnection() {
|
|
1091
1118
|
(0, import_invariant4.invariant)(!this.initiating, "Initiation in progress.", {
|
|
1092
|
-
F:
|
|
1119
|
+
F: __dxlog_file4,
|
|
1093
1120
|
L: 170,
|
|
1094
1121
|
S: this,
|
|
1095
1122
|
A: [
|
|
@@ -1098,7 +1125,7 @@ var Peer = class {
|
|
|
1098
1125
|
]
|
|
1099
1126
|
});
|
|
1100
1127
|
(0, import_invariant4.invariant)(!this.connection, "Already connected.", {
|
|
1101
|
-
F:
|
|
1128
|
+
F: __dxlog_file4,
|
|
1102
1129
|
L: 171,
|
|
1103
1130
|
S: this,
|
|
1104
1131
|
A: [
|
|
@@ -1107,13 +1134,13 @@ var Peer = class {
|
|
|
1107
1134
|
]
|
|
1108
1135
|
});
|
|
1109
1136
|
const sessionId = import_keys4.PublicKey.random();
|
|
1110
|
-
(0,
|
|
1137
|
+
(0, import_log5.log)("initiating...", {
|
|
1111
1138
|
ownPeerId: this.localPeerId,
|
|
1112
1139
|
topic: this.topic,
|
|
1113
1140
|
remotePeerId: this.id,
|
|
1114
1141
|
sessionId
|
|
1115
1142
|
}, {
|
|
1116
|
-
F:
|
|
1143
|
+
F: __dxlog_file4,
|
|
1117
1144
|
L: 173,
|
|
1118
1145
|
S: this,
|
|
1119
1146
|
C: (f, a) => f(...a)
|
|
@@ -1133,20 +1160,20 @@ var Peer = class {
|
|
|
1133
1160
|
offer: {}
|
|
1134
1161
|
}
|
|
1135
1162
|
});
|
|
1136
|
-
(0,
|
|
1163
|
+
(0, import_log5.log)("received", {
|
|
1137
1164
|
answer,
|
|
1138
1165
|
topic: this.topic,
|
|
1139
1166
|
ownId: this.localPeerId,
|
|
1140
1167
|
remoteId: this.id
|
|
1141
1168
|
}, {
|
|
1142
|
-
F:
|
|
1169
|
+
F: __dxlog_file4,
|
|
1143
1170
|
L: 190,
|
|
1144
1171
|
S: this,
|
|
1145
1172
|
C: (f, a) => f(...a)
|
|
1146
1173
|
});
|
|
1147
1174
|
if (connection.state !== ConnectionState.INITIAL) {
|
|
1148
|
-
(0,
|
|
1149
|
-
F:
|
|
1175
|
+
(0, import_log5.log)("ignoring response", void 0, {
|
|
1176
|
+
F: __dxlog_file4,
|
|
1150
1177
|
L: 192,
|
|
1151
1178
|
S: this,
|
|
1152
1179
|
C: (f, a) => f(...a)
|
|
@@ -1154,13 +1181,13 @@ var Peer = class {
|
|
|
1154
1181
|
return;
|
|
1155
1182
|
}
|
|
1156
1183
|
} catch (err) {
|
|
1157
|
-
(0,
|
|
1184
|
+
(0, import_log5.log)("initiation error: send offer", {
|
|
1158
1185
|
err,
|
|
1159
1186
|
topic: this.topic,
|
|
1160
1187
|
peerId: this.localPeerId,
|
|
1161
1188
|
remoteId: this.id
|
|
1162
1189
|
}, {
|
|
1163
|
-
F:
|
|
1190
|
+
F: __dxlog_file4,
|
|
1164
1191
|
L: 196,
|
|
1165
1192
|
S: this,
|
|
1166
1193
|
C: (f, a) => f(...a)
|
|
@@ -1176,13 +1203,13 @@ var Peer = class {
|
|
|
1176
1203
|
return;
|
|
1177
1204
|
}
|
|
1178
1205
|
} catch (err) {
|
|
1179
|
-
(0,
|
|
1206
|
+
(0, import_log5.log)("initiation error: accept answer", {
|
|
1180
1207
|
err,
|
|
1181
1208
|
topic: this.topic,
|
|
1182
1209
|
peerId: this.localPeerId,
|
|
1183
1210
|
remoteId: this.id
|
|
1184
1211
|
}, {
|
|
1185
|
-
F:
|
|
1212
|
+
F: __dxlog_file4,
|
|
1186
1213
|
L: 209,
|
|
1187
1214
|
S: this,
|
|
1188
1215
|
C: (f, a) => f(...a)
|
|
@@ -1193,8 +1220,8 @@ var Peer = class {
|
|
|
1193
1220
|
this.initiating = false;
|
|
1194
1221
|
}
|
|
1195
1222
|
try {
|
|
1196
|
-
(0,
|
|
1197
|
-
F:
|
|
1223
|
+
(0, import_log5.log)("opening connection as initiator", void 0, {
|
|
1224
|
+
F: __dxlog_file4,
|
|
1198
1225
|
L: 222,
|
|
1199
1226
|
S: this,
|
|
1200
1227
|
C: (f, a) => f(...a)
|
|
@@ -1202,21 +1229,21 @@ var Peer = class {
|
|
|
1202
1229
|
await connection.openConnection();
|
|
1203
1230
|
this._callbacks.onAccepted();
|
|
1204
1231
|
} catch (err) {
|
|
1205
|
-
(0,
|
|
1232
|
+
(0, import_log5.log)("initiation error: open connection", {
|
|
1206
1233
|
err,
|
|
1207
1234
|
topic: this.topic,
|
|
1208
1235
|
peerId: this.localPeerId,
|
|
1209
1236
|
remoteId: this.id
|
|
1210
1237
|
}, {
|
|
1211
|
-
F:
|
|
1238
|
+
F: __dxlog_file4,
|
|
1212
1239
|
L: 226,
|
|
1213
1240
|
S: this,
|
|
1214
1241
|
C: (f, a) => f(...a)
|
|
1215
1242
|
});
|
|
1216
|
-
|
|
1243
|
+
import_log5.log.warn("closing connection due to unhandled error on openConnection", {
|
|
1217
1244
|
err
|
|
1218
1245
|
}, {
|
|
1219
|
-
F:
|
|
1246
|
+
F: __dxlog_file4,
|
|
1220
1247
|
L: 233,
|
|
1221
1248
|
S: this,
|
|
1222
1249
|
C: (f, a) => f(...a)
|
|
@@ -1232,20 +1259,20 @@ var Peer = class {
|
|
|
1232
1259
|
* Either we're initiating a connection or creating one in response to an offer from the other peer.
|
|
1233
1260
|
*/
|
|
1234
1261
|
_createConnection(initiator, sessionId) {
|
|
1235
|
-
(0,
|
|
1262
|
+
(0, import_log5.log)("creating connection", {
|
|
1236
1263
|
topic: this.topic,
|
|
1237
1264
|
peerId: this.localPeerId,
|
|
1238
1265
|
remoteId: this.id,
|
|
1239
1266
|
initiator,
|
|
1240
1267
|
sessionId
|
|
1241
1268
|
}, {
|
|
1242
|
-
F:
|
|
1269
|
+
F: __dxlog_file4,
|
|
1243
1270
|
L: 247,
|
|
1244
1271
|
S: this,
|
|
1245
1272
|
C: (f, a) => f(...a)
|
|
1246
1273
|
});
|
|
1247
1274
|
(0, import_invariant4.invariant)(!this.connection, "Already connected.", {
|
|
1248
|
-
F:
|
|
1275
|
+
F: __dxlog_file4,
|
|
1249
1276
|
L: 254,
|
|
1250
1277
|
S: this,
|
|
1251
1278
|
A: [
|
|
@@ -1274,34 +1301,34 @@ var Peer = class {
|
|
|
1274
1301
|
this._lastConnectionTime = Date.now();
|
|
1275
1302
|
this._callbacks.onConnected();
|
|
1276
1303
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1277
|
-
|
|
1304
|
+
import_log5.log.trace("dxos.mesh.connection.connected", {
|
|
1278
1305
|
topic: this.topic,
|
|
1279
1306
|
localPeerId: this.localPeerId,
|
|
1280
1307
|
remotePeerId: this.id,
|
|
1281
1308
|
sessionId,
|
|
1282
1309
|
initiator
|
|
1283
1310
|
}, {
|
|
1284
|
-
F:
|
|
1311
|
+
F: __dxlog_file4,
|
|
1285
1312
|
L: 273,
|
|
1286
1313
|
S: this,
|
|
1287
1314
|
C: (f, a) => f(...a)
|
|
1288
1315
|
});
|
|
1289
1316
|
},
|
|
1290
1317
|
onClosed: (err) => {
|
|
1291
|
-
(0,
|
|
1318
|
+
(0, import_log5.log)("connection closed", {
|
|
1292
1319
|
topic: this.topic,
|
|
1293
1320
|
peerId: this.localPeerId,
|
|
1294
1321
|
remoteId: this.id,
|
|
1295
1322
|
initiator
|
|
1296
1323
|
}, {
|
|
1297
|
-
F:
|
|
1324
|
+
F: __dxlog_file4,
|
|
1298
1325
|
L: 282,
|
|
1299
1326
|
S: this,
|
|
1300
1327
|
C: (f, a) => f(...a)
|
|
1301
1328
|
});
|
|
1302
1329
|
this._connectionLimiter.doneConnecting(sessionId);
|
|
1303
1330
|
(0, import_invariant4.invariant)(this.connection === connection, "Connection mismatch (race condition).", {
|
|
1304
|
-
F:
|
|
1331
|
+
F: __dxlog_file4,
|
|
1305
1332
|
L: 287,
|
|
1306
1333
|
S: this,
|
|
1307
1334
|
A: [
|
|
@@ -1309,14 +1336,14 @@ var Peer = class {
|
|
|
1309
1336
|
"'Connection mismatch (race condition).'"
|
|
1310
1337
|
]
|
|
1311
1338
|
});
|
|
1312
|
-
|
|
1339
|
+
import_log5.log.trace("dxos.mesh.connection.closed", {
|
|
1313
1340
|
topic: this.topic,
|
|
1314
1341
|
localPeerId: this.localPeerId,
|
|
1315
1342
|
remotePeerId: this.id,
|
|
1316
1343
|
sessionId,
|
|
1317
1344
|
initiator
|
|
1318
1345
|
}, {
|
|
1319
|
-
F:
|
|
1346
|
+
F: __dxlog_file4,
|
|
1320
1347
|
L: 289,
|
|
1321
1348
|
S: this,
|
|
1322
1349
|
C: (f, a) => f(...a)
|
|
@@ -1331,7 +1358,7 @@ var Peer = class {
|
|
|
1331
1358
|
this._availableAfter = increaseInterval(this._availableAfter);
|
|
1332
1359
|
}
|
|
1333
1360
|
this._callbacks.onDisconnected();
|
|
1334
|
-
(0,
|
|
1361
|
+
(0, import_async4.scheduleTask)(this._connectionCtx, () => {
|
|
1335
1362
|
this.availableToConnect = true;
|
|
1336
1363
|
this._callbacks.onPeerAvailable();
|
|
1337
1364
|
}, this._availableAfter);
|
|
@@ -1344,19 +1371,19 @@ var Peer = class {
|
|
|
1344
1371
|
void this._connectionCtx?.dispose();
|
|
1345
1372
|
this._connectionCtx = this._ctx.derive();
|
|
1346
1373
|
connection.errors.handle((err) => {
|
|
1347
|
-
|
|
1374
|
+
import_log5.log.info("connection error, closing", {
|
|
1348
1375
|
topic: this.topic,
|
|
1349
1376
|
peerId: this.localPeerId,
|
|
1350
1377
|
remoteId: this.id,
|
|
1351
1378
|
initiator,
|
|
1352
1379
|
err
|
|
1353
1380
|
}, {
|
|
1354
|
-
F:
|
|
1381
|
+
F: __dxlog_file4,
|
|
1355
1382
|
L: 329,
|
|
1356
1383
|
S: this,
|
|
1357
1384
|
C: (f, a) => f(...a)
|
|
1358
1385
|
});
|
|
1359
|
-
|
|
1386
|
+
import_log5.log.trace("dxos.mesh.connection.error", {
|
|
1360
1387
|
topic: this.topic,
|
|
1361
1388
|
localPeerId: this.localPeerId,
|
|
1362
1389
|
remotePeerId: this.id,
|
|
@@ -1364,7 +1391,7 @@ var Peer = class {
|
|
|
1364
1391
|
initiator,
|
|
1365
1392
|
err
|
|
1366
1393
|
}, {
|
|
1367
|
-
F:
|
|
1394
|
+
F: __dxlog_file4,
|
|
1368
1395
|
L: 336,
|
|
1369
1396
|
S: this,
|
|
1370
1397
|
C: (f, a) => f(...a)
|
|
@@ -1379,21 +1406,21 @@ var Peer = class {
|
|
|
1379
1406
|
return;
|
|
1380
1407
|
}
|
|
1381
1408
|
const connection = this.connection;
|
|
1382
|
-
(0,
|
|
1409
|
+
(0, import_log5.log)("closing...", {
|
|
1383
1410
|
peerId: this.id,
|
|
1384
1411
|
sessionId: connection.sessionId
|
|
1385
1412
|
}, {
|
|
1386
|
-
F:
|
|
1413
|
+
F: __dxlog_file4,
|
|
1387
1414
|
L: 361,
|
|
1388
1415
|
S: this,
|
|
1389
1416
|
C: (f, a) => f(...a)
|
|
1390
1417
|
});
|
|
1391
1418
|
await connection.close(err);
|
|
1392
|
-
(0,
|
|
1419
|
+
(0, import_log5.log)("closed", {
|
|
1393
1420
|
peerId: this.id,
|
|
1394
1421
|
sessionId: connection.sessionId
|
|
1395
1422
|
}, {
|
|
1396
|
-
F:
|
|
1423
|
+
F: __dxlog_file4,
|
|
1397
1424
|
L: 367,
|
|
1398
1425
|
S: this,
|
|
1399
1426
|
C: (f, a) => f(...a)
|
|
@@ -1401,10 +1428,10 @@ var Peer = class {
|
|
|
1401
1428
|
}
|
|
1402
1429
|
async onSignal(message) {
|
|
1403
1430
|
if (!this.connection) {
|
|
1404
|
-
(0,
|
|
1431
|
+
(0, import_log5.log)("dropping signal message for non-existent connection", {
|
|
1405
1432
|
message
|
|
1406
1433
|
}, {
|
|
1407
|
-
F:
|
|
1434
|
+
F: __dxlog_file4,
|
|
1408
1435
|
L: 372,
|
|
1409
1436
|
S: this,
|
|
1410
1437
|
C: (f, a) => f(...a)
|
|
@@ -1415,11 +1442,11 @@ var Peer = class {
|
|
|
1415
1442
|
}
|
|
1416
1443
|
async safeDestroy(reason) {
|
|
1417
1444
|
await this._ctx.dispose();
|
|
1418
|
-
(0,
|
|
1445
|
+
(0, import_log5.log)("Destroying peer", {
|
|
1419
1446
|
peerId: this.id,
|
|
1420
1447
|
topic: this.topic
|
|
1421
1448
|
}, {
|
|
1422
|
-
F:
|
|
1449
|
+
F: __dxlog_file4,
|
|
1423
1450
|
L: 382,
|
|
1424
1451
|
S: this,
|
|
1425
1452
|
C: (f, a) => f(...a)
|
|
@@ -1428,7 +1455,7 @@ var Peer = class {
|
|
|
1428
1455
|
}
|
|
1429
1456
|
};
|
|
1430
1457
|
_ts_decorate2([
|
|
1431
|
-
|
|
1458
|
+
import_async4.synchronized
|
|
1432
1459
|
], Peer.prototype, "safeDestroy", null);
|
|
1433
1460
|
var increaseInterval = (interval) => {
|
|
1434
1461
|
if (interval === 0) {
|
|
@@ -1452,7 +1479,7 @@ function _ts_decorate3(decorators, target, key, desc) {
|
|
|
1452
1479
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1453
1480
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1454
1481
|
}
|
|
1455
|
-
var
|
|
1482
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm.ts";
|
|
1456
1483
|
var INITIATION_DELAY = 100;
|
|
1457
1484
|
var getClassName = (obj) => Object.getPrototypeOf(obj).constructor.name;
|
|
1458
1485
|
var Swarm = class {
|
|
@@ -1469,32 +1496,32 @@ var Swarm = class {
|
|
|
1469
1496
|
this._connectionLimiter = _connectionLimiter;
|
|
1470
1497
|
this._initiationDelay = _initiationDelay;
|
|
1471
1498
|
this._ctx = new import_context3.Context(void 0, {
|
|
1472
|
-
F:
|
|
1499
|
+
F: __dxlog_file5,
|
|
1473
1500
|
L: 39
|
|
1474
1501
|
});
|
|
1475
1502
|
this._listeningHandle = void 0;
|
|
1476
|
-
this._peers = new
|
|
1503
|
+
this._peers = new import_util3.ComplexMap(import_keys3.PublicKey.hash);
|
|
1477
1504
|
this._instanceId = import_keys3.PublicKey.random().toHex();
|
|
1478
|
-
this.connectionAdded = new
|
|
1479
|
-
this.disconnected = new
|
|
1480
|
-
this.connected = new
|
|
1505
|
+
this.connectionAdded = new import_async3.Event();
|
|
1506
|
+
this.disconnected = new import_async3.Event();
|
|
1507
|
+
this.connected = new import_async3.Event();
|
|
1481
1508
|
this.errors = new import_debug2.ErrorStream();
|
|
1482
|
-
|
|
1509
|
+
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.begin({
|
|
1483
1510
|
id: this._instanceId,
|
|
1484
1511
|
data: {
|
|
1485
1512
|
topic: this._topic.toHex(),
|
|
1486
1513
|
peerId: this._ownPeerId.toHex()
|
|
1487
1514
|
}
|
|
1488
1515
|
}), {
|
|
1489
|
-
F:
|
|
1516
|
+
F: __dxlog_file5,
|
|
1490
1517
|
L: 89,
|
|
1491
1518
|
S: this,
|
|
1492
1519
|
C: (f, a) => f(...a)
|
|
1493
1520
|
});
|
|
1494
|
-
(0,
|
|
1521
|
+
(0, import_log4.log)("creating swarm", {
|
|
1495
1522
|
peerId: _ownPeerId
|
|
1496
1523
|
}, {
|
|
1497
|
-
F:
|
|
1524
|
+
F: __dxlog_file5,
|
|
1498
1525
|
L: 93,
|
|
1499
1526
|
S: this,
|
|
1500
1527
|
C: (f, a) => f(...a)
|
|
@@ -1506,17 +1533,17 @@ var Swarm = class {
|
|
|
1506
1533
|
onOffer: async (msg) => await this.onOffer(msg),
|
|
1507
1534
|
topic: this._topic
|
|
1508
1535
|
});
|
|
1509
|
-
|
|
1536
|
+
import_log4.log.trace("dxos.mesh.swarm.constructor", import_protocols3.trace.end({
|
|
1510
1537
|
id: this._instanceId
|
|
1511
1538
|
}), {
|
|
1512
|
-
F:
|
|
1539
|
+
F: __dxlog_file5,
|
|
1513
1540
|
L: 102,
|
|
1514
1541
|
S: this,
|
|
1515
1542
|
C: (f, a) => f(...a)
|
|
1516
1543
|
});
|
|
1517
1544
|
}
|
|
1518
1545
|
get connections() {
|
|
1519
|
-
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(
|
|
1546
|
+
return Array.from(this._peers.values()).map((peer) => peer.connection).filter(import_util3.isNotNullOrUndefined);
|
|
1520
1547
|
}
|
|
1521
1548
|
get ownPeerId() {
|
|
1522
1549
|
return this._ownPeerId;
|
|
@@ -1532,7 +1559,7 @@ var Swarm = class {
|
|
|
1532
1559
|
}
|
|
1533
1560
|
async open() {
|
|
1534
1561
|
(0, import_invariant3.invariant)(!this._listeningHandle, void 0, {
|
|
1535
|
-
F:
|
|
1562
|
+
F: __dxlog_file5,
|
|
1536
1563
|
L: 129,
|
|
1537
1564
|
S: this,
|
|
1538
1565
|
A: [
|
|
@@ -1544,10 +1571,10 @@ var Swarm = class {
|
|
|
1544
1571
|
peerId: this._ownPeerId,
|
|
1545
1572
|
payloadType: "dxos.mesh.swarm.SwarmMessage",
|
|
1546
1573
|
onMessage: async (message) => {
|
|
1547
|
-
await this._swarmMessenger.receiveMessage(message).catch((err) =>
|
|
1574
|
+
await this._swarmMessenger.receiveMessage(message).catch((err) => import_log4.log.info("Error while receiving message", {
|
|
1548
1575
|
err
|
|
1549
1576
|
}, {
|
|
1550
|
-
F:
|
|
1577
|
+
F: __dxlog_file5,
|
|
1551
1578
|
L: 137,
|
|
1552
1579
|
S: this,
|
|
1553
1580
|
C: (f, a) => f(...a)
|
|
@@ -1556,8 +1583,8 @@ var Swarm = class {
|
|
|
1556
1583
|
});
|
|
1557
1584
|
}
|
|
1558
1585
|
async destroy() {
|
|
1559
|
-
(0,
|
|
1560
|
-
F:
|
|
1586
|
+
(0, import_log4.log)("destroying...", void 0, {
|
|
1587
|
+
F: __dxlog_file5,
|
|
1561
1588
|
L: 143,
|
|
1562
1589
|
S: this,
|
|
1563
1590
|
C: (f, a) => f(...a)
|
|
@@ -1567,8 +1594,8 @@ var Swarm = class {
|
|
|
1567
1594
|
await this._ctx.dispose();
|
|
1568
1595
|
await this._topology.destroy();
|
|
1569
1596
|
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key, "swarm destroyed")));
|
|
1570
|
-
(0,
|
|
1571
|
-
F:
|
|
1597
|
+
(0, import_log4.log)("destroyed", void 0, {
|
|
1598
|
+
F: __dxlog_file5,
|
|
1572
1599
|
L: 150,
|
|
1573
1600
|
S: this,
|
|
1574
1601
|
C: (f, a) => f(...a)
|
|
@@ -1576,7 +1603,7 @@ var Swarm = class {
|
|
|
1576
1603
|
}
|
|
1577
1604
|
async setTopology(topology) {
|
|
1578
1605
|
(0, import_invariant3.invariant)(!this._ctx.disposed, "Swarm is offline", {
|
|
1579
|
-
F:
|
|
1606
|
+
F: __dxlog_file5,
|
|
1580
1607
|
L: 154,
|
|
1581
1608
|
S: this,
|
|
1582
1609
|
A: [
|
|
@@ -1587,11 +1614,11 @@ var Swarm = class {
|
|
|
1587
1614
|
if (topology === this._topology) {
|
|
1588
1615
|
return;
|
|
1589
1616
|
}
|
|
1590
|
-
(0,
|
|
1617
|
+
(0, import_log4.log)("setting topology", {
|
|
1591
1618
|
previous: getClassName(this._topology),
|
|
1592
1619
|
topology: getClassName(topology)
|
|
1593
1620
|
}, {
|
|
1594
|
-
F:
|
|
1621
|
+
F: __dxlog_file5,
|
|
1595
1622
|
L: 158,
|
|
1596
1623
|
S: this,
|
|
1597
1624
|
C: (f, a) => f(...a)
|
|
@@ -1602,17 +1629,17 @@ var Swarm = class {
|
|
|
1602
1629
|
this._topology.update();
|
|
1603
1630
|
}
|
|
1604
1631
|
onSwarmEvent(swarmEvent) {
|
|
1605
|
-
(0,
|
|
1632
|
+
(0, import_log4.log)("swarm event", {
|
|
1606
1633
|
swarmEvent
|
|
1607
1634
|
}, {
|
|
1608
|
-
F:
|
|
1635
|
+
F: __dxlog_file5,
|
|
1609
1636
|
L: 171,
|
|
1610
1637
|
S: this,
|
|
1611
1638
|
C: (f, a) => f(...a)
|
|
1612
1639
|
});
|
|
1613
1640
|
if (this._ctx.disposed) {
|
|
1614
|
-
(0,
|
|
1615
|
-
F:
|
|
1641
|
+
(0, import_log4.log)("swarm event ignored for disposed swarm", void 0, {
|
|
1642
|
+
F: __dxlog_file5,
|
|
1616
1643
|
L: 174,
|
|
1617
1644
|
S: this,
|
|
1618
1645
|
C: (f, a) => f(...a)
|
|
@@ -1622,10 +1649,10 @@ var Swarm = class {
|
|
|
1622
1649
|
if (swarmEvent.peerAvailable) {
|
|
1623
1650
|
const peerId = import_keys3.PublicKey.from(swarmEvent.peerAvailable.peer);
|
|
1624
1651
|
if (!peerId.equals(this._ownPeerId)) {
|
|
1625
|
-
(0,
|
|
1652
|
+
(0, import_log4.log)("new peer", {
|
|
1626
1653
|
peerId
|
|
1627
1654
|
}, {
|
|
1628
|
-
F:
|
|
1655
|
+
F: __dxlog_file5,
|
|
1629
1656
|
L: 181,
|
|
1630
1657
|
S: this,
|
|
1631
1658
|
C: (f, a) => f(...a)
|
|
@@ -1638,18 +1665,18 @@ var Swarm = class {
|
|
|
1638
1665
|
if (peer) {
|
|
1639
1666
|
peer.advertizing = false;
|
|
1640
1667
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
1641
|
-
void this._destroyPeer(peer.id, "peer left").catch((err) =>
|
|
1642
|
-
F:
|
|
1668
|
+
void this._destroyPeer(peer.id, "peer left").catch((err) => import_log4.log.catch(err, void 0, {
|
|
1669
|
+
F: __dxlog_file5,
|
|
1643
1670
|
L: 191,
|
|
1644
1671
|
S: this,
|
|
1645
1672
|
C: (f, a) => f(...a)
|
|
1646
1673
|
}));
|
|
1647
1674
|
}
|
|
1648
1675
|
} else {
|
|
1649
|
-
(0,
|
|
1676
|
+
(0, import_log4.log)("received peerLeft but no peer found", {
|
|
1650
1677
|
peer: swarmEvent.peerLeft.peer
|
|
1651
1678
|
}, {
|
|
1652
|
-
F:
|
|
1679
|
+
F: __dxlog_file5,
|
|
1653
1680
|
L: 194,
|
|
1654
1681
|
S: this,
|
|
1655
1682
|
C: (f, a) => f(...a)
|
|
@@ -1659,17 +1686,17 @@ var Swarm = class {
|
|
|
1659
1686
|
this._topology.update();
|
|
1660
1687
|
}
|
|
1661
1688
|
async onOffer(message) {
|
|
1662
|
-
(0,
|
|
1689
|
+
(0, import_log4.log)("offer", {
|
|
1663
1690
|
message
|
|
1664
1691
|
}, {
|
|
1665
|
-
F:
|
|
1692
|
+
F: __dxlog_file5,
|
|
1666
1693
|
L: 203,
|
|
1667
1694
|
S: this,
|
|
1668
1695
|
C: (f, a) => f(...a)
|
|
1669
1696
|
});
|
|
1670
1697
|
if (this._ctx.disposed) {
|
|
1671
|
-
(0,
|
|
1672
|
-
F:
|
|
1698
|
+
(0, import_log4.log)("ignored for disposed swarm", void 0, {
|
|
1699
|
+
F: __dxlog_file5,
|
|
1673
1700
|
L: 205,
|
|
1674
1701
|
S: this,
|
|
1675
1702
|
C: (f, a) => f(...a)
|
|
@@ -1679,7 +1706,7 @@ var Swarm = class {
|
|
|
1679
1706
|
};
|
|
1680
1707
|
}
|
|
1681
1708
|
(0, import_invariant3.invariant)(message.author, void 0, {
|
|
1682
|
-
F:
|
|
1709
|
+
F: __dxlog_file5,
|
|
1683
1710
|
L: 210,
|
|
1684
1711
|
S: this,
|
|
1685
1712
|
A: [
|
|
@@ -1688,10 +1715,10 @@ var Swarm = class {
|
|
|
1688
1715
|
]
|
|
1689
1716
|
});
|
|
1690
1717
|
if (!message.recipient?.equals(this._ownPeerId)) {
|
|
1691
|
-
(0,
|
|
1718
|
+
(0, import_log4.log)("rejecting offer with incorrect peerId", {
|
|
1692
1719
|
message
|
|
1693
1720
|
}, {
|
|
1694
|
-
F:
|
|
1721
|
+
F: __dxlog_file5,
|
|
1695
1722
|
L: 212,
|
|
1696
1723
|
S: this,
|
|
1697
1724
|
C: (f, a) => f(...a)
|
|
@@ -1701,10 +1728,10 @@ var Swarm = class {
|
|
|
1701
1728
|
};
|
|
1702
1729
|
}
|
|
1703
1730
|
if (!message.topic?.equals(this._topic)) {
|
|
1704
|
-
(0,
|
|
1731
|
+
(0, import_log4.log)("rejecting offer with incorrect topic", {
|
|
1705
1732
|
message
|
|
1706
1733
|
}, {
|
|
1707
|
-
F:
|
|
1734
|
+
F: __dxlog_file5,
|
|
1708
1735
|
L: 216,
|
|
1709
1736
|
S: this,
|
|
1710
1737
|
C: (f, a) => f(...a)
|
|
@@ -1719,17 +1746,17 @@ var Swarm = class {
|
|
|
1719
1746
|
return answer;
|
|
1720
1747
|
}
|
|
1721
1748
|
async onSignal(message) {
|
|
1722
|
-
(0,
|
|
1749
|
+
(0, import_log4.log)("signal", {
|
|
1723
1750
|
message
|
|
1724
1751
|
}, {
|
|
1725
|
-
F:
|
|
1752
|
+
F: __dxlog_file5,
|
|
1726
1753
|
L: 227,
|
|
1727
1754
|
S: this,
|
|
1728
1755
|
C: (f, a) => f(...a)
|
|
1729
1756
|
});
|
|
1730
1757
|
if (this._ctx.disposed) {
|
|
1731
|
-
|
|
1732
|
-
F:
|
|
1758
|
+
import_log4.log.info("ignored for offline swarm", void 0, {
|
|
1759
|
+
F: __dxlog_file5,
|
|
1733
1760
|
L: 229,
|
|
1734
1761
|
S: this,
|
|
1735
1762
|
C: (f, a) => f(...a)
|
|
@@ -1737,7 +1764,7 @@ var Swarm = class {
|
|
|
1737
1764
|
return;
|
|
1738
1765
|
}
|
|
1739
1766
|
(0, import_invariant3.invariant)(message.recipient?.equals(this._ownPeerId), `Invalid signal peer id expected=${this.ownPeerId}, actual=${message.recipient}`, {
|
|
1740
|
-
F:
|
|
1767
|
+
F: __dxlog_file5,
|
|
1741
1768
|
L: 232,
|
|
1742
1769
|
S: this,
|
|
1743
1770
|
A: [
|
|
@@ -1746,7 +1773,7 @@ var Swarm = class {
|
|
|
1746
1773
|
]
|
|
1747
1774
|
});
|
|
1748
1775
|
(0, import_invariant3.invariant)(message.topic?.equals(this._topic), void 0, {
|
|
1749
|
-
F:
|
|
1776
|
+
F: __dxlog_file5,
|
|
1750
1777
|
L: 236,
|
|
1751
1778
|
S: this,
|
|
1752
1779
|
A: [
|
|
@@ -1755,7 +1782,7 @@ var Swarm = class {
|
|
|
1755
1782
|
]
|
|
1756
1783
|
});
|
|
1757
1784
|
(0, import_invariant3.invariant)(message.author, void 0, {
|
|
1758
|
-
F:
|
|
1785
|
+
F: __dxlog_file5,
|
|
1759
1786
|
L: 237,
|
|
1760
1787
|
S: this,
|
|
1761
1788
|
A: [
|
|
@@ -1776,7 +1803,7 @@ var Swarm = class {
|
|
|
1776
1803
|
// For debug purposes
|
|
1777
1804
|
async goOnline() {
|
|
1778
1805
|
this._ctx = new import_context3.Context(void 0, {
|
|
1779
|
-
F:
|
|
1806
|
+
F: __dxlog_file5,
|
|
1780
1807
|
L: 253
|
|
1781
1808
|
});
|
|
1782
1809
|
}
|
|
@@ -1802,10 +1829,10 @@ var Swarm = class {
|
|
|
1802
1829
|
},
|
|
1803
1830
|
onRejected: () => {
|
|
1804
1831
|
if (!this._isUnregistered(peer)) {
|
|
1805
|
-
(0,
|
|
1832
|
+
(0, import_log4.log)("peer rejected connection", {
|
|
1806
1833
|
peerId
|
|
1807
1834
|
}, {
|
|
1808
|
-
F:
|
|
1835
|
+
F: __dxlog_file5,
|
|
1809
1836
|
L: 289,
|
|
1810
1837
|
S: this,
|
|
1811
1838
|
C: (f, a) => f(...a)
|
|
@@ -1830,7 +1857,7 @@ var Swarm = class {
|
|
|
1830
1857
|
async _destroyPeer(peerId, reason) {
|
|
1831
1858
|
const peer = this._peers.get(peerId);
|
|
1832
1859
|
(0, import_invariant3.invariant)(peer, void 0, {
|
|
1833
|
-
F:
|
|
1860
|
+
F: __dxlog_file5,
|
|
1834
1861
|
L: 312,
|
|
1835
1862
|
S: this,
|
|
1836
1863
|
A: [
|
|
@@ -1853,12 +1880,12 @@ var Swarm = class {
|
|
|
1853
1880
|
if (this._ctx.disposed) {
|
|
1854
1881
|
return;
|
|
1855
1882
|
}
|
|
1856
|
-
(0,
|
|
1883
|
+
(0, import_async3.scheduleTask)(this._ctx, async () => {
|
|
1857
1884
|
try {
|
|
1858
1885
|
await this._initiateConnection(peer);
|
|
1859
1886
|
} catch (err) {
|
|
1860
|
-
(0,
|
|
1861
|
-
F:
|
|
1887
|
+
(0, import_log4.log)("initiation error", err, {
|
|
1888
|
+
F: __dxlog_file5,
|
|
1862
1889
|
L: 339,
|
|
1863
1890
|
S: this,
|
|
1864
1891
|
C: (f, a) => f(...a)
|
|
@@ -1870,7 +1897,7 @@ var Swarm = class {
|
|
|
1870
1897
|
if (this._ctx.disposed) {
|
|
1871
1898
|
return;
|
|
1872
1899
|
}
|
|
1873
|
-
(0,
|
|
1900
|
+
(0, import_async3.scheduleTask)(this._ctx, async () => {
|
|
1874
1901
|
await this._closeConnection(peer);
|
|
1875
1902
|
this._topology.update();
|
|
1876
1903
|
});
|
|
@@ -1884,15 +1911,15 @@ var Swarm = class {
|
|
|
1884
1911
|
const ctx = this._ctx;
|
|
1885
1912
|
const peer = this._getOrCreatePeer(remoteId);
|
|
1886
1913
|
if (remoteId.toHex() < this._ownPeerId.toHex()) {
|
|
1887
|
-
(0,
|
|
1914
|
+
(0, import_log4.log)("initiation delay", {
|
|
1888
1915
|
remoteId
|
|
1889
1916
|
}, {
|
|
1890
|
-
F:
|
|
1917
|
+
F: __dxlog_file5,
|
|
1891
1918
|
L: 367,
|
|
1892
1919
|
S: this,
|
|
1893
1920
|
C: (f, a) => f(...a)
|
|
1894
1921
|
});
|
|
1895
|
-
await (0,
|
|
1922
|
+
await (0, import_async3.sleep)(this._initiationDelay);
|
|
1896
1923
|
}
|
|
1897
1924
|
if (ctx.disposed) {
|
|
1898
1925
|
return;
|
|
@@ -1903,20 +1930,20 @@ var Swarm = class {
|
|
|
1903
1930
|
if (peer.connection) {
|
|
1904
1931
|
return;
|
|
1905
1932
|
}
|
|
1906
|
-
(0,
|
|
1933
|
+
(0, import_log4.log)("initiating connection...", {
|
|
1907
1934
|
remoteId
|
|
1908
1935
|
}, {
|
|
1909
|
-
F:
|
|
1936
|
+
F: __dxlog_file5,
|
|
1910
1937
|
L: 383,
|
|
1911
1938
|
S: this,
|
|
1912
1939
|
C: (f, a) => f(...a)
|
|
1913
1940
|
});
|
|
1914
1941
|
await peer.initiateConnection();
|
|
1915
1942
|
this._topology.update();
|
|
1916
|
-
(0,
|
|
1943
|
+
(0, import_log4.log)("initiated", {
|
|
1917
1944
|
remoteId
|
|
1918
1945
|
}, {
|
|
1919
|
-
F:
|
|
1946
|
+
F: __dxlog_file5,
|
|
1920
1947
|
L: 386,
|
|
1921
1948
|
S: this,
|
|
1922
1949
|
C: (f, a) => f(...a)
|
|
@@ -1934,37 +1961,37 @@ var Swarm = class {
|
|
|
1934
1961
|
}
|
|
1935
1962
|
};
|
|
1936
1963
|
_ts_decorate3([
|
|
1937
|
-
|
|
1964
|
+
import_log4.logInfo
|
|
1938
1965
|
], Swarm.prototype, "_instanceId", void 0);
|
|
1939
1966
|
_ts_decorate3([
|
|
1940
|
-
|
|
1967
|
+
import_log4.logInfo
|
|
1941
1968
|
], Swarm.prototype, "ownPeerId", null);
|
|
1942
1969
|
_ts_decorate3([
|
|
1943
|
-
|
|
1970
|
+
import_log4.logInfo
|
|
1944
1971
|
], Swarm.prototype, "topic", null);
|
|
1945
1972
|
_ts_decorate3([
|
|
1946
|
-
|
|
1973
|
+
import_async3.synchronized
|
|
1947
1974
|
], Swarm.prototype, "onSwarmEvent", null);
|
|
1948
1975
|
_ts_decorate3([
|
|
1949
|
-
|
|
1976
|
+
import_async3.synchronized
|
|
1950
1977
|
], Swarm.prototype, "onOffer", null);
|
|
1951
1978
|
_ts_decorate3([
|
|
1952
|
-
|
|
1979
|
+
import_async3.synchronized
|
|
1953
1980
|
], Swarm.prototype, "goOffline", null);
|
|
1954
1981
|
_ts_decorate3([
|
|
1955
|
-
|
|
1982
|
+
import_async3.synchronized
|
|
1956
1983
|
], Swarm.prototype, "goOnline", null);
|
|
1957
|
-
var
|
|
1984
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts";
|
|
1958
1985
|
var SwarmMapper = class {
|
|
1959
1986
|
get peers() {
|
|
1960
1987
|
return Array.from(this._peers.values());
|
|
1961
1988
|
}
|
|
1962
1989
|
constructor(_swarm) {
|
|
1963
1990
|
this._swarm = _swarm;
|
|
1964
|
-
this._subscriptions = new
|
|
1965
|
-
this._connectionSubscriptions = new
|
|
1966
|
-
this._peers = new
|
|
1967
|
-
this.mapUpdated = new
|
|
1991
|
+
this._subscriptions = new import_async5.EventSubscriptions();
|
|
1992
|
+
this._connectionSubscriptions = new import_util4.ComplexMap(import_keys5.PublicKey.hash);
|
|
1993
|
+
this._peers = new import_util4.ComplexMap(import_keys5.PublicKey.hash);
|
|
1994
|
+
this.mapUpdated = new import_async5.Event();
|
|
1968
1995
|
this._subscriptions.add(_swarm.connectionAdded.on((connection) => {
|
|
1969
1996
|
this._update();
|
|
1970
1997
|
this._connectionSubscriptions.set(connection.remoteId, connection.stateChanged.on(() => {
|
|
@@ -1979,8 +2006,8 @@ var SwarmMapper = class {
|
|
|
1979
2006
|
this._update();
|
|
1980
2007
|
}
|
|
1981
2008
|
_update() {
|
|
1982
|
-
(0,
|
|
1983
|
-
F:
|
|
2009
|
+
(0, import_log6.log)("updating swarm", void 0, {
|
|
2010
|
+
F: __dxlog_file6,
|
|
1984
2011
|
L: 72,
|
|
1985
2012
|
S: this,
|
|
1986
2013
|
C: (f, a) => f(...a)
|
|
@@ -2000,11 +2027,11 @@ var SwarmMapper = class {
|
|
|
2000
2027
|
]
|
|
2001
2028
|
});
|
|
2002
2029
|
}
|
|
2003
|
-
(0,
|
|
2030
|
+
(0, import_log6.log)("graph changed", {
|
|
2004
2031
|
directConnections: this._swarm.connections.length,
|
|
2005
2032
|
totalPeersInSwarm: this._peers.size
|
|
2006
2033
|
}, {
|
|
2007
|
-
F:
|
|
2034
|
+
F: __dxlog_file6,
|
|
2008
2035
|
L: 113,
|
|
2009
2036
|
S: this,
|
|
2010
2037
|
C: (f, a) => f(...a)
|
|
@@ -2017,16 +2044,16 @@ var SwarmMapper = class {
|
|
|
2017
2044
|
this._subscriptions.clear();
|
|
2018
2045
|
}
|
|
2019
2046
|
};
|
|
2020
|
-
var
|
|
2047
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection-limiter.ts";
|
|
2021
2048
|
var MAX_CONCURRENT_INITIATING_CONNECTIONS = 50;
|
|
2022
2049
|
var ConnectionLimiter = class {
|
|
2023
2050
|
constructor({ maxConcurrentInitConnections = MAX_CONCURRENT_INITIATING_CONNECTIONS } = {}) {
|
|
2024
2051
|
this._ctx = new import_context5.Context(void 0, {
|
|
2025
|
-
F:
|
|
2052
|
+
F: __dxlog_file7,
|
|
2026
2053
|
L: 23
|
|
2027
2054
|
});
|
|
2028
|
-
this._waitingPromises = new
|
|
2029
|
-
this.resolveWaitingPromises = new
|
|
2055
|
+
this._waitingPromises = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
|
|
2056
|
+
this.resolveWaitingPromises = new import_async6.DeferredTask(this._ctx, async () => {
|
|
2030
2057
|
Array.from(this._waitingPromises.values()).slice(0, this._maxConcurrentInitConnections).forEach(({ resolve }) => {
|
|
2031
2058
|
resolve();
|
|
2032
2059
|
});
|
|
@@ -2038,7 +2065,7 @@ var ConnectionLimiter = class {
|
|
|
2038
2065
|
*/
|
|
2039
2066
|
async connecting(sessionId) {
|
|
2040
2067
|
(0, import_invariant5.invariant)(!this._waitingPromises.has(sessionId), "Peer is already waiting for connection", {
|
|
2041
|
-
F:
|
|
2068
|
+
F: __dxlog_file7,
|
|
2042
2069
|
L: 48,
|
|
2043
2070
|
S: this,
|
|
2044
2071
|
A: [
|
|
@@ -2046,10 +2073,10 @@ var ConnectionLimiter = class {
|
|
|
2046
2073
|
"'Peer is already waiting for connection'"
|
|
2047
2074
|
]
|
|
2048
2075
|
});
|
|
2049
|
-
(0,
|
|
2076
|
+
(0, import_log7.log)("waiting", {
|
|
2050
2077
|
sessionId
|
|
2051
2078
|
}, {
|
|
2052
|
-
F:
|
|
2079
|
+
F: __dxlog_file7,
|
|
2053
2080
|
L: 49,
|
|
2054
2081
|
S: this,
|
|
2055
2082
|
C: (f, a) => f(...a)
|
|
@@ -2061,10 +2088,10 @@ var ConnectionLimiter = class {
|
|
|
2061
2088
|
});
|
|
2062
2089
|
this.resolveWaitingPromises.schedule();
|
|
2063
2090
|
});
|
|
2064
|
-
(0,
|
|
2091
|
+
(0, import_log7.log)("allow", {
|
|
2065
2092
|
sessionId
|
|
2066
2093
|
}, {
|
|
2067
|
-
F:
|
|
2094
|
+
F: __dxlog_file7,
|
|
2068
2095
|
L: 57,
|
|
2069
2096
|
S: this,
|
|
2070
2097
|
C: (f, a) => f(...a)
|
|
@@ -2074,10 +2101,10 @@ var ConnectionLimiter = class {
|
|
|
2074
2101
|
* Rejects promise returned by `connecting` method.
|
|
2075
2102
|
*/
|
|
2076
2103
|
doneConnecting(sessionId) {
|
|
2077
|
-
(0,
|
|
2104
|
+
(0, import_log7.log)("done", {
|
|
2078
2105
|
sessionId
|
|
2079
2106
|
}, {
|
|
2080
|
-
F:
|
|
2107
|
+
F: __dxlog_file7,
|
|
2081
2108
|
L: 64,
|
|
2082
2109
|
S: this,
|
|
2083
2110
|
C: (f, a) => f(...a)
|
|
@@ -2101,8 +2128,8 @@ var EventType;
|
|
|
2101
2128
|
})(EventType || (EventType = {}));
|
|
2102
2129
|
var ConnectionLog = class {
|
|
2103
2130
|
constructor() {
|
|
2104
|
-
this._swarms = new
|
|
2105
|
-
this.update = new
|
|
2131
|
+
this._swarms = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
|
|
2132
|
+
this.update = new import_async7.Event();
|
|
2106
2133
|
}
|
|
2107
2134
|
getSwarmInfo(swarmId) {
|
|
2108
2135
|
return this._swarms.get(swarmId) ?? (0, import_debug3.raise)(new Error(`Swarm not found: ${swarmId}`));
|
|
@@ -2183,15 +2210,15 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
2183
2210
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2184
2211
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2185
2212
|
}
|
|
2186
|
-
var
|
|
2213
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts";
|
|
2187
2214
|
var SwarmNetworkManager = class {
|
|
2188
|
-
constructor({ transportFactory, signalManager, log:
|
|
2189
|
-
this._swarms = new
|
|
2190
|
-
this._mappers = new
|
|
2215
|
+
constructor({ transportFactory, signalManager, log: log17 }) {
|
|
2216
|
+
this._swarms = new import_util7.ComplexMap(import_keys8.PublicKey.hash);
|
|
2217
|
+
this._mappers = new import_util7.ComplexMap(import_keys8.PublicKey.hash);
|
|
2191
2218
|
this._instanceId = import_keys8.PublicKey.random().toHex();
|
|
2192
2219
|
this._connectionState = import_services.ConnectionState.ONLINE;
|
|
2193
|
-
this.connectionStateChanged = new
|
|
2194
|
-
this.topicsUpdated = new
|
|
2220
|
+
this.connectionStateChanged = new import_async8.Event();
|
|
2221
|
+
this.topicsUpdated = new import_async8.Event();
|
|
2195
2222
|
this._transportFactory = transportFactory;
|
|
2196
2223
|
this._signalManager = signalManager;
|
|
2197
2224
|
this._signalManager.swarmEvent.on(({ topic, swarmEvent: event }) => this._swarms.get(topic)?.onSwarmEvent(event));
|
|
@@ -2203,7 +2230,7 @@ var SwarmNetworkManager = class {
|
|
|
2203
2230
|
leave: (opts) => this._signalManager.leave(opts)
|
|
2204
2231
|
};
|
|
2205
2232
|
this._connectionLimiter = new ConnectionLimiter();
|
|
2206
|
-
if (
|
|
2233
|
+
if (log17) {
|
|
2207
2234
|
this._connectionLog = new ConnectionLog();
|
|
2208
2235
|
}
|
|
2209
2236
|
}
|
|
@@ -2225,20 +2252,20 @@ var SwarmNetworkManager = class {
|
|
|
2225
2252
|
return this._swarms.get(topic);
|
|
2226
2253
|
}
|
|
2227
2254
|
async open() {
|
|
2228
|
-
|
|
2255
|
+
import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.begin({
|
|
2229
2256
|
id: this._instanceId
|
|
2230
2257
|
}), {
|
|
2231
|
-
F:
|
|
2258
|
+
F: __dxlog_file8,
|
|
2232
2259
|
L: 126,
|
|
2233
2260
|
S: this,
|
|
2234
2261
|
C: (f, a) => f(...a)
|
|
2235
2262
|
});
|
|
2236
2263
|
await this._messenger.open();
|
|
2237
2264
|
await this._signalManager.open();
|
|
2238
|
-
|
|
2265
|
+
import_log8.log.trace("dxos.mesh.network-manager.open", import_protocols6.trace.end({
|
|
2239
2266
|
id: this._instanceId
|
|
2240
2267
|
}), {
|
|
2241
|
-
F:
|
|
2268
|
+
F: __dxlog_file8,
|
|
2242
2269
|
L: 129,
|
|
2243
2270
|
S: this,
|
|
2244
2271
|
C: (f, a) => f(...a)
|
|
@@ -2247,8 +2274,8 @@ var SwarmNetworkManager = class {
|
|
|
2247
2274
|
async close() {
|
|
2248
2275
|
for (const topic of this._swarms.keys()) {
|
|
2249
2276
|
await this.leaveSwarm(topic).catch((err) => {
|
|
2250
|
-
(0,
|
|
2251
|
-
F:
|
|
2277
|
+
(0, import_log8.log)(err, void 0, {
|
|
2278
|
+
F: __dxlog_file8,
|
|
2252
2279
|
L: 135,
|
|
2253
2280
|
S: this,
|
|
2254
2281
|
C: (f, a) => f(...a)
|
|
@@ -2263,7 +2290,7 @@ var SwarmNetworkManager = class {
|
|
|
2263
2290
|
*/
|
|
2264
2291
|
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
2265
2292
|
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(topic), void 0, {
|
|
2266
|
-
F:
|
|
2293
|
+
F: __dxlog_file8,
|
|
2267
2294
|
L: 154,
|
|
2268
2295
|
S: this,
|
|
2269
2296
|
A: [
|
|
@@ -2272,7 +2299,7 @@ var SwarmNetworkManager = class {
|
|
|
2272
2299
|
]
|
|
2273
2300
|
});
|
|
2274
2301
|
(0, import_invariant6.invariant)(import_keys8.PublicKey.isPublicKey(peerId), void 0, {
|
|
2275
|
-
F:
|
|
2302
|
+
F: __dxlog_file8,
|
|
2276
2303
|
L: 155,
|
|
2277
2304
|
S: this,
|
|
2278
2305
|
A: [
|
|
@@ -2281,7 +2308,7 @@ var SwarmNetworkManager = class {
|
|
|
2281
2308
|
]
|
|
2282
2309
|
});
|
|
2283
2310
|
(0, import_invariant6.invariant)(topology, void 0, {
|
|
2284
|
-
F:
|
|
2311
|
+
F: __dxlog_file8,
|
|
2285
2312
|
L: 156,
|
|
2286
2313
|
S: this,
|
|
2287
2314
|
A: [
|
|
@@ -2290,7 +2317,7 @@ var SwarmNetworkManager = class {
|
|
|
2290
2317
|
]
|
|
2291
2318
|
});
|
|
2292
2319
|
(0, import_invariant6.invariant)(typeof protocol === "function", void 0, {
|
|
2293
|
-
F:
|
|
2320
|
+
F: __dxlog_file8,
|
|
2294
2321
|
L: 157,
|
|
2295
2322
|
S: this,
|
|
2296
2323
|
A: [
|
|
@@ -2301,22 +2328,22 @@ var SwarmNetworkManager = class {
|
|
|
2301
2328
|
if (this._swarms.has(topic)) {
|
|
2302
2329
|
throw new Error(`Already connected to swarm: ${import_keys8.PublicKey.from(topic)}`);
|
|
2303
2330
|
}
|
|
2304
|
-
(0,
|
|
2331
|
+
(0, import_log8.log)("joining", {
|
|
2305
2332
|
topic: import_keys8.PublicKey.from(topic),
|
|
2306
2333
|
peerId,
|
|
2307
2334
|
topology: topology.toString()
|
|
2308
2335
|
}, {
|
|
2309
|
-
F:
|
|
2336
|
+
F: __dxlog_file8,
|
|
2310
2337
|
L: 162,
|
|
2311
2338
|
S: this,
|
|
2312
2339
|
C: (f, a) => f(...a)
|
|
2313
2340
|
});
|
|
2314
2341
|
const swarm = new Swarm(topic, peerId, topology, protocol, this._messenger, this._transportFactory, label, this._connectionLimiter);
|
|
2315
2342
|
swarm.errors.handle((error) => {
|
|
2316
|
-
(0,
|
|
2343
|
+
(0, import_log8.log)("swarm error", {
|
|
2317
2344
|
error
|
|
2318
2345
|
}, {
|
|
2319
|
-
F:
|
|
2346
|
+
F: __dxlog_file8,
|
|
2320
2347
|
L: 175,
|
|
2321
2348
|
S: this,
|
|
2322
2349
|
C: (f, a) => f(...a)
|
|
@@ -2328,19 +2355,19 @@ var SwarmNetworkManager = class {
|
|
|
2328
2355
|
this._signalConnection.join({
|
|
2329
2356
|
topic,
|
|
2330
2357
|
peerId
|
|
2331
|
-
}).catch((error) =>
|
|
2332
|
-
F:
|
|
2358
|
+
}).catch((error) => import_log8.log.catch(error, void 0, {
|
|
2359
|
+
F: __dxlog_file8,
|
|
2333
2360
|
L: 184,
|
|
2334
2361
|
S: this,
|
|
2335
2362
|
C: (f, a) => f(...a)
|
|
2336
2363
|
}));
|
|
2337
2364
|
this.topicsUpdated.emit();
|
|
2338
2365
|
this._connectionLog?.joinedSwarm(swarm);
|
|
2339
|
-
(0,
|
|
2366
|
+
(0, import_log8.log)("joined", {
|
|
2340
2367
|
topic: import_keys8.PublicKey.from(topic),
|
|
2341
2368
|
count: this._swarms.size
|
|
2342
2369
|
}, {
|
|
2343
|
-
F:
|
|
2370
|
+
F: __dxlog_file8,
|
|
2344
2371
|
L: 188,
|
|
2345
2372
|
S: this,
|
|
2346
2373
|
C: (f, a) => f(...a)
|
|
@@ -2356,10 +2383,10 @@ var SwarmNetworkManager = class {
|
|
|
2356
2383
|
if (!this._swarms.has(topic)) {
|
|
2357
2384
|
return;
|
|
2358
2385
|
}
|
|
2359
|
-
(0,
|
|
2386
|
+
(0, import_log8.log)("leaving", {
|
|
2360
2387
|
topic: import_keys8.PublicKey.from(topic)
|
|
2361
2388
|
}, {
|
|
2362
|
-
F:
|
|
2389
|
+
F: __dxlog_file8,
|
|
2363
2390
|
L: 205,
|
|
2364
2391
|
S: this,
|
|
2365
2392
|
C: (f, a) => f(...a)
|
|
@@ -2376,11 +2403,11 @@ var SwarmNetworkManager = class {
|
|
|
2376
2403
|
await swarm.destroy();
|
|
2377
2404
|
this._swarms.delete(topic);
|
|
2378
2405
|
this.topicsUpdated.emit();
|
|
2379
|
-
(0,
|
|
2406
|
+
(0, import_log8.log)("left", {
|
|
2380
2407
|
topic: import_keys8.PublicKey.from(topic),
|
|
2381
2408
|
count: this._swarms.size
|
|
2382
2409
|
}, {
|
|
2383
|
-
F:
|
|
2410
|
+
F: __dxlog_file8,
|
|
2384
2411
|
L: 219,
|
|
2385
2412
|
S: this,
|
|
2386
2413
|
C: (f, a) => f(...a)
|
|
@@ -2414,19 +2441,19 @@ var SwarmNetworkManager = class {
|
|
|
2414
2441
|
}
|
|
2415
2442
|
};
|
|
2416
2443
|
_ts_decorate4([
|
|
2417
|
-
|
|
2444
|
+
import_async8.synchronized
|
|
2418
2445
|
], SwarmNetworkManager.prototype, "joinSwarm", null);
|
|
2419
2446
|
_ts_decorate4([
|
|
2420
|
-
|
|
2447
|
+
import_async8.synchronized
|
|
2421
2448
|
], SwarmNetworkManager.prototype, "leaveSwarm", null);
|
|
2422
|
-
var
|
|
2449
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts";
|
|
2423
2450
|
var FullyConnectedTopology = class {
|
|
2424
2451
|
toString() {
|
|
2425
2452
|
return "FullyConnectedTopology";
|
|
2426
2453
|
}
|
|
2427
2454
|
init(controller) {
|
|
2428
2455
|
(0, import_invariant7.invariant)(!this._controller, "Already initialized", {
|
|
2429
|
-
F:
|
|
2456
|
+
F: __dxlog_file9,
|
|
2430
2457
|
L: 18,
|
|
2431
2458
|
S: this,
|
|
2432
2459
|
A: [
|
|
@@ -2438,7 +2465,7 @@ var FullyConnectedTopology = class {
|
|
|
2438
2465
|
}
|
|
2439
2466
|
update() {
|
|
2440
2467
|
(0, import_invariant7.invariant)(this._controller, "Not initialized", {
|
|
2441
|
-
F:
|
|
2468
|
+
F: __dxlog_file9,
|
|
2442
2469
|
L: 23,
|
|
2443
2470
|
S: this,
|
|
2444
2471
|
A: [
|
|
@@ -2457,7 +2484,7 @@ var FullyConnectedTopology = class {
|
|
|
2457
2484
|
async destroy() {
|
|
2458
2485
|
}
|
|
2459
2486
|
};
|
|
2460
|
-
var
|
|
2487
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts";
|
|
2461
2488
|
var MIN_UPDATE_INTERVAL = 1e3 * 10;
|
|
2462
2489
|
var MAX_CHANGES_PER_UPDATE = 1;
|
|
2463
2490
|
var MMSTTopology = class {
|
|
@@ -2470,7 +2497,7 @@ var MMSTTopology = class {
|
|
|
2470
2497
|
}
|
|
2471
2498
|
init(controller) {
|
|
2472
2499
|
(0, import_invariant8.invariant)(!this._controller, "Already initialized", {
|
|
2473
|
-
F:
|
|
2500
|
+
F: __dxlog_file10,
|
|
2474
2501
|
L: 51,
|
|
2475
2502
|
S: this,
|
|
2476
2503
|
A: [
|
|
@@ -2482,7 +2509,7 @@ var MMSTTopology = class {
|
|
|
2482
2509
|
}
|
|
2483
2510
|
update() {
|
|
2484
2511
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2485
|
-
F:
|
|
2512
|
+
F: __dxlog_file10,
|
|
2486
2513
|
L: 56,
|
|
2487
2514
|
S: this,
|
|
2488
2515
|
A: [
|
|
@@ -2492,8 +2519,8 @@ var MMSTTopology = class {
|
|
|
2492
2519
|
});
|
|
2493
2520
|
const { connected, candidates } = this._controller.getState();
|
|
2494
2521
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
2495
|
-
(0,
|
|
2496
|
-
F:
|
|
2522
|
+
(0, import_log9.log)("Running the algorithm.", void 0, {
|
|
2523
|
+
F: __dxlog_file10,
|
|
2497
2524
|
L: 60,
|
|
2498
2525
|
S: this,
|
|
2499
2526
|
C: (f, a) => f(...a)
|
|
@@ -2508,7 +2535,7 @@ var MMSTTopology = class {
|
|
|
2508
2535
|
}
|
|
2509
2536
|
async onOffer(peer) {
|
|
2510
2537
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2511
|
-
F:
|
|
2538
|
+
F: __dxlog_file10,
|
|
2512
2539
|
L: 72,
|
|
2513
2540
|
S: this,
|
|
2514
2541
|
A: [
|
|
@@ -2518,8 +2545,8 @@ var MMSTTopology = class {
|
|
|
2518
2545
|
});
|
|
2519
2546
|
const { connected } = this._controller.getState();
|
|
2520
2547
|
const accept = connected.length < this._maxPeers;
|
|
2521
|
-
(0,
|
|
2522
|
-
F:
|
|
2548
|
+
(0, import_log9.log)(`Offer ${peer} accept=${accept}`, void 0, {
|
|
2549
|
+
F: __dxlog_file10,
|
|
2523
2550
|
L: 75,
|
|
2524
2551
|
S: this,
|
|
2525
2552
|
C: (f, a) => f(...a)
|
|
@@ -2530,7 +2557,7 @@ var MMSTTopology = class {
|
|
|
2530
2557
|
}
|
|
2531
2558
|
_runAlgorithm() {
|
|
2532
2559
|
(0, import_invariant8.invariant)(this._controller, "Not initialized", {
|
|
2533
|
-
F:
|
|
2560
|
+
F: __dxlog_file10,
|
|
2534
2561
|
L: 84,
|
|
2535
2562
|
S: this,
|
|
2536
2563
|
A: [
|
|
@@ -2540,15 +2567,15 @@ var MMSTTopology = class {
|
|
|
2540
2567
|
});
|
|
2541
2568
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
2542
2569
|
if (connected.length > this._maxPeers) {
|
|
2543
|
-
(0,
|
|
2544
|
-
F:
|
|
2570
|
+
(0, import_log9.log)(`disconnect ${connected.length - this._maxPeers} peers.`, void 0, {
|
|
2571
|
+
F: __dxlog_file10,
|
|
2545
2572
|
L: 90,
|
|
2546
2573
|
S: this,
|
|
2547
2574
|
C: (f, a) => f(...a)
|
|
2548
2575
|
});
|
|
2549
2576
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
2550
2577
|
(0, import_invariant8.invariant)(sorted.length === 0, void 0, {
|
|
2551
|
-
F:
|
|
2578
|
+
F: __dxlog_file10,
|
|
2552
2579
|
L: 94,
|
|
2553
2580
|
S: this,
|
|
2554
2581
|
A: [
|
|
@@ -2557,8 +2584,8 @@ var MMSTTopology = class {
|
|
|
2557
2584
|
]
|
|
2558
2585
|
});
|
|
2559
2586
|
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2560
|
-
(0,
|
|
2561
|
-
F:
|
|
2587
|
+
(0, import_log9.log)(`want to disconnect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2588
|
+
F: __dxlog_file10,
|
|
2562
2589
|
L: 97,
|
|
2563
2590
|
S: this,
|
|
2564
2591
|
C: (f, a) => f(...a)
|
|
@@ -2566,8 +2593,8 @@ var MMSTTopology = class {
|
|
|
2566
2593
|
}
|
|
2567
2594
|
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2568
2595
|
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2569
|
-
(0,
|
|
2570
|
-
F:
|
|
2596
|
+
(0, import_log9.log)(`Disconnect ${peer}.`, void 0, {
|
|
2597
|
+
F: __dxlog_file10,
|
|
2571
2598
|
L: 102,
|
|
2572
2599
|
S: this,
|
|
2573
2600
|
C: (f, a) => f(...a)
|
|
@@ -2576,16 +2603,16 @@ var MMSTTopology = class {
|
|
|
2576
2603
|
}
|
|
2577
2604
|
this._lastAction = /* @__PURE__ */ new Date();
|
|
2578
2605
|
} else {
|
|
2579
|
-
(0,
|
|
2580
|
-
F:
|
|
2606
|
+
(0, import_log9.log)("rate limited disconnect", void 0, {
|
|
2607
|
+
F: __dxlog_file10,
|
|
2581
2608
|
L: 107,
|
|
2582
2609
|
S: this,
|
|
2583
2610
|
C: (f, a) => f(...a)
|
|
2584
2611
|
});
|
|
2585
2612
|
}
|
|
2586
2613
|
} else if (connected.length < this._originateConnections) {
|
|
2587
|
-
(0,
|
|
2588
|
-
F:
|
|
2614
|
+
(0, import_log9.log)(`connect ${this._originateConnections - connected.length} peers.`, void 0, {
|
|
2615
|
+
F: __dxlog_file10,
|
|
2589
2616
|
L: 111,
|
|
2590
2617
|
S: this,
|
|
2591
2618
|
C: (f, a) => f(...a)
|
|
@@ -2593,8 +2620,8 @@ var MMSTTopology = class {
|
|
|
2593
2620
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
2594
2621
|
const sorted = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
2595
2622
|
if (sorted.length > MAX_CHANGES_PER_UPDATE) {
|
|
2596
|
-
(0,
|
|
2597
|
-
F:
|
|
2623
|
+
(0, import_log9.log)(`want to connect ${sorted.length} peers but limited to ${MAX_CHANGES_PER_UPDATE}`, void 0, {
|
|
2624
|
+
F: __dxlog_file10,
|
|
2598
2625
|
L: 116,
|
|
2599
2626
|
S: this,
|
|
2600
2627
|
C: (f, a) => f(...a)
|
|
@@ -2602,8 +2629,8 @@ var MMSTTopology = class {
|
|
|
2602
2629
|
}
|
|
2603
2630
|
if (Date.now() - this._lastAction.getTime() > MIN_UPDATE_INTERVAL) {
|
|
2604
2631
|
for (const peer of sorted.slice(0, MAX_CHANGES_PER_UPDATE)) {
|
|
2605
|
-
(0,
|
|
2606
|
-
F:
|
|
2632
|
+
(0, import_log9.log)(`Connect ${peer}.`, void 0, {
|
|
2633
|
+
F: __dxlog_file10,
|
|
2607
2634
|
L: 120,
|
|
2608
2635
|
S: this,
|
|
2609
2636
|
C: (f, a) => f(...a)
|
|
@@ -2612,8 +2639,8 @@ var MMSTTopology = class {
|
|
|
2612
2639
|
}
|
|
2613
2640
|
this._lastAction = /* @__PURE__ */ new Date();
|
|
2614
2641
|
} else {
|
|
2615
|
-
(0,
|
|
2616
|
-
F:
|
|
2642
|
+
(0, import_log9.log)("rate limited connect", void 0, {
|
|
2643
|
+
F: __dxlog_file10,
|
|
2617
2644
|
L: 125,
|
|
2618
2645
|
S: this,
|
|
2619
2646
|
C: (f, a) => f(...a)
|
|
@@ -2626,7 +2653,7 @@ var MMSTTopology = class {
|
|
|
2626
2653
|
}
|
|
2627
2654
|
};
|
|
2628
2655
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => import_xor_distance.default.gt((0, import_xor_distance.default)(a.asBuffer(), reference.asBuffer()), (0, import_xor_distance.default)(b.asBuffer(), reference.asBuffer())));
|
|
2629
|
-
var
|
|
2656
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts";
|
|
2630
2657
|
var StarTopology = class {
|
|
2631
2658
|
constructor(_centralPeer) {
|
|
2632
2659
|
this._centralPeer = _centralPeer;
|
|
@@ -2636,7 +2663,7 @@ var StarTopology = class {
|
|
|
2636
2663
|
}
|
|
2637
2664
|
init(controller) {
|
|
2638
2665
|
(0, import_invariant9.invariant)(!this._controller, "Already initialized.", {
|
|
2639
|
-
F:
|
|
2666
|
+
F: __dxlog_file11,
|
|
2640
2667
|
L: 21,
|
|
2641
2668
|
S: this,
|
|
2642
2669
|
A: [
|
|
@@ -2648,7 +2675,7 @@ var StarTopology = class {
|
|
|
2648
2675
|
}
|
|
2649
2676
|
update() {
|
|
2650
2677
|
(0, import_invariant9.invariant)(this._controller, "Not initialized.", {
|
|
2651
|
-
F:
|
|
2678
|
+
F: __dxlog_file11,
|
|
2652
2679
|
L: 26,
|
|
2653
2680
|
S: this,
|
|
2654
2681
|
A: [
|
|
@@ -2658,18 +2685,18 @@ var StarTopology = class {
|
|
|
2658
2685
|
});
|
|
2659
2686
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
2660
2687
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
2661
|
-
(0,
|
|
2662
|
-
F:
|
|
2688
|
+
(0, import_log10.log)("leaf peer dropping all connections apart from central peer.", void 0, {
|
|
2689
|
+
F: __dxlog_file11,
|
|
2663
2690
|
L: 29,
|
|
2664
2691
|
S: this,
|
|
2665
2692
|
C: (f, a) => f(...a)
|
|
2666
2693
|
});
|
|
2667
2694
|
for (const peer of connected) {
|
|
2668
2695
|
if (!peer.equals(this._centralPeer)) {
|
|
2669
|
-
(0,
|
|
2696
|
+
(0, import_log10.log)("dropping connection", {
|
|
2670
2697
|
peer
|
|
2671
2698
|
}, {
|
|
2672
|
-
F:
|
|
2699
|
+
F: __dxlog_file11,
|
|
2673
2700
|
L: 34,
|
|
2674
2701
|
S: this,
|
|
2675
2702
|
C: (f, a) => f(...a)
|
|
@@ -2680,10 +2707,10 @@ var StarTopology = class {
|
|
|
2680
2707
|
}
|
|
2681
2708
|
for (const peer of candidates) {
|
|
2682
2709
|
if (peer.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
2683
|
-
(0,
|
|
2710
|
+
(0, import_log10.log)("connecting to peer", {
|
|
2684
2711
|
peer
|
|
2685
2712
|
}, {
|
|
2686
|
-
F:
|
|
2713
|
+
F: __dxlog_file11,
|
|
2687
2714
|
L: 43,
|
|
2688
2715
|
S: this,
|
|
2689
2716
|
C: (f, a) => f(...a)
|
|
@@ -2694,7 +2721,7 @@ var StarTopology = class {
|
|
|
2694
2721
|
}
|
|
2695
2722
|
async onOffer(peer) {
|
|
2696
2723
|
(0, import_invariant9.invariant)(this._controller, "Not initialized.", {
|
|
2697
|
-
F:
|
|
2724
|
+
F: __dxlog_file11,
|
|
2698
2725
|
L: 50,
|
|
2699
2726
|
S: this,
|
|
2700
2727
|
A: [
|
|
@@ -2703,12 +2730,12 @@ var StarTopology = class {
|
|
|
2703
2730
|
]
|
|
2704
2731
|
});
|
|
2705
2732
|
const { ownPeerId } = this._controller.getState();
|
|
2706
|
-
(0,
|
|
2733
|
+
(0, import_log10.log)("offer", {
|
|
2707
2734
|
peer,
|
|
2708
2735
|
isCentral: peer.equals(this._centralPeer),
|
|
2709
2736
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
2710
2737
|
}, {
|
|
2711
|
-
F:
|
|
2738
|
+
F: __dxlog_file11,
|
|
2712
2739
|
L: 52,
|
|
2713
2740
|
S: this,
|
|
2714
2741
|
C: (f, a) => f(...a)
|
|
@@ -2728,7 +2755,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
2728
2755
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2729
2756
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2730
2757
|
}
|
|
2731
|
-
var
|
|
2758
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts";
|
|
2732
2759
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
2733
2760
|
var createStreamDelay = (delay) => {
|
|
2734
2761
|
return new import_node_stream.Transform({
|
|
@@ -2743,20 +2770,20 @@ var MemoryTransportFactory = {
|
|
|
2743
2770
|
};
|
|
2744
2771
|
var MemoryTransport = class _MemoryTransport {
|
|
2745
2772
|
static {
|
|
2746
|
-
this._connections = new
|
|
2773
|
+
this._connections = new import_util8.ComplexMap(import_keys9.PublicKey.hash);
|
|
2747
2774
|
}
|
|
2748
2775
|
constructor(_options) {
|
|
2749
2776
|
this._options = _options;
|
|
2750
2777
|
this._instanceId = import_keys9.PublicKey.random();
|
|
2751
|
-
this._remote = new
|
|
2778
|
+
this._remote = new import_async9.Trigger();
|
|
2752
2779
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2753
2780
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
2754
2781
|
this._closed = false;
|
|
2755
|
-
this.closed = new
|
|
2756
|
-
this.connected = new
|
|
2782
|
+
this.closed = new import_async9.Event();
|
|
2783
|
+
this.connected = new import_async9.Event();
|
|
2757
2784
|
this.errors = new import_debug4.ErrorStream();
|
|
2758
2785
|
(0, import_invariant10.invariant)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection", {
|
|
2759
|
-
F:
|
|
2786
|
+
F: __dxlog_file12,
|
|
2760
2787
|
L: 64,
|
|
2761
2788
|
S: this,
|
|
2762
2789
|
A: [
|
|
@@ -2770,15 +2797,15 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2770
2797
|
return !this._closed;
|
|
2771
2798
|
}
|
|
2772
2799
|
async open() {
|
|
2773
|
-
(0,
|
|
2774
|
-
F:
|
|
2800
|
+
(0, import_log11.log)("opening...", void 0, {
|
|
2801
|
+
F: __dxlog_file12,
|
|
2775
2802
|
L: 74,
|
|
2776
2803
|
S: this,
|
|
2777
2804
|
C: (f, a) => f(...a)
|
|
2778
2805
|
});
|
|
2779
2806
|
if (this._options.initiator) {
|
|
2780
|
-
(0,
|
|
2781
|
-
F:
|
|
2807
|
+
(0, import_log11.log)("sending signal", void 0, {
|
|
2808
|
+
F: __dxlog_file12,
|
|
2782
2809
|
L: 78,
|
|
2783
2810
|
S: this,
|
|
2784
2811
|
C: (f, a) => f(...a)
|
|
@@ -2809,7 +2836,7 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2809
2836
|
return;
|
|
2810
2837
|
}
|
|
2811
2838
|
(0, import_invariant10.invariant)(!this._remoteConnection._remoteConnection, `Remote already connected: ${this._remoteInstanceId}`, {
|
|
2812
|
-
F:
|
|
2839
|
+
F: __dxlog_file12,
|
|
2813
2840
|
L: 104,
|
|
2814
2841
|
S: this,
|
|
2815
2842
|
A: [
|
|
@@ -2819,8 +2846,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2819
2846
|
});
|
|
2820
2847
|
this._remoteConnection._remoteConnection = this;
|
|
2821
2848
|
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
2822
|
-
(0,
|
|
2823
|
-
F:
|
|
2849
|
+
(0, import_log11.log)("connected", void 0, {
|
|
2850
|
+
F: __dxlog_file12,
|
|
2824
2851
|
L: 108,
|
|
2825
2852
|
S: this,
|
|
2826
2853
|
C: (f, a) => f(...a)
|
|
@@ -2837,8 +2864,8 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2837
2864
|
}
|
|
2838
2865
|
}
|
|
2839
2866
|
async close() {
|
|
2840
|
-
(0,
|
|
2841
|
-
F:
|
|
2867
|
+
(0, import_log11.log)("closing...", void 0, {
|
|
2868
|
+
F: __dxlog_file12,
|
|
2842
2869
|
L: 129,
|
|
2843
2870
|
S: this,
|
|
2844
2871
|
C: (f, a) => f(...a)
|
|
@@ -2858,18 +2885,18 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2858
2885
|
this._remoteConnection = void 0;
|
|
2859
2886
|
}
|
|
2860
2887
|
this.closed.emit();
|
|
2861
|
-
(0,
|
|
2862
|
-
F:
|
|
2888
|
+
(0, import_log11.log)("closed", void 0, {
|
|
2889
|
+
F: __dxlog_file12,
|
|
2863
2890
|
L: 157,
|
|
2864
2891
|
S: this,
|
|
2865
2892
|
C: (f, a) => f(...a)
|
|
2866
2893
|
});
|
|
2867
2894
|
}
|
|
2868
2895
|
async onSignal({ payload }) {
|
|
2869
|
-
(0,
|
|
2896
|
+
(0, import_log11.log)("received signal", {
|
|
2870
2897
|
payload
|
|
2871
2898
|
}, {
|
|
2872
|
-
F:
|
|
2899
|
+
F: __dxlog_file12,
|
|
2873
2900
|
L: 161,
|
|
2874
2901
|
S: this,
|
|
2875
2902
|
C: (f, a) => f(...a)
|
|
@@ -2896,10 +2923,10 @@ var MemoryTransport = class _MemoryTransport {
|
|
|
2896
2923
|
}
|
|
2897
2924
|
};
|
|
2898
2925
|
_ts_decorate5([
|
|
2899
|
-
|
|
2926
|
+
import_log11.logInfo
|
|
2900
2927
|
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
2901
2928
|
_ts_decorate5([
|
|
2902
|
-
|
|
2929
|
+
import_log11.logInfo
|
|
2903
2930
|
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
2904
2931
|
var toError = (err) => err instanceof Error ? err : new Error(String(err));
|
|
2905
2932
|
var TransportKind;
|
|
@@ -2915,11 +2942,22 @@ try {
|
|
|
2915
2942
|
wrtc = __require("@koush/wrtc");
|
|
2916
2943
|
} catch {
|
|
2917
2944
|
}
|
|
2918
|
-
|
|
2919
|
-
var
|
|
2945
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
2946
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2947
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
2948
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
2949
|
+
else
|
|
2950
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
2951
|
+
if (d = decorators[i])
|
|
2952
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2953
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2954
|
+
}
|
|
2955
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport.ts";
|
|
2956
|
+
var createSimplePeerTransportFactory = (webrtcConfig, iceProvider) => ({
|
|
2920
2957
|
createTransport: (options) => new SimplePeerTransport({
|
|
2921
2958
|
...options,
|
|
2922
|
-
webrtcConfig
|
|
2959
|
+
webrtcConfig,
|
|
2960
|
+
iceProvider
|
|
2923
2961
|
})
|
|
2924
2962
|
});
|
|
2925
2963
|
var SimplePeerTransport = class {
|
|
@@ -2931,26 +2969,92 @@ var SimplePeerTransport = class {
|
|
|
2931
2969
|
*/
|
|
2932
2970
|
constructor(_params) {
|
|
2933
2971
|
this._params = _params;
|
|
2972
|
+
this._peer = void 0;
|
|
2934
2973
|
this._closed = false;
|
|
2935
2974
|
this._piped = false;
|
|
2936
|
-
this.closed = new
|
|
2937
|
-
this.connected = new
|
|
2975
|
+
this.closed = new import_async10.Event();
|
|
2976
|
+
this.connected = new import_async10.Event();
|
|
2938
2977
|
this.errors = new import_debug5.ErrorStream();
|
|
2939
2978
|
this._instanceId = import_keys10.PublicKey.random().toHex();
|
|
2940
|
-
|
|
2979
|
+
}
|
|
2980
|
+
async getStats() {
|
|
2981
|
+
const stats = await this._getStats();
|
|
2982
|
+
if (!stats) {
|
|
2983
|
+
return {
|
|
2984
|
+
bytesSent: 0,
|
|
2985
|
+
bytesReceived: 0,
|
|
2986
|
+
packetsSent: 0,
|
|
2987
|
+
packetsReceived: 0,
|
|
2988
|
+
rawStats: {}
|
|
2989
|
+
};
|
|
2990
|
+
}
|
|
2991
|
+
return {
|
|
2992
|
+
bytesSent: stats.transport.bytesSent,
|
|
2993
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
2994
|
+
packetsSent: stats.transport.packetsSent,
|
|
2995
|
+
packetsReceived: stats.transport.packetsReceived,
|
|
2996
|
+
rawStats: stats.raw
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
async _getStats() {
|
|
3000
|
+
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
3001
|
+
return null;
|
|
3002
|
+
}
|
|
3003
|
+
return await this._peer._pc.getStats().then((stats) => {
|
|
3004
|
+
const statsEntries = Array.from(stats.entries());
|
|
3005
|
+
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3006
|
+
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3007
|
+
let selectedCandidatePair;
|
|
3008
|
+
let remoteCandidate;
|
|
3009
|
+
if (candidatePair.length > 0) {
|
|
3010
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
3011
|
+
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3012
|
+
}
|
|
3013
|
+
return {
|
|
3014
|
+
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
3015
|
+
transport,
|
|
3016
|
+
selectedCandidatePair,
|
|
3017
|
+
remoteCandidate,
|
|
3018
|
+
raw: Object.fromEntries(stats.entries())
|
|
3019
|
+
};
|
|
3020
|
+
});
|
|
3021
|
+
}
|
|
3022
|
+
async getDetails() {
|
|
3023
|
+
const stats = await this._getStats();
|
|
3024
|
+
const rc = stats?.remoteCandidate;
|
|
3025
|
+
if (!rc) {
|
|
3026
|
+
return "unavailable";
|
|
3027
|
+
}
|
|
3028
|
+
if (rc.candidateType === "relay") {
|
|
3029
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3030
|
+
}
|
|
3031
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3032
|
+
}
|
|
3033
|
+
async open() {
|
|
3034
|
+
import_log12.log.trace("dxos.mesh.webrtc-transport.open", import_protocols7.trace.begin({
|
|
2941
3035
|
id: this._instanceId
|
|
2942
3036
|
}), {
|
|
2943
|
-
F:
|
|
2944
|
-
L:
|
|
3037
|
+
F: __dxlog_file13,
|
|
3038
|
+
L: 122,
|
|
2945
3039
|
S: this,
|
|
2946
3040
|
C: (f, a) => f(...a)
|
|
2947
3041
|
});
|
|
2948
|
-
(0,
|
|
2949
|
-
|
|
2950
|
-
|
|
3042
|
+
(0, import_log12.log)("created connection", {
|
|
3043
|
+
params: this._params
|
|
3044
|
+
}, {
|
|
3045
|
+
F: __dxlog_file13,
|
|
3046
|
+
L: 123,
|
|
2951
3047
|
S: this,
|
|
2952
3048
|
C: (f, a) => f(...a)
|
|
2953
3049
|
});
|
|
3050
|
+
const providedIceServers = await this._params.iceProvider?.getIceServers();
|
|
3051
|
+
if (!this._params.webrtcConfig) {
|
|
3052
|
+
this._params.webrtcConfig = {};
|
|
3053
|
+
}
|
|
3054
|
+
this._params.webrtcConfig.iceServers = [
|
|
3055
|
+
...this._params.webrtcConfig.iceServers ?? [],
|
|
3056
|
+
...providedIceServers ?? []
|
|
3057
|
+
];
|
|
2954
3058
|
this._peer = new import_simple_peer.default({
|
|
2955
3059
|
channelName: "dxos.mesh.transport",
|
|
2956
3060
|
initiator: this._params.initiator,
|
|
@@ -2958,9 +3062,9 @@ var SimplePeerTransport = class {
|
|
|
2958
3062
|
config: this._params.webrtcConfig
|
|
2959
3063
|
});
|
|
2960
3064
|
this._peer.on("signal", async (data) => {
|
|
2961
|
-
(0,
|
|
2962
|
-
F:
|
|
2963
|
-
L:
|
|
3065
|
+
(0, import_log12.log)("signal", data, {
|
|
3066
|
+
F: __dxlog_file13,
|
|
3067
|
+
L: 142,
|
|
2964
3068
|
S: this,
|
|
2965
3069
|
C: (f, a) => f(...a)
|
|
2966
3070
|
});
|
|
@@ -2971,9 +3075,9 @@ var SimplePeerTransport = class {
|
|
|
2971
3075
|
});
|
|
2972
3076
|
});
|
|
2973
3077
|
this._peer.on("connect", () => {
|
|
2974
|
-
(0,
|
|
2975
|
-
F:
|
|
2976
|
-
L:
|
|
3078
|
+
(0, import_log12.log)("connected", void 0, {
|
|
3079
|
+
F: __dxlog_file13,
|
|
3080
|
+
L: 147,
|
|
2977
3081
|
S: this,
|
|
2978
3082
|
C: (f, a) => f(...a)
|
|
2979
3083
|
});
|
|
@@ -2982,9 +3086,9 @@ var SimplePeerTransport = class {
|
|
|
2982
3086
|
this.connected.emit();
|
|
2983
3087
|
});
|
|
2984
3088
|
this._peer.on("close", async () => {
|
|
2985
|
-
(0,
|
|
2986
|
-
F:
|
|
2987
|
-
L:
|
|
3089
|
+
(0, import_log12.log)("closed", void 0, {
|
|
3090
|
+
F: __dxlog_file13,
|
|
3091
|
+
L: 154,
|
|
2988
3092
|
S: this,
|
|
2989
3093
|
C: (f, a) => f(...a)
|
|
2990
3094
|
});
|
|
@@ -2995,20 +3099,20 @@ var SimplePeerTransport = class {
|
|
|
2995
3099
|
if (err.errorDetail === "sctp-failure") {
|
|
2996
3100
|
this.errors.raise(new import_protocols7.ConnectionResetError("sctp-failure from RTCError", err));
|
|
2997
3101
|
} else {
|
|
2998
|
-
|
|
3102
|
+
import_log12.log.info("unknown RTCError", {
|
|
2999
3103
|
err
|
|
3000
3104
|
}, {
|
|
3001
|
-
F:
|
|
3002
|
-
L:
|
|
3105
|
+
F: __dxlog_file13,
|
|
3106
|
+
L: 165,
|
|
3003
3107
|
S: this,
|
|
3004
3108
|
C: (f, a) => f(...a)
|
|
3005
3109
|
});
|
|
3006
3110
|
this.errors.raise(new import_protocols7.UnknownProtocolError("unknown RTCError", err));
|
|
3007
3111
|
}
|
|
3008
3112
|
} else if ("code" in err) {
|
|
3009
|
-
|
|
3010
|
-
F:
|
|
3011
|
-
L:
|
|
3113
|
+
import_log12.log.info("simple-peer error", err, {
|
|
3114
|
+
F: __dxlog_file13,
|
|
3115
|
+
L: 170,
|
|
3012
3116
|
S: this,
|
|
3013
3117
|
C: (f, a) => f(...a)
|
|
3014
3118
|
});
|
|
@@ -3036,9 +3140,9 @@ var SimplePeerTransport = class {
|
|
|
3036
3140
|
break;
|
|
3037
3141
|
}
|
|
3038
3142
|
} else {
|
|
3039
|
-
|
|
3040
|
-
F:
|
|
3041
|
-
L:
|
|
3143
|
+
import_log12.log.info("unknown peer connection error", err, {
|
|
3144
|
+
F: __dxlog_file13,
|
|
3145
|
+
L: 196,
|
|
3042
3146
|
S: this,
|
|
3043
3147
|
C: (f, a) => f(...a)
|
|
3044
3148
|
});
|
|
@@ -3047,95 +3151,40 @@ var SimplePeerTransport = class {
|
|
|
3047
3151
|
try {
|
|
3048
3152
|
if (typeof this._peer?._pc?.getStats === "function") {
|
|
3049
3153
|
this._peer._pc.getStats().then((stats) => {
|
|
3050
|
-
|
|
3154
|
+
import_log12.log.info("report after webrtc error", {
|
|
3051
3155
|
config: this._params.webrtcConfig,
|
|
3052
3156
|
stats: Object.fromEntries(stats.entries())
|
|
3053
3157
|
}, {
|
|
3054
|
-
F:
|
|
3055
|
-
L:
|
|
3158
|
+
F: __dxlog_file13,
|
|
3159
|
+
L: 204,
|
|
3056
3160
|
S: this,
|
|
3057
3161
|
C: (f, a) => f(...a)
|
|
3058
3162
|
});
|
|
3059
3163
|
});
|
|
3060
3164
|
}
|
|
3061
3165
|
} catch (err2) {
|
|
3062
|
-
|
|
3063
|
-
F:
|
|
3064
|
-
L:
|
|
3166
|
+
import_log12.log.catch(err2, void 0, {
|
|
3167
|
+
F: __dxlog_file13,
|
|
3168
|
+
L: 211,
|
|
3065
3169
|
S: this,
|
|
3066
3170
|
C: (f, a) => f(...a)
|
|
3067
3171
|
});
|
|
3068
3172
|
}
|
|
3069
3173
|
await this.close();
|
|
3070
3174
|
});
|
|
3071
|
-
|
|
3175
|
+
import_log12.log.trace("dxos.mesh.webrtc-transport.open", import_protocols7.trace.end({
|
|
3072
3176
|
id: this._instanceId
|
|
3073
3177
|
}), {
|
|
3074
|
-
F:
|
|
3075
|
-
L:
|
|
3178
|
+
F: __dxlog_file13,
|
|
3179
|
+
L: 217,
|
|
3076
3180
|
S: this,
|
|
3077
3181
|
C: (f, a) => f(...a)
|
|
3078
3182
|
});
|
|
3079
3183
|
}
|
|
3080
|
-
async getStats() {
|
|
3081
|
-
const stats = await this._getStats();
|
|
3082
|
-
if (!stats) {
|
|
3083
|
-
return {
|
|
3084
|
-
bytesSent: 0,
|
|
3085
|
-
bytesReceived: 0,
|
|
3086
|
-
packetsSent: 0,
|
|
3087
|
-
packetsReceived: 0,
|
|
3088
|
-
rawStats: {}
|
|
3089
|
-
};
|
|
3090
|
-
}
|
|
3091
|
-
return {
|
|
3092
|
-
bytesSent: stats.transport.bytesSent,
|
|
3093
|
-
bytesReceived: stats.transport.bytesReceived,
|
|
3094
|
-
packetsSent: stats.transport.packetsSent,
|
|
3095
|
-
packetsReceived: stats.transport.packetsReceived,
|
|
3096
|
-
rawStats: stats.raw
|
|
3097
|
-
};
|
|
3098
|
-
}
|
|
3099
|
-
async _getStats() {
|
|
3100
|
-
if (typeof this._peer?._pc?.getStats !== "function") {
|
|
3101
|
-
return null;
|
|
3102
|
-
}
|
|
3103
|
-
return await this._peer._pc.getStats().then((stats) => {
|
|
3104
|
-
const statsEntries = Array.from(stats.entries());
|
|
3105
|
-
const transport = statsEntries.filter((s) => s[1].type === "transport")[0][1];
|
|
3106
|
-
const candidatePair = statsEntries.filter((s) => s[0] === transport.selectedCandidatePairId);
|
|
3107
|
-
let selectedCandidatePair;
|
|
3108
|
-
let remoteCandidate;
|
|
3109
|
-
if (candidatePair.length > 0) {
|
|
3110
|
-
selectedCandidatePair = candidatePair[0][1];
|
|
3111
|
-
remoteCandidate = statsEntries.filter((s) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
3112
|
-
}
|
|
3113
|
-
return {
|
|
3114
|
-
datachannel: statsEntries.filter((s) => s[1].type === "data-channel")[0][1],
|
|
3115
|
-
transport,
|
|
3116
|
-
selectedCandidatePair,
|
|
3117
|
-
remoteCandidate,
|
|
3118
|
-
raw: Object.fromEntries(stats.entries())
|
|
3119
|
-
};
|
|
3120
|
-
});
|
|
3121
|
-
}
|
|
3122
|
-
async getDetails() {
|
|
3123
|
-
const stats = await this._getStats();
|
|
3124
|
-
const rc = stats?.remoteCandidate;
|
|
3125
|
-
if (!rc) {
|
|
3126
|
-
return "unavailable";
|
|
3127
|
-
}
|
|
3128
|
-
if (rc.candidateType === "relay") {
|
|
3129
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
3130
|
-
}
|
|
3131
|
-
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
3132
|
-
}
|
|
3133
|
-
async open() {
|
|
3134
|
-
}
|
|
3135
3184
|
async close() {
|
|
3136
|
-
(0,
|
|
3137
|
-
F:
|
|
3138
|
-
L:
|
|
3185
|
+
(0, import_log12.log)("closing...", void 0, {
|
|
3186
|
+
F: __dxlog_file13,
|
|
3187
|
+
L: 222,
|
|
3139
3188
|
S: this,
|
|
3140
3189
|
C: (f, a) => f(...a)
|
|
3141
3190
|
});
|
|
@@ -3146,9 +3195,9 @@ var SimplePeerTransport = class {
|
|
|
3146
3195
|
this._peer.destroy();
|
|
3147
3196
|
this._closed = true;
|
|
3148
3197
|
this.closed.emit();
|
|
3149
|
-
(0,
|
|
3150
|
-
F:
|
|
3151
|
-
L:
|
|
3198
|
+
(0, import_log12.log)("closed", void 0, {
|
|
3199
|
+
F: __dxlog_file13,
|
|
3200
|
+
L: 230,
|
|
3152
3201
|
S: this,
|
|
3153
3202
|
C: (f, a) => f(...a)
|
|
3154
3203
|
});
|
|
@@ -3158,6 +3207,7 @@ var SimplePeerTransport = class {
|
|
|
3158
3207
|
return;
|
|
3159
3208
|
}
|
|
3160
3209
|
(0, import_tiny_invariant.default)(signal.payload.data, "Signal message must contain signal data.");
|
|
3210
|
+
(0, import_tiny_invariant.default)(this._peer, "Peer must be initialized before receiving signals.");
|
|
3161
3211
|
this._peer.signal(signal.payload.data);
|
|
3162
3212
|
}
|
|
3163
3213
|
_disconnectStreams() {
|
|
@@ -3166,11 +3216,21 @@ var SimplePeerTransport = class {
|
|
|
3166
3216
|
}
|
|
3167
3217
|
}
|
|
3168
3218
|
};
|
|
3169
|
-
|
|
3219
|
+
_ts_decorate6([
|
|
3220
|
+
import_async10.synchronized
|
|
3221
|
+
], SimplePeerTransport.prototype, "open", null);
|
|
3222
|
+
_ts_decorate6([
|
|
3223
|
+
import_async10.synchronized
|
|
3224
|
+
], SimplePeerTransport.prototype, "close", null);
|
|
3225
|
+
_ts_decorate6([
|
|
3226
|
+
import_async10.synchronized
|
|
3227
|
+
], SimplePeerTransport.prototype, "onSignal", null);
|
|
3228
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-service.ts";
|
|
3170
3229
|
var SimplePeerTransportService = class {
|
|
3171
|
-
constructor(_webrtcConfig) {
|
|
3230
|
+
constructor(_webrtcConfig, _iceProvider) {
|
|
3172
3231
|
this._webrtcConfig = _webrtcConfig;
|
|
3173
|
-
this.
|
|
3232
|
+
this._iceProvider = _iceProvider;
|
|
3233
|
+
this.transports = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
|
|
3174
3234
|
}
|
|
3175
3235
|
open(request) {
|
|
3176
3236
|
const rpcStream = new import_codec_protobuf.Stream(({ ready, next, close }) => {
|
|
@@ -3203,7 +3263,8 @@ var SimplePeerTransportService = class {
|
|
|
3203
3263
|
payload: signal
|
|
3204
3264
|
}
|
|
3205
3265
|
});
|
|
3206
|
-
}
|
|
3266
|
+
},
|
|
3267
|
+
iceProvider: this._iceProvider
|
|
3207
3268
|
});
|
|
3208
3269
|
void transport.open();
|
|
3209
3270
|
next({
|
|
@@ -3248,8 +3309,8 @@ var SimplePeerTransportService = class {
|
|
|
3248
3309
|
}
|
|
3249
3310
|
async sendSignal({ proxyId, signal }) {
|
|
3250
3311
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3251
|
-
F:
|
|
3252
|
-
L:
|
|
3312
|
+
F: __dxlog_file14,
|
|
3313
|
+
L: 124,
|
|
3253
3314
|
S: this,
|
|
3254
3315
|
A: [
|
|
3255
3316
|
"this.transports.has(proxyId)",
|
|
@@ -3260,8 +3321,8 @@ var SimplePeerTransportService = class {
|
|
|
3260
3321
|
}
|
|
3261
3322
|
async getDetails({ proxyId }) {
|
|
3262
3323
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3263
|
-
F:
|
|
3264
|
-
L:
|
|
3324
|
+
F: __dxlog_file14,
|
|
3325
|
+
L: 129,
|
|
3265
3326
|
S: this,
|
|
3266
3327
|
A: [
|
|
3267
3328
|
"this.transports.has(proxyId)",
|
|
@@ -3274,8 +3335,8 @@ var SimplePeerTransportService = class {
|
|
|
3274
3335
|
}
|
|
3275
3336
|
async getStats({ proxyId }) {
|
|
3276
3337
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3277
|
-
F:
|
|
3278
|
-
L:
|
|
3338
|
+
F: __dxlog_file14,
|
|
3339
|
+
L: 134,
|
|
3279
3340
|
S: this,
|
|
3280
3341
|
A: [
|
|
3281
3342
|
"this.transports.has(proxyId)",
|
|
@@ -3288,16 +3349,16 @@ var SimplePeerTransportService = class {
|
|
|
3288
3349
|
}
|
|
3289
3350
|
async sendData({ proxyId, payload }) {
|
|
3290
3351
|
if (this.transports.get(proxyId)?.state !== "OPEN") {
|
|
3291
|
-
|
|
3292
|
-
F:
|
|
3293
|
-
L:
|
|
3352
|
+
import_log13.log.debug("transport is closed", void 0, {
|
|
3353
|
+
F: __dxlog_file14,
|
|
3354
|
+
L: 140,
|
|
3294
3355
|
S: this,
|
|
3295
3356
|
C: (f, a) => f(...a)
|
|
3296
3357
|
});
|
|
3297
3358
|
}
|
|
3298
3359
|
(0, import_invariant11.invariant)(this.transports.has(proxyId), void 0, {
|
|
3299
|
-
F:
|
|
3300
|
-
L:
|
|
3360
|
+
F: __dxlog_file14,
|
|
3361
|
+
L: 142,
|
|
3301
3362
|
S: this,
|
|
3302
3363
|
A: [
|
|
3303
3364
|
"this.transports.has(proxyId)",
|
|
@@ -3318,15 +3379,15 @@ var SimplePeerTransportService = class {
|
|
|
3318
3379
|
if (this.transports.get(proxyId)) {
|
|
3319
3380
|
this.transports.get(proxyId).state = "CLOSED";
|
|
3320
3381
|
}
|
|
3321
|
-
(0,
|
|
3322
|
-
F:
|
|
3323
|
-
L:
|
|
3382
|
+
(0, import_log13.log)("Closed.", void 0, {
|
|
3383
|
+
F: __dxlog_file14,
|
|
3384
|
+
L: 158,
|
|
3324
3385
|
S: this,
|
|
3325
3386
|
C: (f, a) => f(...a)
|
|
3326
3387
|
});
|
|
3327
3388
|
}
|
|
3328
3389
|
};
|
|
3329
|
-
var
|
|
3390
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/simplepeer-transport-proxy.ts";
|
|
3330
3391
|
var RPC_TIMEOUT = 1e4;
|
|
3331
3392
|
var RESP_MIN_THRESHOLD = 500;
|
|
3332
3393
|
var TIMEOUT_THRESHOLD = 10;
|
|
@@ -3335,12 +3396,12 @@ var SimplePeerTransportProxy = class {
|
|
|
3335
3396
|
this._options = _options;
|
|
3336
3397
|
this._proxyId = import_keys12.PublicKey.random();
|
|
3337
3398
|
this._ctx = new import_context6.Context(void 0, {
|
|
3338
|
-
F:
|
|
3399
|
+
F: __dxlog_file15,
|
|
3339
3400
|
L: 37
|
|
3340
3401
|
});
|
|
3341
3402
|
this._timeoutCount = 0;
|
|
3342
|
-
this.closed = new
|
|
3343
|
-
this.connected = new
|
|
3403
|
+
this.closed = new import_async11.Event();
|
|
3404
|
+
this.connected = new import_async11.Event();
|
|
3344
3405
|
this.errors = new import_debug6.ErrorStream();
|
|
3345
3406
|
this._closed = false;
|
|
3346
3407
|
}
|
|
@@ -3356,8 +3417,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3356
3417
|
});
|
|
3357
3418
|
this._serviceStream.waitUntilReady().then(() => {
|
|
3358
3419
|
this._serviceStream.subscribe(async (event) => {
|
|
3359
|
-
(0,
|
|
3360
|
-
F:
|
|
3420
|
+
(0, import_log14.log)("SimplePeerTransportProxy: event", event, {
|
|
3421
|
+
F: __dxlog_file15,
|
|
3361
3422
|
L: 66,
|
|
3362
3423
|
S: this,
|
|
3363
3424
|
C: (f, a) => f(...a)
|
|
@@ -3380,13 +3441,13 @@ var SimplePeerTransportProxy = class {
|
|
|
3380
3441
|
timeout: RPC_TIMEOUT
|
|
3381
3442
|
}).then(() => {
|
|
3382
3443
|
if (performance.now() - then > RESP_MIN_THRESHOLD) {
|
|
3383
|
-
(0,
|
|
3384
|
-
F:
|
|
3444
|
+
(0, import_log14.log)("slow response, delaying callback", void 0, {
|
|
3445
|
+
F: __dxlog_file15,
|
|
3385
3446
|
L: 90,
|
|
3386
3447
|
S: this,
|
|
3387
3448
|
C: (f, a) => f(...a)
|
|
3388
3449
|
});
|
|
3389
|
-
(0,
|
|
3450
|
+
(0, import_async11.scheduleTask)(this._ctx, () => callback(), RESP_MIN_THRESHOLD);
|
|
3390
3451
|
} else {
|
|
3391
3452
|
callback();
|
|
3392
3453
|
}
|
|
@@ -3396,8 +3457,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3396
3457
|
if (this._timeoutCount++ > TIMEOUT_THRESHOLD) {
|
|
3397
3458
|
throw new import_protocols8.TimeoutError(`too many timeouts (${this._timeoutCount} > ${TIMEOUT_THRESHOLD}`);
|
|
3398
3459
|
} else {
|
|
3399
|
-
(0,
|
|
3400
|
-
F:
|
|
3460
|
+
(0, import_log14.log)("timeout error, but still invoking callback", void 0, {
|
|
3461
|
+
F: __dxlog_file15,
|
|
3401
3462
|
L: 102,
|
|
3402
3463
|
S: this,
|
|
3403
3464
|
C: (f, a) => f(...a)
|
|
@@ -3405,8 +3466,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3405
3466
|
callback();
|
|
3406
3467
|
}
|
|
3407
3468
|
} else {
|
|
3408
|
-
|
|
3409
|
-
F:
|
|
3469
|
+
import_log14.log.catch(err, void 0, {
|
|
3470
|
+
F: __dxlog_file15,
|
|
3410
3471
|
L: 106,
|
|
3411
3472
|
S: this,
|
|
3412
3473
|
C: (f, a) => f(...a)
|
|
@@ -3416,18 +3477,18 @@ var SimplePeerTransportProxy = class {
|
|
|
3416
3477
|
}
|
|
3417
3478
|
});
|
|
3418
3479
|
proxyStream.on("error", (err) => {
|
|
3419
|
-
(0,
|
|
3480
|
+
(0, import_log14.log)("proxystream error", {
|
|
3420
3481
|
err
|
|
3421
3482
|
}, {
|
|
3422
|
-
F:
|
|
3483
|
+
F: __dxlog_file15,
|
|
3423
3484
|
L: 114,
|
|
3424
3485
|
S: this,
|
|
3425
3486
|
C: (f, a) => f(...a)
|
|
3426
3487
|
});
|
|
3427
3488
|
});
|
|
3428
3489
|
this._options.stream.pipe(proxyStream);
|
|
3429
|
-
}, (error) =>
|
|
3430
|
-
F:
|
|
3490
|
+
}, (error) => import_log14.log.catch(error, void 0, {
|
|
3491
|
+
F: __dxlog_file15,
|
|
3431
3492
|
L: 119,
|
|
3432
3493
|
S: this,
|
|
3433
3494
|
C: (f, a) => f(...a)
|
|
@@ -3446,8 +3507,8 @@ var SimplePeerTransportProxy = class {
|
|
|
3446
3507
|
timeout: RPC_TIMEOUT
|
|
3447
3508
|
});
|
|
3448
3509
|
} catch (err) {
|
|
3449
|
-
|
|
3450
|
-
F:
|
|
3510
|
+
import_log14.log.catch(err, void 0, {
|
|
3511
|
+
F: __dxlog_file15,
|
|
3451
3512
|
L: 134,
|
|
3452
3513
|
S: this,
|
|
3453
3514
|
C: (f, a) => f(...a)
|
|
@@ -3480,7 +3541,7 @@ var SimplePeerTransportProxy = class {
|
|
|
3480
3541
|
}
|
|
3481
3542
|
}
|
|
3482
3543
|
_handleData(dataEvent) {
|
|
3483
|
-
this._options.stream.write((0,
|
|
3544
|
+
this._options.stream.write((0, import_util10.arrayToBuffer)(dataEvent.payload));
|
|
3484
3545
|
}
|
|
3485
3546
|
async _handleSignal(signalEvent) {
|
|
3486
3547
|
await this._options.sendSignal(signalEvent.payload);
|
|
@@ -3526,7 +3587,7 @@ var SimplePeerTransportProxyFactory = class {
|
|
|
3526
3587
|
}
|
|
3527
3588
|
createTransport(options) {
|
|
3528
3589
|
(0, import_invariant12.invariant)(this._bridgeService, "SimplePeerTransportProxyFactory is not ready to open connections", {
|
|
3529
|
-
F:
|
|
3590
|
+
F: __dxlog_file15,
|
|
3530
3591
|
L: 218,
|
|
3531
3592
|
S: this,
|
|
3532
3593
|
A: [
|
|
@@ -3559,7 +3620,7 @@ var decodeError = (err) => {
|
|
|
3559
3620
|
return typeof err === "string" ? new Error(err) : err;
|
|
3560
3621
|
}
|
|
3561
3622
|
};
|
|
3562
|
-
function
|
|
3623
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
3563
3624
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3564
3625
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3565
3626
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -3569,16 +3630,19 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
3569
3630
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3570
3631
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3571
3632
|
}
|
|
3572
|
-
var
|
|
3633
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/libdatachannel-transport.ts";
|
|
3573
3634
|
var DATACHANNEL_LABEL = "dxos.mesh.transport";
|
|
3574
3635
|
var MAX_BUFFERED_AMOUNT = 64 * 1024;
|
|
3575
3636
|
var MAX_MESSAGE_SIZE = 64 * 1024;
|
|
3576
|
-
var createLibDataChannelTransportFactory = (webrtcConfig) =>
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3637
|
+
var createLibDataChannelTransportFactory = (webrtcConfig, iceProvider) => {
|
|
3638
|
+
return {
|
|
3639
|
+
createTransport: (options) => new LibDataChannelTransport({
|
|
3640
|
+
...options,
|
|
3641
|
+
webrtcConfig,
|
|
3642
|
+
iceProvider
|
|
3643
|
+
})
|
|
3644
|
+
};
|
|
3645
|
+
};
|
|
3582
3646
|
var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
3583
3647
|
static {
|
|
3584
3648
|
this._instanceCount = 0;
|
|
@@ -3588,9 +3652,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3588
3652
|
this._closed = false;
|
|
3589
3653
|
this._connected = false;
|
|
3590
3654
|
this._writeCallback = null;
|
|
3591
|
-
this._readyForCandidates = new
|
|
3592
|
-
this.closed = new
|
|
3593
|
-
this.connected = new
|
|
3655
|
+
this._readyForCandidates = new import_async12.Trigger();
|
|
3656
|
+
this.closed = new import_async12.Event();
|
|
3657
|
+
this.connected = new import_async12.Event();
|
|
3594
3658
|
this.errors = new import_debug7.ErrorStream();
|
|
3595
3659
|
}
|
|
3596
3660
|
get isOpen() {
|
|
@@ -3601,42 +3665,43 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3601
3665
|
this.errors.raise(new Error("connection already closed"));
|
|
3602
3666
|
}
|
|
3603
3667
|
const { RTCPeerConnection } = (await importESM("node-datachannel/polyfill")).default;
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
this._options.webrtcConfig = {
|
|
3608
|
-
iceServers: []
|
|
3609
|
-
};
|
|
3668
|
+
const providedIceServers = await this._options.iceProvider?.getIceServers();
|
|
3669
|
+
if (!this._options.webrtcConfig) {
|
|
3670
|
+
this._options.webrtcConfig = {};
|
|
3610
3671
|
}
|
|
3672
|
+
this._options.webrtcConfig.iceServers = [
|
|
3673
|
+
...this._options.webrtcConfig.iceServers ?? [],
|
|
3674
|
+
...providedIceServers ?? []
|
|
3675
|
+
];
|
|
3611
3676
|
this._peer = new RTCPeerConnection(this._options.webrtcConfig);
|
|
3612
3677
|
this._peer.onicecandidateerror = (event) => {
|
|
3613
|
-
|
|
3678
|
+
import_log15.log.error("peer.onicecandidateerror", {
|
|
3614
3679
|
event
|
|
3615
3680
|
}, {
|
|
3616
|
-
F:
|
|
3617
|
-
L:
|
|
3681
|
+
F: __dxlog_file16,
|
|
3682
|
+
L: 93,
|
|
3618
3683
|
S: this,
|
|
3619
3684
|
C: (f, a) => f(...a)
|
|
3620
3685
|
});
|
|
3621
3686
|
};
|
|
3622
3687
|
this._peer.onconnectionstatechange = (event) => {
|
|
3623
|
-
|
|
3688
|
+
import_log15.log.debug("peer.onconnectionstatechange", {
|
|
3624
3689
|
event,
|
|
3625
3690
|
peerConnectionState: this._peer?.connectionState,
|
|
3626
3691
|
transportConnectionState: this._connected
|
|
3627
3692
|
}, {
|
|
3628
|
-
F:
|
|
3629
|
-
L:
|
|
3693
|
+
F: __dxlog_file16,
|
|
3694
|
+
L: 97,
|
|
3630
3695
|
S: this,
|
|
3631
3696
|
C: (f, a) => f(...a)
|
|
3632
3697
|
});
|
|
3633
3698
|
};
|
|
3634
3699
|
this._peer.onicecandidate = async (event) => {
|
|
3635
|
-
|
|
3700
|
+
import_log15.log.debug("peer.onicecandidate", {
|
|
3636
3701
|
event
|
|
3637
3702
|
}, {
|
|
3638
|
-
F:
|
|
3639
|
-
L:
|
|
3703
|
+
F: __dxlog_file16,
|
|
3704
|
+
L: 107,
|
|
3640
3705
|
S: this,
|
|
3641
3706
|
C: (f, a) => f(...a)
|
|
3642
3707
|
});
|
|
@@ -3656,11 +3721,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3656
3721
|
}
|
|
3657
3722
|
});
|
|
3658
3723
|
} catch (err) {
|
|
3659
|
-
|
|
3724
|
+
import_log15.log.info("signaling error", {
|
|
3660
3725
|
err
|
|
3661
3726
|
}, {
|
|
3662
|
-
F:
|
|
3663
|
-
L:
|
|
3727
|
+
F: __dxlog_file16,
|
|
3728
|
+
L: 124,
|
|
3664
3729
|
S: this,
|
|
3665
3730
|
C: (f, a) => f(...a)
|
|
3666
3731
|
});
|
|
@@ -3669,8 +3734,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3669
3734
|
};
|
|
3670
3735
|
if (this._options.initiator) {
|
|
3671
3736
|
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3672
|
-
F:
|
|
3673
|
-
L:
|
|
3737
|
+
F: __dxlog_file16,
|
|
3738
|
+
L: 130,
|
|
3674
3739
|
S: this,
|
|
3675
3740
|
A: [
|
|
3676
3741
|
"this._peer",
|
|
@@ -3682,22 +3747,22 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3682
3747
|
return;
|
|
3683
3748
|
}
|
|
3684
3749
|
if (this._peer?.connectionState !== "connecting") {
|
|
3685
|
-
|
|
3750
|
+
import_log15.log.error("peer not connecting", {
|
|
3686
3751
|
peer: this._peer
|
|
3687
3752
|
}, {
|
|
3688
|
-
F:
|
|
3689
|
-
L:
|
|
3753
|
+
F: __dxlog_file16,
|
|
3754
|
+
L: 141,
|
|
3690
3755
|
S: this,
|
|
3691
3756
|
C: (f, a) => f(...a)
|
|
3692
3757
|
});
|
|
3693
3758
|
this.errors.raise(new Error("invalid state: peer is initiator, but other peer not in state connecting"));
|
|
3694
3759
|
}
|
|
3695
|
-
|
|
3760
|
+
import_log15.log.debug("creating offer", {
|
|
3696
3761
|
peer: this._peer,
|
|
3697
3762
|
offer
|
|
3698
3763
|
}, {
|
|
3699
|
-
F:
|
|
3700
|
-
L:
|
|
3764
|
+
F: __dxlog_file16,
|
|
3765
|
+
L: 145,
|
|
3701
3766
|
S: this,
|
|
3702
3767
|
C: (f, a) => f(...a)
|
|
3703
3768
|
});
|
|
@@ -3714,9 +3779,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3714
3779
|
this.errors.raise(err);
|
|
3715
3780
|
});
|
|
3716
3781
|
this._handleChannel(this._peer.createDataChannel(DATACHANNEL_LABEL));
|
|
3717
|
-
|
|
3718
|
-
F:
|
|
3719
|
-
L:
|
|
3782
|
+
import_log15.log.debug("created data channel", void 0, {
|
|
3783
|
+
F: __dxlog_file16,
|
|
3784
|
+
L: 155,
|
|
3720
3785
|
S: this,
|
|
3721
3786
|
C: (f, a) => f(...a)
|
|
3722
3787
|
});
|
|
@@ -3725,11 +3790,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3725
3790
|
};
|
|
3726
3791
|
} else {
|
|
3727
3792
|
this._peer.ondatachannel = (event) => {
|
|
3728
|
-
|
|
3793
|
+
import_log15.log.debug("peer.ondatachannel (non-initiator)", {
|
|
3729
3794
|
event
|
|
3730
3795
|
}, {
|
|
3731
|
-
F:
|
|
3732
|
-
L:
|
|
3796
|
+
F: __dxlog_file16,
|
|
3797
|
+
L: 161,
|
|
3733
3798
|
S: this,
|
|
3734
3799
|
C: (f, a) => f(...a)
|
|
3735
3800
|
});
|
|
@@ -3767,9 +3832,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3767
3832
|
_handleChannel(dataChannel) {
|
|
3768
3833
|
this._channel = dataChannel;
|
|
3769
3834
|
this._channel.onopen = () => {
|
|
3770
|
-
|
|
3771
|
-
F:
|
|
3772
|
-
L:
|
|
3835
|
+
import_log15.log.debug("channel.onopen", void 0, {
|
|
3836
|
+
F: __dxlog_file16,
|
|
3837
|
+
L: 206,
|
|
3773
3838
|
S: this,
|
|
3774
3839
|
C: (f, a) => f(...a)
|
|
3775
3840
|
});
|
|
@@ -3788,9 +3853,9 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3788
3853
|
}
|
|
3789
3854
|
if (this._channel.bufferedAmount > MAX_BUFFERED_AMOUNT) {
|
|
3790
3855
|
if (this._writeCallback !== null) {
|
|
3791
|
-
|
|
3792
|
-
F:
|
|
3793
|
-
L:
|
|
3856
|
+
import_log15.log.error("consumer trying to write before we are ready for more data", void 0, {
|
|
3857
|
+
F: __dxlog_file16,
|
|
3858
|
+
L: 223,
|
|
3794
3859
|
S: this,
|
|
3795
3860
|
C: (f, a) => f(...a)
|
|
3796
3861
|
});
|
|
@@ -3807,11 +3872,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3807
3872
|
this.connected.emit();
|
|
3808
3873
|
};
|
|
3809
3874
|
this._channel.onclose = async (err) => {
|
|
3810
|
-
|
|
3875
|
+
import_log15.log.info("channel.onclose", {
|
|
3811
3876
|
err
|
|
3812
3877
|
}, {
|
|
3813
|
-
F:
|
|
3814
|
-
L:
|
|
3878
|
+
F: __dxlog_file16,
|
|
3879
|
+
L: 239,
|
|
3815
3880
|
S: this,
|
|
3816
3881
|
C: (f, a) => f(...a)
|
|
3817
3882
|
});
|
|
@@ -3836,8 +3901,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3836
3901
|
}
|
|
3837
3902
|
async onSignal(signal) {
|
|
3838
3903
|
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3839
|
-
F:
|
|
3840
|
-
L:
|
|
3904
|
+
F: __dxlog_file16,
|
|
3905
|
+
L: 265,
|
|
3841
3906
|
S: this,
|
|
3842
3907
|
A: [
|
|
3843
3908
|
"this._peer",
|
|
@@ -3849,11 +3914,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3849
3914
|
switch (data.type) {
|
|
3850
3915
|
case "offer": {
|
|
3851
3916
|
if (this._peer.connectionState !== "new") {
|
|
3852
|
-
|
|
3917
|
+
import_log15.log.error("received offer but peer not in state new", {
|
|
3853
3918
|
peer: this._peer
|
|
3854
3919
|
}, {
|
|
3855
|
-
F:
|
|
3856
|
-
L:
|
|
3920
|
+
F: __dxlog_file16,
|
|
3921
|
+
L: 272,
|
|
3857
3922
|
S: this,
|
|
3858
3923
|
C: (f, a) => f(...a)
|
|
3859
3924
|
});
|
|
@@ -3877,11 +3942,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3877
3942
|
});
|
|
3878
3943
|
this._readyForCandidates.wake();
|
|
3879
3944
|
} catch (err) {
|
|
3880
|
-
|
|
3945
|
+
import_log15.log.error("cannot handle offer from signalling server", {
|
|
3881
3946
|
err
|
|
3882
3947
|
}, {
|
|
3883
|
-
F:
|
|
3884
|
-
L:
|
|
3948
|
+
F: __dxlog_file16,
|
|
3949
|
+
L: 284,
|
|
3885
3950
|
S: this,
|
|
3886
3951
|
C: (f, a) => f(...a)
|
|
3887
3952
|
});
|
|
@@ -3897,11 +3962,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3897
3962
|
});
|
|
3898
3963
|
this._readyForCandidates.wake();
|
|
3899
3964
|
} catch (err) {
|
|
3900
|
-
|
|
3965
|
+
import_log15.log.error("cannot handle answer from signalling server", {
|
|
3901
3966
|
err
|
|
3902
3967
|
}, {
|
|
3903
|
-
F:
|
|
3904
|
-
L:
|
|
3968
|
+
F: __dxlog_file16,
|
|
3969
|
+
L: 295,
|
|
3905
3970
|
S: this,
|
|
3906
3971
|
C: (f, a) => f(...a)
|
|
3907
3972
|
});
|
|
@@ -3915,21 +3980,21 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3915
3980
|
});
|
|
3916
3981
|
break;
|
|
3917
3982
|
default:
|
|
3918
|
-
|
|
3983
|
+
import_log15.log.error("unhandled signal type", {
|
|
3919
3984
|
type: data.type,
|
|
3920
3985
|
signal
|
|
3921
3986
|
}, {
|
|
3922
|
-
F:
|
|
3923
|
-
L:
|
|
3987
|
+
F: __dxlog_file16,
|
|
3988
|
+
L: 306,
|
|
3924
3989
|
S: this,
|
|
3925
3990
|
C: (f, a) => f(...a)
|
|
3926
3991
|
});
|
|
3927
3992
|
this.errors.raise(new Error(`unhandled signal type ${data.type}`));
|
|
3928
3993
|
}
|
|
3929
3994
|
} catch (err) {
|
|
3930
|
-
|
|
3931
|
-
F:
|
|
3932
|
-
L:
|
|
3995
|
+
import_log15.log.catch(err, void 0, {
|
|
3996
|
+
F: __dxlog_file16,
|
|
3997
|
+
L: 310,
|
|
3933
3998
|
S: this,
|
|
3934
3999
|
C: (f, a) => f(...a)
|
|
3935
4000
|
});
|
|
@@ -3967,8 +4032,8 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3967
4032
|
}
|
|
3968
4033
|
async _getStats() {
|
|
3969
4034
|
(0, import_invariant13.invariant)(this._peer, "not open", {
|
|
3970
|
-
F:
|
|
3971
|
-
L:
|
|
4035
|
+
F: __dxlog_file16,
|
|
4036
|
+
L: 350,
|
|
3972
4037
|
S: this,
|
|
3973
4038
|
A: [
|
|
3974
4039
|
"this._peer",
|
|
@@ -3996,11 +4061,11 @@ var LibDataChannelTransport = class _LibDataChannelTransport {
|
|
|
3996
4061
|
this._options.stream.unpipe?.(this._stream)?.unpipe?.(this._options.stream);
|
|
3997
4062
|
}
|
|
3998
4063
|
};
|
|
3999
|
-
|
|
4000
|
-
|
|
4064
|
+
_ts_decorate7([
|
|
4065
|
+
import_async12.synchronized
|
|
4001
4066
|
], LibDataChannelTransport.prototype, "_close", null);
|
|
4002
4067
|
var importESM = Function("path", "return import(path)");
|
|
4003
|
-
var
|
|
4068
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/tcp-transport.ts";
|
|
4004
4069
|
var TcpTransportFactory = {
|
|
4005
4070
|
createTransport: (options) => new TcpTransport(options)
|
|
4006
4071
|
};
|
|
@@ -4011,16 +4076,16 @@ var TcpTransport = class {
|
|
|
4011
4076
|
this._socket = void 0;
|
|
4012
4077
|
this._connected = false;
|
|
4013
4078
|
this._closed = false;
|
|
4014
|
-
this.closed = new
|
|
4015
|
-
this.connected = new
|
|
4079
|
+
this.closed = new import_async13.Event();
|
|
4080
|
+
this.connected = new import_async13.Event();
|
|
4016
4081
|
this.errors = new import_debug8.ErrorStream();
|
|
4017
4082
|
}
|
|
4018
4083
|
get isOpen() {
|
|
4019
4084
|
return this._connected && !this._closed;
|
|
4020
4085
|
}
|
|
4021
4086
|
async open() {
|
|
4022
|
-
(0,
|
|
4023
|
-
F:
|
|
4087
|
+
(0, import_log16.log)("opening", void 0, {
|
|
4088
|
+
F: __dxlog_file17,
|
|
4024
4089
|
L: 39,
|
|
4025
4090
|
S: this,
|
|
4026
4091
|
C: (f, a) => f(...a)
|
|
@@ -4029,8 +4094,8 @@ var TcpTransport = class {
|
|
|
4029
4094
|
setTimeout(async () => {
|
|
4030
4095
|
const { Server } = await import("node:net");
|
|
4031
4096
|
this._server = new Server((socket) => {
|
|
4032
|
-
(0,
|
|
4033
|
-
F:
|
|
4097
|
+
(0, import_log16.log)("new connection", void 0, {
|
|
4098
|
+
F: __dxlog_file17,
|
|
4034
4099
|
L: 47,
|
|
4035
4100
|
S: this,
|
|
4036
4101
|
C: (f, a) => f(...a)
|
|
@@ -4042,10 +4107,10 @@ var TcpTransport = class {
|
|
|
4042
4107
|
});
|
|
4043
4108
|
this._server.on("listening", () => {
|
|
4044
4109
|
const { port } = this._server.address();
|
|
4045
|
-
(0,
|
|
4110
|
+
(0, import_log16.log)("listening", {
|
|
4046
4111
|
port
|
|
4047
4112
|
}, {
|
|
4048
|
-
F:
|
|
4113
|
+
F: __dxlog_file17,
|
|
4049
4114
|
L: 56,
|
|
4050
4115
|
S: this,
|
|
4051
4116
|
C: (f, a) => f(...a)
|
|
@@ -4068,8 +4133,8 @@ var TcpTransport = class {
|
|
|
4068
4133
|
}
|
|
4069
4134
|
}
|
|
4070
4135
|
async close() {
|
|
4071
|
-
(0,
|
|
4072
|
-
F:
|
|
4136
|
+
(0, import_log16.log)("closing", void 0, {
|
|
4137
|
+
F: __dxlog_file17,
|
|
4073
4138
|
L: 78,
|
|
4074
4139
|
S: this,
|
|
4075
4140
|
C: (f, a) => f(...a)
|
|
@@ -4079,10 +4144,10 @@ var TcpTransport = class {
|
|
|
4079
4144
|
this._closed = true;
|
|
4080
4145
|
}
|
|
4081
4146
|
async onSignal({ payload }) {
|
|
4082
|
-
(0,
|
|
4147
|
+
(0, import_log16.log)("received signal", {
|
|
4083
4148
|
payload
|
|
4084
4149
|
}, {
|
|
4085
|
-
F:
|
|
4150
|
+
F: __dxlog_file17,
|
|
4086
4151
|
L: 85,
|
|
4087
4152
|
S: this,
|
|
4088
4153
|
C: (f, a) => f(...a)
|
|
@@ -4114,21 +4179,21 @@ var TcpTransport = class {
|
|
|
4114
4179
|
};
|
|
4115
4180
|
}
|
|
4116
4181
|
_handleSocket(socket) {
|
|
4117
|
-
(0,
|
|
4182
|
+
(0, import_log16.log)("handling socket", {
|
|
4118
4183
|
remotePort: socket.remotePort,
|
|
4119
4184
|
localPort: socket.localPort
|
|
4120
4185
|
}, {
|
|
4121
|
-
F:
|
|
4186
|
+
F: __dxlog_file17,
|
|
4122
4187
|
L: 115,
|
|
4123
4188
|
S: this,
|
|
4124
4189
|
C: (f, a) => f(...a)
|
|
4125
4190
|
});
|
|
4126
4191
|
this._socket = socket;
|
|
4127
4192
|
this._socket.on("connect", () => {
|
|
4128
|
-
(0,
|
|
4193
|
+
(0, import_log16.log)("connected to", {
|
|
4129
4194
|
port: this._socket?.remotePort
|
|
4130
4195
|
}, {
|
|
4131
|
-
F:
|
|
4196
|
+
F: __dxlog_file17,
|
|
4132
4197
|
L: 119,
|
|
4133
4198
|
S: this,
|
|
4134
4199
|
C: (f, a) => f(...a)
|
|
@@ -4191,8 +4256,9 @@ var createTeleportProtocolFactory = (onConnection, defaultParams) => {
|
|
|
4191
4256
|
TcpTransport,
|
|
4192
4257
|
TcpTransportFactory,
|
|
4193
4258
|
TransportKind,
|
|
4259
|
+
createIceProvider,
|
|
4194
4260
|
createLibDataChannelTransportFactory,
|
|
4195
4261
|
createSimplePeerTransportFactory,
|
|
4196
4262
|
createTeleportProtocolFactory
|
|
4197
4263
|
});
|
|
4198
|
-
//# sourceMappingURL=chunk-
|
|
4264
|
+
//# sourceMappingURL=chunk-DZJ3BJOK.cjs.map
|