@dxos/network-manager 0.1.58-next.3349da8 → 0.1.58-next.ffb4cc4
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-PSWNMALH.mjs → chunk-3KLH55NB.mjs} +155 -94
- package/dist/lib/browser/chunk-3KLH55NB.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +5 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +19 -148
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/index.cjs +631 -458
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +957 -917
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/swarm/connection-limiter.d.ts +1 -1
- package/dist/types/src/swarm/connection-limiter.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +3 -3
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm-mapper.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts +2 -2
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/dist/types/src/testing/test-builder.d.ts +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/topology/star-topology.d.ts.map +1 -1
- package/dist/types/src/transport/index.d.ts +1 -0
- package/dist/types/src/transport/index.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-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +12 -0
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -0
- package/package.json +18 -18
- package/src/swarm/connection-limiter.ts +2 -2
- package/src/swarm/connection.test.ts +1 -1
- package/src/swarm/connection.ts +9 -8
- package/src/swarm/peer.ts +8 -3
- package/src/swarm/swarm-mapper.ts +4 -7
- package/src/swarm/swarm.test.ts +3 -3
- package/src/swarm/swarm.ts +3 -3
- package/src/testing/test-builder.ts +1 -1
- package/src/tests/basic-test-suite.ts +1 -1
- package/src/tests/memory-transport.test.ts +2 -2
- package/src/tests/tcp-transport.test.ts +2 -2
- package/src/tests/webrtc-transport.test.ts +1 -1
- package/src/topology/star-topology.ts +1 -4
- package/src/transport/index.ts +1 -0
- package/src/transport/simplepeer-transport-proxy.ts +29 -28
- package/src/transport/simplepeer-transport-service.ts +9 -5
- package/src/transport/simplepeer-transport.ts +9 -7
- package/src/transport/tcp-transport.browser.ts +28 -0
- package/dist/lib/browser/chunk-PSWNMALH.mjs.map +0 -7
|
@@ -8,16 +8,16 @@ 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 { invariant } from '@dxos/invariant';
|
|
12
|
+
import { PublicKey } from '@dxos/keys';
|
|
13
|
+
import { log } from '@dxos/log';
|
|
11
14
|
import {
|
|
12
15
|
ConnectionResetError,
|
|
13
16
|
TimeoutError,
|
|
14
17
|
ProtocolError,
|
|
15
18
|
ConnectivityError,
|
|
16
19
|
UnknownProtocolError,
|
|
17
|
-
} from '@dxos/
|
|
18
|
-
import { invariant } from '@dxos/invariant';
|
|
19
|
-
import { PublicKey } from '@dxos/keys';
|
|
20
|
-
import { log } from '@dxos/log';
|
|
20
|
+
} from '@dxos/protocols';
|
|
21
21
|
import { ConnectionState, BridgeEvent, BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
|
|
22
22
|
import { Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
23
23
|
import { arrayToBuffer } from '@dxos/util';
|
|
@@ -43,13 +43,10 @@ export class SimplePeerTransportProxy implements Transport {
|
|
|
43
43
|
private _closed = false;
|
|
44
44
|
private _serviceStream!: Stream<BridgeEvent>;
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
private readonly _params: SimplePeerTransportProxyParams
|
|
49
|
-
) {
|
|
46
|
+
constructor(private readonly _params: SimplePeerTransportProxyParams) {
|
|
50
47
|
this._serviceStream = this._params.bridgeService.open({
|
|
51
48
|
proxyId: this._proxyId,
|
|
52
|
-
initiator: this._params.initiator
|
|
49
|
+
initiator: this._params.initiator,
|
|
53
50
|
});
|
|
54
51
|
|
|
55
52
|
this._serviceStream.waitUntilReady().then(
|
|
@@ -65,21 +62,25 @@ export class SimplePeerTransportProxy implements Transport {
|
|
|
65
62
|
}
|
|
66
63
|
});
|
|
67
64
|
|
|
68
|
-
this._params.stream.pipe(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
this._params.stream.pipe(
|
|
66
|
+
new Writable({
|
|
67
|
+
write: (chunk, _, callback) => {
|
|
68
|
+
this._params.bridgeService
|
|
69
|
+
.sendData({
|
|
70
|
+
proxyId: this._proxyId,
|
|
71
|
+
payload: chunk,
|
|
72
|
+
})
|
|
73
|
+
.then(
|
|
74
|
+
() => callback(),
|
|
75
|
+
(err: any) => {
|
|
76
|
+
log.catch(err);
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
);
|
|
81
82
|
},
|
|
82
|
-
(error) => log.catch(error)
|
|
83
|
+
(error) => log.catch(error),
|
|
83
84
|
);
|
|
84
85
|
}
|
|
85
86
|
|
|
@@ -185,15 +186,15 @@ export class SimplePeerTransportProxyFactory implements TransportFactory {
|
|
|
185
186
|
const decodeError = (err: Error | string) => {
|
|
186
187
|
const message = typeof err === 'string' ? err : err.message;
|
|
187
188
|
|
|
188
|
-
if (message.includes('
|
|
189
|
+
if (message.includes('CONNECTION_RESET')) {
|
|
189
190
|
return new ConnectionResetError(message);
|
|
190
|
-
} else if (message.includes('
|
|
191
|
+
} else if (message.includes('TIMEOUT')) {
|
|
191
192
|
return new TimeoutError(message);
|
|
192
|
-
} else if (message.includes('
|
|
193
|
+
} else if (message.includes('PROTOCOL_ERROR')) {
|
|
193
194
|
return new ProtocolError(message);
|
|
194
|
-
} else if (message.includes('
|
|
195
|
+
} else if (message.includes('CONNECTIVITY_ERROR')) {
|
|
195
196
|
return new ConnectivityError(message);
|
|
196
|
-
} else if (message.includes('
|
|
197
|
+
} else if (message.includes('UNKNOWN_PROTOCOL_ERROR')) {
|
|
197
198
|
return new UnknownProtocolError(message);
|
|
198
199
|
} else {
|
|
199
200
|
return typeof err === 'string' ? new Error(err) : err;
|
|
@@ -25,15 +25,13 @@ type TransportState = {
|
|
|
25
25
|
transport: SimplePeerTransport;
|
|
26
26
|
stream: Duplex;
|
|
27
27
|
writeCallbacks: (() => void)[];
|
|
28
|
+
state: 'OPEN' | 'CLOSED';
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export class SimplePeerTransportService implements BridgeService {
|
|
31
32
|
private readonly transports = new ComplexMap<PublicKey, TransportState>(PublicKey.hash);
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
constructor(
|
|
35
|
-
private readonly _webrtcConfig?: any
|
|
36
|
-
) { }
|
|
34
|
+
constructor(private readonly _webrtcConfig?: any) {}
|
|
37
35
|
|
|
38
36
|
open(request: ConnectionRequest): Stream<BridgeEvent> {
|
|
39
37
|
const rpcStream: Stream<BridgeEvent> = new Stream(({ ready, next, close }) => {
|
|
@@ -99,6 +97,7 @@ export class SimplePeerTransportService implements BridgeService {
|
|
|
99
97
|
transport,
|
|
100
98
|
stream: duplex,
|
|
101
99
|
writeCallbacks: [],
|
|
100
|
+
state: 'OPEN',
|
|
102
101
|
};
|
|
103
102
|
|
|
104
103
|
ready();
|
|
@@ -115,6 +114,9 @@ export class SimplePeerTransportService implements BridgeService {
|
|
|
115
114
|
}
|
|
116
115
|
|
|
117
116
|
async sendData({ proxyId, payload }: DataRequest): Promise<void> {
|
|
117
|
+
if (this.transports.get(proxyId)?.state !== 'OPEN') {
|
|
118
|
+
log.debug('transport is closed');
|
|
119
|
+
}
|
|
118
120
|
invariant(this.transports.has(proxyId));
|
|
119
121
|
const state = this.transports.get(proxyId)!;
|
|
120
122
|
const bufferHasSpace = state.stream.push(payload);
|
|
@@ -128,7 +130,9 @@ export class SimplePeerTransportService implements BridgeService {
|
|
|
128
130
|
async close({ proxyId }: CloseRequest) {
|
|
129
131
|
await this.transports.get(proxyId)?.transport.destroy();
|
|
130
132
|
await this.transports.get(proxyId)?.stream.end();
|
|
131
|
-
this.transports.
|
|
133
|
+
if (this.transports.get(proxyId)) {
|
|
134
|
+
this.transports.get(proxyId)!.state = 'CLOSED';
|
|
135
|
+
}
|
|
132
136
|
log('Closed.');
|
|
133
137
|
}
|
|
134
138
|
}
|
|
@@ -8,10 +8,9 @@ import invariant from 'tiny-invariant';
|
|
|
8
8
|
|
|
9
9
|
import { Event } from '@dxos/async';
|
|
10
10
|
import { ErrorStream, raise } from '@dxos/debug';
|
|
11
|
-
import { ConnectionResetError, ConnectivityError, ProtocolError, UnknownProtocolError } from '@dxos/errors';
|
|
12
11
|
import { PublicKey } from '@dxos/keys';
|
|
13
12
|
import { log } from '@dxos/log';
|
|
14
|
-
import { trace } from '@dxos/protocols';
|
|
13
|
+
import { ConnectionResetError, ConnectivityError, ProtocolError, UnknownProtocolError, trace } from '@dxos/protocols';
|
|
15
14
|
import { Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
16
15
|
|
|
17
16
|
import { Transport, TransportFactory } from './transport';
|
|
@@ -73,36 +72,39 @@ export class SimplePeerTransport implements Transport {
|
|
|
73
72
|
} else {
|
|
74
73
|
this.errors.raise(new UnknownProtocolError('unknown RTCError', err));
|
|
75
74
|
}
|
|
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
75
|
// catch more generic simple-peer errors: https://github.com/feross/simple-peer/blob/master/README.md#error-codes
|
|
81
76
|
} else if ('code' in err) {
|
|
77
|
+
log.info('simple-peer error', err);
|
|
82
78
|
switch (err.code) {
|
|
83
79
|
case 'ERR_WEBRTC_SUPPORT':
|
|
84
80
|
this.errors.raise(new ProtocolError('WebRTC not supported', err));
|
|
81
|
+
break;
|
|
85
82
|
case 'ERR_ICE_CONNECTION_FAILURE':
|
|
86
83
|
case 'ERR_DATA_CHANNEL':
|
|
87
84
|
case 'ERR_CONNECTION_FAILURE':
|
|
88
85
|
case 'ERR_SIGNALING':
|
|
89
86
|
this.errors.raise(new ConnectivityError('unknown communication failure', err));
|
|
87
|
+
break;
|
|
88
|
+
// errors due to library issues or improper API usage
|
|
90
89
|
case 'ERR_CREATE_OFFER':
|
|
91
90
|
case 'ERR_CREATE_ANSWER':
|
|
92
91
|
case 'ERR_SET_LOCAL_DESCRIPTION':
|
|
93
92
|
case 'ERR_SET_REMOTE_DESCRIPTION':
|
|
94
93
|
case 'ERR_ADD_ICE_CANDIDATE':
|
|
95
94
|
this.errors.raise(new UnknownProtocolError('unknown simple-peer library failure', err));
|
|
95
|
+
break;
|
|
96
96
|
default:
|
|
97
97
|
this.errors.raise(new Error('unknown simple-peer error'));
|
|
98
|
+
break;
|
|
98
99
|
}
|
|
99
100
|
} else {
|
|
101
|
+
log.info('unknown peer connection error', err);
|
|
100
102
|
this.errors.raise(err);
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
// Try to gather additional information about the connection.
|
|
104
106
|
try {
|
|
105
|
-
if (typeof (this._peer as any)?._pc
|
|
107
|
+
if (typeof (this._peer as any)?._pc?.getStats === 'function') {
|
|
106
108
|
(this._peer as any)._pc.getStats().then((stats: any) => {
|
|
107
109
|
log.warn('report after webrtc error', {
|
|
108
110
|
config: this.params.webrtcConfig,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Event } from '@dxos/async';
|
|
6
|
+
import { ErrorStream } from '@dxos/debug';
|
|
7
|
+
|
|
8
|
+
import { Transport, TransportFactory } from './transport';
|
|
9
|
+
|
|
10
|
+
// NOTE: Browser stub.
|
|
11
|
+
|
|
12
|
+
export const TcpTransportFactory: TransportFactory = {
|
|
13
|
+
createTransport: () => new TcpTransport(),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export class TcpTransport implements Transport {
|
|
17
|
+
public readonly closed = new Event<void>();
|
|
18
|
+
public readonly connected = new Event<void>();
|
|
19
|
+
public readonly errors = new ErrorStream();
|
|
20
|
+
|
|
21
|
+
async destroy() {
|
|
22
|
+
throw new Error('Method not implemented.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
signal() {
|
|
26
|
+
throw new Error('Method not implemented.');
|
|
27
|
+
}
|
|
28
|
+
}
|