@dxos/network-manager 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-E3P563GT.mjs → chunk-Y2FDDNGM.mjs} +548 -876
- package/dist/lib/browser/chunk-Y2FDDNGM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +342 -4
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -4
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/transport/tcp/index.mjs +2 -33
- package/dist/lib/browser/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/browser/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-PKBROUZV.mjs → chunk-OU3FYVBA.mjs} +548 -876
- package/dist/lib/node-esm/chunk-OU3FYVBA.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +342 -4
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +14 -4
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/transport/tcp/index.mjs +2 -157
- package/dist/lib/node-esm/transport/tcp/index.mjs.map +4 -4
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs +36 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.browser.mjs.map +7 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs +160 -0
- package/dist/lib/node-esm/transport/tcp/tcp-transport.mjs.map +7 -0
- package/dist/types/src/network-manager.d.ts +5 -4
- package/dist/types/src/network-manager.d.ts.map +1 -1
- package/dist/types/src/signal/signal-connection.d.ts +3 -2
- package/dist/types/src/signal/signal-connection.d.ts.map +1 -1
- package/dist/types/src/signal/signal-messenger.d.ts +3 -2
- package/dist/types/src/signal/signal-messenger.d.ts.map +1 -1
- package/dist/types/src/signal/swarm-messenger.d.ts +7 -7
- package/dist/types/src/signal/swarm-messenger.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +2 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +4 -3
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +3 -2
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts.map +1 -1
- 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/transport/tcp/index.d.ts +1 -1
- package/dist/types/src/transport/tcp/index.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-channel.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-factory.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/webrtc/rtc-transport-service.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +5 -5
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -22
- package/src/network-manager.ts +19 -15
- package/src/signal/integration.node.test.ts +11 -10
- package/src/signal/signal-connection.ts +3 -2
- package/src/signal/signal-messenger.ts +3 -2
- package/src/signal/swarm-messenger.node.test.ts +25 -24
- package/src/signal/swarm-messenger.ts +65 -55
- package/src/swarm/connection.test.ts +6 -7
- package/src/swarm/connection.ts +12 -10
- package/src/swarm/peer.ts +7 -7
- package/src/swarm/swarm.test.ts +2 -3
- package/src/swarm/swarm.ts +9 -10
- package/src/testing/test-builder.ts +4 -4
- package/src/tests/basic-test-suite.ts +0 -1
- package/src/tests/memory-transport.test.ts +0 -2
- package/src/tests/property-test-suite.ts +4 -3
- package/src/tests/tcp-transport.node.test.ts +0 -2
- package/src/tests/webrtc-transport.test.ts +0 -1
- package/src/transport/tcp/index.ts +1 -1
- package/src/transport/webrtc/rtc-peer-connection.ts +1 -2
- package/src/transport/webrtc/rtc-transport-channel.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-channel.ts +1 -2
- package/src/transport/webrtc/rtc-transport-factory.ts +0 -1
- package/src/transport/webrtc/rtc-transport-proxy.test.ts +0 -2
- package/src/transport/webrtc/rtc-transport-proxy.ts +6 -4
- package/src/transport/webrtc/rtc-transport-service.ts +0 -1
- package/src/transport/webrtc/rtc-transport.test.ts +0 -1
- package/src/wire-protocol.ts +6 -6
- package/dist/lib/browser/chunk-E3P563GT.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PKBROUZV.mjs.map +0 -7
|
@@ -10,7 +10,6 @@ import { PublicKey } from '@dxos/keys';
|
|
|
10
10
|
import { TestWireProtocol } from '../testing/test-wire-protocol';
|
|
11
11
|
import { createRtcTransportFactory } from '../transport';
|
|
12
12
|
import { chooseInitiatorPeer } from '../transport/webrtc/utils';
|
|
13
|
-
|
|
14
13
|
import { Connection } from './connection';
|
|
15
14
|
|
|
16
15
|
// Segfault in node-datachannel.
|
|
@@ -44,9 +43,9 @@ describe.skip('Connection', () => {
|
|
|
44
43
|
sessionId,
|
|
45
44
|
true,
|
|
46
45
|
{
|
|
47
|
-
offer: async (
|
|
48
|
-
signal: async (msg) => {
|
|
49
|
-
await fastConnection.signal(msg);
|
|
46
|
+
offer: async (_ctx, _msg) => ({ accept: true }),
|
|
47
|
+
signal: async (ctx, msg) => {
|
|
48
|
+
await fastConnection.signal(ctx, msg);
|
|
50
49
|
},
|
|
51
50
|
},
|
|
52
51
|
slowPeerProtocol.factory({
|
|
@@ -66,9 +65,9 @@ describe.skip('Connection', () => {
|
|
|
66
65
|
sessionId,
|
|
67
66
|
false,
|
|
68
67
|
{
|
|
69
|
-
offer: async (
|
|
70
|
-
signal: async (msg) => {
|
|
71
|
-
await slowConnection.signal(msg);
|
|
68
|
+
offer: async (_ctx, _msg) => ({ accept: true }),
|
|
69
|
+
signal: async (ctx, msg) => {
|
|
70
|
+
await slowConnection.signal(ctx, msg);
|
|
72
71
|
},
|
|
73
72
|
},
|
|
74
73
|
fastPeerProtocol.factory({
|
package/src/swarm/connection.ts
CHANGED
|
@@ -118,7 +118,7 @@ export class Connection {
|
|
|
118
118
|
public readonly transportStats = new Event<TransportStats>();
|
|
119
119
|
|
|
120
120
|
private readonly _signalSendTask = new DeferredTask(this._ctx, async () => {
|
|
121
|
-
await this._flushSignalBuffer();
|
|
121
|
+
await this._flushSignalBuffer(this._ctx);
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
private _signallingDelay = STARTING_SIGNALLING_DELAY;
|
|
@@ -185,16 +185,18 @@ export class Connection {
|
|
|
185
185
|
this._protocol.stream.on('close', () => {
|
|
186
186
|
log('protocol stream closed');
|
|
187
187
|
this._protocolClosed.wake();
|
|
188
|
-
this.close({ error: new ProtocolError('protocol stream closed') }).catch((err) =>
|
|
188
|
+
this.close({ error: new ProtocolError({ message: 'protocol stream closed' }) }).catch((err) =>
|
|
189
|
+
this.errors.raise(err),
|
|
190
|
+
);
|
|
189
191
|
});
|
|
190
192
|
|
|
191
193
|
scheduleTask(
|
|
192
194
|
this.connectedTimeoutContext,
|
|
193
195
|
async () => {
|
|
194
196
|
log.info(`timeout waiting ${TRANSPORT_CONNECTION_TIMEOUT / 1000}s for transport to connect, aborting`);
|
|
195
|
-
await this.abort(
|
|
196
|
-
(
|
|
197
|
-
);
|
|
197
|
+
await this.abort(
|
|
198
|
+
new TimeoutError({ message: `${TRANSPORT_CONNECTION_TIMEOUT / 1000}s for transport to connect` }),
|
|
199
|
+
).catch((err) => this.errors.raise(err));
|
|
198
200
|
},
|
|
199
201
|
TRANSPORT_CONNECTION_TIMEOUT,
|
|
200
202
|
);
|
|
@@ -364,21 +366,21 @@ export class Connection {
|
|
|
364
366
|
this._signalSendTask.schedule();
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
private async _flushSignalBuffer(): Promise<void> {
|
|
369
|
+
private async _flushSignalBuffer(ctx: Context): Promise<void> {
|
|
368
370
|
if (this._outgoingSignalBuffer.length === 0) {
|
|
369
371
|
return;
|
|
370
372
|
}
|
|
371
373
|
|
|
372
374
|
try {
|
|
373
375
|
if (process.env.NODE_ENV !== 'test') {
|
|
374
|
-
await cancelWithContext(
|
|
376
|
+
await cancelWithContext(ctx, sleep(this._signallingDelay));
|
|
375
377
|
this._signallingDelay = Math.min(this._signallingDelay * 2, MAX_SIGNALLING_DELAY);
|
|
376
378
|
}
|
|
377
379
|
|
|
378
380
|
const signals = [...this._outgoingSignalBuffer];
|
|
379
381
|
this._outgoingSignalBuffer.length = 0;
|
|
380
382
|
|
|
381
|
-
await this._signalMessaging.signal({
|
|
383
|
+
await this._signalMessaging.signal(ctx, {
|
|
382
384
|
author: this.localInfo,
|
|
383
385
|
recipient: this.remoteInfo,
|
|
384
386
|
sessionId: this.sessionId,
|
|
@@ -397,14 +399,14 @@ export class Connection {
|
|
|
397
399
|
|
|
398
400
|
// If signal fails treat connection as failed
|
|
399
401
|
log.info('signal message failed to deliver', { err });
|
|
400
|
-
await this.close({ error: new ConnectivityError('signal message failed to deliver', err) });
|
|
402
|
+
await this.close({ error: new ConnectivityError({ message: 'signal message failed to deliver', cause: err }) });
|
|
401
403
|
}
|
|
402
404
|
}
|
|
403
405
|
|
|
404
406
|
/**
|
|
405
407
|
* Receive a signal from the remote peer.
|
|
406
408
|
*/
|
|
407
|
-
async signal(msg: SignalMessage): Promise<void> {
|
|
409
|
+
async signal(_ctx: Context, msg: SignalMessage): Promise<void> {
|
|
408
410
|
invariant(msg.sessionId);
|
|
409
411
|
if (!msg.sessionId.equals(this.sessionId)) {
|
|
410
412
|
log('dropping signal for incorrect session id');
|
package/src/swarm/peer.ts
CHANGED
|
@@ -14,13 +14,12 @@ import { type Answer } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
|
14
14
|
import { type OfferMessage, type SignalMessage, type SignalMessenger } from '../signal';
|
|
15
15
|
import { type TransportFactory } from '../transport';
|
|
16
16
|
import { type WireProtocolProvider } from '../wire-protocol';
|
|
17
|
-
|
|
18
17
|
import { Connection, ConnectionState } from './connection';
|
|
19
18
|
import { type ConnectionLimiter } from './connection-limiter';
|
|
20
19
|
|
|
21
20
|
export class ConnectionDisplacedError extends SystemError {
|
|
22
21
|
constructor() {
|
|
23
|
-
super('Connection displaced by remote initiator.');
|
|
22
|
+
super({ message: 'Connection displaced by remote initiator.' });
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
|
|
@@ -106,7 +105,7 @@ export class Peer {
|
|
|
106
105
|
/**
|
|
107
106
|
* Respond to remote offer.
|
|
108
107
|
*/
|
|
109
|
-
async onOffer(message: OfferMessage): Promise<Answer> {
|
|
108
|
+
async onOffer(_ctx: Context, message: OfferMessage): Promise<Answer> {
|
|
110
109
|
const remote = message.author;
|
|
111
110
|
|
|
112
111
|
if (
|
|
@@ -162,13 +161,14 @@ export class Peer {
|
|
|
162
161
|
return { accept: true };
|
|
163
162
|
}
|
|
164
163
|
}
|
|
164
|
+
|
|
165
165
|
return { accept: false };
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Initiate a connection to the remote peer.
|
|
170
170
|
*/
|
|
171
|
-
async initiateConnection(): Promise<void> {
|
|
171
|
+
async initiateConnection(ctx: Context): Promise<void> {
|
|
172
172
|
invariant(!this.initiating, 'Initiation in progress.');
|
|
173
173
|
invariant(!this.connection, 'Already connected.');
|
|
174
174
|
const sessionId = PublicKey.random();
|
|
@@ -182,7 +182,7 @@ export class Peer {
|
|
|
182
182
|
await this._connectionLimiter.connecting(sessionId);
|
|
183
183
|
connection.initiate();
|
|
184
184
|
|
|
185
|
-
answer = await this._signalMessaging.offer({
|
|
185
|
+
answer = await this._signalMessaging.offer(ctx, {
|
|
186
186
|
author: this.localInfo,
|
|
187
187
|
recipient: this.remoteInfo,
|
|
188
188
|
sessionId,
|
|
@@ -377,13 +377,13 @@ export class Peer {
|
|
|
377
377
|
log('closed', { peerId: this.remoteInfo, sessionId: connection.sessionId });
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
async onSignal(message: SignalMessage): Promise<void> {
|
|
380
|
+
async onSignal(ctx: Context, message: SignalMessage): Promise<void> {
|
|
381
381
|
if (!this.connection) {
|
|
382
382
|
log('dropping signal message for non-existent connection', { message });
|
|
383
383
|
return;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
|
-
await this.connection.signal(message);
|
|
386
|
+
await this.connection.signal(ctx, message);
|
|
387
387
|
}
|
|
388
388
|
|
|
389
389
|
@synchronized
|
package/src/swarm/swarm.test.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { ComplexSet } from '@dxos/util';
|
|
|
18
18
|
import { TestWireProtocol } from '../testing/test-wire-protocol';
|
|
19
19
|
import { FullyConnectedTopology } from '../topology';
|
|
20
20
|
import { createRtcTransportFactory } from '../transport';
|
|
21
|
-
|
|
22
21
|
import { ConnectionState } from './connection';
|
|
23
22
|
import { ConnectionLimiter } from './connection-limiter';
|
|
24
23
|
import { Swarm } from './swarm';
|
|
@@ -159,9 +158,9 @@ describe.skip('Swarm', () => {
|
|
|
159
158
|
const messages = new ComplexSet<{ author: PeerInfo; recipient: PeerInfo }>(
|
|
160
159
|
({ author, recipient }) => author.peerKey + recipient.peerKey,
|
|
161
160
|
);
|
|
162
|
-
signalManager.sendMessage = async (message) => {
|
|
161
|
+
signalManager.sendMessage = async (ctx, message) => {
|
|
163
162
|
messages.add({ author: message.author, recipient: message.recipient });
|
|
164
|
-
return sendOriginal(message);
|
|
163
|
+
return sendOriginal(ctx, message);
|
|
165
164
|
};
|
|
166
165
|
// Stop signaling to stop connection in initiation state.
|
|
167
166
|
signalManager.freeze();
|
package/src/swarm/swarm.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { type SwarmController, type Topology } from '../topology';
|
|
|
18
18
|
import { type TransportFactory } from '../transport';
|
|
19
19
|
import { type Topic } from '../types';
|
|
20
20
|
import { type WireProtocolProvider } from '../wire-protocol';
|
|
21
|
-
|
|
22
21
|
import { type Connection, ConnectionState } from './connection';
|
|
23
22
|
import { type ConnectionLimiter } from './connection-limiter';
|
|
24
23
|
import { Peer } from './peer';
|
|
@@ -94,9 +93,9 @@ export class Swarm {
|
|
|
94
93
|
_topology.init(this._getSwarmController());
|
|
95
94
|
|
|
96
95
|
this._swarmMessenger = new SwarmMessenger({
|
|
97
|
-
sendMessage: async (msg) => await this._messenger.sendMessage(msg),
|
|
98
|
-
onSignal: async (msg) => await this.onSignal(msg),
|
|
99
|
-
onOffer: async (msg) => await this.onOffer(msg),
|
|
96
|
+
sendMessage: async (ctx, msg) => await this._messenger.sendMessage(ctx, msg),
|
|
97
|
+
onSignal: async (ctx, msg) => await this.onSignal(ctx, msg),
|
|
98
|
+
onOffer: async (ctx, msg) => await this.onOffer(ctx, msg),
|
|
100
99
|
topic: this._topic,
|
|
101
100
|
});
|
|
102
101
|
log.trace('dxos.mesh.swarm.constructor', trace.end({ id: this._instanceId }));
|
|
@@ -136,7 +135,7 @@ export class Swarm {
|
|
|
136
135
|
payloadType: 'dxos.mesh.swarm.SwarmMessage',
|
|
137
136
|
onMessage: async (message) => {
|
|
138
137
|
await this._swarmMessenger
|
|
139
|
-
.receiveMessage(message)
|
|
138
|
+
.receiveMessage(this._ctx, message)
|
|
140
139
|
// TODO(nf): discriminate between errors
|
|
141
140
|
.catch((err) => log.info('Error while receiving message', { err }));
|
|
142
141
|
},
|
|
@@ -205,7 +204,7 @@ export class Swarm {
|
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
@synchronized
|
|
208
|
-
async onOffer(message: OfferMessage): Promise<Answer> {
|
|
207
|
+
async onOffer(ctx: Context, message: OfferMessage): Promise<Answer> {
|
|
209
208
|
log('offer', { message });
|
|
210
209
|
if (this._ctx.disposed) {
|
|
211
210
|
log('ignored for disposed swarm');
|
|
@@ -224,7 +223,7 @@ export class Swarm {
|
|
|
224
223
|
}
|
|
225
224
|
|
|
226
225
|
const peer = this._getOfferSenderPeer(message.author);
|
|
227
|
-
const answer = await peer.onOffer(message);
|
|
226
|
+
const answer = await peer.onOffer(ctx, message);
|
|
228
227
|
this._topology.update();
|
|
229
228
|
return answer;
|
|
230
229
|
}
|
|
@@ -243,7 +242,7 @@ export class Swarm {
|
|
|
243
242
|
return peer;
|
|
244
243
|
}
|
|
245
244
|
|
|
246
|
-
async onSignal(message: SignalMessage): Promise<void> {
|
|
245
|
+
async onSignal(ctx: Context, message: SignalMessage): Promise<void> {
|
|
247
246
|
log('signal', { message });
|
|
248
247
|
if (this._ctx.disposed) {
|
|
249
248
|
log.info('ignored for offline swarm');
|
|
@@ -257,7 +256,7 @@ export class Swarm {
|
|
|
257
256
|
invariant(message.author);
|
|
258
257
|
|
|
259
258
|
const peer = this._getOrCreatePeer(message.author);
|
|
260
|
-
await peer.onSignal(message);
|
|
259
|
+
await peer.onSignal(ctx, message);
|
|
261
260
|
}
|
|
262
261
|
|
|
263
262
|
// For debug purposes
|
|
@@ -404,7 +403,7 @@ export class Swarm {
|
|
|
404
403
|
}
|
|
405
404
|
|
|
406
405
|
log('initiating connection...', { remotePeer });
|
|
407
|
-
await peer.initiateConnection();
|
|
406
|
+
await peer.initiateConnection(ctx);
|
|
408
407
|
this._topology.update();
|
|
409
408
|
log('initiated', { remotePeer });
|
|
410
409
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Context } from '@dxos/context';
|
|
5
6
|
import { PublicKey } from '@dxos/keys';
|
|
6
7
|
import { log } from '@dxos/log';
|
|
7
8
|
import {
|
|
@@ -28,7 +29,6 @@ import {
|
|
|
28
29
|
TransportKind,
|
|
29
30
|
createRtcTransportFactory,
|
|
30
31
|
} from '../transport';
|
|
31
|
-
|
|
32
32
|
import { type TestTeleportExtensionFactory, TestWireProtocol } from './test-wire-protocol';
|
|
33
33
|
|
|
34
34
|
// Signal server will be started by the setup script.
|
|
@@ -169,7 +169,7 @@ export class TestPeer {
|
|
|
169
169
|
|
|
170
170
|
await this._proxy?.close();
|
|
171
171
|
await this._service?.close();
|
|
172
|
-
await this._networkManager.close();
|
|
172
|
+
await this._networkManager.close(Context.default());
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
getSwarm(topic: PublicKey): TestSwarmConnection {
|
|
@@ -218,7 +218,7 @@ export class TestSwarmConnection {
|
|
|
218
218
|
// TODO(burdon): Need to create new plugin instance per swarm?
|
|
219
219
|
// If so, then perhaps joinSwarm should return swarm object with access to plugins.
|
|
220
220
|
async join(topology = new FullyConnectedTopology()): Promise<this> {
|
|
221
|
-
await this.peer._networkManager.joinSwarm({
|
|
221
|
+
await this.peer._networkManager.joinSwarm(Context.default(), {
|
|
222
222
|
topic: this.topic,
|
|
223
223
|
peerInfo: { peerKey: this.peer.peerId.toHex(), identityKey: this.peer.peerId.toHex() },
|
|
224
224
|
protocolProvider: this.protocol.factory,
|
|
@@ -229,7 +229,7 @@ export class TestSwarmConnection {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
async leave(): Promise<this> {
|
|
232
|
-
await this.peer._networkManager.leaveSwarm(this.topic);
|
|
232
|
+
await this.peer._networkManager.leaveSwarm(Context.default(), this.topic);
|
|
233
233
|
return this;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -11,7 +11,6 @@ import { range } from '@dxos/util';
|
|
|
11
11
|
|
|
12
12
|
import { type TestBuilder } from '../testing';
|
|
13
13
|
import { FullyConnectedTopology, StarTopology } from '../topology';
|
|
14
|
-
|
|
15
14
|
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
16
15
|
|
|
17
16
|
// TODO(burdon): Use PublicKey throughout (remove conversion to strings, from buffers, etc.)
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { randomBytes } from 'node:crypto';
|
|
6
|
-
|
|
7
6
|
import { describe, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -11,7 +10,6 @@ import { range } from '@dxos/util';
|
|
|
11
10
|
|
|
12
11
|
import { TestBuilder } from '../testing';
|
|
13
12
|
import { FullyConnectedTopology } from '../topology';
|
|
14
|
-
|
|
15
13
|
import { basicTestSuite } from './basic-test-suite';
|
|
16
14
|
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
17
15
|
|
|
@@ -6,6 +6,7 @@ import * as fc from 'fast-check';
|
|
|
6
6
|
import { type ModelRunSetup } from 'fast-check';
|
|
7
7
|
import { test } from 'vitest';
|
|
8
8
|
|
|
9
|
+
import { Context } from '@dxos/context';
|
|
9
10
|
import { todo } from '@dxos/debug';
|
|
10
11
|
import { PublicKey } from '@dxos/keys';
|
|
11
12
|
import { ComplexMap, ComplexSet, range } from '@dxos/util';
|
|
@@ -97,7 +98,7 @@ export const propertyTestSuite = () => {
|
|
|
97
98
|
model.joinedPeers.delete(this.peerId);
|
|
98
99
|
|
|
99
100
|
const peer = real.peers.get(this.peerId);
|
|
100
|
-
await peer!.networkManager.close();
|
|
101
|
+
await peer!.networkManager.close(Context.default());
|
|
101
102
|
real.peers.delete(this.peerId);
|
|
102
103
|
|
|
103
104
|
await assertState(model, real);
|
|
@@ -119,7 +120,7 @@ export const propertyTestSuite = () => {
|
|
|
119
120
|
// afterTest(() => presence.stop());
|
|
120
121
|
// const protocol = createProtocolFactory(model.topic, this.peerId, [presence]);
|
|
121
122
|
|
|
122
|
-
await peer.networkManager.joinSwarm({
|
|
123
|
+
await peer.networkManager.joinSwarm(Context.default(), {
|
|
123
124
|
peerInfo: {
|
|
124
125
|
peerKey: this.peerId.toHex(),
|
|
125
126
|
identityKey: this.peerId.toHex(),
|
|
@@ -146,7 +147,7 @@ export const propertyTestSuite = () => {
|
|
|
146
147
|
model.joinedPeers.delete(this.peerId);
|
|
147
148
|
|
|
148
149
|
const peer = real.peers.get(this.peerId)!;
|
|
149
|
-
await peer.networkManager.leaveSwarm(model.topic);
|
|
150
|
+
await peer.networkManager.leaveSwarm(Context.default(), model.topic);
|
|
150
151
|
peer.presence = undefined;
|
|
151
152
|
|
|
152
153
|
await assertState(model, real);
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { randomBytes } from 'node:crypto';
|
|
6
|
-
|
|
7
6
|
import { describe, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -12,7 +11,6 @@ import { range } from '@dxos/util';
|
|
|
12
11
|
import { TestBuilder } from '../testing';
|
|
13
12
|
import { FullyConnectedTopology } from '../topology';
|
|
14
13
|
import { TransportKind } from '../transport';
|
|
15
|
-
|
|
16
14
|
import { basicTestSuite } from './basic-test-suite';
|
|
17
15
|
import { exchangeMessages, joinSwarm, leaveSwarm, openAndCloseAfterTest } from './utils';
|
|
18
16
|
|
|
@@ -11,7 +11,6 @@ import { trace } from '@dxos/tracing';
|
|
|
11
11
|
|
|
12
12
|
import type { IceProvider } from '../../signal';
|
|
13
13
|
import { type TransportOptions } from '../transport';
|
|
14
|
-
|
|
15
14
|
import { type RtcConnectionFactory } from './rtc-connection-factory';
|
|
16
15
|
import { RtcTransportChannel } from './rtc-transport-channel';
|
|
17
16
|
import { areSdpEqual, chooseInitiatorPeer } from './utils';
|
|
@@ -469,7 +468,7 @@ type IceCandidateErrorDetails = { url: string; errorCode: number; errorText: str
|
|
|
469
468
|
|
|
470
469
|
const createIceFailureError = (details: IceCandidateErrorDetails[]) => {
|
|
471
470
|
const candidateErrors = details.map(({ url, errorCode, errorText }) => `${errorCode} ${url}: ${errorText}`);
|
|
472
|
-
return new ConnectivityError(`ICE failed:\n${candidateErrors.join('\n')}`);
|
|
471
|
+
return new ConnectivityError({ message: `ICE failed:\n${candidateErrors.join('\n')}` });
|
|
473
472
|
};
|
|
474
473
|
|
|
475
474
|
type ChannelCreatedCallback = {
|
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Duplex } from 'node:stream';
|
|
6
|
-
|
|
7
6
|
import { describe, expect, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { sleep } from '@dxos/async';
|
|
10
9
|
|
|
11
10
|
import { type TransportOptions } from '../transport';
|
|
12
|
-
|
|
13
11
|
import { type RtcPeerConnection } from './rtc-peer-connection';
|
|
14
12
|
import { RtcTransportChannel } from './rtc-transport-channel';
|
|
15
13
|
import { handleChannelErrors } from './test-utils';
|
|
@@ -13,7 +13,6 @@ import { ConnectivityError } from '@dxos/protocols';
|
|
|
13
13
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
14
14
|
|
|
15
15
|
import { type Transport, type TransportOptions, type TransportStats } from '../transport';
|
|
16
|
-
|
|
17
16
|
import { type RtcPeerConnection } from './rtc-peer-connection';
|
|
18
17
|
import { createRtcTransportStats, describeSelectedRemoteCandidate } from './rtc-transport-stats';
|
|
19
18
|
|
|
@@ -71,7 +70,7 @@ export class RtcTransportChannel extends Resource implements Transport {
|
|
|
71
70
|
const error =
|
|
72
71
|
err instanceof Error
|
|
73
72
|
? err
|
|
74
|
-
: new ConnectivityError(`Failed to create a channel: ${JSON.stringify(err?.message)}`);
|
|
73
|
+
: new ConnectivityError({ message: `Failed to create a channel: ${JSON.stringify(err?.message)}` });
|
|
75
74
|
this.errors.raise(error);
|
|
76
75
|
} else {
|
|
77
76
|
log.verbose('connection establishment failed after transport was closed', { err });
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Duplex } from 'stream';
|
|
6
|
-
|
|
7
6
|
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { Event as AsyncEvent, TestStream, Trigger, sleep } from '@dxos/async';
|
|
@@ -14,7 +13,6 @@ import { type BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
|
14
13
|
import { type RpcPort, createLinkedPorts, createProtoRpcPeer } from '@dxos/rpc';
|
|
15
14
|
|
|
16
15
|
import { type Transport, type TransportFactory, type TransportOptions, type TransportStats } from '../transport';
|
|
17
|
-
|
|
18
16
|
import { RtcTransportProxy } from './rtc-transport-proxy';
|
|
19
17
|
import { RtcTransportService } from './rtc-transport-service';
|
|
20
18
|
import { handleChannelErrors } from './test-utils';
|
|
@@ -176,7 +176,9 @@ export class RtcTransportProxy extends Resource implements Transport {
|
|
|
176
176
|
} catch (error) {
|
|
177
177
|
const type = signalEvent.payload.payload.data?.type;
|
|
178
178
|
if (type === 'offer' || type === 'answer') {
|
|
179
|
-
this._raiseIfOpen(
|
|
179
|
+
this._raiseIfOpen(
|
|
180
|
+
new ConnectivityError({ message: `Session establishment failed: ${type} couldn't be sent.` }),
|
|
181
|
+
);
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
184
|
}
|
|
@@ -255,11 +257,11 @@ export class RtcTransportProxyFactory implements TransportFactory {
|
|
|
255
257
|
const decodeError = (err: Error | string) => {
|
|
256
258
|
const message = typeof err === 'string' ? err : err.message;
|
|
257
259
|
if (message.includes('CONNECTION_RESET')) {
|
|
258
|
-
return new ConnectionResetError(message);
|
|
260
|
+
return new ConnectionResetError({ message });
|
|
259
261
|
} else if (message.includes('TIMEOUT')) {
|
|
260
|
-
return new TimeoutError(message);
|
|
262
|
+
return new TimeoutError({ message });
|
|
261
263
|
} else if (message.includes('CONNECTIVITY_ERROR')) {
|
|
262
|
-
return new ConnectivityError(message);
|
|
264
|
+
return new ConnectivityError({ message });
|
|
263
265
|
} else {
|
|
264
266
|
return typeof err === 'string' ? new Error(err) : err;
|
|
265
267
|
}
|
|
@@ -25,7 +25,6 @@ import { ComplexMap } from '@dxos/util';
|
|
|
25
25
|
|
|
26
26
|
import { type IceProvider } from '../../signal';
|
|
27
27
|
import { type Transport, type TransportFactory } from '../transport';
|
|
28
|
-
|
|
29
28
|
import { createRtcTransportFactory } from './rtc-transport-factory';
|
|
30
29
|
|
|
31
30
|
type TransportState = {
|
|
@@ -8,7 +8,6 @@ import { TestStream, sleep } from '@dxos/async';
|
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
|
|
10
10
|
import { type TransportOptions } from '../transport';
|
|
11
|
-
|
|
12
11
|
import { getRtcConnectionFactory } from './rtc-connection-factory';
|
|
13
12
|
import { RtcPeerConnection } from './rtc-peer-connection';
|
|
14
13
|
import { type RtcTransportChannel } from './rtc-transport-channel';
|
package/src/wire-protocol.ts
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
import { type Duplex } from 'node:stream';
|
|
6
6
|
|
|
7
7
|
import { type PublicKey } from '@dxos/keys';
|
|
8
|
-
import { Teleport, type
|
|
8
|
+
import { Teleport, type TeleportProps } from '@dxos/teleport';
|
|
9
9
|
|
|
10
|
-
export type
|
|
10
|
+
export type WireProtocolProps = {
|
|
11
11
|
initiator: boolean;
|
|
12
12
|
localPeerId: PublicKey;
|
|
13
13
|
remotePeerId: PublicKey;
|
|
14
14
|
topic: PublicKey;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export type WireProtocolProvider = (params:
|
|
17
|
+
export type WireProtocolProvider = (params: WireProtocolProps) => WireProtocol;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Application-specific network protocol that is used when a connection to a peer is established.
|
|
@@ -31,15 +31,15 @@ export interface WireProtocol {
|
|
|
31
31
|
/**
|
|
32
32
|
* Create a wire-protocol provider backed by a teleport instance.
|
|
33
33
|
* @param onConnection Called after teleport is initialized for the session. Protocol extensions could be attached here.
|
|
34
|
-
* @param
|
|
34
|
+
* @param defaultProps Optionally provide default Teleport params that might be overridden by factory callers.
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
37
|
export const createTeleportProtocolFactory = (
|
|
38
38
|
onConnection: (teleport: Teleport) => Promise<void>,
|
|
39
|
-
|
|
39
|
+
defaultProps?: Partial<TeleportProps>,
|
|
40
40
|
): WireProtocolProvider => {
|
|
41
41
|
return (params) => {
|
|
42
|
-
const teleport = new Teleport({ ...
|
|
42
|
+
const teleport = new Teleport({ ...defaultProps, ...params });
|
|
43
43
|
return {
|
|
44
44
|
stream: teleport.stream,
|
|
45
45
|
open: async (sessionId?: PublicKey) => {
|