@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
|
@@ -33,6 +33,7 @@ var ConnectionState;
|
|
|
33
33
|
ConnectionState4["INITIAL"] = "INITIAL";
|
|
34
34
|
ConnectionState4["CONNECTING"] = "CONNECTING";
|
|
35
35
|
ConnectionState4["CONNECTED"] = "CONNECTED";
|
|
36
|
+
ConnectionState4["CLOSING"] = "CLOSING";
|
|
36
37
|
ConnectionState4["CLOSED"] = "CLOSED";
|
|
37
38
|
})(ConnectionState || (ConnectionState = {}));
|
|
38
39
|
var Connection = class {
|
|
@@ -88,7 +89,11 @@ var Connection = class {
|
|
|
88
89
|
this._transport = void 0;
|
|
89
90
|
this.close().catch((err) => this.errors.raise(err));
|
|
90
91
|
});
|
|
91
|
-
this._transport.errors.
|
|
92
|
+
this._transport.errors.handle((err) => {
|
|
93
|
+
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
94
|
+
this.errors.raise(err);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
92
97
|
for (const signal of this._bufferedSignals) {
|
|
93
98
|
void this._transport.signal(signal);
|
|
94
99
|
}
|
|
@@ -99,11 +104,12 @@ var Connection = class {
|
|
|
99
104
|
if (this._state === ConnectionState.CLOSED) {
|
|
100
105
|
return;
|
|
101
106
|
}
|
|
107
|
+
this._changeState(ConnectionState.CLOSING);
|
|
102
108
|
log("closing...", {
|
|
103
109
|
peerId: this.ownId
|
|
104
110
|
}, {
|
|
105
111
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
106
|
-
line:
|
|
112
|
+
line: 142,
|
|
107
113
|
scope: this,
|
|
108
114
|
callSite: (f, a) => f(...a)
|
|
109
115
|
});
|
|
@@ -112,7 +118,7 @@ var Connection = class {
|
|
|
112
118
|
} catch (err) {
|
|
113
119
|
log.catch(err, {}, {
|
|
114
120
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
115
|
-
line:
|
|
121
|
+
line: 148,
|
|
116
122
|
scope: this,
|
|
117
123
|
callSite: (f, a) => f(...a)
|
|
118
124
|
});
|
|
@@ -122,7 +128,7 @@ var Connection = class {
|
|
|
122
128
|
} catch (err1) {
|
|
123
129
|
log.catch(err1, {}, {
|
|
124
130
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
125
|
-
line:
|
|
131
|
+
line: 155,
|
|
126
132
|
scope: this,
|
|
127
133
|
callSite: (f, a) => f(...a)
|
|
128
134
|
});
|
|
@@ -131,7 +137,7 @@ var Connection = class {
|
|
|
131
137
|
peerId: this.ownId
|
|
132
138
|
}, {
|
|
133
139
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
134
|
-
line:
|
|
140
|
+
line: 158,
|
|
135
141
|
scope: this,
|
|
136
142
|
callSite: (f, a) => f(...a)
|
|
137
143
|
});
|
|
@@ -143,7 +149,7 @@ var Connection = class {
|
|
|
143
149
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
144
150
|
log("dropping signal for incorrect session id", {}, {
|
|
145
151
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
146
|
-
line:
|
|
152
|
+
line: 165,
|
|
147
153
|
scope: this,
|
|
148
154
|
callSite: (f, a) => f(...a)
|
|
149
155
|
});
|
|
@@ -159,7 +165,7 @@ var Connection = class {
|
|
|
159
165
|
msg: msg.data
|
|
160
166
|
}, {
|
|
161
167
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
162
|
-
line:
|
|
168
|
+
line: 173,
|
|
163
169
|
scope: this,
|
|
164
170
|
callSite: (f, a) => f(...a)
|
|
165
171
|
});
|
|
@@ -173,7 +179,7 @@ var Connection = class {
|
|
|
173
179
|
msg: msg.data
|
|
174
180
|
}, {
|
|
175
181
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/connection.ts",
|
|
176
|
-
line:
|
|
182
|
+
line: 179,
|
|
177
183
|
scope: this,
|
|
178
184
|
callSite: (f, a) => f(...a)
|
|
179
185
|
});
|
|
@@ -580,14 +586,7 @@ var Peer = class {
|
|
|
580
586
|
scope: this,
|
|
581
587
|
callSite: (f, a) => f(...a)
|
|
582
588
|
});
|
|
583
|
-
void this.closeConnection()
|
|
584
|
-
log3.catch(err, {}, {
|
|
585
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
586
|
-
line: 207,
|
|
587
|
-
scope: this,
|
|
588
|
-
callSite: (f, a) => f(...a)
|
|
589
|
-
});
|
|
590
|
-
});
|
|
589
|
+
void this.closeConnection();
|
|
591
590
|
});
|
|
592
591
|
this.connection = connection;
|
|
593
592
|
return connection;
|
|
@@ -602,7 +601,7 @@ var Peer = class {
|
|
|
602
601
|
sessionId: connection.sessionId
|
|
603
602
|
}, {
|
|
604
603
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
605
|
-
line:
|
|
604
|
+
line: 219,
|
|
606
605
|
scope: this,
|
|
607
606
|
callSite: (f, a) => f(...a)
|
|
608
607
|
});
|
|
@@ -612,7 +611,7 @@ var Peer = class {
|
|
|
612
611
|
sessionId: connection.sessionId
|
|
613
612
|
}, {
|
|
614
613
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
615
|
-
line:
|
|
614
|
+
line: 225,
|
|
616
615
|
scope: this,
|
|
617
616
|
callSite: (f, a) => f(...a)
|
|
618
617
|
});
|
|
@@ -623,7 +622,7 @@ var Peer = class {
|
|
|
623
622
|
message
|
|
624
623
|
}, {
|
|
625
624
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
626
|
-
line:
|
|
625
|
+
line: 230,
|
|
627
626
|
scope: this,
|
|
628
627
|
callSite: (f, a) => f(...a)
|
|
629
628
|
});
|
|
@@ -638,7 +637,7 @@ var Peer = class {
|
|
|
638
637
|
topic: this.topic
|
|
639
638
|
}, {
|
|
640
639
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/peer.ts",
|
|
641
|
-
line:
|
|
640
|
+
line: 238,
|
|
642
641
|
scope: this,
|
|
643
642
|
callSite: (f, a) => f(...a)
|
|
644
643
|
});
|
|
@@ -1010,9 +1009,8 @@ var SwarmMapper = class {
|
|
|
1010
1009
|
get peers() {
|
|
1011
1010
|
return Array.from(this._peers.values());
|
|
1012
1011
|
}
|
|
1013
|
-
constructor(_swarm
|
|
1012
|
+
constructor(_swarm) {
|
|
1014
1013
|
this._swarm = _swarm;
|
|
1015
|
-
this._presence = _presence;
|
|
1016
1014
|
this._subscriptions = new EventSubscriptions();
|
|
1017
1015
|
this._connectionSubscriptions = new ComplexMap3(PublicKey4.hash);
|
|
1018
1016
|
this._peers = new ComplexMap3(PublicKey4.hash);
|
|
@@ -1029,17 +1027,12 @@ var SwarmMapper = class {
|
|
|
1029
1027
|
this._connectionSubscriptions.delete(peerId);
|
|
1030
1028
|
this._update();
|
|
1031
1029
|
}));
|
|
1032
|
-
if (_presence) {
|
|
1033
|
-
this._subscriptions.add(_presence.graphUpdated.on(() => {
|
|
1034
|
-
this._update();
|
|
1035
|
-
}));
|
|
1036
|
-
}
|
|
1037
1030
|
this._update();
|
|
1038
1031
|
}
|
|
1039
1032
|
_update() {
|
|
1040
1033
|
log5("updating swarm", {}, {
|
|
1041
1034
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1042
|
-
line:
|
|
1035
|
+
line: 75,
|
|
1043
1036
|
scope: this,
|
|
1044
1037
|
callSite: (f, a) => f(...a)
|
|
1045
1038
|
});
|
|
@@ -1058,32 +1051,12 @@ var SwarmMapper = class {
|
|
|
1058
1051
|
]
|
|
1059
1052
|
});
|
|
1060
1053
|
}
|
|
1061
|
-
if (this._presence) {
|
|
1062
|
-
this._presence.graph.forEachNode((node) => {
|
|
1063
|
-
const id = PublicKey4.fromHex(node.id);
|
|
1064
|
-
if (this._peers.has(id)) {
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
this._peers.set(id, {
|
|
1068
|
-
id,
|
|
1069
|
-
state: "INDIRECTLY_CONNECTED",
|
|
1070
|
-
connections: []
|
|
1071
|
-
});
|
|
1072
|
-
});
|
|
1073
|
-
this._presence.graph.forEachLink((link) => {
|
|
1074
|
-
const from = PublicKey4.from(link.fromId);
|
|
1075
|
-
const to = PublicKey4.from(link.toId);
|
|
1076
|
-
if (!from.equals(this._swarm.ownPeerId) && !to.equals(this._swarm.ownPeerId)) {
|
|
1077
|
-
this._peers.get(from).connections.push(to);
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
1054
|
log5("graph changed", {
|
|
1082
1055
|
directConnections: this._swarm.connections.length,
|
|
1083
1056
|
totalPeersInSwarm: this._peers.size
|
|
1084
1057
|
}, {
|
|
1085
1058
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/swarm/swarm-mapper.ts",
|
|
1086
|
-
line:
|
|
1059
|
+
line: 116,
|
|
1087
1060
|
scope: this,
|
|
1088
1061
|
callSite: (f, a) => f(...a)
|
|
1089
1062
|
});
|
|
@@ -1127,13 +1100,12 @@ var ConnectionLog = class {
|
|
|
1127
1100
|
this._swarms.set(swarm.instanceId, info);
|
|
1128
1101
|
this.update.emit();
|
|
1129
1102
|
swarm.connectionAdded.on((connection) => {
|
|
1130
|
-
var _a, _b, _c, _d, _e;
|
|
1131
1103
|
const connectionInfo = {
|
|
1132
1104
|
state: ConnectionState.INITIAL,
|
|
1133
1105
|
remotePeerId: connection.remoteId,
|
|
1134
1106
|
sessionId: connection.sessionId,
|
|
1135
1107
|
transport: connection.transport && Object.getPrototypeOf(connection.transport).constructor.name,
|
|
1136
|
-
protocolExtensions:
|
|
1108
|
+
protocolExtensions: [],
|
|
1137
1109
|
events: []
|
|
1138
1110
|
};
|
|
1139
1111
|
info.connections.push(connectionInfo);
|
|
@@ -1146,32 +1118,6 @@ var ConnectionLog = class {
|
|
|
1146
1118
|
});
|
|
1147
1119
|
this.update.emit();
|
|
1148
1120
|
});
|
|
1149
|
-
(_b = connection.protocol.protocol) == null ? void 0 : _b.error.on((error) => {
|
|
1150
|
-
var _a2;
|
|
1151
|
-
connectionInfo.events.push({
|
|
1152
|
-
type: EventType.PROTOCOL_ERROR,
|
|
1153
|
-
error: (_a2 = error.stack) != null ? _a2 : error.message
|
|
1154
|
-
});
|
|
1155
|
-
this.update.emit();
|
|
1156
|
-
});
|
|
1157
|
-
(_c = connection.protocol.protocol) == null ? void 0 : _c.extensionsInitialized.on(() => {
|
|
1158
|
-
connectionInfo.events.push({
|
|
1159
|
-
type: EventType.PROTOCOL_EXTENSIONS_INITIALIZED
|
|
1160
|
-
});
|
|
1161
|
-
this.update.emit();
|
|
1162
|
-
});
|
|
1163
|
-
(_d = connection.protocol.protocol) == null ? void 0 : _d.extensionsHandshake.on(() => {
|
|
1164
|
-
connectionInfo.events.push({
|
|
1165
|
-
type: EventType.PROTOCOL_EXTENSIONS_HANDSHAKE
|
|
1166
|
-
});
|
|
1167
|
-
this.update.emit();
|
|
1168
|
-
});
|
|
1169
|
-
(_e = connection.protocol.protocol) == null ? void 0 : _e.handshake.on(() => {
|
|
1170
|
-
connectionInfo.events.push({
|
|
1171
|
-
type: EventType.PROTOCOL_HANDSHAKE
|
|
1172
|
-
});
|
|
1173
|
-
this.update.emit();
|
|
1174
|
-
});
|
|
1175
1121
|
});
|
|
1176
1122
|
}
|
|
1177
1123
|
swarmLeft(swarm) {
|
|
@@ -1188,7 +1134,7 @@ import { log as log6 } from "@dxos/log";
|
|
|
1188
1134
|
import { Messenger } from "@dxos/messaging";
|
|
1189
1135
|
import { ComplexMap as ComplexMap5 } from "@dxos/util";
|
|
1190
1136
|
var NetworkManager = class {
|
|
1191
|
-
constructor({ transportFactory, signalManager, log:
|
|
1137
|
+
constructor({ transportFactory, signalManager, log: log13 }) {
|
|
1192
1138
|
this._swarms = new ComplexMap5(PublicKey6.hash);
|
|
1193
1139
|
this._mappers = new ComplexMap5(PublicKey6.hash);
|
|
1194
1140
|
this.topicsUpdated = new Event5();
|
|
@@ -1205,7 +1151,7 @@ var NetworkManager = class {
|
|
|
1205
1151
|
join: (opts) => this._signalManager.join(opts),
|
|
1206
1152
|
leave: (opts) => this._signalManager.leave(opts)
|
|
1207
1153
|
};
|
|
1208
|
-
if (
|
|
1154
|
+
if (log13) {
|
|
1209
1155
|
this._connectionLog = new ConnectionLog();
|
|
1210
1156
|
}
|
|
1211
1157
|
}
|
|
@@ -1229,7 +1175,7 @@ var NetworkManager = class {
|
|
|
1229
1175
|
await this.leaveSwarm(topic).catch((err) => {
|
|
1230
1176
|
log6(err, {}, {
|
|
1231
1177
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1232
|
-
line:
|
|
1178
|
+
line: 122,
|
|
1233
1179
|
scope: this,
|
|
1234
1180
|
callSite: (f, a) => f(...a)
|
|
1235
1181
|
});
|
|
@@ -1237,7 +1183,7 @@ var NetworkManager = class {
|
|
|
1237
1183
|
}
|
|
1238
1184
|
await this._signalManager.destroy();
|
|
1239
1185
|
}
|
|
1240
|
-
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol,
|
|
1186
|
+
async joinSwarm({ topic, peerId, topology, protocolProvider: protocol, label }) {
|
|
1241
1187
|
var _a;
|
|
1242
1188
|
assert5(PublicKey6.isPublicKey(topic));
|
|
1243
1189
|
assert5(PublicKey6.isPublicKey(peerId));
|
|
@@ -1252,7 +1198,7 @@ var NetworkManager = class {
|
|
|
1252
1198
|
topology: topology.toString()
|
|
1253
1199
|
}, {
|
|
1254
1200
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1255
|
-
line:
|
|
1201
|
+
line: 148,
|
|
1256
1202
|
scope: this,
|
|
1257
1203
|
callSite: (f, a) => f(...a)
|
|
1258
1204
|
});
|
|
@@ -1262,7 +1208,7 @@ var NetworkManager = class {
|
|
|
1262
1208
|
error
|
|
1263
1209
|
}, {
|
|
1264
1210
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1265
|
-
line:
|
|
1211
|
+
line: 151,
|
|
1266
1212
|
scope: this,
|
|
1267
1213
|
callSite: (f, a) => f(...a)
|
|
1268
1214
|
});
|
|
@@ -1273,11 +1219,11 @@ var NetworkManager = class {
|
|
|
1273
1219
|
peerId
|
|
1274
1220
|
}).catch((error) => log6.catch(error, {}, {
|
|
1275
1221
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1276
|
-
line:
|
|
1222
|
+
line: 155,
|
|
1277
1223
|
scope: this,
|
|
1278
1224
|
callSite: (f, a) => f(...a)
|
|
1279
1225
|
}));
|
|
1280
|
-
this._mappers.set(topic, new SwarmMapper(swarm
|
|
1226
|
+
this._mappers.set(topic, new SwarmMapper(swarm));
|
|
1281
1227
|
this.topicsUpdated.emit();
|
|
1282
1228
|
(_a = this._connectionLog) == null ? void 0 : _a.swarmJoined(swarm);
|
|
1283
1229
|
log6("joined", {
|
|
@@ -1285,7 +1231,7 @@ var NetworkManager = class {
|
|
|
1285
1231
|
count: this._swarms.size
|
|
1286
1232
|
}, {
|
|
1287
1233
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1288
|
-
line:
|
|
1234
|
+
line: 160,
|
|
1289
1235
|
scope: this,
|
|
1290
1236
|
callSite: (f, a) => f(...a)
|
|
1291
1237
|
});
|
|
@@ -1300,7 +1246,7 @@ var NetworkManager = class {
|
|
|
1300
1246
|
topic: PublicKey6.from(topic)
|
|
1301
1247
|
}, {
|
|
1302
1248
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1303
|
-
line:
|
|
1249
|
+
line: 172,
|
|
1304
1250
|
scope: this,
|
|
1305
1251
|
callSite: (f, a) => f(...a)
|
|
1306
1252
|
});
|
|
@@ -1310,7 +1256,7 @@ var NetworkManager = class {
|
|
|
1310
1256
|
topic: PublicKey6.from(topic)
|
|
1311
1257
|
}, {
|
|
1312
1258
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1313
|
-
line:
|
|
1259
|
+
line: 176,
|
|
1314
1260
|
scope: this,
|
|
1315
1261
|
callSite: (f, a) => f(...a)
|
|
1316
1262
|
});
|
|
@@ -1331,85 +1277,25 @@ var NetworkManager = class {
|
|
|
1331
1277
|
count: this._swarms.size
|
|
1332
1278
|
}, {
|
|
1333
1279
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/network-manager.ts",
|
|
1334
|
-
line:
|
|
1280
|
+
line: 190,
|
|
1335
1281
|
scope: this,
|
|
1336
1282
|
callSite: (f, a) => f(...a)
|
|
1337
1283
|
});
|
|
1338
1284
|
}
|
|
1339
1285
|
};
|
|
1340
1286
|
|
|
1341
|
-
// packages/core/mesh/network-manager/src/protocol-factory.ts
|
|
1342
|
-
import assert6 from "@dxos/node-std/assert";
|
|
1343
|
-
import { discoveryKey } from "@dxos/crypto";
|
|
1344
|
-
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1345
|
-
import { log as log7 } from "@dxos/log";
|
|
1346
|
-
import { Protocol } from "@dxos/mesh-protocol";
|
|
1347
|
-
var protocolFactory = ({ session = {}, plugins = [], getTopics }) => {
|
|
1348
|
-
assert6(getTopics);
|
|
1349
|
-
return ({ channel, initiator }) => {
|
|
1350
|
-
log7("creating protocol", {}, {
|
|
1351
|
-
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/protocol-factory.ts",
|
|
1352
|
-
line: 41,
|
|
1353
|
-
scope: void 0,
|
|
1354
|
-
callSite: (f, a) => f(...a)
|
|
1355
|
-
});
|
|
1356
|
-
const protocol = new Protocol({
|
|
1357
|
-
streamOptions: {
|
|
1358
|
-
live: true
|
|
1359
|
-
},
|
|
1360
|
-
discoveryToPublicKey: (dk) => {
|
|
1361
|
-
const publicKey = getTopics().find((topic) => discoveryKey(topic).equals(dk));
|
|
1362
|
-
if (publicKey) {
|
|
1363
|
-
protocol.setContext({
|
|
1364
|
-
topic: PublicKey7.stringify(publicKey)
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
assert6(publicKey, "PublicKey not found in discovery.");
|
|
1368
|
-
return publicKey;
|
|
1369
|
-
},
|
|
1370
|
-
initiator,
|
|
1371
|
-
userSession: session,
|
|
1372
|
-
discoveryKey: channel
|
|
1373
|
-
});
|
|
1374
|
-
protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
|
|
1375
|
-
return protocol;
|
|
1376
|
-
};
|
|
1377
|
-
};
|
|
1378
|
-
var createProtocolFactory = (topic, peerId, plugins) => protocolFactory({
|
|
1379
|
-
getTopics: () => [
|
|
1380
|
-
topic.asBuffer()
|
|
1381
|
-
],
|
|
1382
|
-
session: {
|
|
1383
|
-
peerId: PublicKey7.stringify(peerId.asBuffer())
|
|
1384
|
-
},
|
|
1385
|
-
plugins
|
|
1386
|
-
});
|
|
1387
|
-
var transportProtocolProvider = (rendezvousKey, peerId, protocolPlugin) => {
|
|
1388
|
-
return protocolFactory({
|
|
1389
|
-
getTopics: () => [
|
|
1390
|
-
rendezvousKey
|
|
1391
|
-
],
|
|
1392
|
-
session: {
|
|
1393
|
-
peerId: PublicKey7.stringify(peerId)
|
|
1394
|
-
},
|
|
1395
|
-
plugins: [
|
|
1396
|
-
protocolPlugin
|
|
1397
|
-
]
|
|
1398
|
-
});
|
|
1399
|
-
};
|
|
1400
|
-
|
|
1401
1287
|
// packages/core/mesh/network-manager/src/topology/fully-connected-topology.ts
|
|
1402
|
-
import
|
|
1288
|
+
import assert6 from "@dxos/node-std/assert";
|
|
1403
1289
|
var FullyConnectedTopology = class {
|
|
1404
1290
|
toString() {
|
|
1405
1291
|
return "FullyConnectedTopology";
|
|
1406
1292
|
}
|
|
1407
1293
|
init(controller) {
|
|
1408
|
-
|
|
1294
|
+
assert6(!this._controller, "Already initialized");
|
|
1409
1295
|
this._controller = controller;
|
|
1410
1296
|
}
|
|
1411
1297
|
update() {
|
|
1412
|
-
|
|
1298
|
+
assert6(this._controller, "Not initialized");
|
|
1413
1299
|
const { candidates: discovered } = this._controller.getState();
|
|
1414
1300
|
for (const peer of discovered) {
|
|
1415
1301
|
this._controller.connect(peer);
|
|
@@ -1423,9 +1309,9 @@ var FullyConnectedTopology = class {
|
|
|
1423
1309
|
};
|
|
1424
1310
|
|
|
1425
1311
|
// packages/core/mesh/network-manager/src/topology/mmst-topology.ts
|
|
1426
|
-
import
|
|
1312
|
+
import assert7 from "@dxos/node-std/assert";
|
|
1427
1313
|
import distance from "xor-distance";
|
|
1428
|
-
import { log as
|
|
1314
|
+
import { log as log7 } from "@dxos/log";
|
|
1429
1315
|
var MMSTTopology = class {
|
|
1430
1316
|
constructor({ originateConnections = 2, maxPeers = 4, sampleSize = 10 } = {}) {
|
|
1431
1317
|
this._sampleCollected = false;
|
|
@@ -1434,14 +1320,14 @@ var MMSTTopology = class {
|
|
|
1434
1320
|
this._sampleSize = sampleSize;
|
|
1435
1321
|
}
|
|
1436
1322
|
init(controller) {
|
|
1437
|
-
|
|
1323
|
+
assert7(!this._controller, "Already initialized");
|
|
1438
1324
|
this._controller = controller;
|
|
1439
1325
|
}
|
|
1440
1326
|
update() {
|
|
1441
|
-
|
|
1327
|
+
assert7(this._controller, "Not initialized");
|
|
1442
1328
|
const { connected, candidates } = this._controller.getState();
|
|
1443
1329
|
if (this._sampleCollected || connected.length > this._maxPeers || candidates.length > 0) {
|
|
1444
|
-
|
|
1330
|
+
log7("Running the algorithm.", {}, {
|
|
1445
1331
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts",
|
|
1446
1332
|
line: 55,
|
|
1447
1333
|
scope: this,
|
|
@@ -1452,10 +1338,10 @@ var MMSTTopology = class {
|
|
|
1452
1338
|
}
|
|
1453
1339
|
}
|
|
1454
1340
|
async onOffer(peer) {
|
|
1455
|
-
|
|
1341
|
+
assert7(this._controller, "Not initialized");
|
|
1456
1342
|
const { connected } = this._controller.getState();
|
|
1457
1343
|
const accept = connected.length < this._maxPeers;
|
|
1458
|
-
|
|
1344
|
+
log7(`Offer ${peer} accept=${accept}`, {}, {
|
|
1459
1345
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts",
|
|
1460
1346
|
line: 65,
|
|
1461
1347
|
scope: this,
|
|
@@ -1466,12 +1352,12 @@ var MMSTTopology = class {
|
|
|
1466
1352
|
async destroy() {
|
|
1467
1353
|
}
|
|
1468
1354
|
_runAlgorithm() {
|
|
1469
|
-
|
|
1355
|
+
assert7(this._controller, "Not initialized");
|
|
1470
1356
|
const { connected, candidates, ownPeerId } = this._controller.getState();
|
|
1471
1357
|
if (connected.length > this._maxPeers) {
|
|
1472
1358
|
const sorted = sortByXorDistance(connected, ownPeerId).reverse().slice(0, this._maxPeers - connected.length);
|
|
1473
1359
|
for (const peer of sorted) {
|
|
1474
|
-
|
|
1360
|
+
log7(`Disconnect ${peer}.`, {}, {
|
|
1475
1361
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts",
|
|
1476
1362
|
line: 83,
|
|
1477
1363
|
scope: this,
|
|
@@ -1483,7 +1369,7 @@ var MMSTTopology = class {
|
|
|
1483
1369
|
const sample = candidates.sort(() => Math.random() - 0.5).slice(0, this._sampleSize);
|
|
1484
1370
|
const sorted1 = sortByXorDistance(sample, ownPeerId).slice(0, this._originateConnections - connected.length);
|
|
1485
1371
|
for (const peer1 of sorted1) {
|
|
1486
|
-
|
|
1372
|
+
log7(`Connect ${peer1}.`, {}, {
|
|
1487
1373
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/mmst-topology.ts",
|
|
1488
1374
|
line: 91,
|
|
1489
1375
|
scope: this,
|
|
@@ -1500,8 +1386,8 @@ var MMSTTopology = class {
|
|
|
1500
1386
|
var sortByXorDistance = (keys, reference) => keys.sort((a, b) => distance.gt(distance(a.asBuffer(), reference.asBuffer()), distance(b.asBuffer(), reference.asBuffer())));
|
|
1501
1387
|
|
|
1502
1388
|
// packages/core/mesh/network-manager/src/topology/star-topology.ts
|
|
1503
|
-
import
|
|
1504
|
-
import { log as
|
|
1389
|
+
import assert8 from "@dxos/node-std/assert";
|
|
1390
|
+
import { log as log8 } from "@dxos/log";
|
|
1505
1391
|
var StarTopology = class {
|
|
1506
1392
|
constructor(_centralPeer) {
|
|
1507
1393
|
this._centralPeer = _centralPeer;
|
|
@@ -1510,14 +1396,14 @@ var StarTopology = class {
|
|
|
1510
1396
|
return `StarTopology(${this._centralPeer.truncate()})`;
|
|
1511
1397
|
}
|
|
1512
1398
|
init(controller) {
|
|
1513
|
-
|
|
1399
|
+
assert8(!this._controller, "Already initialized.");
|
|
1514
1400
|
this._controller = controller;
|
|
1515
1401
|
}
|
|
1516
1402
|
update() {
|
|
1517
|
-
|
|
1403
|
+
assert8(this._controller, "Not initialized.");
|
|
1518
1404
|
const { candidates, connected, ownPeerId } = this._controller.getState();
|
|
1519
1405
|
if (!ownPeerId.equals(this._centralPeer)) {
|
|
1520
|
-
|
|
1406
|
+
log8("leaf peer dropping all connections apart from central peer.", {}, {
|
|
1521
1407
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts",
|
|
1522
1408
|
line: 33,
|
|
1523
1409
|
scope: this,
|
|
@@ -1525,7 +1411,7 @@ var StarTopology = class {
|
|
|
1525
1411
|
});
|
|
1526
1412
|
for (const peer of connected) {
|
|
1527
1413
|
if (!peer.equals(this._centralPeer)) {
|
|
1528
|
-
|
|
1414
|
+
log8("dropping connection", {
|
|
1529
1415
|
peer
|
|
1530
1416
|
}, {
|
|
1531
1417
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts",
|
|
@@ -1539,7 +1425,7 @@ var StarTopology = class {
|
|
|
1539
1425
|
}
|
|
1540
1426
|
for (const peer1 of candidates) {
|
|
1541
1427
|
if (peer1.equals(this._centralPeer) || ownPeerId.equals(this._centralPeer)) {
|
|
1542
|
-
|
|
1428
|
+
log8("connecting to peer", {
|
|
1543
1429
|
peer: peer1
|
|
1544
1430
|
}, {
|
|
1545
1431
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/topology/star-topology.ts",
|
|
@@ -1552,9 +1438,9 @@ var StarTopology = class {
|
|
|
1552
1438
|
}
|
|
1553
1439
|
}
|
|
1554
1440
|
async onOffer(peer) {
|
|
1555
|
-
|
|
1441
|
+
assert8(this._controller, "Not initialized.");
|
|
1556
1442
|
const { ownPeerId } = this._controller.getState();
|
|
1557
|
-
|
|
1443
|
+
log8("offer", {
|
|
1558
1444
|
peer,
|
|
1559
1445
|
isCentral: peer.equals(this._centralPeer),
|
|
1560
1446
|
isSelfCentral: ownPeerId.equals(this._centralPeer)
|
|
@@ -1571,13 +1457,23 @@ var StarTopology = class {
|
|
|
1571
1457
|
};
|
|
1572
1458
|
|
|
1573
1459
|
// packages/core/mesh/network-manager/src/transport/memory-transport.ts
|
|
1574
|
-
import
|
|
1460
|
+
import assert9 from "@dxos/node-std/assert";
|
|
1575
1461
|
import { Transform } from "@dxos/node-std/stream";
|
|
1576
1462
|
import { Event as Event6, Trigger } from "@dxos/async";
|
|
1577
1463
|
import { ErrorStream as ErrorStream3 } from "@dxos/debug";
|
|
1578
|
-
import { PublicKey as
|
|
1579
|
-
import { log as
|
|
1464
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1465
|
+
import { log as log9, logInfo as logInfo2 } from "@dxos/log";
|
|
1580
1466
|
import { ComplexMap as ComplexMap6 } from "@dxos/util";
|
|
1467
|
+
var __decorate4 = function(decorators, target, key, desc) {
|
|
1468
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1469
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
1470
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
1471
|
+
else
|
|
1472
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
1473
|
+
if (d = decorators[i])
|
|
1474
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1475
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1476
|
+
};
|
|
1581
1477
|
var MEMORY_TRANSPORT_DELAY = 1;
|
|
1582
1478
|
var createStreamDelay = (delay) => {
|
|
1583
1479
|
return new Transform({
|
|
@@ -1597,34 +1493,30 @@ var _MemoryTransport = class {
|
|
|
1597
1493
|
this.closed = new Event6();
|
|
1598
1494
|
this.connected = new Event6();
|
|
1599
1495
|
this.errors = new ErrorStream3();
|
|
1600
|
-
this._id = PublicKey8.random();
|
|
1601
1496
|
this._remote = new Trigger();
|
|
1602
1497
|
this._outgoingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1603
1498
|
this._incomingDelay = createStreamDelay(MEMORY_TRANSPORT_DELAY);
|
|
1604
1499
|
this._destroyed = false;
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
}, {
|
|
1500
|
+
this._instanceId = PublicKey7.random();
|
|
1501
|
+
log9("creating", {}, {
|
|
1608
1502
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1609
|
-
line:
|
|
1503
|
+
line: 64,
|
|
1610
1504
|
scope: this,
|
|
1611
1505
|
callSite: (f, a) => f(...a)
|
|
1612
1506
|
});
|
|
1613
|
-
|
|
1614
|
-
_MemoryTransport._connections.set(this.
|
|
1507
|
+
assert9(!_MemoryTransport._connections.has(this._instanceId), "Duplicate memory connection");
|
|
1508
|
+
_MemoryTransport._connections.set(this._instanceId, this);
|
|
1615
1509
|
if (this.options.initiator) {
|
|
1616
1510
|
setTimeout(async () => {
|
|
1617
|
-
|
|
1618
|
-
transportId: this._id
|
|
1619
|
-
}, {
|
|
1511
|
+
log9("sending signal", {}, {
|
|
1620
1512
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1621
|
-
line:
|
|
1513
|
+
line: 73,
|
|
1622
1514
|
scope: this,
|
|
1623
1515
|
callSite: (f, a) => f(...a)
|
|
1624
1516
|
});
|
|
1625
1517
|
void this.options.sendSignal({
|
|
1626
1518
|
payload: {
|
|
1627
|
-
transportId: this.
|
|
1519
|
+
transportId: this._instanceId.toHex()
|
|
1628
1520
|
}
|
|
1629
1521
|
});
|
|
1630
1522
|
});
|
|
@@ -1635,22 +1527,19 @@ var _MemoryTransport = class {
|
|
|
1635
1527
|
if (this._destroyed) {
|
|
1636
1528
|
return;
|
|
1637
1529
|
}
|
|
1638
|
-
this.
|
|
1639
|
-
this._remoteConnection = _MemoryTransport._connections.get(this.
|
|
1530
|
+
this._remoteInstanceId = remoteId;
|
|
1531
|
+
this._remoteConnection = _MemoryTransport._connections.get(this._remoteInstanceId);
|
|
1640
1532
|
if (!this._remoteConnection) {
|
|
1641
1533
|
this._destroyed = true;
|
|
1642
1534
|
this.closed.emit();
|
|
1643
1535
|
return;
|
|
1644
1536
|
}
|
|
1645
|
-
|
|
1537
|
+
assert9(!this._remoteConnection._remoteConnection, new Error(`Remote already connected: ${this._remoteInstanceId}`));
|
|
1646
1538
|
this._remoteConnection._remoteConnection = this;
|
|
1647
|
-
this._remoteConnection.
|
|
1648
|
-
|
|
1649
|
-
id: this._id,
|
|
1650
|
-
remote: this._remoteId
|
|
1651
|
-
}, {
|
|
1539
|
+
this._remoteConnection._remoteInstanceId = this._instanceId;
|
|
1540
|
+
log9("connected", {}, {
|
|
1652
1541
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1653
|
-
line:
|
|
1542
|
+
line: 102,
|
|
1654
1543
|
scope: this,
|
|
1655
1544
|
callSite: (f, a) => f(...a)
|
|
1656
1545
|
});
|
|
@@ -1666,80 +1555,77 @@ var _MemoryTransport = class {
|
|
|
1666
1555
|
}
|
|
1667
1556
|
}
|
|
1668
1557
|
async destroy() {
|
|
1669
|
-
|
|
1670
|
-
id: this._id
|
|
1671
|
-
}, {
|
|
1558
|
+
log9("closing", {}, {
|
|
1672
1559
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1673
|
-
line:
|
|
1560
|
+
line: 123,
|
|
1674
1561
|
scope: this,
|
|
1675
1562
|
callSite: (f, a) => f(...a)
|
|
1676
1563
|
});
|
|
1677
1564
|
this._destroyed = true;
|
|
1678
|
-
_MemoryTransport._connections.delete(this.
|
|
1565
|
+
_MemoryTransport._connections.delete(this._instanceId);
|
|
1679
1566
|
if (this._remoteConnection) {
|
|
1680
|
-
|
|
1681
|
-
id: this._remoteId
|
|
1682
|
-
}, {
|
|
1567
|
+
log9("closing", {}, {
|
|
1683
1568
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1684
|
-
line:
|
|
1569
|
+
line: 128,
|
|
1685
1570
|
scope: this,
|
|
1686
1571
|
callSite: (f, a) => f(...a)
|
|
1687
1572
|
});
|
|
1688
1573
|
this._remoteConnection._destroyed = true;
|
|
1689
|
-
_MemoryTransport._connections.delete(this.
|
|
1574
|
+
_MemoryTransport._connections.delete(this._remoteInstanceId);
|
|
1690
1575
|
this._outgoingDelay.unpipe();
|
|
1691
1576
|
this._incomingDelay.unpipe();
|
|
1692
1577
|
this._remoteConnection.closed.emit();
|
|
1693
1578
|
this._remoteConnection._remoteConnection = void 0;
|
|
1694
1579
|
this._remoteConnection = void 0;
|
|
1695
|
-
|
|
1696
|
-
id: this._remoteId
|
|
1697
|
-
}, {
|
|
1580
|
+
log9("closed", {}, {
|
|
1698
1581
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1699
|
-
line:
|
|
1582
|
+
line: 146,
|
|
1700
1583
|
scope: this,
|
|
1701
1584
|
callSite: (f, a) => f(...a)
|
|
1702
1585
|
});
|
|
1703
1586
|
}
|
|
1704
1587
|
this.closed.emit();
|
|
1705
|
-
|
|
1706
|
-
id: this._id
|
|
1707
|
-
}, {
|
|
1588
|
+
log9("closed", {}, {
|
|
1708
1589
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1709
|
-
line:
|
|
1590
|
+
line: 150,
|
|
1710
1591
|
scope: this,
|
|
1711
1592
|
callSite: (f, a) => f(...a)
|
|
1712
1593
|
});
|
|
1713
1594
|
}
|
|
1714
|
-
signal(
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
}
|
|
1595
|
+
signal({ payload }) {
|
|
1596
|
+
log9("received signal", {
|
|
1597
|
+
payload
|
|
1598
|
+
}, {
|
|
1599
|
+
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/memory-transport.ts",
|
|
1600
|
+
line: 154,
|
|
1601
|
+
scope: this,
|
|
1602
|
+
callSite: (f, a) => f(...a)
|
|
1603
|
+
});
|
|
1604
|
+
if (!(payload == null ? void 0 : payload.transportId)) {
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
const transportId = payload.transportId;
|
|
1608
|
+
if (transportId) {
|
|
1609
|
+
const remoteId = PublicKey7.fromHex(transportId);
|
|
1610
|
+
this._remote.wake(remoteId);
|
|
1731
1611
|
}
|
|
1732
1612
|
}
|
|
1733
1613
|
};
|
|
1734
1614
|
var MemoryTransport = _MemoryTransport;
|
|
1735
|
-
MemoryTransport._connections = new ComplexMap6(
|
|
1615
|
+
MemoryTransport._connections = new ComplexMap6(PublicKey7.hash);
|
|
1616
|
+
__decorate4([
|
|
1617
|
+
logInfo2
|
|
1618
|
+
], MemoryTransport.prototype, "_instanceId", void 0);
|
|
1619
|
+
__decorate4([
|
|
1620
|
+
logInfo2
|
|
1621
|
+
], MemoryTransport.prototype, "_remoteInstanceId", void 0);
|
|
1736
1622
|
|
|
1737
1623
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport.ts
|
|
1738
|
-
import
|
|
1624
|
+
import assert10 from "@dxos/node-std/assert";
|
|
1739
1625
|
import SimplePeerConstructor from "simple-peer";
|
|
1740
1626
|
import { Event as Event7 } from "@dxos/async";
|
|
1741
1627
|
import { ErrorStream as ErrorStream4, raise as raise2 } from "@dxos/debug";
|
|
1742
|
-
import { log as
|
|
1628
|
+
import { log as log10 } from "@dxos/log";
|
|
1743
1629
|
|
|
1744
1630
|
// packages/core/mesh/network-manager/src/transport/webrtc.ts
|
|
1745
1631
|
var wrtc = null;
|
|
@@ -1756,7 +1642,7 @@ var WebRTCTransport = class {
|
|
|
1756
1642
|
this.closed = new Event7();
|
|
1757
1643
|
this.connected = new Event7();
|
|
1758
1644
|
this.errors = new ErrorStream4();
|
|
1759
|
-
|
|
1645
|
+
log10("created connection", params, {
|
|
1760
1646
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1761
1647
|
line: 34,
|
|
1762
1648
|
scope: this,
|
|
@@ -1768,7 +1654,7 @@ var WebRTCTransport = class {
|
|
|
1768
1654
|
config: this.params.webrtcConfig
|
|
1769
1655
|
});
|
|
1770
1656
|
this._peer.on("signal", async (data) => {
|
|
1771
|
-
|
|
1657
|
+
log10("signal", data, {
|
|
1772
1658
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1773
1659
|
line: 42,
|
|
1774
1660
|
scope: this,
|
|
@@ -1781,7 +1667,7 @@ var WebRTCTransport = class {
|
|
|
1781
1667
|
});
|
|
1782
1668
|
});
|
|
1783
1669
|
this._peer.on("connect", () => {
|
|
1784
|
-
|
|
1670
|
+
log10("connected", {}, {
|
|
1785
1671
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1786
1672
|
line: 47,
|
|
1787
1673
|
scope: this,
|
|
@@ -1791,7 +1677,7 @@ var WebRTCTransport = class {
|
|
|
1791
1677
|
this.connected.emit();
|
|
1792
1678
|
});
|
|
1793
1679
|
this._peer.on("close", async () => {
|
|
1794
|
-
|
|
1680
|
+
log10("closed", {}, {
|
|
1795
1681
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1796
1682
|
line: 53,
|
|
1797
1683
|
scope: this,
|
|
@@ -1806,7 +1692,7 @@ var WebRTCTransport = class {
|
|
|
1806
1692
|
});
|
|
1807
1693
|
}
|
|
1808
1694
|
async destroy() {
|
|
1809
|
-
|
|
1695
|
+
log10("closing...", {}, {
|
|
1810
1696
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1811
1697
|
line: 65,
|
|
1812
1698
|
scope: this,
|
|
@@ -1815,7 +1701,7 @@ var WebRTCTransport = class {
|
|
|
1815
1701
|
await this._disconnectStreams();
|
|
1816
1702
|
this._peer.destroy();
|
|
1817
1703
|
this.closed.emit();
|
|
1818
|
-
|
|
1704
|
+
log10("closed", {}, {
|
|
1819
1705
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport.ts",
|
|
1820
1706
|
line: 69,
|
|
1821
1707
|
scope: this,
|
|
@@ -1823,8 +1709,8 @@ var WebRTCTransport = class {
|
|
|
1823
1709
|
});
|
|
1824
1710
|
}
|
|
1825
1711
|
signal(signal) {
|
|
1826
|
-
|
|
1827
|
-
|
|
1712
|
+
assert10(this._peer, "Connection not ready to accept signals.");
|
|
1713
|
+
assert10(signal.payload.data, "Signal message must contain signal data.");
|
|
1828
1714
|
this._peer.signal(signal.payload.data);
|
|
1829
1715
|
}
|
|
1830
1716
|
async _disconnectStreams() {
|
|
@@ -1840,17 +1726,17 @@ var createWebRTCTransportFactory = (webrtcConfig) => ({
|
|
|
1840
1726
|
});
|
|
1841
1727
|
|
|
1842
1728
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts
|
|
1843
|
-
import
|
|
1729
|
+
import assert11 from "@dxos/node-std/assert";
|
|
1844
1730
|
import { Duplex } from "@dxos/node-std/stream";
|
|
1845
1731
|
import { Stream } from "@dxos/codec-protobuf";
|
|
1846
|
-
import { PublicKey as
|
|
1847
|
-
import { log as
|
|
1732
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
1733
|
+
import { log as log11 } from "@dxos/log";
|
|
1848
1734
|
import { ConnectionState as ConnectionState2 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
1849
1735
|
import { ComplexMap as ComplexMap7 } from "@dxos/util";
|
|
1850
1736
|
var WebRTCTransportService = class {
|
|
1851
1737
|
constructor(_webrtcConfig) {
|
|
1852
1738
|
this._webrtcConfig = _webrtcConfig;
|
|
1853
|
-
this.transports = new ComplexMap7(
|
|
1739
|
+
this.transports = new ComplexMap7(PublicKey8.hash);
|
|
1854
1740
|
}
|
|
1855
1741
|
open(request) {
|
|
1856
1742
|
const rpcStream = new Stream(({ ready, next, close }) => {
|
|
@@ -1915,11 +1801,11 @@ var WebRTCTransportService = class {
|
|
|
1915
1801
|
return rpcStream;
|
|
1916
1802
|
}
|
|
1917
1803
|
async sendSignal({ proxyId, signal }) {
|
|
1918
|
-
|
|
1804
|
+
assert11(this.transports.has(proxyId));
|
|
1919
1805
|
await this.transports.get(proxyId).transport.signal(signal);
|
|
1920
1806
|
}
|
|
1921
1807
|
async sendData({ proxyId, payload }) {
|
|
1922
|
-
|
|
1808
|
+
assert11(this.transports.has(proxyId));
|
|
1923
1809
|
await this.transports.get(proxyId).stream.push(payload);
|
|
1924
1810
|
}
|
|
1925
1811
|
async close({ proxyId }) {
|
|
@@ -1927,7 +1813,7 @@ var WebRTCTransportService = class {
|
|
|
1927
1813
|
await ((_a = this.transports.get(proxyId)) == null ? void 0 : _a.transport.destroy());
|
|
1928
1814
|
await ((_b = this.transports.get(proxyId)) == null ? void 0 : _b.stream.end());
|
|
1929
1815
|
this.transports.delete(proxyId);
|
|
1930
|
-
|
|
1816
|
+
log11("Closed.", {}, {
|
|
1931
1817
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-service.ts",
|
|
1932
1818
|
line: 108,
|
|
1933
1819
|
scope: this,
|
|
@@ -1937,11 +1823,11 @@ var WebRTCTransportService = class {
|
|
|
1937
1823
|
};
|
|
1938
1824
|
|
|
1939
1825
|
// packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts
|
|
1940
|
-
import
|
|
1826
|
+
import assert12 from "@dxos/node-std/assert";
|
|
1941
1827
|
import { Event as Event8 } from "@dxos/async";
|
|
1942
1828
|
import { ErrorStream as ErrorStream5 } from "@dxos/debug";
|
|
1943
|
-
import { PublicKey as
|
|
1944
|
-
import { log as
|
|
1829
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
1830
|
+
import { log as log12 } from "@dxos/log";
|
|
1945
1831
|
import { ConnectionState as ConnectionState3 } from "@dxos/protocols/proto/dxos/mesh/bridge";
|
|
1946
1832
|
var WebRTCTransportProxy = class {
|
|
1947
1833
|
constructor(_params) {
|
|
@@ -1950,14 +1836,14 @@ var WebRTCTransportProxy = class {
|
|
|
1950
1836
|
this._closed = false;
|
|
1951
1837
|
this.connected = new Event8();
|
|
1952
1838
|
this.errors = new ErrorStream5();
|
|
1953
|
-
this._proxyId =
|
|
1839
|
+
this._proxyId = PublicKey9.random();
|
|
1954
1840
|
this._serviceStream = this._params.bridgeService.open({
|
|
1955
1841
|
proxyId: this._proxyId,
|
|
1956
1842
|
initiator: this._params.initiator
|
|
1957
1843
|
});
|
|
1958
1844
|
this._serviceStream.waitUntilReady().then(() => {
|
|
1959
1845
|
this._serviceStream.subscribe(async (event) => {
|
|
1960
|
-
|
|
1846
|
+
log12("WebRTCTransportProxy: event", event, {
|
|
1961
1847
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
|
|
1962
1848
|
line: 46,
|
|
1963
1849
|
scope: this,
|
|
@@ -1978,7 +1864,7 @@ var WebRTCTransportProxy = class {
|
|
|
1978
1864
|
payload: data
|
|
1979
1865
|
});
|
|
1980
1866
|
} catch (err) {
|
|
1981
|
-
|
|
1867
|
+
log12.catch(err, {}, {
|
|
1982
1868
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
|
|
1983
1869
|
line: 63,
|
|
1984
1870
|
scope: this,
|
|
@@ -1986,7 +1872,7 @@ var WebRTCTransportProxy = class {
|
|
|
1986
1872
|
});
|
|
1987
1873
|
}
|
|
1988
1874
|
});
|
|
1989
|
-
}, (error) =>
|
|
1875
|
+
}, (error) => log12.catch(error, {}, {
|
|
1990
1876
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
|
|
1991
1877
|
line: 67,
|
|
1992
1878
|
scope: this,
|
|
@@ -2030,7 +1916,7 @@ var WebRTCTransportProxy = class {
|
|
|
2030
1916
|
proxyId: this._proxyId
|
|
2031
1917
|
});
|
|
2032
1918
|
} catch (err) {
|
|
2033
|
-
|
|
1919
|
+
log12.catch(err, {}, {
|
|
2034
1920
|
file: "/home/runner/work/dxos/dxos/packages/core/mesh/network-manager/src/transport/webrtc-transport-proxy.ts",
|
|
2035
1921
|
line: 117,
|
|
2036
1922
|
scope: this,
|
|
@@ -2058,7 +1944,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2058
1944
|
return this;
|
|
2059
1945
|
}
|
|
2060
1946
|
createTransport(options) {
|
|
2061
|
-
|
|
1947
|
+
assert12(this._bridgeService, "WebRTCTransportProxyFactory is not ready to open connections");
|
|
2062
1948
|
const transport = new WebRTCTransportProxy({
|
|
2063
1949
|
...options,
|
|
2064
1950
|
bridgeService: this._bridgeService
|
|
@@ -2070,20 +1956,7 @@ var WebRTCTransportProxyFactory = class {
|
|
|
2070
1956
|
};
|
|
2071
1957
|
|
|
2072
1958
|
// packages/core/mesh/network-manager/src/wire-protocol.ts
|
|
2073
|
-
import { discoveryKey as discoveryKey2 } from "@dxos/crypto";
|
|
2074
1959
|
import { Teleport } from "@dxos/teleport";
|
|
2075
|
-
var adaptProtocolProvider = (factory) => ({ initiator, localPeerId, remotePeerId, topic }) => {
|
|
2076
|
-
const protocol = factory({
|
|
2077
|
-
channel: discoveryKey2(topic),
|
|
2078
|
-
initiator
|
|
2079
|
-
});
|
|
2080
|
-
return {
|
|
2081
|
-
initialize: () => protocol.open(),
|
|
2082
|
-
destroy: () => protocol.close(),
|
|
2083
|
-
stream: protocol.stream,
|
|
2084
|
-
protocol
|
|
2085
|
-
};
|
|
2086
|
-
};
|
|
2087
1960
|
var createTeleportProtocolFactory = (onConnection) => {
|
|
2088
1961
|
return (params) => {
|
|
2089
1962
|
const teleport = new Teleport(params);
|
|
@@ -2117,11 +1990,6 @@ export {
|
|
|
2117
1990
|
WebRTCTransportProxy,
|
|
2118
1991
|
WebRTCTransportProxyFactory,
|
|
2119
1992
|
WebRTCTransportService,
|
|
2120
|
-
adaptProtocolProvider,
|
|
2121
|
-
createProtocolFactory,
|
|
2122
1993
|
createTeleportProtocolFactory,
|
|
2123
|
-
createWebRTCTransportFactory
|
|
2124
|
-
protocolFactory,
|
|
2125
|
-
transportProtocolProvider
|
|
1994
|
+
createWebRTCTransportFactory
|
|
2126
1995
|
};
|
|
2127
|
-
//# sourceMappingURL=index.mjs.map
|