@dxos/network-manager 0.3.1-main.5e68e9d → 0.3.1-main.b9bb100
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-54UAGQNZ.mjs → chunk-TRMX3E42.mjs} +105 -182
- package/dist/lib/browser/chunk-TRMX3E42.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/index.cjs +95 -172
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +95 -172
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/swarm/connection.d.ts +0 -1
- package/dist/types/src/swarm/connection.d.ts.map +1 -1
- package/dist/types/src/swarm/peer.d.ts +1 -1
- package/dist/types/src/swarm/peer.d.ts.map +1 -1
- package/dist/types/src/swarm/swarm.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/swarm/connection.ts +4 -26
- package/src/swarm/peer.ts +11 -47
- package/src/swarm/swarm.ts +7 -10
- package/dist/lib/browser/chunk-54UAGQNZ.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,
|
|
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;AAE1C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAYvC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAA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ChB,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;IA6Ed,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"}
|
|
@@ -84,7 +84,7 @@ export declare class Peer {
|
|
|
84
84
|
private _createConnection;
|
|
85
85
|
closeConnection(err?: Error): Promise<void>;
|
|
86
86
|
onSignal(message: SignalMessage): Promise<void>;
|
|
87
|
-
destroy(
|
|
87
|
+
destroy(): Promise<void>;
|
|
88
88
|
}
|
|
89
89
|
export {};
|
|
90
90
|
//# sourceMappingURL=peer.d.ts.map
|
|
@@ -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;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,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;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAkB,WAAW,E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Q,CAAC,WAAW,SAA8B;IAoBlD,QAAQ,CAAC,MAAM,cAAqB;gBAMjB,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,SAAS,EAC9B,SAAS,EAAE,QAAQ,EACV,iBAAiB,EAAE,oBAAoB,EACvC,UAAU,EAAE,SAAS,EACrB,iBAAiB,EAAE,gBAAgB,EACnC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,kBAAkB,EAAE,iBAAiB,EACrC,gBAAgB,SAAmB;IAkBtD,IAAI,WAAW,iBAId;IAED,IACI,SAAS,cAEZ;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAED,IACI,KAAK,IAAI,KAAK,CAEjB;IAEK,IAAI;IAaJ,OAAO;IAWP,WAAW,CAAC,QAAQ,EAAE,QAAQ;IAiBpC,YAAY,CAAC,UAAU,EAAE,UAAU;IA8B7B,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAwB/C,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB/C,SAAS;IAOT,QAAQ;IAId,OAAO,CAAC,gBAAgB;YAkDV,YAAY;IAM1B,OAAO,CAAC,mBAAmB;IAuC3B;;OAEG;YACW,mBAAmB;YA0BnB,gBAAgB;CAQ/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/network-manager",
|
|
3
|
-
"version": "0.3.1-main.
|
|
3
|
+
"version": "0.3.1-main.b9bb100",
|
|
4
4
|
"description": "Network Manager",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -31,21 +31,21 @@
|
|
|
31
31
|
"tiny-invariant": "^1.3.1",
|
|
32
32
|
"ws": "^7.4.4",
|
|
33
33
|
"xor-distance": "^2.0.0",
|
|
34
|
-
"@dxos/async": "0.3.1-main.
|
|
35
|
-
"@dxos/codec-protobuf": "0.3.1-main.
|
|
36
|
-
"@dxos/context": "0.3.1-main.
|
|
37
|
-
"@dxos/credentials": "0.3.1-main.
|
|
38
|
-
"@dxos/crypto": "0.3.1-main.
|
|
39
|
-
"@dxos/debug": "0.3.1-main.
|
|
40
|
-
"@dxos/invariant": "0.3.1-main.
|
|
41
|
-
"@dxos/keys": "0.3.1-main.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/rpc": "0.3.1-main.
|
|
47
|
-
"@dxos/teleport": "0.3.1-main.
|
|
48
|
-
"@dxos/util": "0.3.1-main.
|
|
34
|
+
"@dxos/async": "0.3.1-main.b9bb100",
|
|
35
|
+
"@dxos/codec-protobuf": "0.3.1-main.b9bb100",
|
|
36
|
+
"@dxos/context": "0.3.1-main.b9bb100",
|
|
37
|
+
"@dxos/credentials": "0.3.1-main.b9bb100",
|
|
38
|
+
"@dxos/crypto": "0.3.1-main.b9bb100",
|
|
39
|
+
"@dxos/debug": "0.3.1-main.b9bb100",
|
|
40
|
+
"@dxos/invariant": "0.3.1-main.b9bb100",
|
|
41
|
+
"@dxos/keys": "0.3.1-main.b9bb100",
|
|
42
|
+
"@dxos/messaging": "0.3.1-main.b9bb100",
|
|
43
|
+
"@dxos/node-std": "0.3.1-main.b9bb100",
|
|
44
|
+
"@dxos/protocols": "0.3.1-main.b9bb100",
|
|
45
|
+
"@dxos/log": "0.3.1-main.b9bb100",
|
|
46
|
+
"@dxos/rpc": "0.3.1-main.b9bb100",
|
|
47
|
+
"@dxos/teleport": "0.3.1-main.b9bb100",
|
|
48
|
+
"@dxos/util": "0.3.1-main.b9bb100"
|
|
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.3.1-main.
|
|
58
|
+
"@dxos/signal": "0.3.1-main.b9bb100"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public"
|
package/src/swarm/connection.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { DeferredTask, Event, sleep,
|
|
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
8
|
import { invariant } from '@dxos/invariant';
|
|
@@ -28,11 +28,6 @@ import { WireProtocol } from '../wire-protocol';
|
|
|
28
28
|
*/
|
|
29
29
|
const STARTING_SIGNALLING_DELAY = 10;
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* How long to wait for the transport to establish connectivity, i.e. for the connection to move between CONNECTING and CONNECTED.
|
|
33
|
-
*/
|
|
34
|
-
const TRANSPORT_CONNECTION_TIMEOUT = 10_000;
|
|
35
|
-
|
|
36
31
|
/**
|
|
37
32
|
* Maximum delay between signal batches.
|
|
38
33
|
*/
|
|
@@ -95,7 +90,6 @@ export enum ConnectionState {
|
|
|
95
90
|
*/
|
|
96
91
|
export class Connection {
|
|
97
92
|
private readonly _ctx = new Context();
|
|
98
|
-
private connectedTimeoutContext = new Context();
|
|
99
93
|
|
|
100
94
|
private _state: ConnectionState = ConnectionState.CREATED;
|
|
101
95
|
private _transport: Transport | undefined;
|
|
@@ -174,15 +168,6 @@ export class Connection {
|
|
|
174
168
|
this.close(new ProtocolError('protocol stream closed')).catch((err) => this.errors.raise(err));
|
|
175
169
|
});
|
|
176
170
|
|
|
177
|
-
scheduleTask(
|
|
178
|
-
this.connectedTimeoutContext,
|
|
179
|
-
async () => {
|
|
180
|
-
log.warn('timeout waiting for transport to connect, aborting');
|
|
181
|
-
await this.abort().catch((err) => this.errors.raise(err));
|
|
182
|
-
},
|
|
183
|
-
TRANSPORT_CONNECTION_TIMEOUT,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
171
|
invariant(!this._transport);
|
|
187
172
|
this._transport = this._transportFactory.createTransport({
|
|
188
173
|
initiator: this.initiator,
|
|
@@ -190,9 +175,8 @@ export class Connection {
|
|
|
190
175
|
sendSignal: async (signal) => this._sendSignal(signal),
|
|
191
176
|
});
|
|
192
177
|
|
|
193
|
-
this._transport.connected.once(
|
|
178
|
+
this._transport.connected.once(() => {
|
|
194
179
|
this._changeState(ConnectionState.CONNECTED);
|
|
195
|
-
await this.connectedTimeoutContext.dispose();
|
|
196
180
|
this._callbacks?.onConnected?.();
|
|
197
181
|
});
|
|
198
182
|
|
|
@@ -202,7 +186,7 @@ export class Connection {
|
|
|
202
186
|
this.abort().catch((err) => this.errors.raise(err));
|
|
203
187
|
});
|
|
204
188
|
|
|
205
|
-
this._transport.errors.handle(
|
|
189
|
+
this._transport.errors.handle((err) => {
|
|
206
190
|
log('transport error:', { err });
|
|
207
191
|
if (!this.closeReason) {
|
|
208
192
|
this.closeReason = err?.message;
|
|
@@ -220,7 +204,6 @@ export class Connection {
|
|
|
220
204
|
}
|
|
221
205
|
|
|
222
206
|
if (this._state !== ConnectionState.CLOSED && this._state !== ConnectionState.CLOSING) {
|
|
223
|
-
await this.connectedTimeoutContext.dispose();
|
|
224
207
|
this.errors.raise(err);
|
|
225
208
|
}
|
|
226
209
|
});
|
|
@@ -245,7 +228,6 @@ export class Connection {
|
|
|
245
228
|
return;
|
|
246
229
|
}
|
|
247
230
|
|
|
248
|
-
await this.connectedTimeoutContext.dispose();
|
|
249
231
|
this._changeState(ConnectionState.ABORTING);
|
|
250
232
|
if (!this.closeReason) {
|
|
251
233
|
this.closeReason = err?.message;
|
|
@@ -280,8 +262,6 @@ export class Connection {
|
|
|
280
262
|
async close(err?: Error) {
|
|
281
263
|
if (!this.closeReason) {
|
|
282
264
|
this.closeReason = err?.message;
|
|
283
|
-
} else {
|
|
284
|
-
this.closeReason += `; ${err?.message}`;
|
|
285
265
|
}
|
|
286
266
|
if (
|
|
287
267
|
this._state === ConnectionState.CLOSED ||
|
|
@@ -293,7 +273,6 @@ export class Connection {
|
|
|
293
273
|
const lastState = this._state;
|
|
294
274
|
this._changeState(ConnectionState.CLOSING);
|
|
295
275
|
|
|
296
|
-
await this.connectedTimeoutContext.dispose();
|
|
297
276
|
await this._ctx.dispose();
|
|
298
277
|
|
|
299
278
|
log('closing...', { peerId: this.ownId });
|
|
@@ -346,8 +325,7 @@ export class Connection {
|
|
|
346
325
|
data: { signalBatch: { signals } },
|
|
347
326
|
});
|
|
348
327
|
} catch (err) {
|
|
349
|
-
|
|
350
|
-
if (err instanceof CancelledError || (err instanceof Error && err.message?.includes('CANCELLED'))) {
|
|
328
|
+
if (err instanceof CancelledError) {
|
|
351
329
|
return;
|
|
352
330
|
}
|
|
353
331
|
|
package/src/swarm/peer.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { Context } from '@dxos/context';
|
|
|
7
7
|
import { invariant } from '@dxos/invariant';
|
|
8
8
|
import { PublicKey } from '@dxos/keys';
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
|
-
import { CancelledError, SystemError } from '@dxos/protocols';
|
|
10
|
+
import { CancelledError, SystemError, TimeoutError } from '@dxos/protocols';
|
|
11
11
|
import { Answer } from '@dxos/protocols/proto/dxos/mesh/swarm';
|
|
12
12
|
|
|
13
13
|
import { Connection, ConnectionState } from './connection';
|
|
@@ -108,10 +108,7 @@ export class Peer {
|
|
|
108
108
|
async onOffer(message: OfferMessage): Promise<Answer> {
|
|
109
109
|
const remoteId = message.author;
|
|
110
110
|
|
|
111
|
-
if (
|
|
112
|
-
this.connection &&
|
|
113
|
-
![ConnectionState.CREATED, ConnectionState.INITIAL, ConnectionState.CONNECTING].includes(this.connection.state)
|
|
114
|
-
) {
|
|
111
|
+
if (this.connection && ![ConnectionState.CREATED, ConnectionState.INITIAL].includes(this.connection.state)) {
|
|
115
112
|
log.info(`received offer when connection already in ${this.connection.state} state`);
|
|
116
113
|
return { accept: false };
|
|
117
114
|
}
|
|
@@ -176,12 +173,11 @@ export class Peer {
|
|
|
176
173
|
const connection = this._createConnection(true, sessionId);
|
|
177
174
|
this.initiating = true;
|
|
178
175
|
|
|
179
|
-
let answer: Answer;
|
|
180
176
|
try {
|
|
181
177
|
await this._connectionLimiter.connecting(sessionId);
|
|
182
178
|
connection.initiate();
|
|
183
179
|
|
|
184
|
-
answer = await this._signalMessaging.offer({
|
|
180
|
+
const answer = await this._signalMessaging.offer({
|
|
185
181
|
author: this.localPeerId,
|
|
186
182
|
recipient: this.id,
|
|
187
183
|
sessionId,
|
|
@@ -193,45 +189,19 @@ export class Peer {
|
|
|
193
189
|
log('ignoring response');
|
|
194
190
|
return;
|
|
195
191
|
}
|
|
196
|
-
} catch (err: any) {
|
|
197
|
-
log('initiation error: send offer', { err, topic: this.topic, peerId: this.localPeerId, remoteId: this.id });
|
|
198
|
-
await connection.abort(err);
|
|
199
|
-
throw err;
|
|
200
|
-
} finally {
|
|
201
|
-
this.initiating = false;
|
|
202
|
-
}
|
|
203
192
|
|
|
204
|
-
try {
|
|
205
193
|
if (!answer.accept) {
|
|
206
194
|
this._callbacks.onRejected();
|
|
207
195
|
return;
|
|
208
196
|
}
|
|
209
|
-
} catch (err: any) {
|
|
210
|
-
log('initiation error: accept answer', {
|
|
211
|
-
err,
|
|
212
|
-
topic: this.topic,
|
|
213
|
-
peerId: this.localPeerId,
|
|
214
|
-
remoteId: this.id,
|
|
215
|
-
});
|
|
216
|
-
await connection.abort(err);
|
|
217
|
-
throw err;
|
|
218
|
-
} finally {
|
|
219
|
-
this.initiating = false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
try {
|
|
223
|
-
log('opening connection as initiator');
|
|
224
197
|
await connection.openConnection();
|
|
225
198
|
this._callbacks.onAccepted();
|
|
226
199
|
} catch (err: any) {
|
|
227
|
-
log('initiation error:
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
});
|
|
233
|
-
// TODO(nf): unsure when this will be called and the connection won't abort itself. but if it does fall through we should probably abort and not close.
|
|
234
|
-
log.warn('closing connection due to unhandled error on openConnection', { err });
|
|
200
|
+
log('initiation error', { err, topic: this.topic, peerId: this.localPeerId, remoteId: this.id });
|
|
201
|
+
if (err instanceof TimeoutError) {
|
|
202
|
+
log.warn('aborting connection due to signalling failure');
|
|
203
|
+
await connection.abort(err);
|
|
204
|
+
}
|
|
235
205
|
// Calls `onStateChange` with CLOSED state.
|
|
236
206
|
await this.closeConnection(err);
|
|
237
207
|
throw err;
|
|
@@ -327,13 +297,7 @@ export class Peer {
|
|
|
327
297
|
this._connectionCtx = this._ctx.derive();
|
|
328
298
|
|
|
329
299
|
connection.errors.handle((err) => {
|
|
330
|
-
log.warn('connection error,
|
|
331
|
-
topic: this.topic,
|
|
332
|
-
peerId: this.localPeerId,
|
|
333
|
-
remoteId: this.id,
|
|
334
|
-
initiator,
|
|
335
|
-
err,
|
|
336
|
-
});
|
|
300
|
+
log.warn('connection error', { topic: this.topic, peerId: this.localPeerId, remoteId: this.id, initiator, err });
|
|
337
301
|
log.trace('dxos.mesh.connection.error', {
|
|
338
302
|
topic: this.topic,
|
|
339
303
|
localPeerId: this.localPeerId,
|
|
@@ -378,12 +342,12 @@ export class Peer {
|
|
|
378
342
|
}
|
|
379
343
|
|
|
380
344
|
@synchronized
|
|
381
|
-
async destroy(
|
|
345
|
+
async destroy() {
|
|
382
346
|
await this._ctx.dispose();
|
|
383
347
|
log('Destroying peer', { peerId: this.id, topic: this.topic });
|
|
384
348
|
|
|
385
349
|
// Won't throw.
|
|
386
|
-
await this?.connection?.close(
|
|
350
|
+
await this?.connection?.close();
|
|
387
351
|
}
|
|
388
352
|
}
|
|
389
353
|
|
package/src/swarm/swarm.ts
CHANGED
|
@@ -144,7 +144,7 @@ export class Swarm {
|
|
|
144
144
|
|
|
145
145
|
await this._ctx.dispose();
|
|
146
146
|
await this._topology.destroy();
|
|
147
|
-
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key
|
|
147
|
+
await Promise.all(Array.from(this._peers.keys()).map((key) => this._destroyPeer(key)));
|
|
148
148
|
log('destroyed');
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -186,10 +186,8 @@ export class Swarm {
|
|
|
186
186
|
peer.advertizing = false;
|
|
187
187
|
if (peer.connection?.state !== ConnectionState.CONNECTED) {
|
|
188
188
|
// Destroy peer only if there is no p2p-connection established
|
|
189
|
-
void this._destroyPeer(peer.id
|
|
189
|
+
void this._destroyPeer(peer.id).catch((err) => log.catch(err));
|
|
190
190
|
}
|
|
191
|
-
} else {
|
|
192
|
-
log('received peerLeft but no peer found', { peer: swarmEvent.peerLeft.peer });
|
|
193
191
|
}
|
|
194
192
|
}
|
|
195
193
|
|
|
@@ -242,7 +240,7 @@ export class Swarm {
|
|
|
242
240
|
@synchronized
|
|
243
241
|
async goOffline() {
|
|
244
242
|
await this._ctx.dispose();
|
|
245
|
-
await Promise.all([...this._peers.keys()].map((peerId) => this._destroyPeer(peerId
|
|
243
|
+
await Promise.all([...this._peers.keys()].map((peerId) => this._destroyPeer(peerId)));
|
|
246
244
|
}
|
|
247
245
|
|
|
248
246
|
// For debug purposes
|
|
@@ -271,7 +269,7 @@ export class Swarm {
|
|
|
271
269
|
},
|
|
272
270
|
onDisconnected: async () => {
|
|
273
271
|
if (!peer!.advertizing) {
|
|
274
|
-
await this._destroyPeer(peer!.id
|
|
272
|
+
await this._destroyPeer(peer!.id);
|
|
275
273
|
}
|
|
276
274
|
|
|
277
275
|
this.disconnected.emit(peerId);
|
|
@@ -281,8 +279,7 @@ export class Swarm {
|
|
|
281
279
|
// If the peer rejected our connection remove it from the set of candidates.
|
|
282
280
|
// TODO(dmaretskyi): Set flag instead.
|
|
283
281
|
if (this._peers.has(peerId)) {
|
|
284
|
-
|
|
285
|
-
void this._destroyPeer(peerId, 'peer rejected connection');
|
|
282
|
+
void this._destroyPeer(peerId);
|
|
286
283
|
}
|
|
287
284
|
},
|
|
288
285
|
onAccepted: () => {
|
|
@@ -302,9 +299,9 @@ export class Swarm {
|
|
|
302
299
|
return peer;
|
|
303
300
|
}
|
|
304
301
|
|
|
305
|
-
private async _destroyPeer(peerId: PublicKey
|
|
302
|
+
private async _destroyPeer(peerId: PublicKey) {
|
|
306
303
|
invariant(this._peers.has(peerId));
|
|
307
|
-
await this._peers.get(peerId)!.destroy(
|
|
304
|
+
await this._peers.get(peerId)!.destroy();
|
|
308
305
|
this._peers.delete(peerId);
|
|
309
306
|
}
|
|
310
307
|
|