@leofcoin/peernet 1.1.67 → 1.1.69
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/exports/browser/{index-1d597e6b.js → index-7dedefe5.js} +1 -1
- package/exports/browser/{messages-67e5efa0.js → messages-7cab2a51.js} +1 -1
- package/exports/browser/{peernet-55ce42c7.js → peernet-4d189113.js} +105 -82
- package/exports/browser/peernet.d.ts +9 -6
- package/exports/browser/peernet.js +1 -1
- package/exports/peernet.js +80 -73
- package/exports/types/peernet.d.ts +9 -6
- package/package.json +2 -2
- package/src/peernet.ts +86 -78
|
@@ -27088,7 +27088,7 @@ class Identity {
|
|
|
27088
27088
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
27089
27089
|
}
|
|
27090
27090
|
else {
|
|
27091
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-
|
|
27091
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-7dedefe5.js');
|
|
27092
27092
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
27093
27093
|
await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
|
|
27094
27094
|
await globalThis.walletStore.put('version', String(1));
|
|
@@ -27164,17 +27164,18 @@ class Peernet {
|
|
|
27164
27164
|
autoStart = true;
|
|
27165
27165
|
#starting = false;
|
|
27166
27166
|
#started = false;
|
|
27167
|
-
#connections = {};
|
|
27168
27167
|
requestProtos = {};
|
|
27169
27168
|
_messageHandler;
|
|
27170
27169
|
_peerHandler;
|
|
27171
27170
|
protos;
|
|
27171
|
+
version;
|
|
27172
27172
|
/**
|
|
27173
27173
|
* @access public
|
|
27174
27174
|
* @param {Object} options
|
|
27175
27175
|
* @param {String} options.network - desired network
|
|
27176
27176
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
27177
27177
|
* @param {String} options.root - path to root directory
|
|
27178
|
+
* @param {String} options.version - path to root directory
|
|
27178
27179
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
27179
27180
|
*
|
|
27180
27181
|
* @return {Promise} instance of Peernet
|
|
@@ -27189,6 +27190,7 @@ class Peernet {
|
|
|
27189
27190
|
this.network = options.network || 'leofcoin';
|
|
27190
27191
|
this.autoStart = options.autoStart === undefined ? true : options.autoStart;
|
|
27191
27192
|
this.stars = options.stars;
|
|
27193
|
+
this.version = options.version;
|
|
27192
27194
|
const parts = this.network.split(':');
|
|
27193
27195
|
this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet';
|
|
27194
27196
|
if (!options.storePrefix)
|
|
@@ -27253,13 +27255,10 @@ class Peernet {
|
|
|
27253
27255
|
* @return {Array} peerId
|
|
27254
27256
|
*/
|
|
27255
27257
|
get peers() {
|
|
27256
|
-
return Object.entries(this
|
|
27258
|
+
return Object.entries(this.client?.connections);
|
|
27257
27259
|
}
|
|
27258
27260
|
get connections() {
|
|
27259
|
-
return
|
|
27260
|
-
}
|
|
27261
|
-
get peerEntries() {
|
|
27262
|
-
return Object.values(this.#connections);
|
|
27261
|
+
return this.client?.connections || {};
|
|
27263
27262
|
}
|
|
27264
27263
|
/**
|
|
27265
27264
|
* @return {String} id - peerId
|
|
@@ -27280,7 +27279,7 @@ class Peernet {
|
|
|
27280
27279
|
this.root = options.root;
|
|
27281
27280
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27282
27281
|
// FolderMessageResponse
|
|
27283
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27282
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-7cab2a51.js');
|
|
27284
27283
|
/**
|
|
27285
27284
|
* proto Object containing protos
|
|
27286
27285
|
* @type {Object}
|
|
@@ -27314,55 +27313,58 @@ class Peernet {
|
|
|
27314
27313
|
await this.identity.load(password);
|
|
27315
27314
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
27316
27315
|
this.peerId = this.id;
|
|
27317
|
-
this.addRequestHandler('handshake', () => {
|
|
27318
|
-
|
|
27319
|
-
|
|
27320
|
-
|
|
27321
|
-
})
|
|
27322
|
-
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
27323
|
-
|
|
27324
|
-
|
|
27325
|
-
|
|
27326
|
-
|
|
27327
|
-
|
|
27328
|
-
|
|
27329
|
-
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
}
|
|
27344
|
-
|
|
27316
|
+
// this.addRequestHandler('handshake', () => {
|
|
27317
|
+
// return new peernet.protos['peernet-response']({
|
|
27318
|
+
// response: { peerId: this.id }
|
|
27319
|
+
// })
|
|
27320
|
+
// })
|
|
27321
|
+
// pubsub.subscribe('peer:discovered', async (peer) => {
|
|
27322
|
+
// // console.log(peer);
|
|
27323
|
+
// if (this.requestProtos['version'] && !peer.version) {
|
|
27324
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
27325
|
+
// request: 'version'
|
|
27326
|
+
// })
|
|
27327
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
27328
|
+
// let response = await peer.request(node.encoded)
|
|
27329
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
27330
|
+
// peer.version = response.decoded.response.version
|
|
27331
|
+
// }
|
|
27332
|
+
// if (!peer.peerId) {
|
|
27333
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
27334
|
+
// request: 'handshake'
|
|
27335
|
+
// })
|
|
27336
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
27337
|
+
// let response = await peer.request(node.encoded)
|
|
27338
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
27339
|
+
// // todo: response.decoded should be the response and not response.peerId
|
|
27340
|
+
// // todo: ignore above and remove discover completly
|
|
27341
|
+
// response.decoded.response.peerId
|
|
27342
|
+
// }
|
|
27343
|
+
// this.connections[peer.peerId] = peer
|
|
27344
|
+
// pubsub.publish('peer:connected', peer)
|
|
27345
|
+
// todo: cleanup discovered
|
|
27346
|
+
// })
|
|
27347
|
+
// pubsub.subscribe('peer:left', this.#peerLeft.bind(this))
|
|
27345
27348
|
/**
|
|
27346
27349
|
* converts data -> message -> proto
|
|
27347
27350
|
* @see DataHandler
|
|
27348
27351
|
*/
|
|
27349
27352
|
pubsub.subscribe('peer:data', dataHandler);
|
|
27350
|
-
|
|
27351
|
-
|
|
27352
|
-
|
|
27353
|
-
else {
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
|
|
27358
|
-
|
|
27359
|
-
|
|
27360
|
-
|
|
27361
|
-
|
|
27362
|
-
|
|
27363
|
-
|
|
27364
|
-
|
|
27365
|
-
}
|
|
27353
|
+
// // todo: remove below, already handles in the swarm
|
|
27354
|
+
// if (globalThis.navigator) {
|
|
27355
|
+
// globalThis.addEventListener('beforeunload', async () => this.client.close())
|
|
27356
|
+
// } else {
|
|
27357
|
+
// process.on('SIGTERM', async () => {
|
|
27358
|
+
// process.stdin.resume()
|
|
27359
|
+
// try {
|
|
27360
|
+
// await this.client.close()
|
|
27361
|
+
// } catch (error) {
|
|
27362
|
+
// // @ts-ignore
|
|
27363
|
+
// await this.client.close()
|
|
27364
|
+
// }
|
|
27365
|
+
// process.exit()
|
|
27366
|
+
// })
|
|
27367
|
+
// }
|
|
27366
27368
|
if (this.autoStart)
|
|
27367
27369
|
await this.start();
|
|
27368
27370
|
return this;
|
|
@@ -27375,6 +27377,7 @@ class Peernet {
|
|
|
27375
27377
|
#peerId;
|
|
27376
27378
|
#connections = {};
|
|
27377
27379
|
#stars = {};
|
|
27380
|
+
#connectEvent = 'peer:connected';
|
|
27378
27381
|
id;
|
|
27379
27382
|
networkVersion;
|
|
27380
27383
|
starsConfig;
|
|
@@ -27394,18 +27397,32 @@ class Peernet {
|
|
|
27394
27397
|
getPeer(peerId) {
|
|
27395
27398
|
return this.#connections[peerId];
|
|
27396
27399
|
}
|
|
27397
|
-
|
|
27400
|
+
/**
|
|
27401
|
+
*
|
|
27402
|
+
* @param options {object}
|
|
27403
|
+
* @param options.peerId {string}
|
|
27404
|
+
* @param options.networkVersion {string}
|
|
27405
|
+
* @param options.version {string}
|
|
27406
|
+
* @param options.stars {string[]}
|
|
27407
|
+
* @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
|
|
27408
|
+
*/
|
|
27409
|
+
constructor(options) {
|
|
27410
|
+
const { peerId, networkVersion, version, connectEvent, stars } = {
|
|
27411
|
+
...defaultOptions,
|
|
27412
|
+
...options
|
|
27413
|
+
};
|
|
27398
27414
|
this.#peerId = peerId;
|
|
27399
27415
|
this.networkVersion = networkVersion;
|
|
27400
27416
|
this.version = version;
|
|
27401
|
-
this
|
|
27402
|
-
}
|
|
27403
|
-
async _init(stars = []) {
|
|
27417
|
+
this.#connectEvent = connectEvent;
|
|
27404
27418
|
this.starsConfig = stars;
|
|
27419
|
+
this._init();
|
|
27420
|
+
}
|
|
27421
|
+
async _init() {
|
|
27405
27422
|
// reconnectJob()
|
|
27406
27423
|
if (!globalThis.RTCPeerConnection)
|
|
27407
27424
|
globalThis.wrtc = (await import('./browser-2c73e2ef.js').then(function (n) { return n.b; })).default;
|
|
27408
|
-
for (const star of
|
|
27425
|
+
for (const star of this.starsConfig) {
|
|
27409
27426
|
try {
|
|
27410
27427
|
const client = new SocketRequestClient(star, this.networkVersion);
|
|
27411
27428
|
this.#stars[star] = await client.init();
|
|
@@ -27416,7 +27433,8 @@ class Peernet {
|
|
|
27416
27433
|
});
|
|
27417
27434
|
}
|
|
27418
27435
|
catch (e) {
|
|
27419
|
-
if (
|
|
27436
|
+
if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
|
|
27437
|
+
!this.socketClient)
|
|
27420
27438
|
throw new Error(`No star available to connect`);
|
|
27421
27439
|
}
|
|
27422
27440
|
}
|
|
@@ -27542,7 +27560,7 @@ class Peernet {
|
|
|
27542
27560
|
};
|
|
27543
27561
|
#peerConnect = (peer) => {
|
|
27544
27562
|
globalThis.debug(`${peer.peerId} connected`);
|
|
27545
|
-
globalThis.pubsub.publish(
|
|
27563
|
+
globalThis.pubsub.publish(this.#connectEvent, peer.peerId);
|
|
27546
27564
|
};
|
|
27547
27565
|
#noticeMessage = (message, id) => {
|
|
27548
27566
|
if (globalThis.pubsub.subscribers[id]) {
|
|
@@ -27592,18 +27610,24 @@ class Peernet {
|
|
|
27592
27610
|
* @type {PeernetClient}
|
|
27593
27611
|
*/
|
|
27594
27612
|
console.log(this.stars);
|
|
27595
|
-
this.client = new importee.default(
|
|
27613
|
+
this.client = new importee.default({
|
|
27614
|
+
peerId: this.id,
|
|
27615
|
+
networkVersion: this.networkVersion,
|
|
27616
|
+
version: this.version,
|
|
27617
|
+
stars: this.stars
|
|
27618
|
+
});
|
|
27596
27619
|
this.#started = true;
|
|
27597
27620
|
this.#starting = false;
|
|
27598
27621
|
}
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
|
|
27604
|
-
|
|
27605
|
-
|
|
27606
|
-
}
|
|
27622
|
+
// todo: remove, handled in swarm now
|
|
27623
|
+
// #peerLeft(peer: SwarmPeer) {
|
|
27624
|
+
// for (const [id, _peer] of Object.entries(this.connections)) {
|
|
27625
|
+
// if (_peer.id === peer.id && this.connections[id] && !this.connections[id].connected) {
|
|
27626
|
+
// delete this.connections[id]
|
|
27627
|
+
// this.removePeer(_peer)
|
|
27628
|
+
// }
|
|
27629
|
+
// }
|
|
27630
|
+
// }
|
|
27607
27631
|
addRequestHandler(name, method) {
|
|
27608
27632
|
this.requestProtos[name] = method;
|
|
27609
27633
|
}
|
|
@@ -27707,7 +27731,7 @@ class Peernet {
|
|
|
27707
27731
|
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
27708
27732
|
};
|
|
27709
27733
|
let walks = [];
|
|
27710
|
-
for (const [peerId, peer] of Object.entries(this
|
|
27734
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
27711
27735
|
if (peerId !== this.id) {
|
|
27712
27736
|
walks.push(walk(peer, peerId));
|
|
27713
27737
|
}
|
|
@@ -27774,7 +27798,7 @@ class Peernet {
|
|
|
27774
27798
|
if (!closestPeer || !closestPeer.id)
|
|
27775
27799
|
return this.requestData(hash, store?.name || store);
|
|
27776
27800
|
const id = closestPeer.id;
|
|
27777
|
-
const peer = this
|
|
27801
|
+
const peer = this.connections[id];
|
|
27778
27802
|
if (peer?.connected) {
|
|
27779
27803
|
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
27780
27804
|
hash,
|
|
@@ -27788,7 +27812,7 @@ class Peernet {
|
|
|
27788
27812
|
const promises = [];
|
|
27789
27813
|
const providers = await this.providersFor(hash, store);
|
|
27790
27814
|
for (const provider of Object.values(providers)) {
|
|
27791
|
-
const peer = this
|
|
27815
|
+
const peer = this.connections[provider.id];
|
|
27792
27816
|
if (peer)
|
|
27793
27817
|
promises.push(peer.request(node.encoded));
|
|
27794
27818
|
}
|
|
@@ -28002,7 +28026,7 @@ class Peernet {
|
|
|
28002
28026
|
// globalSub.publish(topic, data)
|
|
28003
28027
|
const id = Math.random().toString(36).slice(-12);
|
|
28004
28028
|
data = await new globalThis.peernet.protos['peernet-ps']({ data, topic });
|
|
28005
|
-
for (const [peerId, peer] of Object.entries(this
|
|
28029
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
28006
28030
|
if (peerId !== this.id) {
|
|
28007
28031
|
const node = await this.prepareMessage(data);
|
|
28008
28032
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -28024,16 +28048,15 @@ class Peernet {
|
|
|
28024
28048
|
}
|
|
28025
28049
|
async removePeer(peer) {
|
|
28026
28050
|
console.log('removepeer', peer.id);
|
|
28027
|
-
|
|
28028
|
-
await this.client.
|
|
28029
|
-
if (this.client.peers[id]) {
|
|
28030
|
-
|
|
28031
|
-
|
|
28032
|
-
|
|
28033
|
-
|
|
28034
|
-
|
|
28035
|
-
|
|
28036
|
-
}
|
|
28051
|
+
peer.id;
|
|
28052
|
+
// await this.client.connections(peer)
|
|
28053
|
+
// if (this.client.peers[id]) {
|
|
28054
|
+
// for (const connection of Object.keys(this.client.peers[id])) {
|
|
28055
|
+
// // if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
28056
|
+
// // @ts-ignore
|
|
28057
|
+
// if (this.client.peers[id][connection].connected) return this.client.emit('peerconnect', connection)
|
|
28058
|
+
// }
|
|
28059
|
+
// }
|
|
28037
28060
|
}
|
|
28038
28061
|
get Buffer() {
|
|
28039
28062
|
return Buffer;
|
|
@@ -6,7 +6,7 @@ import DHT from './dht/dht.js';
|
|
|
6
6
|
import MessageHandler from './handlers/message.js';
|
|
7
7
|
import { Storage as LeofcoinStorageClass } from '@leofcoin/storage';
|
|
8
8
|
import Identity from './identity.js';
|
|
9
|
-
import swarm from '@netpeer/
|
|
9
|
+
import swarm from '@netpeer/swarm/client';
|
|
10
10
|
declare global {
|
|
11
11
|
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
12
12
|
var peernet: Peernet;
|
|
@@ -51,12 +51,14 @@ export default class Peernet {
|
|
|
51
51
|
_messageHandler: MessageHandler;
|
|
52
52
|
_peerHandler: PeerDiscovery;
|
|
53
53
|
protos: {};
|
|
54
|
+
version: any;
|
|
54
55
|
/**
|
|
55
56
|
* @access public
|
|
56
57
|
* @param {Object} options
|
|
57
58
|
* @param {String} options.network - desired network
|
|
58
59
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
59
60
|
* @param {String} options.root - path to root directory
|
|
61
|
+
* @param {String} options.version - path to root directory
|
|
60
62
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
61
63
|
*
|
|
62
64
|
* @return {Promise} instance of Peernet
|
|
@@ -82,13 +84,14 @@ export default class Peernet {
|
|
|
82
84
|
*
|
|
83
85
|
* @return {Array} peerId
|
|
84
86
|
*/
|
|
85
|
-
get peers(): [string,
|
|
86
|
-
get connections():
|
|
87
|
-
|
|
87
|
+
get peers(): [string, import("@netpeer/swarm/peer").default][];
|
|
88
|
+
get connections(): {
|
|
89
|
+
[x: string]: import("@netpeer/swarm/peer").default;
|
|
90
|
+
};
|
|
88
91
|
/**
|
|
89
92
|
* @return {String} id - peerId
|
|
90
93
|
*/
|
|
91
|
-
getConnection(id: any):
|
|
94
|
+
getConnection(id: any): import("@netpeer/swarm/peer").default;
|
|
92
95
|
/**
|
|
93
96
|
* @private
|
|
94
97
|
*
|
|
@@ -238,6 +241,6 @@ export default class Peernet {
|
|
|
238
241
|
* @param {Method} cb
|
|
239
242
|
*/
|
|
240
243
|
subscribe(topic: string, callback: Function): Promise<void>;
|
|
241
|
-
removePeer(peer: any): Promise<
|
|
244
|
+
removePeer(peer: any): Promise<void>;
|
|
242
245
|
get Buffer(): BufferConstructor;
|
|
243
246
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
1
|
+
export { P as default } from './peernet-4d189113.js';
|
|
2
2
|
import './value-4e80eeeb.js';
|
package/exports/peernet.js
CHANGED
|
@@ -425,17 +425,18 @@ class Peernet {
|
|
|
425
425
|
autoStart = true;
|
|
426
426
|
#starting = false;
|
|
427
427
|
#started = false;
|
|
428
|
-
#connections = {};
|
|
429
428
|
requestProtos = {};
|
|
430
429
|
_messageHandler;
|
|
431
430
|
_peerHandler;
|
|
432
431
|
protos;
|
|
432
|
+
version;
|
|
433
433
|
/**
|
|
434
434
|
* @access public
|
|
435
435
|
* @param {Object} options
|
|
436
436
|
* @param {String} options.network - desired network
|
|
437
437
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
438
438
|
* @param {String} options.root - path to root directory
|
|
439
|
+
* @param {String} options.version - path to root directory
|
|
439
440
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
440
441
|
*
|
|
441
442
|
* @return {Promise} instance of Peernet
|
|
@@ -450,6 +451,7 @@ class Peernet {
|
|
|
450
451
|
this.network = options.network || 'leofcoin';
|
|
451
452
|
this.autoStart = options.autoStart === undefined ? true : options.autoStart;
|
|
452
453
|
this.stars = options.stars;
|
|
454
|
+
this.version = options.version;
|
|
453
455
|
const parts = this.network.split(':');
|
|
454
456
|
this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet';
|
|
455
457
|
if (!options.storePrefix)
|
|
@@ -514,13 +516,10 @@ class Peernet {
|
|
|
514
516
|
* @return {Array} peerId
|
|
515
517
|
*/
|
|
516
518
|
get peers() {
|
|
517
|
-
return Object.entries(this
|
|
519
|
+
return Object.entries(this.client?.connections);
|
|
518
520
|
}
|
|
519
521
|
get connections() {
|
|
520
|
-
return
|
|
521
|
-
}
|
|
522
|
-
get peerEntries() {
|
|
523
|
-
return Object.values(this.#connections);
|
|
522
|
+
return this.client?.connections || {};
|
|
524
523
|
}
|
|
525
524
|
/**
|
|
526
525
|
* @return {String} id - peerId
|
|
@@ -575,55 +574,58 @@ class Peernet {
|
|
|
575
574
|
await this.identity.load(password);
|
|
576
575
|
this._peerHandler = new PeerDiscovery(this.id);
|
|
577
576
|
this.peerId = this.id;
|
|
578
|
-
this.addRequestHandler('handshake', () => {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
})
|
|
583
|
-
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
605
|
-
|
|
577
|
+
// this.addRequestHandler('handshake', () => {
|
|
578
|
+
// return new peernet.protos['peernet-response']({
|
|
579
|
+
// response: { peerId: this.id }
|
|
580
|
+
// })
|
|
581
|
+
// })
|
|
582
|
+
// pubsub.subscribe('peer:discovered', async (peer) => {
|
|
583
|
+
// // console.log(peer);
|
|
584
|
+
// if (this.requestProtos['version'] && !peer.version) {
|
|
585
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
586
|
+
// request: 'version'
|
|
587
|
+
// })
|
|
588
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
589
|
+
// let response = await peer.request(node.encoded)
|
|
590
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
591
|
+
// peer.version = response.decoded.response.version
|
|
592
|
+
// }
|
|
593
|
+
// if (!peer.peerId) {
|
|
594
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
595
|
+
// request: 'handshake'
|
|
596
|
+
// })
|
|
597
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
598
|
+
// let response = await peer.request(node.encoded)
|
|
599
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
600
|
+
// // todo: response.decoded should be the response and not response.peerId
|
|
601
|
+
// // todo: ignore above and remove discover completly
|
|
602
|
+
// response.decoded.response.peerId
|
|
603
|
+
// }
|
|
604
|
+
// this.connections[peer.peerId] = peer
|
|
605
|
+
// pubsub.publish('peer:connected', peer)
|
|
606
|
+
// todo: cleanup discovered
|
|
607
|
+
// })
|
|
608
|
+
// pubsub.subscribe('peer:left', this.#peerLeft.bind(this))
|
|
606
609
|
/**
|
|
607
610
|
* converts data -> message -> proto
|
|
608
611
|
* @see DataHandler
|
|
609
612
|
*/
|
|
610
613
|
pubsub.subscribe('peer:data', dataHandler);
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
else {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
}
|
|
614
|
+
// // todo: remove below, already handles in the swarm
|
|
615
|
+
// if (globalThis.navigator) {
|
|
616
|
+
// globalThis.addEventListener('beforeunload', async () => this.client.close())
|
|
617
|
+
// } else {
|
|
618
|
+
// process.on('SIGTERM', async () => {
|
|
619
|
+
// process.stdin.resume()
|
|
620
|
+
// try {
|
|
621
|
+
// await this.client.close()
|
|
622
|
+
// } catch (error) {
|
|
623
|
+
// // @ts-ignore
|
|
624
|
+
// await this.client.close()
|
|
625
|
+
// }
|
|
626
|
+
// process.exit()
|
|
627
|
+
// })
|
|
628
|
+
// }
|
|
627
629
|
if (this.autoStart)
|
|
628
630
|
await this.start();
|
|
629
631
|
return this;
|
|
@@ -638,18 +640,24 @@ class Peernet {
|
|
|
638
640
|
* @type {PeernetClient}
|
|
639
641
|
*/
|
|
640
642
|
console.log(this.stars);
|
|
641
|
-
this.client = new importee.default(
|
|
643
|
+
this.client = new importee.default({
|
|
644
|
+
peerId: this.id,
|
|
645
|
+
networkVersion: this.networkVersion,
|
|
646
|
+
version: this.version,
|
|
647
|
+
stars: this.stars
|
|
648
|
+
});
|
|
642
649
|
this.#started = true;
|
|
643
650
|
this.#starting = false;
|
|
644
651
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
652
|
+
// todo: remove, handled in swarm now
|
|
653
|
+
// #peerLeft(peer: SwarmPeer) {
|
|
654
|
+
// for (const [id, _peer] of Object.entries(this.connections)) {
|
|
655
|
+
// if (_peer.id === peer.id && this.connections[id] && !this.connections[id].connected) {
|
|
656
|
+
// delete this.connections[id]
|
|
657
|
+
// this.removePeer(_peer)
|
|
658
|
+
// }
|
|
659
|
+
// }
|
|
660
|
+
// }
|
|
653
661
|
addRequestHandler(name, method) {
|
|
654
662
|
this.requestProtos[name] = method;
|
|
655
663
|
}
|
|
@@ -753,7 +761,7 @@ class Peernet {
|
|
|
753
761
|
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
754
762
|
};
|
|
755
763
|
let walks = [];
|
|
756
|
-
for (const [peerId, peer] of Object.entries(this
|
|
764
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
757
765
|
if (peerId !== this.id) {
|
|
758
766
|
walks.push(walk(peer, peerId));
|
|
759
767
|
}
|
|
@@ -820,7 +828,7 @@ class Peernet {
|
|
|
820
828
|
if (!closestPeer || !closestPeer.id)
|
|
821
829
|
return this.requestData(hash, store?.name || store);
|
|
822
830
|
const id = closestPeer.id;
|
|
823
|
-
const peer = this
|
|
831
|
+
const peer = this.connections[id];
|
|
824
832
|
if (peer?.connected) {
|
|
825
833
|
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
826
834
|
hash,
|
|
@@ -834,7 +842,7 @@ class Peernet {
|
|
|
834
842
|
const promises = [];
|
|
835
843
|
const providers = await this.providersFor(hash, store);
|
|
836
844
|
for (const provider of Object.values(providers)) {
|
|
837
|
-
const peer = this
|
|
845
|
+
const peer = this.connections[provider.id];
|
|
838
846
|
if (peer)
|
|
839
847
|
promises.push(peer.request(node.encoded));
|
|
840
848
|
}
|
|
@@ -1048,7 +1056,7 @@ class Peernet {
|
|
|
1048
1056
|
// globalSub.publish(topic, data)
|
|
1049
1057
|
const id = Math.random().toString(36).slice(-12);
|
|
1050
1058
|
data = await new globalThis.peernet.protos['peernet-ps']({ data, topic });
|
|
1051
|
-
for (const [peerId, peer] of Object.entries(this
|
|
1059
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
1052
1060
|
if (peerId !== this.id) {
|
|
1053
1061
|
const node = await this.prepareMessage(data);
|
|
1054
1062
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -1070,16 +1078,15 @@ class Peernet {
|
|
|
1070
1078
|
}
|
|
1071
1079
|
async removePeer(peer) {
|
|
1072
1080
|
console.log('removepeer', peer.id);
|
|
1073
|
-
|
|
1074
|
-
await this.client.
|
|
1075
|
-
if (this.client.peers[id]) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
}
|
|
1081
|
+
peer.id;
|
|
1082
|
+
// await this.client.connections(peer)
|
|
1083
|
+
// if (this.client.peers[id]) {
|
|
1084
|
+
// for (const connection of Object.keys(this.client.peers[id])) {
|
|
1085
|
+
// // if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
1086
|
+
// // @ts-ignore
|
|
1087
|
+
// if (this.client.peers[id][connection].connected) return this.client.emit('peerconnect', connection)
|
|
1088
|
+
// }
|
|
1089
|
+
// }
|
|
1083
1090
|
}
|
|
1084
1091
|
get Buffer() {
|
|
1085
1092
|
return Buffer;
|
|
@@ -6,7 +6,7 @@ import DHT from './dht/dht.js';
|
|
|
6
6
|
import MessageHandler from './handlers/message.js';
|
|
7
7
|
import { Storage as LeofcoinStorageClass } from '@leofcoin/storage';
|
|
8
8
|
import Identity from './identity.js';
|
|
9
|
-
import swarm from '@netpeer/
|
|
9
|
+
import swarm from '@netpeer/swarm/client';
|
|
10
10
|
declare global {
|
|
11
11
|
var LeofcoinStorage: typeof LeofcoinStorageClass;
|
|
12
12
|
var peernet: Peernet;
|
|
@@ -51,12 +51,14 @@ export default class Peernet {
|
|
|
51
51
|
_messageHandler: MessageHandler;
|
|
52
52
|
_peerHandler: PeerDiscovery;
|
|
53
53
|
protos: {};
|
|
54
|
+
version: any;
|
|
54
55
|
/**
|
|
55
56
|
* @access public
|
|
56
57
|
* @param {Object} options
|
|
57
58
|
* @param {String} options.network - desired network
|
|
58
59
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
59
60
|
* @param {String} options.root - path to root directory
|
|
61
|
+
* @param {String} options.version - path to root directory
|
|
60
62
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
61
63
|
*
|
|
62
64
|
* @return {Promise} instance of Peernet
|
|
@@ -82,13 +84,14 @@ export default class Peernet {
|
|
|
82
84
|
*
|
|
83
85
|
* @return {Array} peerId
|
|
84
86
|
*/
|
|
85
|
-
get peers(): [string,
|
|
86
|
-
get connections():
|
|
87
|
-
|
|
87
|
+
get peers(): [string, import("@netpeer/swarm/peer").default][];
|
|
88
|
+
get connections(): {
|
|
89
|
+
[x: string]: import("@netpeer/swarm/peer").default;
|
|
90
|
+
};
|
|
88
91
|
/**
|
|
89
92
|
* @return {String} id - peerId
|
|
90
93
|
*/
|
|
91
|
-
getConnection(id: any):
|
|
94
|
+
getConnection(id: any): import("@netpeer/swarm/peer").default;
|
|
92
95
|
/**
|
|
93
96
|
* @private
|
|
94
97
|
*
|
|
@@ -238,6 +241,6 @@ export default class Peernet {
|
|
|
238
241
|
* @param {Method} cb
|
|
239
242
|
*/
|
|
240
243
|
subscribe(topic: string, callback: Function): Promise<void>;
|
|
241
|
-
removePeer(peer: any): Promise<
|
|
244
|
+
removePeer(peer: any): Promise<void>;
|
|
242
245
|
get Buffer(): BufferConstructor;
|
|
243
246
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.69",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
38
38
|
"@leofcoin/storage": "^3.0.0",
|
|
39
39
|
"@netpeer/p2pt-swarm": "^1.3.5",
|
|
40
|
-
"@netpeer/swarm": "^0.
|
|
40
|
+
"@netpeer/swarm": "^0.8.1",
|
|
41
41
|
"@types/node": "^18.11.18",
|
|
42
42
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
43
43
|
"@vandeurenglenn/base58": "^1.1.0",
|
package/src/peernet.ts
CHANGED
|
@@ -9,8 +9,7 @@ import { dhtError, nothingFoundError } from './errors/errors.js'
|
|
|
9
9
|
import { Storage as LeofcoinStorageClass } from '@leofcoin/storage'
|
|
10
10
|
import { utils as codecUtils } from '@leofcoin/codecs'
|
|
11
11
|
import Identity from './identity.js'
|
|
12
|
-
import swarm
|
|
13
|
-
import P2PTPeer from '@netpeer/p2pt-swarm/peer'
|
|
12
|
+
import swarm from '@netpeer/swarm/client'
|
|
14
13
|
|
|
15
14
|
globalThis.LeofcoinStorage = LeofcoinStorageClass
|
|
16
15
|
|
|
@@ -60,11 +59,11 @@ export default class Peernet {
|
|
|
60
59
|
autoStart: boolean = true
|
|
61
60
|
#starting: boolean = false
|
|
62
61
|
#started: boolean = false
|
|
63
|
-
#connections: { [index: PeerId]: P2PTPeer } = {}
|
|
64
62
|
requestProtos = {}
|
|
65
63
|
_messageHandler: MessageHandler
|
|
66
64
|
_peerHandler: PeerDiscovery
|
|
67
65
|
protos: {}
|
|
66
|
+
version
|
|
68
67
|
|
|
69
68
|
/**
|
|
70
69
|
* @access public
|
|
@@ -72,6 +71,7 @@ export default class Peernet {
|
|
|
72
71
|
* @param {String} options.network - desired network
|
|
73
72
|
* @param {String} options.stars - star list for selected network (these should match, don't mix networks)
|
|
74
73
|
* @param {String} options.root - path to root directory
|
|
74
|
+
* @param {String} options.version - path to root directory
|
|
75
75
|
* @param {String} options.storePrefix - prefix for datatores (lfc)
|
|
76
76
|
*
|
|
77
77
|
* @return {Promise} instance of Peernet
|
|
@@ -86,6 +86,7 @@ export default class Peernet {
|
|
|
86
86
|
this.network = options.network || 'leofcoin'
|
|
87
87
|
this.autoStart = options.autoStart === undefined ? true : options.autoStart
|
|
88
88
|
this.stars = options.stars
|
|
89
|
+
this.version = options.version
|
|
89
90
|
const parts = this.network.split(':')
|
|
90
91
|
this.networkVersion = options.networkVersion || parts.length > 1 ? parts[1] : 'mainnet'
|
|
91
92
|
|
|
@@ -162,15 +163,11 @@ export default class Peernet {
|
|
|
162
163
|
* @return {Array} peerId
|
|
163
164
|
*/
|
|
164
165
|
get peers() {
|
|
165
|
-
return Object.entries(this
|
|
166
|
+
return Object.entries(this.client?.connections)
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
get connections() {
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get peerEntries() {
|
|
173
|
-
return Object.values(this.#connections)
|
|
170
|
+
return this.client?.connections || {}
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
/**
|
|
@@ -248,40 +245,44 @@ export default class Peernet {
|
|
|
248
245
|
this._peerHandler = new PeerDiscovery(this.id)
|
|
249
246
|
this.peerId = this.id
|
|
250
247
|
|
|
251
|
-
this.addRequestHandler('handshake', () => {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
pubsub.
|
|
248
|
+
// this.addRequestHandler('handshake', () => {
|
|
249
|
+
// return new peernet.protos['peernet-response']({
|
|
250
|
+
// response: { peerId: this.id }
|
|
251
|
+
// })
|
|
252
|
+
// })
|
|
253
|
+
|
|
254
|
+
// pubsub.subscribe('peer:discovered', async (peer) => {
|
|
255
|
+
// // console.log(peer);
|
|
256
|
+
|
|
257
|
+
// if (this.requestProtos['version'] && !peer.version) {
|
|
258
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
259
|
+
// request: 'version'
|
|
260
|
+
// })
|
|
261
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
262
|
+
// let response = await peer.request(node.encoded)
|
|
263
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
264
|
+
// peer.version = response.decoded.response.version
|
|
265
|
+
// }
|
|
266
|
+
|
|
267
|
+
// if (!peer.peerId) {
|
|
268
|
+
// let data = await new globalThis.peernet.protos['peernet-request']({
|
|
269
|
+
// request: 'handshake'
|
|
270
|
+
// })
|
|
271
|
+
// let node = await globalThis.peernet.prepareMessage(data)
|
|
272
|
+
// let response = await peer.request(node.encoded)
|
|
273
|
+
|
|
274
|
+
// response = await new globalThis.peernet.protos['peernet-response'](new Uint8Array(Object.values(response)))
|
|
275
|
+
// // todo: response.decoded should be the response and not response.peerId
|
|
276
|
+
// // todo: ignore above and remove discover completly
|
|
277
|
+
// response.decoded.response.peerId
|
|
278
|
+
// }
|
|
279
|
+
|
|
280
|
+
// this.connections[peer.peerId] = peer
|
|
281
|
+
// pubsub.publish('peer:connected', peer)
|
|
282
|
+
// todo: cleanup discovered
|
|
283
|
+
// })
|
|
284
|
+
|
|
285
|
+
// pubsub.subscribe('peer:left', this.#peerLeft.bind(this))
|
|
285
286
|
|
|
286
287
|
/**
|
|
287
288
|
* converts data -> message -> proto
|
|
@@ -289,20 +290,21 @@ export default class Peernet {
|
|
|
289
290
|
*/
|
|
290
291
|
pubsub.subscribe('peer:data', dataHandler)
|
|
291
292
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
293
|
+
// // todo: remove below, already handles in the swarm
|
|
294
|
+
// if (globalThis.navigator) {
|
|
295
|
+
// globalThis.addEventListener('beforeunload', async () => this.client.close())
|
|
296
|
+
// } else {
|
|
297
|
+
// process.on('SIGTERM', async () => {
|
|
298
|
+
// process.stdin.resume()
|
|
299
|
+
// try {
|
|
300
|
+
// await this.client.close()
|
|
301
|
+
// } catch (error) {
|
|
302
|
+
// // @ts-ignore
|
|
303
|
+
// await this.client.close()
|
|
304
|
+
// }
|
|
305
|
+
// process.exit()
|
|
306
|
+
// })
|
|
307
|
+
// }
|
|
306
308
|
if (this.autoStart) await this.start()
|
|
307
309
|
return this
|
|
308
310
|
}
|
|
@@ -318,19 +320,25 @@ export default class Peernet {
|
|
|
318
320
|
*/
|
|
319
321
|
console.log(this.stars)
|
|
320
322
|
|
|
321
|
-
this.client = new importee.default(
|
|
323
|
+
this.client = new importee.default({
|
|
324
|
+
peerId: this.id,
|
|
325
|
+
networkVersion: this.networkVersion,
|
|
326
|
+
version: this.version,
|
|
327
|
+
stars: this.stars
|
|
328
|
+
})
|
|
322
329
|
this.#started = true
|
|
323
330
|
this.#starting = false
|
|
324
331
|
}
|
|
325
332
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
333
|
+
// todo: remove, handled in swarm now
|
|
334
|
+
// #peerLeft(peer: SwarmPeer) {
|
|
335
|
+
// for (const [id, _peer] of Object.entries(this.connections)) {
|
|
336
|
+
// if (_peer.id === peer.id && this.connections[id] && !this.connections[id].connected) {
|
|
337
|
+
// delete this.connections[id]
|
|
338
|
+
// this.removePeer(_peer)
|
|
339
|
+
// }
|
|
340
|
+
// }
|
|
341
|
+
// }
|
|
334
342
|
|
|
335
343
|
addRequestHandler(name, method) {
|
|
336
344
|
this.requestProtos[name] = method
|
|
@@ -447,7 +455,7 @@ export default class Peernet {
|
|
|
447
455
|
if (proto.decoded.has) this.dht.addProvider(peerInfo, proto.decoded.hash)
|
|
448
456
|
}
|
|
449
457
|
let walks = []
|
|
450
|
-
for (const [peerId, peer] of Object.entries(this
|
|
458
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
451
459
|
if (peerId !== this.id) {
|
|
452
460
|
walks.push(walk(peer, peerId))
|
|
453
461
|
}
|
|
@@ -514,7 +522,7 @@ export default class Peernet {
|
|
|
514
522
|
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store?.name || store)
|
|
515
523
|
|
|
516
524
|
const id = closestPeer.id
|
|
517
|
-
const peer = this
|
|
525
|
+
const peer = this.connections[id]
|
|
518
526
|
|
|
519
527
|
if (peer?.connected) {
|
|
520
528
|
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
@@ -530,7 +538,7 @@ export default class Peernet {
|
|
|
530
538
|
const promises = []
|
|
531
539
|
const providers = await this.providersFor(hash, store)
|
|
532
540
|
for (const provider of Object.values(providers)) {
|
|
533
|
-
const peer = this
|
|
541
|
+
const peer = this.connections[provider.id]
|
|
534
542
|
|
|
535
543
|
if (peer) promises.push(peer.request(node.encoded))
|
|
536
544
|
}
|
|
@@ -745,7 +753,7 @@ export default class Peernet {
|
|
|
745
753
|
// globalSub.publish(topic, data)
|
|
746
754
|
const id = Math.random().toString(36).slice(-12)
|
|
747
755
|
data = await new globalThis.peernet.protos['peernet-ps']({ data, topic })
|
|
748
|
-
for (const [peerId, peer] of Object.entries(this
|
|
756
|
+
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
749
757
|
if (peerId !== this.id) {
|
|
750
758
|
const node = await this.prepareMessage(data)
|
|
751
759
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -771,14 +779,14 @@ export default class Peernet {
|
|
|
771
779
|
async removePeer(peer) {
|
|
772
780
|
console.log('removepeer', peer.id)
|
|
773
781
|
const id = peer.id
|
|
774
|
-
await this.client.
|
|
775
|
-
if (this.client.peers[id]) {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
}
|
|
782
|
+
// await this.client.connections(peer)
|
|
783
|
+
// if (this.client.peers[id]) {
|
|
784
|
+
// for (const connection of Object.keys(this.client.peers[id])) {
|
|
785
|
+
// // if (this.client.peers[id][connection].connected === false) delete this.client.peers[id][connection]
|
|
786
|
+
// // @ts-ignore
|
|
787
|
+
// if (this.client.peers[id][connection].connected) return this.client.emit('peerconnect', connection)
|
|
788
|
+
// }
|
|
789
|
+
// }
|
|
782
790
|
}
|
|
783
791
|
|
|
784
792
|
get Buffer() {
|