@dxos/network-manager 0.1.17 → 0.1.18
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/index.mjs +144 -276
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +153 -342
- package/dist/lib/node/index.cjs +145 -281
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +153 -345
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/network-manager.d.ts +1 -5
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +4 -0
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts +1 -3
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +0 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +2 -2
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-wire-protocol.d.ts +14 -0
- package/dist/types/src/testing/test-wire-protocol.d.ts.map +1 -0
- package/dist/types/src/tests/basic-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/property-test-suite.d.ts.map +1 -1
- package/dist/types/src/tests/utils.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +3 -3
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +0 -10
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/package.json +16 -18
- package/src/connection-log.ts +26 -26
- package/src/index.ts +0 -1
- package/src/network-manager.ts +1 -8
- package/src/swarm/connection.ts +12 -1
- package/src/swarm/peer.ts +1 -3
- package/src/swarm/swarm-mapper.ts +29 -31
- package/src/swarm/swarm.test.ts +12 -34
- package/src/testing/index.ts +0 -1
- package/src/testing/test-builder.ts +4 -7
- package/src/testing/test-wire-protocol.ts +44 -0
- package/src/tests/basic-test-suite.ts +13 -53
- package/src/tests/property-test-suite.ts +13 -15
- package/src/tests/utils.ts +10 -37
- package/src/transport/memory-transport.test.ts +13 -52
- package/src/transport/memory-transport.ts +37 -29
- package/src/transport/webrtc-transport-proxy.test.ts +13 -73
- package/src/transport/webrtc-transport.test.ts +7 -38
- package/src/wire-protocol.ts +0 -24
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/types/src/protocol-factory.d.ts +0 -36
- package/dist/types/src/protocol-factory.d.ts.map +0 -1
- package/dist/types/src/testing/test-protocol.d.ts +0 -52
- package/dist/types/src/testing/test-protocol.d.ts.map +0 -1
- package/dist/types/src/tests/presence.test.d.ts +0 -2
- package/dist/types/src/tests/presence.test.d.ts.map +0 -1
- package/src/protocol-factory.ts +0 -88
- package/src/testing/test-protocol.ts +0 -166
- package/src/tests/presence.test.ts +0 -80
|
@@ -29,19 +29,16 @@ __export(testing_exports, {
|
|
|
29
29
|
TEST_SIGNAL_URL: () => TEST_SIGNAL_URL,
|
|
30
30
|
TestBuilder: () => TestBuilder,
|
|
31
31
|
TestPeer: () => TestPeer,
|
|
32
|
-
|
|
33
|
-
TestSwarmConnection: () => TestSwarmConnection,
|
|
34
|
-
getPeerId: () => getPeerId,
|
|
35
|
-
testProtocolProvider: () => testProtocolProvider
|
|
32
|
+
TestSwarmConnection: () => TestSwarmConnection
|
|
36
33
|
});
|
|
37
34
|
module.exports = __toCommonJS(testing_exports);
|
|
38
35
|
|
|
39
36
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
40
|
-
var
|
|
37
|
+
var import_keys11 = require("@dxos/keys");
|
|
41
38
|
var import_messaging2 = require("@dxos/messaging");
|
|
42
39
|
var import_protocols2 = require("@dxos/protocols");
|
|
43
40
|
var import_rpc = require("@dxos/rpc");
|
|
44
|
-
var
|
|
41
|
+
var import_util9 = require("@dxos/util");
|
|
45
42
|
|
|
46
43
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
47
44
|
var import_node_assert5 = __toESM(require("node:assert"));
|
|
@@ -77,6 +74,7 @@ var ConnectionState;
|
|
|
77
74
|
ConnectionState4["INITIAL"] = "INITIAL";
|
|
78
75
|
ConnectionState4["CONNECTING"] = "CONNECTING";
|
|
79
76
|
ConnectionState4["CONNECTED"] = "CONNECTED";
|
|
77
|
+
ConnectionState4["CLOSING"] = "CLOSING";
|
|
80
78
|
ConnectionState4["CLOSED"] = "CLOSED";
|
|
81
79
|
})(ConnectionState || (ConnectionState = {}));
|
|
82
80
|
var Connection = class {
|
|
@@ -132,7 +130,11 @@ var Connection = class {
|
|
|
132
130
|
this._transport = void 0;
|
|
133
131
|
this.close().catch((err) => this.errors.raise(err));
|
|
134
132
|
});
|
|
135
|
-
this._transport.errors.
|
|
133
|
+
this._transport.errors.handle((err) => {
|
|
134
|
+
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
135
|
+
this.errors.raise(err);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
136
138
|
for (const signal of this._bufferedSignals) {
|
|
137
139
|
void this._transport.signal(signal);
|
|
138
140
|
}
|
|
@@ -143,11 +145,12 @@ var Connection = class {
|
|
|
143
145
|
if (this._state === ConnectionState.CLOSED) {
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
148
|
+
this._changeState(ConnectionState.CLOSING);
|
|
146
149
|
(0, import_log.log)("closing...", {
|
|
147
150
|
peerId: this.ownId
|
|
148
151
|
}, {
|
|
149
152
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
150
|
-
line:
|
|
153
|
+
line: 142,
|
|
151
154
|
scope: this,
|
|
152
155
|
callSite: (f, a) => f(...a)
|
|
153
156
|
});
|
|
@@ -156,7 +159,7 @@ var Connection = class {
|
|
|
156
159
|
} catch (err) {
|
|
157
160
|
import_log.log.catch(err, {}, {
|
|
158
161
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
159
|
-
line:
|
|
162
|
+
line: 148,
|
|
160
163
|
scope: this,
|
|
161
164
|
callSite: (f, a) => f(...a)
|
|
162
165
|
});
|
|
@@ -166,7 +169,7 @@ var Connection = class {
|
|
|
166
169
|
} catch (err1) {
|
|
167
170
|
import_log.log.catch(err1, {}, {
|
|
168
171
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
169
|
-
line:
|
|
172
|
+
line: 155,
|
|
170
173
|
scope: this,
|
|
171
174
|
callSite: (f, a) => f(...a)
|
|
172
175
|
});
|
|
@@ -175,7 +178,7 @@ var Connection = class {
|
|
|
175
178
|
peerId: this.ownId
|
|
176
179
|
}, {
|
|
177
180
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
178
|
-
line:
|
|
181
|
+
line: 158,
|
|
179
182
|
scope: this,
|
|
180
183
|
callSite: (f, a) => f(...a)
|
|
181
184
|
});
|
|
@@ -187,7 +190,7 @@ var Connection = class {
|
|
|
187
190
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
188
191
|
(0, import_log.log)("dropping signal for incorrect session id", {}, {
|
|
189
192
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
190
|
-
line:
|
|
193
|
+
line: 165,
|
|
191
194
|
scope: this,
|
|
192
195
|
callSite: (f, a) => f(...a)
|
|
193
196
|
});
|
|
@@ -203,7 +206,7 @@ var Connection = class {
|
|
|
203
206
|
msg: msg.data
|
|
204
207
|
}, {
|
|
205
208
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
206
|
-
line:
|
|
209
|
+
line: 173,
|
|
207
210
|
scope: this,
|
|
208
211
|
callSite: (f, a) => f(...a)
|
|
209
212
|
});
|
|
@@ -217,7 +220,7 @@ var Connection = class {
|
|
|
217
220
|
msg: msg.data
|
|
218
221
|
}, {
|
|
219
222
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
220
|
-
line:
|
|
223
|
+
line: 179,
|
|
221
224
|
scope: this,
|
|
222
225
|
callSite: (f, a) => f(...a)
|
|
223
226
|
});
|
|
@@ -624,14 +627,7 @@ var Peer = class {
|
|
|
624
627
|
scope: this,
|
|
625
628
|
callSite: (f, a) => f(...a)
|
|
626
629
|
});
|
|
627
|
-
void this.closeConnection()
|
|
628
|
-
import_log3.log.catch(err, {}, {
|
|
629
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
630
|
-
line: 207,
|
|
631
|
-
scope: this,
|
|
632
|
-
callSite: (f, a) => f(...a)
|
|
633
|
-
});
|
|
634
|
-
});
|
|
630
|
+
void this.closeConnection();
|
|
635
631
|
});
|
|
636
632
|
this.connection = connection;
|
|
637
633
|
return connection;
|
|
@@ -646,7 +642,7 @@ var Peer = class {
|
|
|
646
642
|
sessionId: connection.sessionId
|
|
647
643
|
}, {
|
|
648
644
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
649
|
-
line:
|
|
645
|
+
line: 219,
|
|
650
646
|
scope: this,
|
|
651
647
|
callSite: (f, a) => f(...a)
|
|
652
648
|
});
|
|
@@ -656,7 +652,7 @@ var Peer = class {
|
|
|
656
652
|
sessionId: connection.sessionId
|
|
657
653
|
}, {
|
|
658
654
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
659
|
-
line:
|
|
655
|
+
line: 225,
|
|
660
656
|
scope: this,
|
|
661
657
|
callSite: (f, a) => f(...a)
|
|
662
658
|
});
|
|
@@ -667,7 +663,7 @@ var Peer = class {
|
|
|
667
663
|
message
|
|
668
664
|
}, {
|
|
669
665
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
670
|
-
line:
|
|
666
|
+
line: 230,
|
|
671
667
|
scope: this,
|
|
672
668
|
callSite: (f, a) => f(...a)
|
|
673
669
|
});
|
|
@@ -682,7 +678,7 @@ var Peer = class {
|
|
|
682
678
|
topic: this.topic
|
|
683
679
|
}, {
|
|
684
680
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
685
|
-
line:
|
|
681
|
+
line: 238,
|
|
686
682
|
scope: this,
|
|
687
683
|
callSite: (f, a) => f(...a)
|
|
688
684
|
});
|
|
@@ -1054,9 +1050,8 @@ var SwarmMapper = class {
|
|
|
1054
1050
|
get peers() {
|
|
1055
1051
|
return Array.from(this._peers.values());
|
|
1056
1052
|
}
|
|
1057
|
-
constructor(_swarm
|
|
1053
|
+
constructor(_swarm) {
|
|
1058
1054
|
this._swarm = _swarm;
|
|
1059
|
-
this._presence = _presence;
|
|
1060
1055
|
this._subscriptions = new import_async4.EventSubscriptions();
|
|
1061
1056
|
this._connectionSubscriptions = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
|
|
1062
1057
|
this._peers = new import_util3.ComplexMap(import_keys4.PublicKey.hash);
|
|
@@ -1073,17 +1068,12 @@ var SwarmMapper = class {
|
|
|
1073
1068
|
this._connectionSubscriptions.delete(peerId);
|
|
1074
1069
|
this._update();
|
|
1075
1070
|
}));
|
|
1076
|
-
if (_presence) {
|
|
1077
|
-
this._subscriptions.add(_presence.graphUpdated.on(() => {
|
|
1078
|
-
this._update();
|
|
1079
|
-
}));
|
|
1080
|
-
}
|
|
1081
1071
|
this._update();
|
|
1082
1072
|
}
|
|
1083
1073
|
_update() {
|
|
1084
1074
|
(0, import_log5.log)("updating swarm", {}, {
|
|
1085
1075
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1086
|
-
line:
|
|
1076
|
+
line: 75,
|
|
1087
1077
|
scope: this,
|
|
1088
1078
|
callSite: (f, a) => f(...a)
|
|
1089
1079
|
});
|
|
@@ -1102,32 +1092,12 @@ var SwarmMapper = class {
|
|
|
1102
1092
|
]
|
|
1103
1093
|
});
|
|
1104
1094
|
}
|
|
1105
|
-
if (this._presence) {
|
|
1106
|
-
this._presence.graph.forEachNode((node) => {
|
|
1107
|
-
const id = import_keys4.PublicKey.fromHex(node.id);
|
|
1108
|
-
if (this._peers.has(id)) {
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
this._peers.set(id, {
|
|
1112
|
-
id,
|
|
1113
|
-
state: "INDIRECTLY_CONNECTED",
|
|
1114
|
-
connections: []
|
|
1115
|
-
});
|
|
1116
|
-
});
|
|
1117
|
-
this._presence.graph.forEachLink((link) => {
|
|
1118
|
-
const from = import_keys4.PublicKey.from(link.fromId);
|
|
1119
|
-
const to = import_keys4.PublicKey.from(link.toId);
|
|
1120
|
-
if (!from.equals(this._swarm.ownPeerId) && !to.equals(this._swarm.ownPeerId)) {
|
|
1121
|
-
this._peers.get(from).connections.push(to);
|
|
1122
|
-
}
|
|
1123
|
-
});
|
|
1124
|
-
}
|
|
1125
1095
|
(0, import_log5.log)("graph changed", {
|
|
1126
1096
|
directConnections: this._swarm.connections.length,
|
|
1127
1097
|
totalPeersInSwarm: this._peers.size
|
|
1128
1098
|
}, {
|
|
1129
1099
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1130
|
-
line:
|
|
1100
|
+
line: 116,
|
|
1131
1101
|
scope: this,
|
|
1132
1102
|
callSite: (f, a) => f(...a)
|
|
1133
1103
|
});
|
|
@@ -1171,13 +1141,12 @@ var ConnectionLog = class {
|
|
|
1171
1141
|
this._swarms.set(swarm.instanceId, info);
|
|
1172
1142
|
this.update.emit();
|
|
1173
1143
|
swarm.connectionAdded.on((connection) => {
|
|
1174
|
-
var _a, _b, _c, _d, _e;
|
|
1175
1144
|
const connectionInfo = {
|
|
1176
1145
|
state: ConnectionState.INITIAL,
|
|
1177
1146
|
remotePeerId: connection.remoteId,
|
|
1178
1147
|
sessionId: connection.sessionId,
|
|
1179
1148
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
1180
|
-
protocolExtensions:
|
|
1149
|
+
protocolExtensions: [],
|
|
1181
1150
|
events: []
|
|
1182
1151
|
};
|
|
1183
1152
|
info.connections.push(connectionInfo);
|
|
@@ -1190,32 +1159,6 @@ var ConnectionLog = class {
|
|
|
1190
1159
|
});
|
|
1191
1160
|
this.update.emit();
|
|
1192
1161
|
});
|
|
1193
|
-
(_b = connection.protocol.protocol) == null ? void 0 : _b.error.on((error) => {
|
|
1194
|
-
var _a2;
|
|
1195
|
-
connectionInfo.events.push({
|
|
1196
|
-
type: EventType.PROTOCOL_ERROR,
|
|
1197
|
-
error: (_a2 = error.stack) != null ? _a2 : error.message
|
|
1198
|
-
});
|
|
1199
|
-
this.update.emit();
|
|
1200
|
-
});
|
|
1201
|
-
(_c = connection.protocol.protocol) == null ? void 0 : _c.extensionsInitialized.on(() => {
|
|
1202
|
-
connectionInfo.events.push({
|
|
1203
|
-
type: EventType.PROTOCOL_EXTENSIONS_INITIALIZED
|
|
1204
|
-
});
|
|
1205
|
-
this.update.emit();
|
|
1206
|
-
});
|
|
1207
|
-
(_d = connection.protocol.protocol) == null ? void 0 : _d.extensionsHandshake.on(() => {
|
|
1208
|
-
connectionInfo.events.push({
|
|
1209
|
-
type: EventType.PROTOCOL_EXTENSIONS_HANDSHAKE
|
|
1210
|
-
});
|
|
1211
|
-
this.update.emit();
|
|
1212
|
-
});
|
|
1213
|
-
(_e = connection.protocol.protocol) == null ? void 0 : _e.handshake.on(() => {
|
|
1214
|
-
connectionInfo.events.push({
|
|
1215
|
-
type: EventType.PROTOCOL_HANDSHAKE
|
|
1216
|
-
});
|
|
1217
|
-
this.update.emit();
|
|
1218
|
-
});
|
|
1219
1162
|
});
|
|
1220
1163
|
}
|
|
1221
1164
|
swarmLeft(swarm) {
|
|
@@ -1226,7 +1169,7 @@ var ConnectionLog = class {
|
|
|
1226
1169
|
|
|
1227
1170
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1228
1171
|
var NetworkManager = class {
|
|
1229
|
-
constructor({ transportFactory, signalManager, log:
|
|
1172
|
+
constructor({ transportFactory, signalManager, log: log14 }) {
|
|
1230
1173
|
this._swarms = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
|
|
1231
1174
|
this._mappers = new import_util5.ComplexMap(import_keys6.PublicKey.hash);
|
|
1232
1175
|
this.topicsUpdated = new import_async6.Event();
|
|
@@ -1243,7 +1186,7 @@ var NetworkManager = class {
|
|
|
1243
1186
|
join: (opts) => this._signalManager.join(opts),
|
|
1244
1187
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1245
1188
|
};
|
|
1246
|
-
if (
|
|
1189
|
+
if (log14) {
|
|
1247
1190
|
this._connectionLog = new ConnectionLog();
|
|
1248
1191
|
}
|
|
1249
1192
|
}
|
|
@@ -1267,7 +1210,7 @@ var NetworkManager = class {
|
|
|
1267
1210
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1268
1211
|
(0, import_log6.log)(err, {}, {
|
|
1269
1212
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1270
|
-
line:
|
|
1213
|
+
line: 122,
|
|
1271
1214
|
scope: this,
|
|
1272
1215
|
callSite: (f, a) => f(...a)
|
|
1273
1216
|
});
|
|
@@ -1275,7 +1218,7 @@ var NetworkManager = class {
|
|
|
1275
1218
|
}
|
|
1276
1219
|
await this._signalManager.destroy();
|
|
1277
1220
|
}
|
|
1278
|
-
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol,
|
|
1221
|
+
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1279
1222
|
var _a;
|
|
1280
1223
|
(0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(topic));
|
|
1281
1224
|
(0, import_node_assert5.default)(import_keys6.PublicKey.isPublicKey(peerId));
|
|
@@ -1290,7 +1233,7 @@ var NetworkManager = class {
|
|
|
1290
1233
|
topology: topology.toString()
|
|
1291
1234
|
}, {
|
|
1292
1235
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1293
|
-
line:
|
|
1236
|
+
line: 148,
|
|
1294
1237
|
scope: this,
|
|
1295
1238
|
callSite: (f, a) => f(...a)
|
|
1296
1239
|
});
|
|
@@ -1300,7 +1243,7 @@ var NetworkManager = class {
|
|
|
1300
1243
|
error
|
|
1301
1244
|
}, {
|
|
1302
1245
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1303
|
-
line:
|
|
1246
|
+
line: 151,
|
|
1304
1247
|
scope: this,
|
|
1305
1248
|
callSite: (f, a) => f(...a)
|
|
1306
1249
|
});
|
|
@@ -1311,11 +1254,11 @@ var NetworkManager = class {
|
|
|
1311
1254
|
peerId
|
|
1312
1255
|
}).catch((error) => import_log6.log.catch(error, {}, {
|
|
1313
1256
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1314
|
-
line:
|
|
1257
|
+
line: 155,
|
|
1315
1258
|
scope: this,
|
|
1316
1259
|
callSite: (f, a) => f(...a)
|
|
1317
1260
|
}));
|
|
1318
|
-
this._mappers.set(topic, new SwarmMapper(swarm
|
|
1261
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1319
1262
|
this.topicsUpdated.emit();
|
|
1320
1263
|
(_a = this._connectionLog) == null ? void 0 : _a.swarmJoined(swarm);
|
|
1321
1264
|
(0, import_log6.log)("joined", {
|
|
@@ -1323,7 +1266,7 @@ var NetworkManager = class {
|
|
|
1323
1266
|
count: this._swarms.size
|
|
1324
1267
|
}, {
|
|
1325
1268
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1326
|
-
line:
|
|
1269
|
+
line: 160,
|
|
1327
1270
|
scope: this,
|
|
1328
1271
|
callSite: (f, a) => f(...a)
|
|
1329
1272
|
});
|
|
@@ -1338,7 +1281,7 @@ var NetworkManager = class {
|
|
|
1338
1281
|
topic: import_keys6.PublicKey.from(topic)
|
|
1339
1282
|
}, {
|
|
1340
1283
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1341
|
-
line:
|
|
1284
|
+
line: 172,
|
|
1342
1285
|
scope: this,
|
|
1343
1286
|
callSite: (f, a) => f(...a)
|
|
1344
1287
|
});
|
|
@@ -1348,7 +1291,7 @@ var NetworkManager = class {
|
|
|
1348
1291
|
topic: import_keys6.PublicKey.from(topic)
|
|
1349
1292
|
}, {
|
|
1350
1293
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1351
|
-
line:
|
|
1294
|
+
line: 176,
|
|
1352
1295
|
scope: this,
|
|
1353
1296
|
callSite: (f, a) => f(...a)
|
|
1354
1297
|
});
|
|
@@ -1369,7 +1312,7 @@ var NetworkManager = class {
|
|
|
1369
1312
|
count: this._swarms.size
|
|
1370
1313
|
}, {
|
|
1371
1314
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1372
|
-
line:
|
|
1315
|
+
line: 190,
|
|
1373
1316
|
scope: this,
|
|
1374
1317
|
callSite: (f, a) => f(...a)
|
|
1375
1318
|
});
|
|
@@ -1415,6 +1358,16 @@ var import_debug4 = require("@dxos/debug");
|
|
|
1415
1358
|
var import_keys7 = require("@dxos/keys");
|
|
1416
1359
|
var import_log9 = require("@dxos/log");
|
|
1417
1360
|
var import_util6 = require("@dxos/util");
|
|
1361
|
+
var __decorate4 = function(decorators, target, key, desc) {
|
|
1362
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1363
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1364
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1365
|
+
else
|
|
1366
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1367
|
+
if (d = decorators[i])
|
|
1368
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1369
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1370
|
+
};
|
|
1418
1371
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1419
1372
|
var createStreamDelay = (delay) => {
|
|
1420
1373
|
return new import_node_stream.Transform({
|
|
@@ -1434,34 +1387,30 @@ var _MemoryTransport = class {
|
|
|
1434
1387
|
this.closed = new import_async7.Event();
|
|
1435
1388
|
this.connected = new import_async7.Event();
|
|
1436
1389
|
this.errors = new import_debug4.ErrorStream();
|
|
1437
|
-
this._id = import_keys7.PublicKey.random();
|
|
1438
1390
|
this._remote = new import_async7.Trigger();
|
|
1439
1391
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1440
1392
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1441
1393
|
this._destroyed = false;
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
}, {
|
|
1394
|
+
this._instanceId = import_keys7.PublicKey.random();
|
|
1395
|
+
(0, import_log9.log)("creating", {}, {
|
|
1445
1396
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1446
|
-
line:
|
|
1397
|
+
line: 64,
|
|
1447
1398
|
scope: this,
|
|
1448
1399
|
callSite: (f, a) => f(...a)
|
|
1449
1400
|
});
|
|
1450
|
-
(0, import_node_assert7.default)(!_MemoryTransport._connections.has(this.
|
|
1451
|
-
_MemoryTransport._connections.set(this.
|
|
1401
|
+
(0, import_node_assert7.default)(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1402
|
+
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1452
1403
|
if (this.options.initiator) {
|
|
1453
1404
|
setTimeout(async () => {
|
|
1454
|
-
(0, import_log9.log)("sending signal", {
|
|
1455
|
-
transportId: this._id
|
|
1456
|
-
}, {
|
|
1405
|
+
(0, import_log9.log)("sending signal", {}, {
|
|
1457
1406
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1458
|
-
line:
|
|
1407
|
+
line: 73,
|
|
1459
1408
|
scope: this,
|
|
1460
1409
|
callSite: (f, a) => f(...a)
|
|
1461
1410
|
});
|
|
1462
1411
|
void this.options.sendSignal({
|
|
1463
1412
|
payload: {
|
|
1464
|
-
transportId: this.
|
|
1413
|
+
transportId: this._instanceId.toHex()
|
|
1465
1414
|
}
|
|
1466
1415
|
});
|
|
1467
1416
|
});
|
|
@@ -1472,22 +1421,19 @@ var _MemoryTransport = class {
|
|
|
1472
1421
|
if (this._destroyed) {
|
|
1473
1422
|
return;
|
|
1474
1423
|
}
|
|
1475
|
-
this.
|
|
1476
|
-
this._remoteConnection = _MemoryTransport._connections.get(this.
|
|
1424
|
+
this._remoteInstanceId = remoteId;
|
|
1425
|
+
this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
|
|
1477
1426
|
if (!this._remoteConnection) {
|
|
1478
1427
|
this._destroyed = true;
|
|
1479
1428
|
this.closed.emit();
|
|
1480
1429
|
return;
|
|
1481
1430
|
}
|
|
1482
|
-
(0, import_node_assert7.default)(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this.
|
|
1431
|
+
(0, import_node_assert7.default)(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteInstanceId}`));
|
|
1483
1432
|
this._remoteConnection._remoteConnection = this;
|
|
1484
|
-
this._remoteConnection.
|
|
1485
|
-
(0, import_log9.log)("connected", {
|
|
1486
|
-
id: this._id,
|
|
1487
|
-
remote: this._remoteId
|
|
1488
|
-
}, {
|
|
1433
|
+
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1434
|
+
(0, import_log9.log)("connected", {}, {
|
|
1489
1435
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1490
|
-
line:
|
|
1436
|
+
line: 102,
|
|
1491
1437
|
scope: this,
|
|
1492
1438
|
callSite: (f, a) => f(...a)
|
|
1493
1439
|
});
|
|
@@ -1503,73 +1449,70 @@ var _MemoryTransport = class {
|
|
|
1503
1449
|
}
|
|
1504
1450
|
}
|
|
1505
1451
|
async destroy() {
|
|
1506
|
-
(0, import_log9.log)("closing", {
|
|
1507
|
-
id: this._id
|
|
1508
|
-
}, {
|
|
1452
|
+
(0, import_log9.log)("closing", {}, {
|
|
1509
1453
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1510
|
-
line:
|
|
1454
|
+
line: 123,
|
|
1511
1455
|
scope: this,
|
|
1512
1456
|
callSite: (f, a) => f(...a)
|
|
1513
1457
|
});
|
|
1514
1458
|
this._destroyed = true;
|
|
1515
|
-
_MemoryTransport._connections.delete(this.
|
|
1459
|
+
_MemoryTransport._connections.delete(this._instanceId);
|
|
1516
1460
|
if (this._remoteConnection) {
|
|
1517
|
-
(0, import_log9.log)("closing", {
|
|
1518
|
-
id: this._remoteId
|
|
1519
|
-
}, {
|
|
1461
|
+
(0, import_log9.log)("closing", {}, {
|
|
1520
1462
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1521
|
-
line:
|
|
1463
|
+
line: 128,
|
|
1522
1464
|
scope: this,
|
|
1523
1465
|
callSite: (f, a) => f(...a)
|
|
1524
1466
|
});
|
|
1525
1467
|
this._remoteConnection._destroyed = true;
|
|
1526
|
-
_MemoryTransport._connections.delete(this.
|
|
1468
|
+
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
1527
1469
|
this._outgoingDelay.unpipe();
|
|
1528
1470
|
this._incomingDelay.unpipe();
|
|
1529
1471
|
this._remoteConnection.closed.emit();
|
|
1530
1472
|
this._remoteConnection._remoteConnection = void 0;
|
|
1531
1473
|
this._remoteConnection = void 0;
|
|
1532
|
-
(0, import_log9.log)("closed", {
|
|
1533
|
-
id: this._remoteId
|
|
1534
|
-
}, {
|
|
1474
|
+
(0, import_log9.log)("closed", {}, {
|
|
1535
1475
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1536
|
-
line:
|
|
1476
|
+
line: 146,
|
|
1537
1477
|
scope: this,
|
|
1538
1478
|
callSite: (f, a) => f(...a)
|
|
1539
1479
|
});
|
|
1540
1480
|
}
|
|
1541
1481
|
this.closed.emit();
|
|
1542
|
-
(0, import_log9.log)("closed", {
|
|
1543
|
-
id: this._id
|
|
1544
|
-
}, {
|
|
1482
|
+
(0, import_log9.log)("closed", {}, {
|
|
1545
1483
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1546
|
-
line:
|
|
1484
|
+
line: 150,
|
|
1547
1485
|
scope: this,
|
|
1548
1486
|
callSite: (f, a) => f(...a)
|
|
1549
1487
|
});
|
|
1550
1488
|
}
|
|
1551
|
-
signal(
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1489
|
+
signal({ payload }) {
|
|
1490
|
+
(0, import_log9.log)("received signal", {
|
|
1491
|
+
payload
|
|
1492
|
+
}, {
|
|
1493
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1494
|
+
line: 154,
|
|
1495
|
+
scope: this,
|
|
1496
|
+
callSite: (f, a) => f(...a)
|
|
1497
|
+
});
|
|
1498
|
+
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
const transportId = payload.transportId;
|
|
1502
|
+
if (transportId) {
|
|
1503
|
+
const remoteId = import_keys7.PublicKey.fromHex(transportId);
|
|
1504
|
+
this._remote.wake(remoteId);
|
|
1568
1505
|
}
|
|
1569
1506
|
}
|
|
1570
1507
|
};
|
|
1571
1508
|
var MemoryTransport = _MemoryTransport;
|
|
1572
1509
|
MemoryTransport._connections = new import_util6.ComplexMap(import_keys7.PublicKey.hash);
|
|
1510
|
+
__decorate4([
|
|
1511
|
+
import_log9.logInfo
|
|
1512
|
+
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1513
|
+
__decorate4([
|
|
1514
|
+
import_log9.logInfo
|
|
1515
|
+
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1573
1516
|
|
|
1574
1517
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1575
1518
|
var import_node_assert8 = __toESM(require("node:assert"));
|
|
@@ -1900,205 +1843,74 @@ var WebRTCTransportProxyFactory = class {
|
|
|
1900
1843
|
}
|
|
1901
1844
|
};
|
|
1902
1845
|
|
|
1903
|
-
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
1904
|
-
var
|
|
1905
|
-
var import_teleport = require("@dxos/teleport");
|
|
1906
|
-
var adaptProtocolProvider = (factory) => ({ initiator, localPeerId, remotePeerId, topic }) => {
|
|
1907
|
-
const protocol = factory({
|
|
1908
|
-
channel: (0, import_crypto.discoveryKey)(topic),
|
|
1909
|
-
initiator
|
|
1910
|
-
});
|
|
1911
|
-
return {
|
|
1912
|
-
initialize: () => protocol.open(),
|
|
1913
|
-
destroy: () => protocol.close(),
|
|
1914
|
-
stream: protocol.stream,
|
|
1915
|
-
protocol
|
|
1916
|
-
};
|
|
1917
|
-
};
|
|
1918
|
-
|
|
1919
|
-
// packages/core/mesh/network-manager/src/testing/test-protocol.ts
|
|
1920
|
-
var import_node_assert12 = __toESM(require("node:assert"));
|
|
1921
|
-
var import_node_events = require("node:events");
|
|
1922
|
-
var import_keys11 = require("@dxos/keys");
|
|
1923
|
-
var import_log14 = require("@dxos/log");
|
|
1924
|
-
var import_mesh_protocol2 = require("@dxos/mesh-protocol");
|
|
1925
|
-
|
|
1926
|
-
// packages/core/mesh/network-manager/src/protocol-factory.ts
|
|
1927
|
-
var import_node_assert11 = __toESM(require("node:assert"));
|
|
1928
|
-
var import_crypto2 = require("@dxos/crypto");
|
|
1846
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
1847
|
+
var import_async10 = require("@dxos/async");
|
|
1929
1848
|
var import_keys10 = require("@dxos/keys");
|
|
1930
1849
|
var import_log13 = require("@dxos/log");
|
|
1931
|
-
var
|
|
1932
|
-
var
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
},
|
|
1945
|
-
discoveryToPublicKey: (dk) => {
|
|
1946
|
-
const publicKey = getTopics().find((topic) => (0, import_crypto2.discoveryKey)(topic).equals(dk));
|
|
1947
|
-
if (publicKey) {
|
|
1948
|
-
protocol.setContext({
|
|
1949
|
-
topic: import_keys10.PublicKey.stringify(publicKey)
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
(0, import_node_assert11.default)(publicKey, "PublicKey not found in discovery.");
|
|
1953
|
-
return publicKey;
|
|
1850
|
+
var import_teleport2 = require("@dxos/teleport");
|
|
1851
|
+
var import_util8 = require("@dxos/util");
|
|
1852
|
+
|
|
1853
|
+
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
1854
|
+
var import_teleport = require("@dxos/teleport");
|
|
1855
|
+
var createTeleportProtocolFactory = (onConnection) => {
|
|
1856
|
+
return (params) => {
|
|
1857
|
+
const teleport = new import_teleport.Teleport(params);
|
|
1858
|
+
return {
|
|
1859
|
+
stream: teleport.stream,
|
|
1860
|
+
initialize: async () => {
|
|
1861
|
+
await teleport.open();
|
|
1862
|
+
await onConnection(teleport);
|
|
1954
1863
|
},
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
}
|
|
1959
|
-
protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
|
|
1960
|
-
return protocol;
|
|
1864
|
+
destroy: async () => {
|
|
1865
|
+
await teleport.close();
|
|
1866
|
+
}
|
|
1867
|
+
};
|
|
1961
1868
|
};
|
|
1962
1869
|
};
|
|
1963
1870
|
|
|
1964
|
-
// packages/core/mesh/network-manager/src/testing/test-protocol.ts
|
|
1965
|
-
var
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
],
|
|
1988
|
-
session: {
|
|
1989
|
-
peerId: peerId.toHex()
|
|
1990
|
-
},
|
|
1991
|
-
plugins: [
|
|
1992
|
-
protocolPlugin
|
|
1993
|
-
]
|
|
1994
|
-
});
|
|
1995
|
-
};
|
|
1996
|
-
var TestProtocolPlugin = class extends import_node_events.EventEmitter {
|
|
1997
|
-
constructor(peerId, uppercase = false) {
|
|
1998
|
-
super();
|
|
1999
|
-
this._peers = /* @__PURE__ */ new Map();
|
|
2000
|
-
this.initCalled = false;
|
|
2001
|
-
(0, import_node_assert12.default)(Buffer.isBuffer(peerId));
|
|
2002
|
-
this._peerId = peerId;
|
|
2003
|
-
this._uppercase = uppercase;
|
|
2004
|
-
}
|
|
2005
|
-
get peerId() {
|
|
2006
|
-
return this._peerId;
|
|
2007
|
-
}
|
|
2008
|
-
get peers() {
|
|
2009
|
-
return Array.from(this._peers.values());
|
|
2010
|
-
}
|
|
2011
|
-
createExtension() {
|
|
2012
|
-
(0, import_log14.log)("creating extension", {
|
|
2013
|
-
peerId: import_keys11.PublicKey.from(this.peerId)
|
|
2014
|
-
}, {
|
|
2015
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2016
|
-
line: 92,
|
|
2017
|
-
scope: this,
|
|
2018
|
-
callSite: (f, a) => f(...a)
|
|
2019
|
-
});
|
|
2020
|
-
return new import_mesh_protocol2.Extension(EXTENSION_NAME, {
|
|
2021
|
-
binary: true
|
|
2022
|
-
}).setInitHandler(this._init.bind(this)).setMessageHandler(this._receive.bind(this)).setHandshakeHandler(this._onPeerConnect.bind(this)).setCloseHandler(this._onPeerDisconnect.bind(this));
|
|
2023
|
-
}
|
|
2024
|
-
async _init(protocol) {
|
|
2025
|
-
this.initCalled = true;
|
|
2026
|
-
}
|
|
2027
|
-
async send(peerId, payload) {
|
|
2028
|
-
(0, import_node_assert12.default)(Buffer.isBuffer(peerId));
|
|
2029
|
-
const peerIdStr = import_keys11.PublicKey.stringify(peerId);
|
|
2030
|
-
const peer = this._peers.get(peerIdStr);
|
|
2031
|
-
if (!peer) {
|
|
2032
|
-
throw new Error(`peer not found: ${import_keys11.PublicKey.from(peerId).truncate()}`);
|
|
2033
|
-
}
|
|
2034
|
-
const extension = peer.getExtension(EXTENSION_NAME);
|
|
2035
|
-
const encoded = Buffer.from(payload);
|
|
2036
|
-
(0, import_log14.log)("sending", {
|
|
2037
|
-
peerId: import_keys11.PublicKey.from(peerId),
|
|
2038
|
-
payload
|
|
2039
|
-
}, {
|
|
2040
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2041
|
-
line: 124,
|
|
2042
|
-
scope: this,
|
|
2043
|
-
callSite: (f, a) => f(...a)
|
|
2044
|
-
});
|
|
2045
|
-
return await extension.send(encoded, {
|
|
2046
|
-
oneway: true
|
|
1871
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
1872
|
+
var TestWireProtocol = class {
|
|
1873
|
+
constructor(peerId) {
|
|
1874
|
+
this.peerId = peerId;
|
|
1875
|
+
this.connections = new import_util8.ComplexMap(import_keys10.PublicKey.hash);
|
|
1876
|
+
this.connected = new import_async10.Event();
|
|
1877
|
+
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
1878
|
+
(0, import_log13.log)("create", {
|
|
1879
|
+
remotePeerId: teleport.remotePeerId
|
|
1880
|
+
}, {
|
|
1881
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts",
|
|
1882
|
+
line: 20,
|
|
1883
|
+
scope: this,
|
|
1884
|
+
callSite: (f, a) => f(...a)
|
|
1885
|
+
});
|
|
1886
|
+
const extension = new import_teleport2.TestExtension({
|
|
1887
|
+
onClose: async () => {
|
|
1888
|
+
this.connections.delete(teleport.remotePeerId);
|
|
1889
|
+
}
|
|
1890
|
+
});
|
|
1891
|
+
this.connections.set(teleport.remotePeerId, extension);
|
|
1892
|
+
teleport.addExtension("test", extension);
|
|
1893
|
+
this.connected.emit(teleport.remotePeerId);
|
|
2047
1894
|
});
|
|
2048
1895
|
}
|
|
2049
|
-
async
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
let payload = data.data.toString();
|
|
2053
|
-
if (this._uppercase) {
|
|
2054
|
-
payload = payload.toUpperCase();
|
|
1896
|
+
async waitForConnection(peerId) {
|
|
1897
|
+
if (this.connections.has(peerId)) {
|
|
1898
|
+
return this.connections.get(peerId);
|
|
2055
1899
|
}
|
|
2056
|
-
(0,
|
|
2057
|
-
peerId
|
|
2058
|
-
payload
|
|
1900
|
+
(0, import_log13.log)("waitForConnection", {
|
|
1901
|
+
peerId
|
|
2059
1902
|
}, {
|
|
2060
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2061
|
-
line:
|
|
1903
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts",
|
|
1904
|
+
line: 35,
|
|
2062
1905
|
scope: this,
|
|
2063
1906
|
callSite: (f, a) => f(...a)
|
|
2064
1907
|
});
|
|
2065
|
-
this.
|
|
1908
|
+
await this.connected.waitFor((connectedId) => connectedId.equals(peerId));
|
|
1909
|
+
return this.connections.get(peerId);
|
|
2066
1910
|
}
|
|
2067
|
-
async
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
}, {
|
|
2071
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2072
|
-
line: 141,
|
|
2073
|
-
scope: this,
|
|
2074
|
-
callSite: (f, a) => f(...a)
|
|
2075
|
-
});
|
|
2076
|
-
const peerId = getPeerId(protocol);
|
|
2077
|
-
if (peerId === void 0) {
|
|
2078
|
-
return;
|
|
2079
|
-
}
|
|
2080
|
-
const peerIdStr = import_keys11.PublicKey.stringify(peerId);
|
|
2081
|
-
if (this._peers.has(peerIdStr)) {
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
this._peers.set(peerIdStr, protocol);
|
|
2085
|
-
this.emit("connect", protocol);
|
|
2086
|
-
}
|
|
2087
|
-
async _onPeerDisconnect(protocol) {
|
|
2088
|
-
(0, import_log14.log)("disconnecting", {
|
|
2089
|
-
id: import_keys11.PublicKey.from(protocol.id)
|
|
2090
|
-
}, {
|
|
2091
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2092
|
-
line: 157,
|
|
2093
|
-
scope: this,
|
|
2094
|
-
callSite: (f, a) => f(...a)
|
|
2095
|
-
});
|
|
2096
|
-
const peerId = getPeerId(protocol);
|
|
2097
|
-
if (peerId === void 0) {
|
|
2098
|
-
return;
|
|
2099
|
-
}
|
|
2100
|
-
this._peers.delete(import_keys11.PublicKey.stringify(peerId));
|
|
2101
|
-
this.emit("disconnect", peerId);
|
|
1911
|
+
async testConnection(peerId) {
|
|
1912
|
+
const connection = await this.waitForConnection(peerId);
|
|
1913
|
+
await connection.test();
|
|
2102
1914
|
}
|
|
2103
1915
|
};
|
|
2104
1916
|
|
|
@@ -2122,8 +1934,8 @@ var TestBuilder = class {
|
|
|
2122
1934
|
var TestPeer = class {
|
|
2123
1935
|
constructor(testBuilder) {
|
|
2124
1936
|
this.testBuilder = testBuilder;
|
|
2125
|
-
this.peerId =
|
|
2126
|
-
this._swarms = new
|
|
1937
|
+
this.peerId = import_keys11.PublicKey.random();
|
|
1938
|
+
this._swarms = new import_util9.ComplexMap(import_keys11.PublicKey.hash);
|
|
2127
1939
|
this._networkManager = this.createNetworkManager();
|
|
2128
1940
|
}
|
|
2129
1941
|
createNetworkManager() {
|
|
@@ -2196,13 +2008,13 @@ var TestSwarmConnection = class {
|
|
|
2196
2008
|
constructor(peer, topic) {
|
|
2197
2009
|
this.peer = peer;
|
|
2198
2010
|
this.topic = topic;
|
|
2199
|
-
this.
|
|
2011
|
+
this.protocol = new TestWireProtocol(this.peer.peerId);
|
|
2200
2012
|
}
|
|
2201
2013
|
async join(topology = new FullyConnectedTopology()) {
|
|
2202
2014
|
await this.peer._networkManager.joinSwarm({
|
|
2203
2015
|
topic: this.topic,
|
|
2204
2016
|
peerId: this.peer.peerId,
|
|
2205
|
-
protocolProvider:
|
|
2017
|
+
protocolProvider: this.protocol.factory,
|
|
2206
2018
|
topology
|
|
2207
2019
|
});
|
|
2208
2020
|
return this;
|
|
@@ -2217,9 +2029,5 @@ var TestSwarmConnection = class {
|
|
|
2217
2029
|
TEST_SIGNAL_URL,
|
|
2218
2030
|
TestBuilder,
|
|
2219
2031
|
TestPeer,
|
|
2220
|
-
|
|
2221
|
-
TestSwarmConnection,
|
|
2222
|
-
getPeerId,
|
|
2223
|
-
testProtocolProvider
|
|
2032
|
+
TestSwarmConnection
|
|
2224
2033
|
});
|
|
2225
|
-
//# sourceMappingURL=index.cjs.map
|