@dxos/network-manager 0.3.9-main.3a0f16f → 0.3.9-main.3fcc0fa
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-4HITD6WI.mjs → chunk-KGZ5C6JO.mjs} +324 -87
- package/dist/lib/browser/chunk-KGZ5C6JO.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 +1 -1
- package/dist/lib/node/{chunk-XE5JOIGD.cjs → chunk-JDKM4UPJ.cjs} +21 -13
- package/dist/lib/node/chunk-JDKM4UPJ.cjs.map +7 -0
- package/dist/lib/node/{chunk-6AD7QA4X.cjs → chunk-WUBZ4UOJ.cjs} +333 -86
- package/dist/lib/node/chunk-WUBZ4UOJ.cjs.map +7 -0
- package/dist/lib/node/{datachannel-53JZPGFA.cjs → datachannel-3VTTIMR5.cjs} +9 -9
- package/dist/lib/node/{datachannel-53JZPGFA.cjs.map → datachannel-3VTTIMR5.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +32 -32
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +19 -19
- package/dist/types/src/connection-log.d.ts.map +1 -1
- package/dist/types/src/swarm/connection.d.ts +4 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/topology/mmst-topology.d.ts +1 -0
- package/dist/types/src/topology/mmst-topology.d.ts.map +1 -1
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts +7 -0
- package/dist/types/src/transport/datachannel/rtc-peer-connection.d.ts.map +1 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts +3 -1
- package/dist/types/src/transport/libdatachannel-transport.d.ts.map +1 -1
- package/dist/types/src/transport/memory-transport.d.ts +3 -1
- package/dist/types/src/transport/memory-transport.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-proxy.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts +3 -1
- package/dist/types/src/transport/simplepeer-transport-service.d.ts.map +1 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts +7 -1
- package/dist/types/src/transport/simplepeer-transport.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts +3 -1
- package/dist/types/src/transport/tcp-transport.browser.d.ts.map +1 -1
- package/dist/types/src/transport/tcp-transport.d.ts +3 -1
- package/dist/types/src/transport/tcp-transport.d.ts.map +1 -1
- package/dist/types/src/transport/transport.d.ts +17 -0
- package/dist/types/src/transport/transport.d.ts.map +1 -1
- package/dist/types/src/wire-protocol.d.ts +1 -1
- package/dist/types/src/wire-protocol.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/connection-log.ts +14 -1
- package/src/swarm/connection.ts +23 -4
- package/src/topology/mmst-topology.ts +34 -6
- package/src/transport/datachannel/rtc-peer-connection.ts +20 -12
- package/src/transport/libdatachannel-transport.test.ts +0 -4
- package/src/transport/libdatachannel-transport.ts +37 -1
- package/src/transport/memory-transport.ts +14 -1
- package/src/transport/simplepeer-transport-proxy.ts +9 -1
- package/src/transport/simplepeer-transport-service.ts +14 -0
- package/src/transport/simplepeer-transport.ts +66 -3
- package/src/transport/tcp-transport.browser.ts +9 -1
- package/src/transport/tcp-transport.ts +19 -1
- package/src/transport/transport.ts +19 -0
- package/src/wire-protocol.ts +3 -3
- package/dist/lib/browser/chunk-4HITD6WI.mjs.map +0 -7
- package/dist/lib/node/chunk-6AD7QA4X.cjs.map +0 -7
- package/dist/lib/node/chunk-XE5JOIGD.cjs.map +0 -7
|
@@ -13,7 +13,7 @@ import { log } from '@dxos/log';
|
|
|
13
13
|
import { ConnectionResetError, ConnectivityError, ProtocolError, UnknownProtocolError, trace } from '@dxos/protocols';
|
|
14
14
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
15
15
|
|
|
16
|
-
import { type Transport, type TransportFactory } from './transport';
|
|
16
|
+
import { type Transport, type TransportFactory, type TransportStats } from './transport';
|
|
17
17
|
import { wrtc } from './webrtc';
|
|
18
18
|
|
|
19
19
|
export type SimplePeerTransportParams = {
|
|
@@ -37,6 +37,9 @@ export class SimplePeerTransport implements Transport {
|
|
|
37
37
|
|
|
38
38
|
private readonly _instanceId = PublicKey.random().toHex();
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @params opts.config formatted as per https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
|
42
|
+
*/
|
|
40
43
|
constructor(private readonly params: SimplePeerTransportParams) {
|
|
41
44
|
log.trace('dxos.mesh.webrtc-transport.constructor', trace.begin({ id: this._instanceId }));
|
|
42
45
|
log('created connection', params);
|
|
@@ -112,7 +115,7 @@ export class SimplePeerTransport implements Transport {
|
|
|
112
115
|
(this._peer as any)._pc.getStats().then((stats: any) => {
|
|
113
116
|
log.info('report after webrtc error', {
|
|
114
117
|
config: this.params.webrtcConfig,
|
|
115
|
-
stats,
|
|
118
|
+
stats: Object.fromEntries((stats as any).entries()),
|
|
116
119
|
});
|
|
117
120
|
});
|
|
118
121
|
}
|
|
@@ -122,17 +125,77 @@ export class SimplePeerTransport implements Transport {
|
|
|
122
125
|
|
|
123
126
|
await this.destroy();
|
|
124
127
|
});
|
|
128
|
+
|
|
125
129
|
log.trace('dxos.mesh.webrtc-transport.constructor', trace.end({ id: this._instanceId }));
|
|
126
130
|
}
|
|
127
131
|
|
|
132
|
+
async getStats(): Promise<TransportStats> {
|
|
133
|
+
const stats = await this._getStats();
|
|
134
|
+
if (!stats) {
|
|
135
|
+
return {
|
|
136
|
+
bytesSent: 0,
|
|
137
|
+
bytesReceived: 0,
|
|
138
|
+
packetsSent: 0,
|
|
139
|
+
packetsReceived: 0,
|
|
140
|
+
rawStats: {},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// TODO(nf): transport or candidatePair?
|
|
145
|
+
return {
|
|
146
|
+
bytesSent: stats.transport.bytesSent,
|
|
147
|
+
bytesReceived: stats.transport.bytesReceived,
|
|
148
|
+
packetsSent: stats.transport.messagesSent,
|
|
149
|
+
packetsReceived: stats.transport.messagesReceived,
|
|
150
|
+
rawStats: stats.raw,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async _getStats(): Promise<any> {
|
|
155
|
+
if (typeof (this._peer as any)?._pc?.getStats !== 'function') {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
return await (this._peer as any)._pc.getStats().then((stats: any) => {
|
|
159
|
+
const statsEntries = Array.from(stats.entries() as any[]);
|
|
160
|
+
const transport = statsEntries.filter((s: any) => s[1].type === 'transport')[0][1];
|
|
161
|
+
const candidatePair = statsEntries.filter((s: any) => s[0] === transport.selectedCandidatePairId);
|
|
162
|
+
let selectedCandidatePair: any;
|
|
163
|
+
let remoteCandidate: any;
|
|
164
|
+
if (candidatePair.length > 0) {
|
|
165
|
+
selectedCandidatePair = candidatePair[0][1];
|
|
166
|
+
remoteCandidate = statsEntries.filter((s: any) => s[0] === selectedCandidatePair.remoteCandidateId)[0][1];
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
datachannel: statsEntries.filter((s: any) => s[1].type === 'data-channel')[0][1],
|
|
170
|
+
transport,
|
|
171
|
+
selectedCandidatePair,
|
|
172
|
+
remoteCandidate,
|
|
173
|
+
raw: Object.fromEntries(stats.entries()),
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async getDetails(): Promise<string> {
|
|
179
|
+
const stats = await this._getStats();
|
|
180
|
+
const rc = stats?.remoteCandidate;
|
|
181
|
+
if (!rc) {
|
|
182
|
+
return 'unavailable';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (rc.candidateType === 'relay') {
|
|
186
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} relay for ${rc.relatedAddress}:${rc.relatedPort}`;
|
|
187
|
+
}
|
|
188
|
+
return `${rc.ip}:${rc.port}/${rc.protocol} ${rc.candidateType}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
128
191
|
async destroy() {
|
|
129
192
|
log('closing...');
|
|
130
193
|
if (this._closed) {
|
|
131
194
|
return;
|
|
132
195
|
}
|
|
133
|
-
this._closed = true;
|
|
134
196
|
this._disconnectStreams();
|
|
135
197
|
this._peer!.destroy();
|
|
198
|
+
this._closed = true;
|
|
136
199
|
this.closed.emit();
|
|
137
200
|
log('closed');
|
|
138
201
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Event } from '@dxos/async';
|
|
6
6
|
import { ErrorStream } from '@dxos/debug';
|
|
7
7
|
|
|
8
|
-
import { type Transport, type TransportFactory } from './transport';
|
|
8
|
+
import { type Transport, type TransportFactory, type TransportStats } from './transport';
|
|
9
9
|
|
|
10
10
|
// NOTE: Browser stub.
|
|
11
11
|
|
|
@@ -25,4 +25,12 @@ export class TcpTransport implements Transport {
|
|
|
25
25
|
signal() {
|
|
26
26
|
throw new Error('Method not implemented.');
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
async getStats(): Promise<TransportStats> {
|
|
30
|
+
throw new Error('Method not implemented.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getDetails(): Promise<string> {
|
|
34
|
+
throw new Error('Method not implemented.');
|
|
35
|
+
}
|
|
28
36
|
}
|
|
@@ -9,7 +9,7 @@ import { ErrorStream } from '@dxos/debug';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
11
11
|
|
|
12
|
-
import { type Transport, type TransportFactory, type TransportOptions } from './transport';
|
|
12
|
+
import { type Transport, type TransportFactory, type TransportOptions, type TransportStats } from './transport';
|
|
13
13
|
|
|
14
14
|
export const TcpTransportFactory: TransportFactory = {
|
|
15
15
|
createTransport: (params) => new TcpTransport(params),
|
|
@@ -87,6 +87,24 @@ export class TcpTransport implements Transport {
|
|
|
87
87
|
socket.connect({ port: payload.port, host: 'localhost' });
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
async getDetails(): Promise<string> {
|
|
91
|
+
if (this.options.initiator) {
|
|
92
|
+
const { port, address } = this._server?.address() as AddressInfo;
|
|
93
|
+
return `LISTEN ${address}:${port}`;
|
|
94
|
+
}
|
|
95
|
+
const { port, address } = this._socket?.address() as AddressInfo;
|
|
96
|
+
return `ACCEPT ${address}:${port}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async getStats(): Promise<TransportStats> {
|
|
100
|
+
return {
|
|
101
|
+
bytesSent: 0,
|
|
102
|
+
bytesReceived: 0,
|
|
103
|
+
packetsSent: 0,
|
|
104
|
+
packetsReceived: 0,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
90
108
|
private _handleSocket(socket: Socket) {
|
|
91
109
|
log('handling socket', { remotePort: socket.remotePort, localPort: socket.localPort });
|
|
92
110
|
this._socket = socket;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Event } from '@dxos/async';
|
|
6
6
|
import { type ErrorStream } from '@dxos/debug';
|
|
7
|
+
import { type PublicKey } from '@dxos/keys';
|
|
7
8
|
import { type Signal } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
8
9
|
|
|
9
10
|
export enum TransportKind {
|
|
@@ -22,6 +23,14 @@ export interface Transport {
|
|
|
22
23
|
connected: Event;
|
|
23
24
|
errors: ErrorStream;
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Transport-specfic stats.
|
|
28
|
+
*/
|
|
29
|
+
getStats(): Promise<TransportStats>;
|
|
30
|
+
/**
|
|
31
|
+
* Transport-specfic connection details.
|
|
32
|
+
*/
|
|
33
|
+
getDetails(): Promise<string>;
|
|
25
34
|
destroy(): Promise<void>;
|
|
26
35
|
signal(signal: Signal): void;
|
|
27
36
|
}
|
|
@@ -43,6 +52,8 @@ export type TransportOptions = {
|
|
|
43
52
|
sendSignal: (signal: Signal) => Promise<void>; // TODO(burdon): Remove async?
|
|
44
53
|
|
|
45
54
|
timeout?: number;
|
|
55
|
+
|
|
56
|
+
sessionId?: PublicKey;
|
|
46
57
|
};
|
|
47
58
|
|
|
48
59
|
/**
|
|
@@ -51,3 +62,11 @@ export type TransportOptions = {
|
|
|
51
62
|
export interface TransportFactory {
|
|
52
63
|
createTransport(options: TransportOptions): Transport;
|
|
53
64
|
}
|
|
65
|
+
|
|
66
|
+
export type TransportStats = {
|
|
67
|
+
bytesSent: number;
|
|
68
|
+
bytesReceived: number;
|
|
69
|
+
packetsSent: number;
|
|
70
|
+
packetsReceived: number;
|
|
71
|
+
rawStats?: any;
|
|
72
|
+
};
|
package/src/wire-protocol.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type WireProtocolProvider = (params: WireProtocolParams) => WireProtocol;
|
|
|
23
23
|
export interface WireProtocol {
|
|
24
24
|
stream: Duplex;
|
|
25
25
|
|
|
26
|
-
open(): Promise<void>;
|
|
26
|
+
open(sessionId?: PublicKey): Promise<void>;
|
|
27
27
|
close(): Promise<void>;
|
|
28
28
|
abort(): Promise<void>;
|
|
29
29
|
}
|
|
@@ -40,8 +40,8 @@ export const createTeleportProtocolFactory = (
|
|
|
40
40
|
const teleport = new Teleport(params);
|
|
41
41
|
return {
|
|
42
42
|
stream: teleport.stream,
|
|
43
|
-
open: async () => {
|
|
44
|
-
await teleport.open();
|
|
43
|
+
open: async (sessionId?: PublicKey) => {
|
|
44
|
+
await teleport.open(sessionId);
|
|
45
45
|
await onConnection(teleport);
|
|
46
46
|
},
|
|
47
47
|
close: async () => {
|