@dxos/network-manager 0.1.4 → 0.1.6
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/LICENSE +5 -18
- package/README.md +22 -0
- package/dist/src/network-manager.d.ts +2 -1
- package/dist/src/network-manager.d.ts.map +1 -1
- package/dist/src/network-manager.js +8 -8
- package/dist/src/network-manager.js.map +1 -1
- package/dist/src/network-manager.test.js +47 -69
- package/dist/src/network-manager.test.js.map +1 -1
- package/dist/src/protocol-factory.js +1 -1
- package/dist/src/protocol-factory.js.map +1 -1
- package/dist/src/swarm/swarm.test.js +46 -56
- package/dist/src/swarm/swarm.test.js.map +1 -1
- package/dist/src/testing/index.d.ts +1 -0
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -0
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/test-builder.d.ts +32 -0
- package/dist/src/testing/test-builder.d.ts.map +1 -0
- package/dist/src/testing/test-builder.js +73 -0
- package/dist/src/testing/test-builder.js.map +1 -0
- package/dist/src/testing/test-protocol.d.ts +3 -10
- package/dist/src/testing/test-protocol.d.ts.map +1 -1
- package/dist/src/testing/test-protocol.js +15 -16
- package/dist/src/testing/test-protocol.js.map +1 -1
- package/dist/src/transport/memory-transport.test.js +3 -3
- package/dist/src/transport/memory-transport.test.js.map +1 -1
- package/dist/src/transport/webrtc-transport-proxy.test.js +4 -4
- package/dist/src/transport/webrtc-transport-proxy.test.js.map +1 -1
- package/dist/src/transport/webrtc-transport.d.ts +0 -2
- package/dist/src/transport/webrtc-transport.d.ts.map +1 -1
- package/dist/src/transport/webrtc-transport.js +2 -5
- package/dist/src/transport/webrtc-transport.js.map +1 -1
- package/dist/src/transport/webrtc-transport.test.js +2 -2
- package/dist/src/transport/webrtc-transport.test.js.map +1 -1
- package/package.json +16 -16
- package/src/network-manager.test.ts +27 -81
- package/src/network-manager.ts +4 -3
- package/src/protocol-factory.ts +1 -1
- package/src/swarm/swarm.test.ts +54 -76
- package/src/testing/index.ts +1 -0
- package/src/testing/test-builder.ts +99 -0
- package/src/testing/test-protocol.ts +14 -16
- package/src/transport/memory-transport.test.ts +3 -3
- package/src/transport/webrtc-transport-proxy.test.ts +4 -4
- package/src/transport/webrtc-transport.test.ts +2 -2
- package/src/transport/webrtc-transport.ts +0 -4
|
@@ -47,15 +47,12 @@ class WebRTCTransport {
|
|
|
47
47
|
await this.close();
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
-
get peer() {
|
|
51
|
-
return this._peer;
|
|
52
|
-
}
|
|
53
50
|
async close() {
|
|
54
|
-
(0, log_1.log)('closing...', {}, { file: "packages/core/mesh/network-manager/src/transport/webrtc-transport.ts", line:
|
|
51
|
+
(0, log_1.log)('closing...', {}, { file: "packages/core/mesh/network-manager/src/transport/webrtc-transport.ts", line: 65 });
|
|
55
52
|
await this._disconnectStreams();
|
|
56
53
|
this._peer.destroy();
|
|
57
54
|
this.closed.emit();
|
|
58
|
-
(0, log_1.log)('closed', {}, { file: "packages/core/mesh/network-manager/src/transport/webrtc-transport.ts", line:
|
|
55
|
+
(0, log_1.log)('closed', {}, { file: "packages/core/mesh/network-manager/src/transport/webrtc-transport.ts", line: 69 });
|
|
59
56
|
}
|
|
60
57
|
async signal(signal) {
|
|
61
58
|
(0, node_assert_1.default)(this._peer, 'Connection not ready to accept signals.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webrtc-transport.js","sourceRoot":"","sources":["../../../src/transport/webrtc-transport.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,8DAAiC;AACjC,8DAA4E;AAE5E,uCAAoC;AACpC,uCAAiD;AACjD,mCAAgC;AAIhC,qCAAgC;AAShC;;GAEG;AACH,MAAa,eAAe;IAO1B,YAA6B,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;QAJjD,WAAM,GAAG,IAAI,aAAK,EAAE,CAAC;QACrB,cAAS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B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc;QACzB,IAAA,qBAAM,EAAC,IAAI,CAAC,KAAK,EAAE,yCAAyC,CAAC,CAAC;QAC9D,IAAA,qBAAM,EAAC,MAAM,CAAC,IAAI,EAAE,0CAA0C,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7C,CAAC;IAEO,KAAK,CAAC,kBAAkB;;QAC9B,4CAA4C;QAC5C,MAAA,MAAA,MAAA,MAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAC,MAAM,mDAAG,IAAI,CAAC,KAAK,CAAC,0CAAE,MAAM,mDAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxE,CAAC;CACF;AAxDD,0CAwDC;AAED,sCAAsC;AAC/B,MAAM,4BAA4B,GAAG,CAAC,YAAkB,EAAoB,EAAE,CAAC,CAAC;IACrF,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CACjB,IAAI,eAAe,CAAC;QAClB,GAAG,MAAM;QACT,YAAY;KACb,CAAC;CACL,CAAC,CAAC;AANU,QAAA,4BAA4B,gCAMtC"}
|
|
@@ -41,7 +41,7 @@ describe('WebRTCTransport', function () {
|
|
|
41
41
|
const peer1Id = keys_1.PublicKey.random();
|
|
42
42
|
const peer2Id = keys_1.PublicKey.random();
|
|
43
43
|
const plugin1 = new testing_1.TestProtocolPlugin(peer1Id.asBuffer());
|
|
44
|
-
const protocolProvider1 = (0, testing_1.testProtocolProvider)(topic.asBuffer(), peer1Id
|
|
44
|
+
const protocolProvider1 = (0, testing_1.testProtocolProvider)(topic.asBuffer(), peer1Id, plugin1);
|
|
45
45
|
const connection1 = new webrtc_transport_1.WebRTCTransport({
|
|
46
46
|
initiator: true,
|
|
47
47
|
stream: protocolProvider1({
|
|
@@ -56,7 +56,7 @@ describe('WebRTCTransport', function () {
|
|
|
56
56
|
(0, testutils_1.afterTest)(() => connection1.close());
|
|
57
57
|
(0, testutils_1.afterTest)(() => connection1.errors.assertNoUnhandledErrors());
|
|
58
58
|
const plugin2 = new testing_1.TestProtocolPlugin(peer2Id.asBuffer());
|
|
59
|
-
const protocolProvider2 = (0, testing_1.testProtocolProvider)(topic.asBuffer(), peer2Id
|
|
59
|
+
const protocolProvider2 = (0, testing_1.testProtocolProvider)(topic.asBuffer(), peer2Id, plugin2);
|
|
60
60
|
const connection2 = new webrtc_transport_1.WebRTCTransport({
|
|
61
61
|
initiator: false,
|
|
62
62
|
stream: protocolProvider2({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webrtc-transport.test.js","sourceRoot":"","sources":["../../../src/transport/webrtc-transport.test.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;AAEF,oDAA4B;AAC5B,mCAAgC;AAChC,sEAA4C;AAE5C,uCAAoC;AACpC,yCAA4C;AAC5C,qCAAuC;AACvC,uDAA+C;AAC/C,+CAA4C;AAE5C,wCAAsE;AACtE,yDAAqD;AAErD,QAAQ,CAAC,iBAAiB,EAAE;IAC1B,sHAAsH;IACtH,EAAE,CAAC,gBAAgB,EAAE,KAAK;QACxB,MAAM,UAAU,GAAG,IAAI,kCAAe,CAAC;YACrC,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,IAAI,eAAM,EAAE;YACpB,UAAU,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;SAC3B,CAAC,CAAC;QAEH,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,MAAM,QAAQ,GAAG,GAAG,EAAE;YACpB,YAAY,EAAE,CAAC;QACjB,CAAC,CAAC;QACF,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEjC,MAAM,IAAA,aAAK,EAAC,EAAE,CAAC,CAAC,CAAC,kCAAkC;QACnD,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;QAEzB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AAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,sBAAsB,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;QAEH,MAAM,IAAA,yBAAa,EAAC,GAAG,EAAE;YACvB,IAAA,gBAAM,EAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAChC,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,wBAAQ,CAAC,CAAC;YAC7C,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;SACC,OAAO,CAAC,IAAK,CAAC;SACd,OAAO,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/network-manager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Network Manager",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@dxos/async": "0.1.
|
|
21
|
-
"@dxos/codec-protobuf": "0.1.
|
|
22
|
-
"@dxos/credentials": "0.1.
|
|
23
|
-
"@dxos/crypto": "0.1.
|
|
24
|
-
"@dxos/debug": "0.1.
|
|
25
|
-
"@dxos/keys": "0.1.
|
|
26
|
-
"@dxos/log": "0.1.
|
|
27
|
-
"@dxos/mesh-protocol": "0.1.
|
|
28
|
-
"@dxos/messaging": "0.1.
|
|
29
|
-
"@dxos/protocol-plugin-presence": "0.1.
|
|
30
|
-
"@dxos/protocols": "0.1.
|
|
31
|
-
"@dxos/rpc": "0.1.
|
|
32
|
-
"@dxos/util": "0.1.
|
|
20
|
+
"@dxos/async": "0.1.6",
|
|
21
|
+
"@dxos/codec-protobuf": "0.1.6",
|
|
22
|
+
"@dxos/credentials": "0.1.6",
|
|
23
|
+
"@dxos/crypto": "0.1.6",
|
|
24
|
+
"@dxos/debug": "0.1.6",
|
|
25
|
+
"@dxos/keys": "0.1.6",
|
|
26
|
+
"@dxos/log": "0.1.6",
|
|
27
|
+
"@dxos/mesh-protocol": "0.1.6",
|
|
28
|
+
"@dxos/messaging": "0.1.6",
|
|
29
|
+
"@dxos/protocol-plugin-presence": "0.1.6",
|
|
30
|
+
"@dxos/protocols": "0.1.6",
|
|
31
|
+
"@dxos/rpc": "0.1.6",
|
|
32
|
+
"@dxos/util": "0.1.6",
|
|
33
33
|
"@koush/wrtc": "^0.5.3",
|
|
34
34
|
"assert": "^2.0.0",
|
|
35
35
|
"isomorphic-ws": "^4.0.1",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"xor-distance": "^2.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@dxos/signal": "0.1.
|
|
43
|
-
"@dxos/testutils": "0.1.
|
|
42
|
+
"@dxos/signal": "0.1.6",
|
|
43
|
+
"@dxos/testutils": "0.1.6",
|
|
44
44
|
"@swc-node/register": "^1.5.4",
|
|
45
45
|
"@swc/core": "^1.3.9",
|
|
46
46
|
"@types/simple-peer": "9.11.3",
|
|
@@ -11,7 +11,6 @@ import { Event, latch, sleep } from '@dxos/async';
|
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { Protocol } from '@dxos/mesh-protocol';
|
|
14
|
-
import { MemorySignalManagerContext, MemorySignalManager, WebsocketSignalManager } from '@dxos/messaging';
|
|
15
14
|
import { PresencePlugin } from '@dxos/protocol-plugin-presence';
|
|
16
15
|
import { schema } from '@dxos/protocols';
|
|
17
16
|
import { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
@@ -21,8 +20,8 @@ import { range, ComplexMap, ComplexSet } from '@dxos/util';
|
|
|
21
20
|
|
|
22
21
|
import { NetworkManager } from './network-manager';
|
|
23
22
|
import { createProtocolFactory } from './protocol-factory';
|
|
24
|
-
import { TestProtocolPlugin, testProtocolProvider } from './testing';
|
|
25
|
-
import { FullyConnectedTopology, StarTopology
|
|
23
|
+
import { createPeer, TEST_SIGNAL_URL, TestBuilder, TestProtocolPlugin, testProtocolProvider } from './testing';
|
|
24
|
+
import { FullyConnectedTopology, StarTopology } from './topology';
|
|
26
25
|
import {
|
|
27
26
|
createWebRTCTransportFactory,
|
|
28
27
|
MemoryTransportFactory,
|
|
@@ -31,67 +30,6 @@ import {
|
|
|
31
30
|
WebRTCTransportService
|
|
32
31
|
} from './transport';
|
|
33
32
|
|
|
34
|
-
// Signal server will be started by the setup script.
|
|
35
|
-
const SIGNAL_URL = 'ws://localhost:4000/.well-known/dx/signal';
|
|
36
|
-
|
|
37
|
-
// TODO(burdon): Remove global and replace with factories.
|
|
38
|
-
const signalContext = new MemorySignalManagerContext();
|
|
39
|
-
|
|
40
|
-
// const createMemoryNetworkManager = (signalContext: MemorySignalManagerContext) => {
|
|
41
|
-
// return new NetworkManager({
|
|
42
|
-
// signalManager: new MemorySignalManager(signalContext),
|
|
43
|
-
// transportFactory: MemoryTransportFactory
|
|
44
|
-
// });
|
|
45
|
-
// };
|
|
46
|
-
|
|
47
|
-
// const createWebRTCNetworkManager = async (config: any, peerId: PublicKey) => {
|
|
48
|
-
// const signalManager = new WebsocketSignalManager(signalHosts!);
|
|
49
|
-
// await signalManager.subscribeMessages(peerId);
|
|
50
|
-
//
|
|
51
|
-
// return new NetworkManager({
|
|
52
|
-
// signalManager,
|
|
53
|
-
// transportFactory: createWebRTCTransportFactory(config)
|
|
54
|
-
// });
|
|
55
|
-
// };
|
|
56
|
-
|
|
57
|
-
interface CreatePeerOptions {
|
|
58
|
-
topic: PublicKey;
|
|
59
|
-
peerId: PublicKey;
|
|
60
|
-
topology?: Topology;
|
|
61
|
-
signalHosts?: string[];
|
|
62
|
-
transportFactory: TransportFactory;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @deprecated
|
|
67
|
-
*/
|
|
68
|
-
// TODO(burdon): Builder pattern.
|
|
69
|
-
const createPeer = async ({
|
|
70
|
-
topic,
|
|
71
|
-
peerId,
|
|
72
|
-
topology = new FullyConnectedTopology(),
|
|
73
|
-
signalHosts,
|
|
74
|
-
transportFactory
|
|
75
|
-
}: CreatePeerOptions) => {
|
|
76
|
-
const signalManager = signalHosts ? new WebsocketSignalManager(signalHosts!) : new MemorySignalManager(signalContext);
|
|
77
|
-
await signalManager.subscribeMessages(peerId);
|
|
78
|
-
const networkManager = new NetworkManager({
|
|
79
|
-
signalManager,
|
|
80
|
-
transportFactory
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
afterTest(() => networkManager.destroy());
|
|
84
|
-
|
|
85
|
-
const plugin = new TestProtocolPlugin(peerId.asBuffer());
|
|
86
|
-
const protocolProvider = testProtocolProvider(topic.asBuffer(), peerId.asBuffer(), plugin);
|
|
87
|
-
await networkManager.openSwarmConnection({ topic, peerId, protocol: protocolProvider, topology });
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
networkManager,
|
|
91
|
-
plugin
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
|
|
95
33
|
describe('NetworkManager', function () {
|
|
96
34
|
describe('WebRTC transport', function () {
|
|
97
35
|
let topic: PublicKey;
|
|
@@ -106,7 +44,7 @@ describe('NetworkManager', function () {
|
|
|
106
44
|
|
|
107
45
|
sharedTests({
|
|
108
46
|
inMemory: false,
|
|
109
|
-
signalUrl:
|
|
47
|
+
signalUrl: TEST_SIGNAL_URL,
|
|
110
48
|
getTransportFactory: async () => createWebRTCTransportFactory()
|
|
111
49
|
});
|
|
112
50
|
|
|
@@ -235,7 +173,7 @@ describe('NetworkManager', function () {
|
|
|
235
173
|
|
|
236
174
|
sharedTests({
|
|
237
175
|
inMemory: false,
|
|
238
|
-
signalUrl:
|
|
176
|
+
signalUrl: TEST_SIGNAL_URL,
|
|
239
177
|
getTransportFactory: createTransportFactory
|
|
240
178
|
});
|
|
241
179
|
});
|
|
@@ -291,9 +229,12 @@ describe('NetworkManager', function () {
|
|
|
291
229
|
);
|
|
292
230
|
});
|
|
293
231
|
|
|
232
|
+
// TODO(burdon): Remove flaky tests.
|
|
294
233
|
// This test performs random actions in the real system and compares it's state with a simplified model.
|
|
295
234
|
// TODO(dmaretskyi): Run this on with actual webrtc and signal servers.
|
|
296
|
-
it('property-based tests', async function () {
|
|
235
|
+
it.skip('property-based tests', async function () {
|
|
236
|
+
const testBuilder = new TestBuilder();
|
|
237
|
+
|
|
297
238
|
/**
|
|
298
239
|
* The simplified model of the system.
|
|
299
240
|
*/
|
|
@@ -345,6 +286,8 @@ describe('NetworkManager', function () {
|
|
|
345
286
|
);
|
|
346
287
|
};
|
|
347
288
|
|
|
289
|
+
// TODO(burdon): Factor out to TestBuilder.
|
|
290
|
+
|
|
348
291
|
class CreatePeerCommand implements fc.AsyncCommand<Model, Real> {
|
|
349
292
|
constructor(readonly peerId: PublicKey) {}
|
|
350
293
|
|
|
@@ -352,10 +295,7 @@ describe('NetworkManager', function () {
|
|
|
352
295
|
async run(model: Model, real: Real) {
|
|
353
296
|
model.peers.add(this.peerId);
|
|
354
297
|
|
|
355
|
-
const networkManager =
|
|
356
|
-
signalManager: new MemorySignalManager(signalContext),
|
|
357
|
-
transportFactory: MemoryTransportFactory
|
|
358
|
-
});
|
|
298
|
+
const networkManager = testBuilder.createNetworkManager();
|
|
359
299
|
afterTest(() => networkManager.destroy());
|
|
360
300
|
|
|
361
301
|
real.peers.set(this.peerId, {
|
|
@@ -501,6 +441,7 @@ describe('NetworkManager', function () {
|
|
|
501
441
|
}).timeout(30_000);
|
|
502
442
|
});
|
|
503
443
|
|
|
444
|
+
// TODO(burdon): Factor out test-suite.
|
|
504
445
|
function sharedTests({
|
|
505
446
|
inMemory,
|
|
506
447
|
signalUrl,
|
|
@@ -631,7 +572,7 @@ function sharedTests({
|
|
|
631
572
|
await networkManager2.openSwarmConnection({
|
|
632
573
|
topic,
|
|
633
574
|
peerId: newPeer2Id,
|
|
634
|
-
protocol: testProtocolProvider(topic.asBuffer(), peer2Id
|
|
575
|
+
protocol: testProtocolProvider(topic.asBuffer(), peer2Id, plugin2),
|
|
635
576
|
topology: new FullyConnectedTopology()
|
|
636
577
|
});
|
|
637
578
|
|
|
@@ -646,28 +587,28 @@ function sharedTests({
|
|
|
646
587
|
.timeout(10_000)
|
|
647
588
|
.retries(10);
|
|
648
589
|
|
|
649
|
-
it('join
|
|
590
|
+
it.skip('join two swarms', async function () {
|
|
591
|
+
const testBuilder = new TestBuilder({ signalUrl: !inMemory ? signalUrl : undefined });
|
|
592
|
+
|
|
650
593
|
const peerId = PublicKey.random();
|
|
651
594
|
const plugin1 = new TestProtocolPlugin(peerId.asBuffer());
|
|
652
595
|
const plugin2 = new TestProtocolPlugin(peerId.asBuffer());
|
|
653
596
|
|
|
654
|
-
const signalManager =
|
|
655
|
-
const networkManager = new NetworkManager({
|
|
656
|
-
signalManager,
|
|
657
|
-
transportFactory: await getTransportFactory()
|
|
658
|
-
});
|
|
597
|
+
const signalManager = testBuilder.createSignalManager();
|
|
598
|
+
const networkManager = new NetworkManager({ signalManager, transportFactory: await getTransportFactory() });
|
|
659
599
|
afterTest(() => networkManager.destroy());
|
|
660
600
|
|
|
661
601
|
// Joining first swarm.
|
|
662
602
|
{
|
|
663
603
|
const topic = PublicKey.random();
|
|
664
|
-
const protocolProvider = testProtocolProvider(topic.asBuffer(), peerId
|
|
604
|
+
const protocolProvider = testProtocolProvider(topic.asBuffer(), peerId, plugin1);
|
|
665
605
|
await networkManager.openSwarmConnection({
|
|
666
606
|
topic,
|
|
667
607
|
peerId,
|
|
668
608
|
protocol: protocolProvider,
|
|
669
609
|
topology: new FullyConnectedTopology()
|
|
670
610
|
});
|
|
611
|
+
|
|
671
612
|
// Creating and joining second peer.
|
|
672
613
|
await createPeer({
|
|
673
614
|
topic,
|
|
@@ -680,13 +621,14 @@ function sharedTests({
|
|
|
680
621
|
// Joining second swarm with same peerId.
|
|
681
622
|
{
|
|
682
623
|
const topic = PublicKey.random();
|
|
683
|
-
const protocolProvider = testProtocolProvider(topic.asBuffer(), peerId
|
|
624
|
+
const protocolProvider = testProtocolProvider(topic.asBuffer(), peerId, plugin2);
|
|
684
625
|
await networkManager.openSwarmConnection({
|
|
685
626
|
topic,
|
|
686
627
|
peerId,
|
|
687
628
|
protocol: protocolProvider,
|
|
688
629
|
topology: new FullyConnectedTopology()
|
|
689
630
|
});
|
|
631
|
+
|
|
690
632
|
// Creating and joining second peer.
|
|
691
633
|
await createPeer({
|
|
692
634
|
topic,
|
|
@@ -696,7 +638,11 @@ function sharedTests({
|
|
|
696
638
|
});
|
|
697
639
|
}
|
|
698
640
|
|
|
699
|
-
|
|
641
|
+
// prettier-ignore
|
|
642
|
+
await Promise.all([
|
|
643
|
+
Event.wrap(plugin1, 'connect').waitForCount(1),
|
|
644
|
+
Event.wrap(plugin2, 'connect').waitForCount(1)
|
|
645
|
+
]);
|
|
700
646
|
});
|
|
701
647
|
|
|
702
648
|
it('two swarms at the same time', async function () {
|
package/src/network-manager.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type SwarmConnection = {
|
|
|
23
23
|
close(): Promise<void>;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
// TODO(burdon):
|
|
26
|
+
// TODO(burdon): Add timeout.
|
|
27
27
|
export type SwarmOptions = {
|
|
28
28
|
/**
|
|
29
29
|
* Swarm topic.
|
|
@@ -51,7 +51,8 @@ export type SwarmOptions = {
|
|
|
51
51
|
presence?: any;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* Custom label assigned to this swarm.
|
|
54
|
+
* Custom label assigned to this swarm.
|
|
55
|
+
* Used in devtools to display human-readable names for swarms.
|
|
55
56
|
*/
|
|
56
57
|
label?: string;
|
|
57
58
|
};
|
|
@@ -59,7 +60,7 @@ export type SwarmOptions = {
|
|
|
59
60
|
export type NetworkManagerOptions = {
|
|
60
61
|
transportFactory: TransportFactory;
|
|
61
62
|
signalManager: SignalManager;
|
|
62
|
-
log?: boolean; //
|
|
63
|
+
log?: boolean; // Log to devtools.
|
|
63
64
|
};
|
|
64
65
|
|
|
65
66
|
/**
|
package/src/protocol-factory.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const protocolFactory = ({
|
|
|
34
34
|
assert(getTopics);
|
|
35
35
|
// eslint-disable-next-line no-unused-vars
|
|
36
36
|
return ({ channel, initiator }) => {
|
|
37
|
+
log('creating protocol');
|
|
37
38
|
const protocol = new Protocol({
|
|
38
39
|
streamOptions: { live: true },
|
|
39
40
|
discoveryToPublicKey: (dk) => {
|
|
@@ -51,7 +52,6 @@ export const protocolFactory = ({
|
|
|
51
52
|
|
|
52
53
|
protocol.setExtensions(plugins.map((plugin) => plugin.createExtension())).init();
|
|
53
54
|
|
|
54
|
-
log('Created protocol');
|
|
55
55
|
return protocol;
|
|
56
56
|
};
|
|
57
57
|
};
|
package/src/swarm/swarm.test.ts
CHANGED
|
@@ -4,58 +4,64 @@
|
|
|
4
4
|
|
|
5
5
|
// @dxos/mocha platform=nodejs
|
|
6
6
|
|
|
7
|
-
import { expect
|
|
7
|
+
import { expect } from 'earljs';
|
|
8
8
|
import waitForExpect from 'wait-for-expect';
|
|
9
9
|
|
|
10
10
|
import { sleep, asyncTimeout } from '@dxos/async';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
|
-
import { Protocol } from '@dxos/mesh-protocol';
|
|
14
13
|
import { MemorySignalManager, MemorySignalManagerContext, Messenger } from '@dxos/messaging';
|
|
15
14
|
import { afterTest } from '@dxos/testutils';
|
|
16
15
|
|
|
16
|
+
import { TestProtocolPlugin, testProtocolProvider } from '../testing';
|
|
17
17
|
import { FullyConnectedTopology } from '../topology';
|
|
18
|
-
import { createWebRTCTransportFactory
|
|
18
|
+
import { createWebRTCTransportFactory } from '../transport';
|
|
19
19
|
import { Swarm } from './swarm';
|
|
20
20
|
|
|
21
21
|
describe('Swarm', function () {
|
|
22
22
|
const context = new MemorySignalManagerContext();
|
|
23
|
+
let signalManager: MemorySignalManager;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
beforeEach(function () {
|
|
26
|
+
signalManager = new MemorySignalManager(context);
|
|
27
|
+
afterTest(() => signalManager.destroy());
|
|
28
|
+
});
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
const setupSwarm = ({ topic, peerId }: { topic: PublicKey; peerId: PublicKey }) => {
|
|
31
|
+
const plugin = new TestProtocolPlugin(peerId.asBuffer());
|
|
32
|
+
const swarm = new Swarm(
|
|
30
33
|
topic,
|
|
31
|
-
|
|
34
|
+
peerId,
|
|
32
35
|
new FullyConnectedTopology(),
|
|
33
|
-
()
|
|
34
|
-
new Messenger({ signalManager
|
|
35
|
-
createWebRTCTransportFactory(),
|
|
36
|
-
undefined
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const swarm2 = new Swarm(
|
|
40
|
-
topic,
|
|
41
|
-
peerId2,
|
|
42
|
-
new FullyConnectedTopology(),
|
|
43
|
-
() => new Protocol(),
|
|
44
|
-
new Messenger({ signalManager: new MemorySignalManager(context) }),
|
|
36
|
+
testProtocolProvider(topic.asBuffer(), peerId, plugin),
|
|
37
|
+
new Messenger({ signalManager }),
|
|
45
38
|
createWebRTCTransportFactory(),
|
|
46
39
|
undefined
|
|
47
40
|
);
|
|
48
41
|
|
|
49
42
|
afterTest(async () => {
|
|
50
|
-
await
|
|
51
|
-
await swarm2.destroy();
|
|
43
|
+
await swarm.destroy();
|
|
52
44
|
});
|
|
53
45
|
|
|
54
|
-
return {
|
|
46
|
+
return { swarm, plugin };
|
|
55
47
|
};
|
|
56
48
|
|
|
57
49
|
it('connects two peers in a swarm', async function () {
|
|
58
|
-
const
|
|
50
|
+
const topic = PublicKey.random();
|
|
51
|
+
const peerId1 = PublicKey.random();
|
|
52
|
+
const peerId2 = PublicKey.random();
|
|
53
|
+
const data = 'Hello';
|
|
54
|
+
|
|
55
|
+
const { swarm: swarm1, plugin: plugin1 } = setupSwarm({ topic, peerId: peerId1 });
|
|
56
|
+
let receivedData: string;
|
|
57
|
+
plugin1.on('receive', async (_, payload) => {
|
|
58
|
+
receivedData = payload;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { swarm: swarm2, plugin: plugin2 } = setupSwarm({ topic, peerId: peerId2 });
|
|
62
|
+
plugin2.on('connect', async () => {
|
|
63
|
+
await plugin2.send(peerId1.asBuffer(), data);
|
|
64
|
+
});
|
|
59
65
|
|
|
60
66
|
expect(swarm1.connections.length).toEqual(0);
|
|
61
67
|
expect(swarm2.connections.length).toEqual(0);
|
|
@@ -84,20 +90,18 @@ describe('Swarm', function () {
|
|
|
84
90
|
await promise;
|
|
85
91
|
log('Swarms connected');
|
|
86
92
|
|
|
87
|
-
const swarm1Connection = swarm1.connections[0];
|
|
88
|
-
const swarm2Connection = swarm2.connections[0];
|
|
89
|
-
const onData = mockFn<(data: Buffer) => void>().returns(undefined);
|
|
90
|
-
(swarm2Connection.transport as WebRTCTransport).peer!.on('data', onData);
|
|
91
|
-
|
|
92
|
-
const data = Buffer.from('1234');
|
|
93
|
-
(swarm1Connection.transport as WebRTCTransport).peer!.send(data);
|
|
94
93
|
await waitForExpect(() => {
|
|
95
|
-
expect(
|
|
94
|
+
expect(receivedData).toEqual(data);
|
|
96
95
|
});
|
|
97
96
|
}).timeout(5_000);
|
|
98
97
|
|
|
99
98
|
it('two peers try to originate connections to each other simultaneously', async function () {
|
|
100
|
-
const
|
|
99
|
+
const topic = PublicKey.random();
|
|
100
|
+
const peerId1 = PublicKey.random();
|
|
101
|
+
const peerId2 = PublicKey.random();
|
|
102
|
+
|
|
103
|
+
const { swarm: swarm1 } = setupSwarm({ topic, peerId: peerId1 });
|
|
104
|
+
const { swarm: swarm2 } = setupSwarm({ topic, peerId: peerId2 });
|
|
101
105
|
|
|
102
106
|
expect(swarm1.connections.length).toEqual(0);
|
|
103
107
|
expect(swarm2.connections.length).toEqual(0);
|
|
@@ -122,7 +126,21 @@ describe('Swarm', function () {
|
|
|
122
126
|
}).timeout(5_000);
|
|
123
127
|
|
|
124
128
|
it('second peer discovered after delay', async function () {
|
|
125
|
-
const
|
|
129
|
+
const topic = PublicKey.random();
|
|
130
|
+
const peerId1 = PublicKey.random();
|
|
131
|
+
const peerId2 = PublicKey.random();
|
|
132
|
+
const data = 'Hello';
|
|
133
|
+
|
|
134
|
+
const { swarm: swarm1, plugin: plugin1 } = setupSwarm({ topic, peerId: peerId1 });
|
|
135
|
+
let receivedData: string;
|
|
136
|
+
plugin1.on('receive', async (_, payload) => {
|
|
137
|
+
receivedData = payload;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const { swarm: swarm2, plugin: plugin2 } = setupSwarm({ topic, peerId: peerId2 });
|
|
141
|
+
plugin2.on('connect', async () => {
|
|
142
|
+
await plugin2.send(peerId1.asBuffer(), data);
|
|
143
|
+
});
|
|
126
144
|
|
|
127
145
|
expect(swarm1.connections.length).toEqual(0);
|
|
128
146
|
expect(swarm2.connections.length).toEqual(0);
|
|
@@ -145,48 +163,8 @@ describe('Swarm', function () {
|
|
|
145
163
|
|
|
146
164
|
await connectPromises;
|
|
147
165
|
|
|
148
|
-
const swarm1Connection = swarm1.connections[0];
|
|
149
|
-
const swarm2Connection = swarm2.connections[0];
|
|
150
|
-
const onData = mockFn<(data: Buffer) => void>().returns(undefined);
|
|
151
|
-
(swarm2Connection.transport as WebRTCTransport).peer!.on('data', onData);
|
|
152
|
-
|
|
153
|
-
const data = Buffer.from('1234');
|
|
154
|
-
(swarm1Connection.transport as WebRTCTransport).peer!.send(data);
|
|
155
166
|
await waitForExpect(() => {
|
|
156
|
-
expect(
|
|
167
|
+
expect(receivedData).toEqual(data);
|
|
157
168
|
});
|
|
158
169
|
}).timeout(10_000);
|
|
159
|
-
|
|
160
|
-
it('swarming with message router', async function () {
|
|
161
|
-
const { swarm1, swarm2, peerId2 } = setupSwarm();
|
|
162
|
-
|
|
163
|
-
const promise = Promise.all([
|
|
164
|
-
asyncTimeout(swarm1.connected.waitForCount(1), 3000, new Error('Swarm1 connect timeout.')),
|
|
165
|
-
asyncTimeout(swarm2.connected.waitForCount(1), 3000, new Error('Swarm2 connect timeout.'))
|
|
166
|
-
]);
|
|
167
|
-
|
|
168
|
-
swarm1.onSwarmEvent({
|
|
169
|
-
peerAvailable: {
|
|
170
|
-
peer: peerId2.asUint8Array(),
|
|
171
|
-
since: new Date()
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
log('Candidates changed');
|
|
176
|
-
await promise;
|
|
177
|
-
log('Swarms connected');
|
|
178
|
-
|
|
179
|
-
const swarm1Connection = swarm1.connections[0];
|
|
180
|
-
const swarm2Connection = swarm2.connections[0];
|
|
181
|
-
const onData = mockFn<(data: Buffer) => void>().returns(undefined);
|
|
182
|
-
(swarm2Connection.transport as WebRTCTransport).peer!.on('data', onData);
|
|
183
|
-
|
|
184
|
-
const data = Buffer.from('1234');
|
|
185
|
-
(swarm1Connection.transport as WebRTCTransport).peer!.send(data);
|
|
186
|
-
await waitForExpect(() => {
|
|
187
|
-
expect(onData).toHaveBeenCalledWith([data]);
|
|
188
|
-
});
|
|
189
|
-
await swarm1.destroy();
|
|
190
|
-
await swarm2.destroy();
|
|
191
|
-
}).timeout(5_000);
|
|
192
170
|
});
|