@dxos/network-manager 0.1.16 → 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
|
@@ -8,11 +8,11 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
// packages/core/mesh/network-manager/src/testing/test-builder.ts
|
|
11
|
-
import { PublicKey as
|
|
11
|
+
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
12
12
|
import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from "@dxos/messaging";
|
|
13
13
|
import { schema as schema2 } from "@dxos/protocols";
|
|
14
14
|
import { createLinkedPorts, createProtoRpcPeer } from "@dxos/rpc";
|
|
15
|
-
import { ComplexMap as
|
|
15
|
+
import { ComplexMap as ComplexMap9 } from "@dxos/util";
|
|
16
16
|
|
|
17
17
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
18
18
|
import assert5 from "@dxos/node-std/assert";
|
|
@@ -48,6 +48,7 @@ var ConnectionState;
|
|
|
48
48
|
ConnectionState4["INITIAL"] = "INITIAL";
|
|
49
49
|
ConnectionState4["CONNECTING"] = "CONNECTING";
|
|
50
50
|
ConnectionState4["CONNECTED"] = "CONNECTED";
|
|
51
|
+
ConnectionState4["CLOSING"] = "CLOSING";
|
|
51
52
|
ConnectionState4["CLOSED"] = "CLOSED";
|
|
52
53
|
})(ConnectionState || (ConnectionState = {}));
|
|
53
54
|
var Connection = class {
|
|
@@ -103,7 +104,11 @@ var Connection = class {
|
|
|
103
104
|
this._transport = void 0;
|
|
104
105
|
this.close().catch((err) => this.errors.raise(err));
|
|
105
106
|
});
|
|
106
|
-
this._transport.errors.
|
|
107
|
+
this._transport.errors.handle((err) => {
|
|
108
|
+
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
109
|
+
this.errors.raise(err);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
107
112
|
for (const signal of this._bufferedSignals) {
|
|
108
113
|
void this._transport.signal(signal);
|
|
109
114
|
}
|
|
@@ -114,11 +119,12 @@ var Connection = class {
|
|
|
114
119
|
if (this._state === ConnectionState.CLOSED) {
|
|
115
120
|
return;
|
|
116
121
|
}
|
|
122
|
+
this._changeState(ConnectionState.CLOSING);
|
|
117
123
|
log("closing...", {
|
|
118
124
|
peerId: this.ownId
|
|
119
125
|
}, {
|
|
120
126
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
121
|
-
line:
|
|
127
|
+
line: 142,
|
|
122
128
|
scope: this,
|
|
123
129
|
callSite: (f, a) => f(...a)
|
|
124
130
|
});
|
|
@@ -127,7 +133,7 @@ var Connection = class {
|
|
|
127
133
|
} catch (err) {
|
|
128
134
|
log.catch(err, {}, {
|
|
129
135
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
130
|
-
line:
|
|
136
|
+
line: 148,
|
|
131
137
|
scope: this,
|
|
132
138
|
callSite: (f, a) => f(...a)
|
|
133
139
|
});
|
|
@@ -137,7 +143,7 @@ var Connection = class {
|
|
|
137
143
|
} catch (err1) {
|
|
138
144
|
log.catch(err1, {}, {
|
|
139
145
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
140
|
-
line:
|
|
146
|
+
line: 155,
|
|
141
147
|
scope: this,
|
|
142
148
|
callSite: (f, a) => f(...a)
|
|
143
149
|
});
|
|
@@ -146,7 +152,7 @@ var Connection = class {
|
|
|
146
152
|
peerId: this.ownId
|
|
147
153
|
}, {
|
|
148
154
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
149
|
-
line:
|
|
155
|
+
line: 158,
|
|
150
156
|
scope: this,
|
|
151
157
|
callSite: (f, a) => f(...a)
|
|
152
158
|
});
|
|
@@ -158,7 +164,7 @@ var Connection = class {
|
|
|
158
164
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
159
165
|
log("dropping signal for incorrect session id", {}, {
|
|
160
166
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
161
|
-
line:
|
|
167
|
+
line: 165,
|
|
162
168
|
scope: this,
|
|
163
169
|
callSite: (f, a) => f(...a)
|
|
164
170
|
});
|
|
@@ -174,7 +180,7 @@ var Connection = class {
|
|
|
174
180
|
msg: msg.data
|
|
175
181
|
}, {
|
|
176
182
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
177
|
-
line:
|
|
183
|
+
line: 173,
|
|
178
184
|
scope: this,
|
|
179
185
|
callSite: (f, a) => f(...a)
|
|
180
186
|
});
|
|
@@ -188,7 +194,7 @@ var Connection = class {
|
|
|
188
194
|
msg: msg.data
|
|
189
195
|
}, {
|
|
190
196
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
191
|
-
line:
|
|
197
|
+
line: 179,
|
|
192
198
|
scope: this,
|
|
193
199
|
callSite: (f, a) => f(...a)
|
|
194
200
|
});
|
|
@@ -595,14 +601,7 @@ var Peer = class {
|
|
|
595
601
|
scope: this,
|
|
596
602
|
callSite: (f, a) => f(...a)
|
|
597
603
|
});
|
|
598
|
-
void this.closeConnection()
|
|
599
|
-
log3.catch(err, {}, {
|
|
600
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
601
|
-
line: 207,
|
|
602
|
-
scope: this,
|
|
603
|
-
callSite: (f, a) => f(...a)
|
|
604
|
-
});
|
|
605
|
-
});
|
|
604
|
+
void this.closeConnection();
|
|
606
605
|
});
|
|
607
606
|
this.connection = connection;
|
|
608
607
|
return connection;
|
|
@@ -617,7 +616,7 @@ var Peer = class {
|
|
|
617
616
|
sessionId: connection.sessionId
|
|
618
617
|
}, {
|
|
619
618
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
620
|
-
line:
|
|
619
|
+
line: 219,
|
|
621
620
|
scope: this,
|
|
622
621
|
callSite: (f, a) => f(...a)
|
|
623
622
|
});
|
|
@@ -627,7 +626,7 @@ var Peer = class {
|
|
|
627
626
|
sessionId: connection.sessionId
|
|
628
627
|
}, {
|
|
629
628
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
630
|
-
line:
|
|
629
|
+
line: 225,
|
|
631
630
|
scope: this,
|
|
632
631
|
callSite: (f, a) => f(...a)
|
|
633
632
|
});
|
|
@@ -638,7 +637,7 @@ var Peer = class {
|
|
|
638
637
|
message
|
|
639
638
|
}, {
|
|
640
639
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
641
|
-
line:
|
|
640
|
+
line: 230,
|
|
642
641
|
scope: this,
|
|
643
642
|
callSite: (f, a) => f(...a)
|
|
644
643
|
});
|
|
@@ -653,7 +652,7 @@ var Peer = class {
|
|
|
653
652
|
topic: this.topic
|
|
654
653
|
}, {
|
|
655
654
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
656
|
-
line:
|
|
655
|
+
line: 238,
|
|
657
656
|
scope: this,
|
|
658
657
|
callSite: (f, a) => f(...a)
|
|
659
658
|
});
|
|
@@ -1025,9 +1024,8 @@ var SwarmMapper = class {
|
|
|
1025
1024
|
get peers() {
|
|
1026
1025
|
return Array.from(this._peers.values());
|
|
1027
1026
|
}
|
|
1028
|
-
constructor(_swarm
|
|
1027
|
+
constructor(_swarm) {
|
|
1029
1028
|
this._swarm = _swarm;
|
|
1030
|
-
this._presence = _presence;
|
|
1031
1029
|
this._subscriptions = new EventSubscriptions();
|
|
1032
1030
|
this._connectionSubscriptions = new ComplexMap3(PublicKey4.hash);
|
|
1033
1031
|
this._peers = new ComplexMap3(PublicKey4.hash);
|
|
@@ -1044,17 +1042,12 @@ var SwarmMapper = class {
|
|
|
1044
1042
|
this._connectionSubscriptions.delete(peerId);
|
|
1045
1043
|
this._update();
|
|
1046
1044
|
}));
|
|
1047
|
-
if (_presence) {
|
|
1048
|
-
this._subscriptions.add(_presence.graphUpdated.on(() => {
|
|
1049
|
-
this._update();
|
|
1050
|
-
}));
|
|
1051
|
-
}
|
|
1052
1045
|
this._update();
|
|
1053
1046
|
}
|
|
1054
1047
|
_update() {
|
|
1055
1048
|
log5("updating swarm", {}, {
|
|
1056
1049
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1057
|
-
line:
|
|
1050
|
+
line: 75,
|
|
1058
1051
|
scope: this,
|
|
1059
1052
|
callSite: (f, a) => f(...a)
|
|
1060
1053
|
});
|
|
@@ -1073,32 +1066,12 @@ var SwarmMapper = class {
|
|
|
1073
1066
|
]
|
|
1074
1067
|
});
|
|
1075
1068
|
}
|
|
1076
|
-
if (this._presence) {
|
|
1077
|
-
this._presence.graph.forEachNode((node) => {
|
|
1078
|
-
const id = PublicKey4.fromHex(node.id);
|
|
1079
|
-
if (this._peers.has(id)) {
|
|
1080
|
-
return;
|
|
1081
|
-
}
|
|
1082
|
-
this._peers.set(id, {
|
|
1083
|
-
id,
|
|
1084
|
-
state: "INDIRECTLY_CONNECTED",
|
|
1085
|
-
connections: []
|
|
1086
|
-
});
|
|
1087
|
-
});
|
|
1088
|
-
this._presence.graph.forEachLink((link) => {
|
|
1089
|
-
const from = PublicKey4.from(link.fromId);
|
|
1090
|
-
const to = PublicKey4.from(link.toId);
|
|
1091
|
-
if (!from.equals(this._swarm.ownPeerId) && !to.equals(this._swarm.ownPeerId)) {
|
|
1092
|
-
this._peers.get(from).connections.push(to);
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
1069
|
log5("graph changed", {
|
|
1097
1070
|
directConnections: this._swarm.connections.length,
|
|
1098
1071
|
totalPeersInSwarm: this._peers.size
|
|
1099
1072
|
}, {
|
|
1100
1073
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1101
|
-
line:
|
|
1074
|
+
line: 116,
|
|
1102
1075
|
scope: this,
|
|
1103
1076
|
callSite: (f, a) => f(...a)
|
|
1104
1077
|
});
|
|
@@ -1142,13 +1115,12 @@ var ConnectionLog = class {
|
|
|
1142
1115
|
this._swarms.set(swarm.instanceId, info);
|
|
1143
1116
|
this.update.emit();
|
|
1144
1117
|
swarm.connectionAdded.on((connection) => {
|
|
1145
|
-
var _a, _b, _c, _d, _e;
|
|
1146
1118
|
const connectionInfo = {
|
|
1147
1119
|
state: ConnectionState.INITIAL,
|
|
1148
1120
|
remotePeerId: connection.remoteId,
|
|
1149
1121
|
sessionId: connection.sessionId,
|
|
1150
1122
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
1151
|
-
protocolExtensions:
|
|
1123
|
+
protocolExtensions: [],
|
|
1152
1124
|
events: []
|
|
1153
1125
|
};
|
|
1154
1126
|
info.connections.push(connectionInfo);
|
|
@@ -1161,32 +1133,6 @@ var ConnectionLog = class {
|
|
|
1161
1133
|
});
|
|
1162
1134
|
this.update.emit();
|
|
1163
1135
|
});
|
|
1164
|
-
(_b = connection.protocol.protocol) == null ? void 0 : _b.error.on((error) => {
|
|
1165
|
-
var _a2;
|
|
1166
|
-
connectionInfo.events.push({
|
|
1167
|
-
type: EventType.PROTOCOL_ERROR,
|
|
1168
|
-
error: (_a2 = error.stack) != null ? _a2 : error.message
|
|
1169
|
-
});
|
|
1170
|
-
this.update.emit();
|
|
1171
|
-
});
|
|
1172
|
-
(_c = connection.protocol.protocol) == null ? void 0 : _c.extensionsInitialized.on(() => {
|
|
1173
|
-
connectionInfo.events.push({
|
|
1174
|
-
type: EventType.PROTOCOL_EXTENSIONS_INITIALIZED
|
|
1175
|
-
});
|
|
1176
|
-
this.update.emit();
|
|
1177
|
-
});
|
|
1178
|
-
(_d = connection.protocol.protocol) == null ? void 0 : _d.extensionsHandshake.on(() => {
|
|
1179
|
-
connectionInfo.events.push({
|
|
1180
|
-
type: EventType.PROTOCOL_EXTENSIONS_HANDSHAKE
|
|
1181
|
-
});
|
|
1182
|
-
this.update.emit();
|
|
1183
|
-
});
|
|
1184
|
-
(_e = connection.protocol.protocol) == null ? void 0 : _e.handshake.on(() => {
|
|
1185
|
-
connectionInfo.events.push({
|
|
1186
|
-
type: EventType.PROTOCOL_HANDSHAKE
|
|
1187
|
-
});
|
|
1188
|
-
this.update.emit();
|
|
1189
|
-
});
|
|
1190
1136
|
});
|
|
1191
1137
|
}
|
|
1192
1138
|
swarmLeft(swarm) {
|
|
@@ -1197,7 +1143,7 @@ var ConnectionLog = class {
|
|
|
1197
1143
|
|
|
1198
1144
|
// packages/core/mesh/network-manager/src/network-manager.ts
|
|
1199
1145
|
var NetworkManager = class {
|
|
1200
|
-
constructor({ transportFactory, signalManager, log:
|
|
1146
|
+
constructor({ transportFactory, signalManager, log: log14 }) {
|
|
1201
1147
|
this._swarms = new ComplexMap5(PublicKey6.hash);
|
|
1202
1148
|
this._mappers = new ComplexMap5(PublicKey6.hash);
|
|
1203
1149
|
this.topicsUpdated = new Event5();
|
|
@@ -1214,7 +1160,7 @@ var NetworkManager = class {
|
|
|
1214
1160
|
join: (opts) => this._signalManager.join(opts),
|
|
1215
1161
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1216
1162
|
};
|
|
1217
|
-
if (
|
|
1163
|
+
if (log14) {
|
|
1218
1164
|
this._connectionLog = new ConnectionLog();
|
|
1219
1165
|
}
|
|
1220
1166
|
}
|
|
@@ -1238,7 +1184,7 @@ var NetworkManager = class {
|
|
|
1238
1184
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1239
1185
|
log6(err, {}, {
|
|
1240
1186
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1241
|
-
line:
|
|
1187
|
+
line: 122,
|
|
1242
1188
|
scope: this,
|
|
1243
1189
|
callSite: (f, a) => f(...a)
|
|
1244
1190
|
});
|
|
@@ -1246,7 +1192,7 @@ var NetworkManager = class {
|
|
|
1246
1192
|
}
|
|
1247
1193
|
await this._signalManager.destroy();
|
|
1248
1194
|
}
|
|
1249
|
-
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol,
|
|
1195
|
+
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1250
1196
|
var _a;
|
|
1251
1197
|
assert5(PublicKey6.isPublicKey(topic));
|
|
1252
1198
|
assert5(PublicKey6.isPublicKey(peerId));
|
|
@@ -1261,7 +1207,7 @@ var NetworkManager = class {
|
|
|
1261
1207
|
topology: topology.toString()
|
|
1262
1208
|
}, {
|
|
1263
1209
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1264
|
-
line:
|
|
1210
|
+
line: 148,
|
|
1265
1211
|
scope: this,
|
|
1266
1212
|
callSite: (f, a) => f(...a)
|
|
1267
1213
|
});
|
|
@@ -1271,7 +1217,7 @@ var NetworkManager = class {
|
|
|
1271
1217
|
error
|
|
1272
1218
|
}, {
|
|
1273
1219
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1274
|
-
line:
|
|
1220
|
+
line: 151,
|
|
1275
1221
|
scope: this,
|
|
1276
1222
|
callSite: (f, a) => f(...a)
|
|
1277
1223
|
});
|
|
@@ -1282,11 +1228,11 @@ var NetworkManager = class {
|
|
|
1282
1228
|
peerId
|
|
1283
1229
|
}).catch((error) => log6.catch(error, {}, {
|
|
1284
1230
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1285
|
-
line:
|
|
1231
|
+
line: 155,
|
|
1286
1232
|
scope: this,
|
|
1287
1233
|
callSite: (f, a) => f(...a)
|
|
1288
1234
|
}));
|
|
1289
|
-
this._mappers.set(topic, new SwarmMapper(swarm
|
|
1235
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1290
1236
|
this.topicsUpdated.emit();
|
|
1291
1237
|
(_a = this._connectionLog) == null ? void 0 : _a.swarmJoined(swarm);
|
|
1292
1238
|
log6("joined", {
|
|
@@ -1294,7 +1240,7 @@ var NetworkManager = class {
|
|
|
1294
1240
|
count: this._swarms.size
|
|
1295
1241
|
}, {
|
|
1296
1242
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1297
|
-
line:
|
|
1243
|
+
line: 160,
|
|
1298
1244
|
scope: this,
|
|
1299
1245
|
callSite: (f, a) => f(...a)
|
|
1300
1246
|
});
|
|
@@ -1309,7 +1255,7 @@ var NetworkManager = class {
|
|
|
1309
1255
|
topic: PublicKey6.from(topic)
|
|
1310
1256
|
}, {
|
|
1311
1257
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1312
|
-
line:
|
|
1258
|
+
line: 172,
|
|
1313
1259
|
scope: this,
|
|
1314
1260
|
callSite: (f, a) => f(...a)
|
|
1315
1261
|
});
|
|
@@ -1319,7 +1265,7 @@ var NetworkManager = class {
|
|
|
1319
1265
|
topic: PublicKey6.from(topic)
|
|
1320
1266
|
}, {
|
|
1321
1267
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1322
|
-
line:
|
|
1268
|
+
line: 176,
|
|
1323
1269
|
scope: this,
|
|
1324
1270
|
callSite: (f, a) => f(...a)
|
|
1325
1271
|
});
|
|
@@ -1340,7 +1286,7 @@ var NetworkManager = class {
|
|
|
1340
1286
|
count: this._swarms.size
|
|
1341
1287
|
}, {
|
|
1342
1288
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1343
|
-
line:
|
|
1289
|
+
line: 190,
|
|
1344
1290
|
scope: this,
|
|
1345
1291
|
callSite: (f, a) => f(...a)
|
|
1346
1292
|
});
|
|
@@ -1386,8 +1332,18 @@ import { Transform } from "@dxos/node-std/stream";
|
|
|
1386
1332
|
import { Event as Event6, Trigger } from "@dxos/async";
|
|
1387
1333
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
1388
1334
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1389
|
-
import { log as log9 } from "@dxos/log";
|
|
1335
|
+
import { log as log9, logInfo as logInfo2 } from "@dxos/log";
|
|
1390
1336
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1337
|
+
var __decorate4 = function(decorators, target, key, desc) {
|
|
1338
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1339
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1340
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1341
|
+
else
|
|
1342
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1343
|
+
if (d = decorators[i])
|
|
1344
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1345
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1346
|
+
};
|
|
1391
1347
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1392
1348
|
var createStreamDelay = (delay) => {
|
|
1393
1349
|
return new Transform({
|
|
@@ -1407,34 +1363,30 @@ var _MemoryTransport = class {
|
|
|
1407
1363
|
this.closed = new Event6();
|
|
1408
1364
|
this.connected = new Event6();
|
|
1409
1365
|
this.errors = new ErrorStream3();
|
|
1410
|
-
this._id = PublicKey7.random();
|
|
1411
1366
|
this._remote = new Trigger();
|
|
1412
1367
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1413
1368
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1414
1369
|
this._destroyed = false;
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
}, {
|
|
1370
|
+
this._instanceId = PublicKey7.random();
|
|
1371
|
+
log9("creating", {}, {
|
|
1418
1372
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1419
|
-
line:
|
|
1373
|
+
line: 64,
|
|
1420
1374
|
scope: this,
|
|
1421
1375
|
callSite: (f, a) => f(...a)
|
|
1422
1376
|
});
|
|
1423
|
-
assert9(!_MemoryTransport._connections.has(this.
|
|
1424
|
-
_MemoryTransport._connections.set(this.
|
|
1377
|
+
assert9(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1378
|
+
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1425
1379
|
if (this.options.initiator) {
|
|
1426
1380
|
setTimeout(async () => {
|
|
1427
|
-
log9("sending signal", {
|
|
1428
|
-
transportId: this._id
|
|
1429
|
-
}, {
|
|
1381
|
+
log9("sending signal", {}, {
|
|
1430
1382
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1431
|
-
line:
|
|
1383
|
+
line: 73,
|
|
1432
1384
|
scope: this,
|
|
1433
1385
|
callSite: (f, a) => f(...a)
|
|
1434
1386
|
});
|
|
1435
1387
|
void this.options.sendSignal({
|
|
1436
1388
|
payload: {
|
|
1437
|
-
transportId: this.
|
|
1389
|
+
transportId: this._instanceId.toHex()
|
|
1438
1390
|
}
|
|
1439
1391
|
});
|
|
1440
1392
|
});
|
|
@@ -1445,22 +1397,19 @@ var _MemoryTransport = class {
|
|
|
1445
1397
|
if (this._destroyed) {
|
|
1446
1398
|
return;
|
|
1447
1399
|
}
|
|
1448
|
-
this.
|
|
1449
|
-
this._remoteConnection = _MemoryTransport._connections.get(this.
|
|
1400
|
+
this._remoteInstanceId = remoteId;
|
|
1401
|
+
this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
|
|
1450
1402
|
if (!this._remoteConnection) {
|
|
1451
1403
|
this._destroyed = true;
|
|
1452
1404
|
this.closed.emit();
|
|
1453
1405
|
return;
|
|
1454
1406
|
}
|
|
1455
|
-
assert9(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this.
|
|
1407
|
+
assert9(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteInstanceId}`));
|
|
1456
1408
|
this._remoteConnection._remoteConnection = this;
|
|
1457
|
-
this._remoteConnection.
|
|
1458
|
-
log9("connected", {
|
|
1459
|
-
id: this._id,
|
|
1460
|
-
remote: this._remoteId
|
|
1461
|
-
}, {
|
|
1409
|
+
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1410
|
+
log9("connected", {}, {
|
|
1462
1411
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1463
|
-
line:
|
|
1412
|
+
line: 102,
|
|
1464
1413
|
scope: this,
|
|
1465
1414
|
callSite: (f, a) => f(...a)
|
|
1466
1415
|
});
|
|
@@ -1476,73 +1425,70 @@ var _MemoryTransport = class {
|
|
|
1476
1425
|
}
|
|
1477
1426
|
}
|
|
1478
1427
|
async destroy() {
|
|
1479
|
-
log9("closing", {
|
|
1480
|
-
id: this._id
|
|
1481
|
-
}, {
|
|
1428
|
+
log9("closing", {}, {
|
|
1482
1429
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1483
|
-
line:
|
|
1430
|
+
line: 123,
|
|
1484
1431
|
scope: this,
|
|
1485
1432
|
callSite: (f, a) => f(...a)
|
|
1486
1433
|
});
|
|
1487
1434
|
this._destroyed = true;
|
|
1488
|
-
_MemoryTransport._connections.delete(this.
|
|
1435
|
+
_MemoryTransport._connections.delete(this._instanceId);
|
|
1489
1436
|
if (this._remoteConnection) {
|
|
1490
|
-
log9("closing", {
|
|
1491
|
-
id: this._remoteId
|
|
1492
|
-
}, {
|
|
1437
|
+
log9("closing", {}, {
|
|
1493
1438
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1494
|
-
line:
|
|
1439
|
+
line: 128,
|
|
1495
1440
|
scope: this,
|
|
1496
1441
|
callSite: (f, a) => f(...a)
|
|
1497
1442
|
});
|
|
1498
1443
|
this._remoteConnection._destroyed = true;
|
|
1499
|
-
_MemoryTransport._connections.delete(this.
|
|
1444
|
+
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
1500
1445
|
this._outgoingDelay.unpipe();
|
|
1501
1446
|
this._incomingDelay.unpipe();
|
|
1502
1447
|
this._remoteConnection.closed.emit();
|
|
1503
1448
|
this._remoteConnection._remoteConnection = void 0;
|
|
1504
1449
|
this._remoteConnection = void 0;
|
|
1505
|
-
log9("closed", {
|
|
1506
|
-
id: this._remoteId
|
|
1507
|
-
}, {
|
|
1450
|
+
log9("closed", {}, {
|
|
1508
1451
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1509
|
-
line:
|
|
1452
|
+
line: 146,
|
|
1510
1453
|
scope: this,
|
|
1511
1454
|
callSite: (f, a) => f(...a)
|
|
1512
1455
|
});
|
|
1513
1456
|
}
|
|
1514
1457
|
this.closed.emit();
|
|
1515
|
-
log9("closed", {
|
|
1516
|
-
id: this._id
|
|
1517
|
-
}, {
|
|
1458
|
+
log9("closed", {}, {
|
|
1518
1459
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1519
|
-
line:
|
|
1460
|
+
line: 150,
|
|
1520
1461
|
scope: this,
|
|
1521
1462
|
callSite: (f, a) => f(...a)
|
|
1522
1463
|
});
|
|
1523
1464
|
}
|
|
1524
|
-
signal(
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
}
|
|
1465
|
+
signal({ payload }) {
|
|
1466
|
+
log9("received signal", {
|
|
1467
|
+
payload
|
|
1468
|
+
}, {
|
|
1469
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1470
|
+
line: 154,
|
|
1471
|
+
scope: this,
|
|
1472
|
+
callSite: (f, a) => f(...a)
|
|
1473
|
+
});
|
|
1474
|
+
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
const transportId = payload.transportId;
|
|
1478
|
+
if (transportId) {
|
|
1479
|
+
const remoteId = PublicKey7.fromHex(transportId);
|
|
1480
|
+
this._remote.wake(remoteId);
|
|
1541
1481
|
}
|
|
1542
1482
|
}
|
|
1543
1483
|
};
|
|
1544
1484
|
var MemoryTransport = _MemoryTransport;
|
|
1545
1485
|
MemoryTransport._connections = new ComplexMap6(PublicKey7.hash);
|
|
1486
|
+
__decorate4([
|
|
1487
|
+
logInfo2
|
|
1488
|
+
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1489
|
+
__decorate4([
|
|
1490
|
+
logInfo2
|
|
1491
|
+
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1546
1492
|
|
|
1547
1493
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1548
1494
|
import assert10 from "@dxos/node-std/assert";
|
|
@@ -1873,205 +1819,74 @@ var WebRTCTransportProxyFactory = class {
|
|
|
1873
1819
|
}
|
|
1874
1820
|
};
|
|
1875
1821
|
|
|
1876
|
-
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
1877
|
-
import {
|
|
1878
|
-
import { Teleport } from "@dxos/teleport";
|
|
1879
|
-
var adaptProtocolProvider = (factory) => ({ initiator, localPeerId, remotePeerId, topic }) => {
|
|
1880
|
-
const protocol = factory({
|
|
1881
|
-
channel: discoveryKey(topic),
|
|
1882
|
-
initiator
|
|
1883
|
-
});
|
|
1884
|
-
return {
|
|
1885
|
-
initialize: () => protocol.open(),
|
|
1886
|
-
destroy: () => protocol.close(),
|
|
1887
|
-
stream: protocol.stream,
|
|
1888
|
-
protocol
|
|
1889
|
-
};
|
|
1890
|
-
};
|
|
1891
|
-
|
|
1892
|
-
// packages/core/mesh/network-manager/src/testing/test-protocol.ts
|
|
1893
|
-
import assert14 from "@dxos/node-std/assert";
|
|
1894
|
-
import { EventEmitter } from "@dxos/node-std/events";
|
|
1895
|
-
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
1896
|
-
import { log as log14 } from "@dxos/log";
|
|
1897
|
-
import { Extension } from "@dxos/mesh-protocol";
|
|
1898
|
-
|
|
1899
|
-
// packages/core/mesh/network-manager/src/protocol-factory.ts
|
|
1900
|
-
import assert13 from "@dxos/node-std/assert";
|
|
1901
|
-
import { discoveryKey as discoveryKey2 } from "@dxos/crypto";
|
|
1822
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
1823
|
+
import { Event as Event9 } from "@dxos/async";
|
|
1902
1824
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
1903
1825
|
import { log as log13 } from "@dxos/log";
|
|
1904
|
-
import {
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
},
|
|
1918
|
-
discoveryToPublicKey: (dk) => {
|
|
1919
|
-
const publicKey = getTopics().find((topic) => discoveryKey2(topic).equals(dk));
|
|
1920
|
-
if (publicKey) {
|
|
1921
|
-
protocol.setContext({
|
|
1922
|
-
topic: PublicKey10.stringify(publicKey)
|
|
1923
|
-
});
|
|
1924
|
-
}
|
|
1925
|
-
assert13(publicKey, "PublicKey not found in discovery.");
|
|
1926
|
-
return publicKey;
|
|
1826
|
+
import { TestExtension } from "@dxos/teleport";
|
|
1827
|
+
import { ComplexMap as ComplexMap8 } from "@dxos/util";
|
|
1828
|
+
|
|
1829
|
+
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
1830
|
+
import { Teleport } from "@dxos/teleport";
|
|
1831
|
+
var createTeleportProtocolFactory = (onConnection) => {
|
|
1832
|
+
return (params) => {
|
|
1833
|
+
const teleport = new Teleport(params);
|
|
1834
|
+
return {
|
|
1835
|
+
stream: teleport.stream,
|
|
1836
|
+
initialize: async () => {
|
|
1837
|
+
await teleport.open();
|
|
1838
|
+
await onConnection(teleport);
|
|
1927
1839
|
},
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
}
|
|
1932
|
-
protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
|
|
1933
|
-
return protocol;
|
|
1840
|
+
destroy: async () => {
|
|
1841
|
+
await teleport.close();
|
|
1842
|
+
}
|
|
1843
|
+
};
|
|
1934
1844
|
};
|
|
1935
1845
|
};
|
|
1936
1846
|
|
|
1937
|
-
// packages/core/mesh/network-manager/src/testing/test-protocol.ts
|
|
1938
|
-
var
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
],
|
|
1961
|
-
session: {
|
|
1962
|
-
peerId: peerId.toHex()
|
|
1963
|
-
},
|
|
1964
|
-
plugins: [
|
|
1965
|
-
protocolPlugin
|
|
1966
|
-
]
|
|
1967
|
-
});
|
|
1968
|
-
};
|
|
1969
|
-
var TestProtocolPlugin = class extends EventEmitter {
|
|
1970
|
-
constructor(peerId, uppercase = false) {
|
|
1971
|
-
super();
|
|
1972
|
-
this._peers = /* @__PURE__ */ new Map();
|
|
1973
|
-
this.initCalled = false;
|
|
1974
|
-
assert14(Buffer.isBuffer(peerId));
|
|
1975
|
-
this._peerId = peerId;
|
|
1976
|
-
this._uppercase = uppercase;
|
|
1977
|
-
}
|
|
1978
|
-
get peerId() {
|
|
1979
|
-
return this._peerId;
|
|
1980
|
-
}
|
|
1981
|
-
get peers() {
|
|
1982
|
-
return Array.from(this._peers.values());
|
|
1983
|
-
}
|
|
1984
|
-
createExtension() {
|
|
1985
|
-
log14("creating extension", {
|
|
1986
|
-
peerId: PublicKey11.from(this.peerId)
|
|
1987
|
-
}, {
|
|
1988
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
1989
|
-
line: 92,
|
|
1990
|
-
scope: this,
|
|
1991
|
-
callSite: (f, a) => f(...a)
|
|
1992
|
-
});
|
|
1993
|
-
return new Extension(EXTENSION_NAME, {
|
|
1994
|
-
binary: true
|
|
1995
|
-
}).setInitHandler(this._init.bind(this)).setMessageHandler(this._receive.bind(this)).setHandshakeHandler(this._onPeerConnect.bind(this)).setCloseHandler(this._onPeerDisconnect.bind(this));
|
|
1996
|
-
}
|
|
1997
|
-
async _init(protocol) {
|
|
1998
|
-
this.initCalled = true;
|
|
1999
|
-
}
|
|
2000
|
-
async send(peerId, payload) {
|
|
2001
|
-
assert14(Buffer.isBuffer(peerId));
|
|
2002
|
-
const peerIdStr = PublicKey11.stringify(peerId);
|
|
2003
|
-
const peer = this._peers.get(peerIdStr);
|
|
2004
|
-
if (!peer) {
|
|
2005
|
-
throw new Error(`peer not found: ${PublicKey11.from(peerId).truncate()}`);
|
|
2006
|
-
}
|
|
2007
|
-
const extension = peer.getExtension(EXTENSION_NAME);
|
|
2008
|
-
const encoded = Buffer.from(payload);
|
|
2009
|
-
log14("sending", {
|
|
2010
|
-
peerId: PublicKey11.from(peerId),
|
|
2011
|
-
payload
|
|
2012
|
-
}, {
|
|
2013
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2014
|
-
line: 124,
|
|
2015
|
-
scope: this,
|
|
2016
|
-
callSite: (f, a) => f(...a)
|
|
2017
|
-
});
|
|
2018
|
-
return await extension.send(encoded, {
|
|
2019
|
-
oneway: true
|
|
1847
|
+
// packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts
|
|
1848
|
+
var TestWireProtocol = class {
|
|
1849
|
+
constructor(peerId) {
|
|
1850
|
+
this.peerId = peerId;
|
|
1851
|
+
this.connections = new ComplexMap8(PublicKey10.hash);
|
|
1852
|
+
this.connected = new Event9();
|
|
1853
|
+
this.factory = createTeleportProtocolFactory(async (teleport) => {
|
|
1854
|
+
log13("create", {
|
|
1855
|
+
remotePeerId: teleport.remotePeerId
|
|
1856
|
+
}, {
|
|
1857
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts",
|
|
1858
|
+
line: 20,
|
|
1859
|
+
scope: this,
|
|
1860
|
+
callSite: (f, a) => f(...a)
|
|
1861
|
+
});
|
|
1862
|
+
const extension = new TestExtension({
|
|
1863
|
+
onClose: async () => {
|
|
1864
|
+
this.connections.delete(teleport.remotePeerId);
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1867
|
+
this.connections.set(teleport.remotePeerId, extension);
|
|
1868
|
+
teleport.addExtension("test", extension);
|
|
1869
|
+
this.connected.emit(teleport.remotePeerId);
|
|
2020
1870
|
});
|
|
2021
1871
|
}
|
|
2022
|
-
async
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
let payload = data.data.toString();
|
|
2026
|
-
if (this._uppercase) {
|
|
2027
|
-
payload = payload.toUpperCase();
|
|
1872
|
+
async waitForConnection(peerId) {
|
|
1873
|
+
if (this.connections.has(peerId)) {
|
|
1874
|
+
return this.connections.get(peerId);
|
|
2028
1875
|
}
|
|
2029
|
-
|
|
2030
|
-
peerId
|
|
2031
|
-
payload
|
|
1876
|
+
log13("waitForConnection", {
|
|
1877
|
+
peerId
|
|
2032
1878
|
}, {
|
|
2033
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2034
|
-
line:
|
|
1879
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-wire-protocol.ts",
|
|
1880
|
+
line: 35,
|
|
2035
1881
|
scope: this,
|
|
2036
1882
|
callSite: (f, a) => f(...a)
|
|
2037
1883
|
});
|
|
2038
|
-
this.
|
|
1884
|
+
await this.connected.waitFor((connectedId) => connectedId.equals(peerId));
|
|
1885
|
+
return this.connections.get(peerId);
|
|
2039
1886
|
}
|
|
2040
|
-
async
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
}, {
|
|
2044
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2045
|
-
line: 141,
|
|
2046
|
-
scope: this,
|
|
2047
|
-
callSite: (f, a) => f(...a)
|
|
2048
|
-
});
|
|
2049
|
-
const peerId = getPeerId(protocol);
|
|
2050
|
-
if (peerId === void 0) {
|
|
2051
|
-
return;
|
|
2052
|
-
}
|
|
2053
|
-
const peerIdStr = PublicKey11.stringify(peerId);
|
|
2054
|
-
if (this._peers.has(peerIdStr)) {
|
|
2055
|
-
return;
|
|
2056
|
-
}
|
|
2057
|
-
this._peers.set(peerIdStr, protocol);
|
|
2058
|
-
this.emit("connect", protocol);
|
|
2059
|
-
}
|
|
2060
|
-
async _onPeerDisconnect(protocol) {
|
|
2061
|
-
log14("disconnecting", {
|
|
2062
|
-
id: PublicKey11.from(protocol.id)
|
|
2063
|
-
}, {
|
|
2064
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/testing/test-protocol.ts",
|
|
2065
|
-
line: 157,
|
|
2066
|
-
scope: this,
|
|
2067
|
-
callSite: (f, a) => f(...a)
|
|
2068
|
-
});
|
|
2069
|
-
const peerId = getPeerId(protocol);
|
|
2070
|
-
if (peerId === void 0) {
|
|
2071
|
-
return;
|
|
2072
|
-
}
|
|
2073
|
-
this._peers.delete(PublicKey11.stringify(peerId));
|
|
2074
|
-
this.emit("disconnect", peerId);
|
|
1887
|
+
async testConnection(peerId) {
|
|
1888
|
+
const connection = await this.waitForConnection(peerId);
|
|
1889
|
+
await connection.test();
|
|
2075
1890
|
}
|
|
2076
1891
|
};
|
|
2077
1892
|
|
|
@@ -2095,8 +1910,8 @@ var TestBuilder = class {
|
|
|
2095
1910
|
var TestPeer = class {
|
|
2096
1911
|
constructor(testBuilder) {
|
|
2097
1912
|
this.testBuilder = testBuilder;
|
|
2098
|
-
this.peerId =
|
|
2099
|
-
this._swarms = new
|
|
1913
|
+
this.peerId = PublicKey11.random();
|
|
1914
|
+
this._swarms = new ComplexMap9(PublicKey11.hash);
|
|
2100
1915
|
this._networkManager = this.createNetworkManager();
|
|
2101
1916
|
}
|
|
2102
1917
|
createNetworkManager() {
|
|
@@ -2169,13 +1984,13 @@ var TestSwarmConnection = class {
|
|
|
2169
1984
|
constructor(peer, topic) {
|
|
2170
1985
|
this.peer = peer;
|
|
2171
1986
|
this.topic = topic;
|
|
2172
|
-
this.
|
|
1987
|
+
this.protocol = new TestWireProtocol(this.peer.peerId);
|
|
2173
1988
|
}
|
|
2174
1989
|
async join(topology = new FullyConnectedTopology()) {
|
|
2175
1990
|
await this.peer._networkManager.joinSwarm({
|
|
2176
1991
|
topic: this.topic,
|
|
2177
1992
|
peerId: this.peer.peerId,
|
|
2178
|
-
protocolProvider:
|
|
1993
|
+
protocolProvider: this.protocol.factory,
|
|
2179
1994
|
topology
|
|
2180
1995
|
});
|
|
2181
1996
|
return this;
|
|
@@ -2189,9 +2004,5 @@ export {
|
|
|
2189
2004
|
TEST_SIGNAL_URL,
|
|
2190
2005
|
TestBuilder,
|
|
2191
2006
|
TestPeer,
|
|
2192
|
-
|
|
2193
|
-
TestSwarmConnection,
|
|
2194
|
-
getPeerId,
|
|
2195
|
-
testProtocolProvider
|
|
2007
|
+
TestSwarmConnection
|
|
2196
2008
|
};
|
|
2197
|
-
//# sourceMappingURL=index.mjs.map
|