@dxos/network-manager 0.1.57 → 0.1.58-main.31dfb10
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-UKMTAO4L.mjs → chunk-O2SMNRBC.mjs} +194 -108
- package/dist/lib/browser/chunk-O2SMNRBC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -3
- package/dist/lib/node/index.cjs +191 -105
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +191 -105
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/swarm/connection.d.ts +3 -1
- 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/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/swarm/connection.ts +52 -26
- package/src/swarm/peer.ts +4 -1
- package/src/transport/simplepeer-transport-proxy.ts +28 -2
- package/src/transport/simplepeer-transport.ts +39 -2
- package/dist/lib/browser/chunk-UKMTAO4L.mjs.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/swarm/connection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,EAAuB,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/swarm/connection.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,KAAK,EAAuB,MAAM,aAAa,CAAC;AAEvE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAS1C,OAAO,EAAE,SAAS,EAA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7B,WAAW,SAA8B;IAEhD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAE7B;IAEH,OAAO,CAAC,gBAAgB,CAA6B;gBAGnC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,SAAS,EAAE,wBAAwB;IAC1C,QAAQ,EAAE,SAAS,EACnB,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,OAAO,EACjB,gBAAgB,EAAE,eAAe,EACjC,SAAS,EAAE,YAAY,EACvB,iBAAiB,EAAE,gBAAgB,EACnC,UAAU,CAAC,iCAAqB;IAWnD,IAAI,KAAK,oBAER;IAED,IAAI,SAAS,0BAEZ;IAED,IAAI,QAAQ,iBAEX;IAED;;OAEG;IACG,cAAc;IA4Ed,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK;IAsCjB,KAAK,CAAC,GAAG,CAAC,EAAE,KAAK;IAuCvB,OAAO,CAAC,WAAW;YAKL,kBAAkB;IAgChC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,aAAa;IA2B/B,QAAQ;IAIR,OAAO,CAAC,YAAY;CAMrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../../../src/swarm/peer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAA8B,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAkB,WAAW,
|
|
1
|
+
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../../../src/swarm/peer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAA8B,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAkB,WAAW,EAAgB,MAAM,cAAc,CAAC;AAEzE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACzE,OAAO,EAAE,gBAA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AAS;IAE1B,SAAgB,mBAAmB,oBAA2B;gBAI5C,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,SAAS,EACrB,gBAAgB,EAAE,eAAe,EACjC,iBAAiB,EAAE,oBAAoB,EACvC,iBAAiB,EAAE,gBAAgB,EACnC,kBAAkB,EAAE,iBAAiB,EACrC,UAAU,EAAE,aAAa;IAG5C;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAoDrD;;OAEG;IACG,kBAAkB;IA6CxB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAsGnB,eAAe,CAAC,GAAG,CAAC,EAAE,KAAK;IAgB3B,QAAQ,CAAC,OAAO,EAAE,aAAa;IAU/B,OAAO;CAOd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simplepeer-transport-proxy.d.ts","sourceRoot":"","sources":["../../../../src/transport/simplepeer-transport-proxy.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"simplepeer-transport-proxy.d.ts","sourceRoot":"","sources":["../../../../src/transport/simplepeer-transport-proxy.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAW1C,OAAO,EAAgC,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACrG,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAG/D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC;IAC/B,aAAa,EAAE,aAAa,CAAC;IAE7B,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC;AAEF,qBAAa,wBAAyB,YAAW,SAAS;IAatD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAZ1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAiB;IAEtC,QAAQ,CAAC,MAAM,cAAe;IAC9B,QAAQ,CAAC,SAAS,cAAe;IACjC,QAAQ,CAAC,MAAM,cAAqB;IAEpC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,cAAc,CAAuB;gBAI1B,OAAO,EAAE,8BAA8B;YAsC5C,iBAAiB;IAiB/B,OAAO,CAAC,WAAW;YAKL,aAAa;IAI3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAUtB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;OAEG;IAEH,UAAU;CAKX;AAGD,qBAAa,+BAAgC,YAAW,gBAAgB;IACtE,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,YAAY,CAAuC;IAE3D;;;OAGG;IACH,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,GAAG,IAAI;IAShE,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS;CAatD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simplepeer-transport.d.ts","sourceRoot":"","sources":["../../../../src/transport/simplepeer-transport.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"simplepeer-transport.d.ts","sourceRoot":"","sources":["../../../../src/transport/simplepeer-transport.ts"],"names":[],"mappings":";AAQA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,WAAW,EAAS,MAAM,aAAa,CAAC;AAKjD,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAG1D,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC;IAC/B,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/C,CAAC;AAEF;;GAEG;AACH,qBAAa,mBAAoB,YAAW,SAAS;IAUvC,OAAO,CAAC,QAAQ,CAAC,MAAM;IATnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,OAAO,CAAS;IAExB,QAAQ,CAAC,MAAM,cAAe;IAC9B,QAAQ,CAAC,SAAS,cAAe;IACjC,QAAQ,CAAC,MAAM,cAAqB;IAEpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA8B;gBAE7B,MAAM,EAAE,yBAAyB;IAkFxD,OAAO;IASb,MAAM,CAAC,MAAM,EAAE,MAAM;YASP,kBAAkB;CAIjC;AAED,eAAO,MAAM,gCAAgC,kBAAmB,GAAG,KAAG,gBAMpE,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.58-main.31dfb10",
|
|
4
4
|
"description": "Network Manager",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -30,22 +30,22 @@
|
|
|
30
30
|
"tiny-invariant": "^1.3.1",
|
|
31
31
|
"ws": "^7.4.4",
|
|
32
32
|
"xor-distance": "^2.0.0",
|
|
33
|
-
"@dxos/async": "0.1.
|
|
34
|
-
"@dxos/codec-protobuf": "0.1.
|
|
35
|
-
"@dxos/context": "0.1.
|
|
36
|
-
"@dxos/credentials": "0.1.
|
|
37
|
-
"@dxos/crypto": "0.1.
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
33
|
+
"@dxos/async": "0.1.58-main.31dfb10",
|
|
34
|
+
"@dxos/codec-protobuf": "0.1.58-main.31dfb10",
|
|
35
|
+
"@dxos/context": "0.1.58-main.31dfb10",
|
|
36
|
+
"@dxos/credentials": "0.1.58-main.31dfb10",
|
|
37
|
+
"@dxos/crypto": "0.1.58-main.31dfb10",
|
|
38
|
+
"@dxos/debug": "0.1.58-main.31dfb10",
|
|
39
|
+
"@dxos/errors": "0.1.58-main.31dfb10",
|
|
40
|
+
"@dxos/invariant": "0.1.58-main.31dfb10",
|
|
41
|
+
"@dxos/keys": "0.1.58-main.31dfb10",
|
|
42
|
+
"@dxos/log": "0.1.58-main.31dfb10",
|
|
43
|
+
"@dxos/messaging": "0.1.58-main.31dfb10",
|
|
44
|
+
"@dxos/node-std": "0.1.58-main.31dfb10",
|
|
45
|
+
"@dxos/protocols": "0.1.58-main.31dfb10",
|
|
46
|
+
"@dxos/rpc": "0.1.58-main.31dfb10",
|
|
47
|
+
"@dxos/teleport": "0.1.58-main.31dfb10",
|
|
48
|
+
"@dxos/util": "0.1.58-main.31dfb10"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@swc-node/register": "1.5.4",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"earljs": "~0.1.10",
|
|
56
56
|
"fast-check": "~3.3.0",
|
|
57
57
|
"typescript": "^5.2.2",
|
|
58
|
-
"@dxos/signal": "0.1.
|
|
58
|
+
"@dxos/signal": "0.1.58-main.31dfb10"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
package/src/swarm/connection.ts
CHANGED
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
import { DeferredTask, Event, sleep, synchronized } from '@dxos/async';
|
|
6
6
|
import { Context, cancelWithContext } from '@dxos/context';
|
|
7
7
|
import { ErrorStream } from '@dxos/debug';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
CancelledError,
|
|
10
|
+
ProtocolError,
|
|
11
|
+
ConnectionResetError,
|
|
12
|
+
ConnectivityError,
|
|
13
|
+
UnknownProtocolError,
|
|
14
|
+
} from '@dxos/errors';
|
|
9
15
|
import { invariant } from '@dxos/invariant';
|
|
10
16
|
import { PublicKey } from '@dxos/keys';
|
|
11
17
|
import { log } from '@dxos/log';
|
|
@@ -73,6 +79,9 @@ export enum ConnectionState {
|
|
|
73
79
|
* Connection closed.
|
|
74
80
|
*/
|
|
75
81
|
CLOSED = 'CLOSED',
|
|
82
|
+
|
|
83
|
+
ABORTING = 'ABORTING',
|
|
84
|
+
ABORTED = 'ABORTED',
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/**
|
|
@@ -156,7 +165,7 @@ export class Connection {
|
|
|
156
165
|
// TODO(dmaretskyi): Piped streams should do this automatically, but it break's without this code.
|
|
157
166
|
this._protocol.stream.on('close', () => {
|
|
158
167
|
log('protocol stream closed');
|
|
159
|
-
this.close().catch((err) => this.errors.raise(err));
|
|
168
|
+
this.close(new ProtocolError('protocol stream closed')).catch((err) => this.errors.raise(err));
|
|
160
169
|
});
|
|
161
170
|
|
|
162
171
|
invariant(!this._transport);
|
|
@@ -179,13 +188,19 @@ export class Connection {
|
|
|
179
188
|
|
|
180
189
|
this._transport.errors.handle((err) => {
|
|
181
190
|
log('transport error:', { err });
|
|
182
|
-
// TODO(nf): collect a list of errors?
|
|
183
191
|
if (!this.closeReason) {
|
|
184
192
|
this.closeReason = err?.message;
|
|
185
193
|
}
|
|
186
|
-
|
|
187
|
-
|
|
194
|
+
|
|
195
|
+
// TODO(nf): fix ErrorStream so instanceof works here
|
|
196
|
+
if (err instanceof ConnectionResetError) {
|
|
197
|
+
log('aborting due to transport ConnectionResetError');
|
|
188
198
|
this.abort().catch((err) => this.errors.raise(err));
|
|
199
|
+
} else if (err instanceof ConnectivityError) {
|
|
200
|
+
log('aborting due to transport ConnectivityError');
|
|
201
|
+
this.abort().catch((err) => this.errors.raise(err));
|
|
202
|
+
} else if (err instanceof UnknownProtocolError) {
|
|
203
|
+
log('unsure what to do for UnknownProtocolError', { err });
|
|
189
204
|
}
|
|
190
205
|
|
|
191
206
|
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
@@ -207,15 +222,15 @@ export class Connection {
|
|
|
207
222
|
// TODO(nf): make the caller responsible for recording the reason and determining flow control.
|
|
208
223
|
async abort(err?: Error) {
|
|
209
224
|
log('aborting...', { err });
|
|
225
|
+
if (this._state === ConnectionState.CLOSED || this._state === ConnectionState.ABORTED) {
|
|
226
|
+
log(`abort ignored: already ${this._state}`, this.closeReason);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
this._changeState(ConnectionState.ABORTING);
|
|
210
231
|
if (!this.closeReason) {
|
|
211
232
|
this.closeReason = err?.message;
|
|
212
233
|
}
|
|
213
|
-
if (this._state === ConnectionState.CLOSED) {
|
|
214
|
-
log('abort ignored: already closed', this.closeReason);
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
// TODO(nf): different state?
|
|
218
|
-
this._changeState(ConnectionState.CLOSING);
|
|
219
234
|
|
|
220
235
|
await this._ctx.dispose();
|
|
221
236
|
|
|
@@ -234,8 +249,12 @@ export class Connection {
|
|
|
234
249
|
log.catch(err);
|
|
235
250
|
}
|
|
236
251
|
|
|
237
|
-
|
|
238
|
-
|
|
252
|
+
try {
|
|
253
|
+
this._callbacks?.onClosed?.(err);
|
|
254
|
+
} catch (err) {
|
|
255
|
+
log.catch(err);
|
|
256
|
+
}
|
|
257
|
+
this._changeState(ConnectionState.ABORTED);
|
|
239
258
|
}
|
|
240
259
|
|
|
241
260
|
@synchronized
|
|
@@ -243,27 +262,34 @@ export class Connection {
|
|
|
243
262
|
if (!this.closeReason) {
|
|
244
263
|
this.closeReason = err?.message;
|
|
245
264
|
}
|
|
246
|
-
if (
|
|
265
|
+
if (
|
|
266
|
+
this._state === ConnectionState.CLOSED ||
|
|
267
|
+
this._state === ConnectionState.ABORTING ||
|
|
268
|
+
this._state === ConnectionState.ABORTED
|
|
269
|
+
) {
|
|
247
270
|
return;
|
|
248
271
|
}
|
|
272
|
+
const lastState = this._state;
|
|
249
273
|
this._changeState(ConnectionState.CLOSING);
|
|
250
274
|
|
|
251
275
|
await this._ctx.dispose();
|
|
252
276
|
|
|
253
277
|
log('closing...', { peerId: this.ownId });
|
|
254
278
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
279
|
+
if (lastState === ConnectionState.CONNECTED) {
|
|
280
|
+
try {
|
|
281
|
+
// Gracefully close the stream flushing any unsent data packets.
|
|
282
|
+
await this._protocol.close();
|
|
283
|
+
} catch (err: any) {
|
|
284
|
+
log.catch(err);
|
|
285
|
+
}
|
|
261
286
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
287
|
+
try {
|
|
288
|
+
// After the transport is closed streams are disconnected.
|
|
289
|
+
await this._transport?.destroy();
|
|
290
|
+
} catch (err: any) {
|
|
291
|
+
log.catch(err);
|
|
292
|
+
}
|
|
267
293
|
}
|
|
268
294
|
|
|
269
295
|
log('closed', { peerId: this.ownId });
|
|
@@ -343,7 +369,7 @@ export class Connection {
|
|
|
343
369
|
}
|
|
344
370
|
|
|
345
371
|
private _changeState(state: ConnectionState): void {
|
|
346
|
-
log('stateChanged', { from: this._state,
|
|
372
|
+
log('stateChanged', { from: this._state, to: state, peerId: this.ownId });
|
|
347
373
|
invariant(state !== this._state, 'Already in this state.');
|
|
348
374
|
this._state = state;
|
|
349
375
|
this.stateChanged.emit(state);
|
package/src/swarm/peer.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Event, scheduleTask, synchronized } from '@dxos/async';
|
|
6
6
|
import { Context } from '@dxos/context';
|
|
7
|
-
import { CancelledError, SystemError } from '@dxos/errors';
|
|
7
|
+
import { CancelledError, SystemError, TimeoutError } from '@dxos/errors';
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { log } from '@dxos/log';
|
|
@@ -194,6 +194,9 @@ export class Peer {
|
|
|
194
194
|
this._callbacks.onAccepted();
|
|
195
195
|
} catch (err: any) {
|
|
196
196
|
log('initiation error', { err, topic: this.topic, peerId: this.localPeerId, remoteId: this.id });
|
|
197
|
+
if (err instanceof TimeoutError) {
|
|
198
|
+
await connection.abort(err);
|
|
199
|
+
}
|
|
197
200
|
// Calls `onStateChange` with CLOSED state.
|
|
198
201
|
await this.closeConnection(err);
|
|
199
202
|
throw err;
|
|
@@ -8,6 +8,13 @@ import { Event } from '@dxos/async';
|
|
|
8
8
|
import { Stream } from '@dxos/codec-protobuf';
|
|
9
9
|
import { Context } from '@dxos/context';
|
|
10
10
|
import { ErrorStream } from '@dxos/debug';
|
|
11
|
+
import {
|
|
12
|
+
ConnectionResetError,
|
|
13
|
+
TimeoutError,
|
|
14
|
+
ProtocolError,
|
|
15
|
+
ConnectivityError,
|
|
16
|
+
UnknownProtocolError,
|
|
17
|
+
} from '@dxos/errors';
|
|
11
18
|
import { invariant } from '@dxos/invariant';
|
|
12
19
|
import { PublicKey } from '@dxos/keys';
|
|
13
20
|
import { log } from '@dxos/log';
|
|
@@ -78,7 +85,7 @@ export class SimplePeerTransportProxy implements Transport {
|
|
|
78
85
|
|
|
79
86
|
private async _handleConnection(connectionEvent: BridgeEvent.ConnectionEvent): Promise<void> {
|
|
80
87
|
if (connectionEvent.error) {
|
|
81
|
-
this.errors.raise(
|
|
88
|
+
this.errors.raise(decodeError(connectionEvent.error));
|
|
82
89
|
}
|
|
83
90
|
|
|
84
91
|
switch (connectionEvent.state) {
|
|
@@ -108,7 +115,7 @@ export class SimplePeerTransportProxy implements Transport {
|
|
|
108
115
|
proxyId: this._proxyId,
|
|
109
116
|
signal,
|
|
110
117
|
})
|
|
111
|
-
.catch((err) => this.errors.raise(err));
|
|
118
|
+
.catch((err) => this.errors.raise(decodeError(err)));
|
|
112
119
|
}
|
|
113
120
|
|
|
114
121
|
// TODO(burdon): Move open from constructor.
|
|
@@ -173,3 +180,22 @@ export class SimplePeerTransportProxyFactory implements TransportFactory {
|
|
|
173
180
|
return transport;
|
|
174
181
|
}
|
|
175
182
|
}
|
|
183
|
+
|
|
184
|
+
// TODO(nf): fix so Errors crossing RPC boundary preserve class
|
|
185
|
+
const decodeError = (err: Error | string) => {
|
|
186
|
+
const message = typeof err === 'string' ? err : err.message;
|
|
187
|
+
|
|
188
|
+
if (message.includes('ConnectionResetError')) {
|
|
189
|
+
return new ConnectionResetError(message);
|
|
190
|
+
} else if (message.includes('TimeoutError')) {
|
|
191
|
+
return new TimeoutError(message);
|
|
192
|
+
} else if (message.includes('ProtocolError')) {
|
|
193
|
+
return new ProtocolError(message);
|
|
194
|
+
} else if (message.includes('ConnectivityError')) {
|
|
195
|
+
return new ConnectivityError(message);
|
|
196
|
+
} else if (message.includes('UnknownProtocolError')) {
|
|
197
|
+
return new UnknownProtocolError(message);
|
|
198
|
+
} else {
|
|
199
|
+
return typeof err === 'string' ? new Error(err) : err;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-fallthrough */
|
|
1
2
|
//
|
|
2
3
|
// Copyright 2020 DXOS.org
|
|
3
4
|
//
|
|
@@ -7,6 +8,7 @@ import invariant from 'tiny-invariant';
|
|
|
7
8
|
|
|
8
9
|
import { Event } from '@dxos/async';
|
|
9
10
|
import { ErrorStream, raise } from '@dxos/debug';
|
|
11
|
+
import { ConnectionResetError, ConnectivityError, ProtocolError, UnknownProtocolError } from '@dxos/errors';
|
|
10
12
|
import { PublicKey } from '@dxos/keys';
|
|
11
13
|
import { log } from '@dxos/log';
|
|
12
14
|
import { trace } from '@dxos/protocols';
|
|
@@ -63,7 +65,40 @@ export class SimplePeerTransport implements Transport {
|
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
this._peer.on('error', async (err) => {
|
|
66
|
-
|
|
68
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/RTCError
|
|
69
|
+
if (typeof RTCError !== 'undefined' && err instanceof RTCError) {
|
|
70
|
+
// Sent when connection is unexpectedly severed
|
|
71
|
+
if (err.errorDetail === 'sctp-failure') {
|
|
72
|
+
this.errors.raise(new ConnectionResetError('sctp-failure from RTCError', err));
|
|
73
|
+
} else {
|
|
74
|
+
this.errors.raise(new UnknownProtocolError('unknown RTCError', err));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Safari specific? are all errors of code: "DATA_CHANNEL_ERROR" connection aborts?
|
|
78
|
+
} else if (err.name === 'InvalidStateError') {
|
|
79
|
+
this.errors.raise(new ConnectionResetError('safari WebRTC error', err));
|
|
80
|
+
// catch more generic simple-peer errors: https://github.com/feross/simple-peer/blob/master/README.md#error-codes
|
|
81
|
+
} else if ('code' in err) {
|
|
82
|
+
switch (err.code) {
|
|
83
|
+
case 'ERR_WEBRTC_SUPPORT':
|
|
84
|
+
this.errors.raise(new ProtocolError('WebRTC not supported', err));
|
|
85
|
+
case 'ERR_ICE_CONNECTION_FAILURE':
|
|
86
|
+
case 'ERR_DATA_CHANNEL':
|
|
87
|
+
case 'ERR_CONNECTION_FAILURE':
|
|
88
|
+
case 'ERR_SIGNALING':
|
|
89
|
+
this.errors.raise(new ConnectivityError('unknown communication failure', err));
|
|
90
|
+
case 'ERR_CREATE_OFFER':
|
|
91
|
+
case 'ERR_CREATE_ANSWER':
|
|
92
|
+
case 'ERR_SET_LOCAL_DESCRIPTION':
|
|
93
|
+
case 'ERR_SET_REMOTE_DESCRIPTION':
|
|
94
|
+
case 'ERR_ADD_ICE_CANDIDATE':
|
|
95
|
+
this.errors.raise(new UnknownProtocolError('unknown simple-peer library failure', err));
|
|
96
|
+
default:
|
|
97
|
+
this.errors.raise(new Error('unknown simple-peer error'));
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
this.errors.raise(err);
|
|
101
|
+
}
|
|
67
102
|
|
|
68
103
|
// Try to gather additional information about the connection.
|
|
69
104
|
try {
|
|
@@ -75,7 +110,9 @@ export class SimplePeerTransport implements Transport {
|
|
|
75
110
|
});
|
|
76
111
|
});
|
|
77
112
|
}
|
|
78
|
-
} catch
|
|
113
|
+
} catch (err) {
|
|
114
|
+
log.catch(err);
|
|
115
|
+
}
|
|
79
116
|
|
|
80
117
|
await this.destroy();
|
|
81
118
|
});
|