@leofcoin/peernet 1.1.65 → 1.1.66
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/{client-d602421d.js → client-493cbd83.js} +160 -128
- package/exports/browser/{index-ddb4220d.js → index-34c93510.js} +1 -1
- package/exports/browser/{messages-c24213c9.js → messages-b7f41cba.js} +1 -1
- package/exports/browser/{peernet-4149fb9c.js → peernet-72528dd9.js} +3 -3
- package/exports/browser/peernet.js +1 -1
- package/package.json +3 -2
|
@@ -103,15 +103,18 @@ class LittlePubSub {
|
|
|
103
103
|
if (this.subscribers[event].handlers.length === 0)
|
|
104
104
|
delete this.subscribers[event];
|
|
105
105
|
}
|
|
106
|
-
publish(event,
|
|
106
|
+
publish(event, value) {
|
|
107
|
+
// always set value even when having no subscribers
|
|
107
108
|
if (!this.hasSubscribers(event))
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
this.subscribers[event] = {
|
|
110
|
+
handlers: []
|
|
111
|
+
};
|
|
112
|
+
const oldValue = this.subscribers[event]?.value;
|
|
113
|
+
this.subscribers[event].value = value;
|
|
114
|
+
if (this.verbose || oldValue !== value)
|
|
115
|
+
for (const handler of this.subscribers[event].handlers) {
|
|
116
|
+
handler(value, oldValue);
|
|
117
|
+
}
|
|
115
118
|
}
|
|
116
119
|
once(event) {
|
|
117
120
|
return new Promise((resolve) => {
|
|
@@ -270,53 +273,61 @@ const base = (ALPHABET) => {
|
|
|
270
273
|
const ALPHABET$3 = '0123456789ABCDEF';
|
|
271
274
|
base(ALPHABET$3);
|
|
272
275
|
|
|
273
|
-
const ALPHABET$2 =
|
|
274
|
-
const ALPHABET_HEX$1 =
|
|
275
|
-
base(ALPHABET$2);
|
|
276
|
+
const ALPHABET$2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
277
|
+
const ALPHABET_HEX$1 = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
|
|
278
|
+
base(ALPHABET$2);
|
|
276
279
|
base(ALPHABET_HEX$1);
|
|
277
280
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
try {
|
|
288
|
-
decode(string);
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
catch (e) {
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
try {
|
|
297
|
-
decodeHex(string);
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
catch (e) {
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
decode(string);
|
|
307
|
-
return
|
|
308
|
-
}
|
|
309
|
-
catch (e) {
|
|
310
|
-
try {
|
|
311
|
-
decodeHex(string);
|
|
312
|
-
return
|
|
313
|
-
}
|
|
314
|
-
catch
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
var base58$1 = {
|
|
281
|
+
const ALPHABET$1 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
282
|
+
const ALPHABET_HEX = "0123456789ABCDEFGHJKLMNPQRSTUVabcdefghijklmnopqrstuv";
|
|
283
|
+
const base58 = base(ALPHABET$1);
|
|
284
|
+
const base58Hex = base(ALPHABET_HEX);
|
|
285
|
+
const encode = base58.encode;
|
|
286
|
+
const decode = base58.decode;
|
|
287
|
+
const encodeHex = base58Hex.encode;
|
|
288
|
+
const decodeHex = base58Hex.decode;
|
|
289
|
+
const isBase58 = (string) => {
|
|
290
|
+
try {
|
|
291
|
+
decode(string);
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
return false;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
const isBase58Hex = (string) => {
|
|
299
|
+
try {
|
|
300
|
+
decodeHex(string);
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
catch (e) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
const whatType = (string) => {
|
|
308
|
+
try {
|
|
309
|
+
decode(string);
|
|
310
|
+
return "base58";
|
|
311
|
+
}
|
|
312
|
+
catch (e) {
|
|
313
|
+
try {
|
|
314
|
+
decodeHex(string);
|
|
315
|
+
return "base58Hex";
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var base58$1 = {
|
|
323
|
+
encode,
|
|
324
|
+
decode,
|
|
325
|
+
isBase58,
|
|
326
|
+
isBase58Hex,
|
|
327
|
+
encodeHex,
|
|
328
|
+
decodeHex,
|
|
329
|
+
whatType,
|
|
330
|
+
};
|
|
320
331
|
|
|
321
332
|
const ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
322
333
|
base(ALPHABET);
|
|
@@ -467,18 +478,20 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
467
478
|
infoHash;
|
|
468
479
|
_infoHashBuffer;
|
|
469
480
|
_infoHashBinary;
|
|
481
|
+
#maxPeerChannels;
|
|
470
482
|
/**
|
|
471
483
|
*
|
|
472
484
|
* @param array announceURLs List of announce tracker URLs
|
|
473
485
|
* @param string identifierString Identifier used to discover peers in the network
|
|
474
486
|
*/
|
|
475
|
-
constructor(announceURLs = [], identifierString = '', peerId) {
|
|
487
|
+
constructor(announceURLs = [], identifierString = '', peerId, maxPeerChannels = 5) {
|
|
476
488
|
super();
|
|
477
489
|
this.announceURLs = announceURLs;
|
|
478
490
|
this.trackers = {};
|
|
479
491
|
this.peers = {};
|
|
480
492
|
this.msgChunks = {};
|
|
481
493
|
this.responseWaiting = {};
|
|
494
|
+
this.#maxPeerChannels = maxPeerChannels;
|
|
482
495
|
if (identifierString) {
|
|
483
496
|
this.setIdentifier(identifierString);
|
|
484
497
|
}
|
|
@@ -497,83 +510,94 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
497
510
|
this._infoHashBuffer = hex2arr(this.infoHash);
|
|
498
511
|
this._infoHashBinary = hex2bin(this.infoHash);
|
|
499
512
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
553
|
-
this._destroyChunks(data.id);
|
|
554
|
-
}
|
|
513
|
+
#onPeerConnect = (peer) => {
|
|
514
|
+
let newpeer = false;
|
|
515
|
+
/**
|
|
516
|
+
* peer connected or reconnected
|
|
517
|
+
* Sometimes peers reconnect so need to handle the newpeer here
|
|
518
|
+
*/
|
|
519
|
+
if (!this.peers[peer.id]) {
|
|
520
|
+
newpeer = true;
|
|
521
|
+
this.peers[peer.id] = {};
|
|
522
|
+
if (!this.responseWaiting[peer.id])
|
|
523
|
+
this.responseWaiting[peer.id] = {};
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Multiple data channels to one peer is possible
|
|
527
|
+
* The `peer` object actually refers to a peer with a data channel. Even though it may have same `id` (peerID) property, the data channel will be different. Different trackers giving the same "peer" will give the `peer` object with different channels.
|
|
528
|
+
* We will store all channels as backups in case any one of them fails
|
|
529
|
+
* A peer is removed if all data channels become unavailable
|
|
530
|
+
*/
|
|
531
|
+
for (const channelName in this.peers[peer.id]) {
|
|
532
|
+
if (!this.peers[peer.id][channelName].connected) {
|
|
533
|
+
this.peers[peer.id][channelName].destroy();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (Object.keys(this.peers[peer.id]).length < this.#maxPeerChannels)
|
|
537
|
+
this.peers[peer.id][peer.channelName] = peer;
|
|
538
|
+
else
|
|
539
|
+
peer.destroy();
|
|
540
|
+
if (newpeer) {
|
|
541
|
+
this.emit('peerconnect', peer);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
#onPeerData = (peer, data) => {
|
|
545
|
+
this.emit('data', peer, data);
|
|
546
|
+
data = data.toString();
|
|
547
|
+
debug('got a message from ' + peer.id);
|
|
548
|
+
if (data[0] === JSON_MESSAGE_IDENTIFIER) {
|
|
549
|
+
try {
|
|
550
|
+
data = JSON.parse(data.slice(1));
|
|
551
|
+
// A respond function
|
|
552
|
+
peer.respond = this._peerRespond(peer, data.id);
|
|
553
|
+
let msg = this._chunkHandler(data);
|
|
554
|
+
// msg fully retrieved
|
|
555
|
+
if (msg !== false) {
|
|
556
|
+
if (data.o) {
|
|
557
|
+
msg = JSON.parse(msg);
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* If there's someone waiting for a response, call them
|
|
561
|
+
*/
|
|
562
|
+
if (this.responseWaiting[peer.id] && this.responseWaiting[peer.id][data.id]) {
|
|
563
|
+
this.responseWaiting[peer.id][data.id]([peer, msg]);
|
|
564
|
+
delete this.responseWaiting[peer.id][data.id];
|
|
555
565
|
}
|
|
556
|
-
|
|
557
|
-
|
|
566
|
+
else {
|
|
567
|
+
this.emit('msg', peer, msg, data.id, data.from);
|
|
558
568
|
}
|
|
569
|
+
this._destroyChunks(data.id);
|
|
559
570
|
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
571
|
+
}
|
|
572
|
+
catch (e) {
|
|
573
|
+
console.log(e);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
};
|
|
577
|
+
#onPeer = (peer) => {
|
|
578
|
+
peer.on('connect', () => this.#onPeerConnect(peer));
|
|
579
|
+
peer.on('data', (data) => this.#onPeerData(peer, data));
|
|
580
|
+
peer.on('error', (err) => {
|
|
581
|
+
this._removePeer(peer);
|
|
582
|
+
debug('Error in connection : ' + err);
|
|
569
583
|
});
|
|
584
|
+
peer.on('close', () => {
|
|
585
|
+
this._removePeer(peer);
|
|
586
|
+
debug('Connection closed with ' + peer.id);
|
|
587
|
+
});
|
|
588
|
+
};
|
|
589
|
+
/**
|
|
590
|
+
* Connect to network and start discovering peers
|
|
591
|
+
*/
|
|
592
|
+
start() {
|
|
593
|
+
this.on('peer', this.#onPeer);
|
|
570
594
|
// Tracker responded to the announce request
|
|
571
|
-
this.on('update', response => {
|
|
595
|
+
this.on('update', (response) => {
|
|
572
596
|
const tracker = this.trackers[this.announceURLs.indexOf(response.announce)];
|
|
573
597
|
this.emit('trackerconnect', tracker, this.getTrackerStats());
|
|
574
598
|
});
|
|
575
599
|
// Errors in tracker connection
|
|
576
|
-
this.on('warning', err => {
|
|
600
|
+
this.on('warning', (err) => {
|
|
577
601
|
this.emit('trackerwarning', err, this.getTrackerStats());
|
|
578
602
|
});
|
|
579
603
|
this._fetchPeers();
|
|
@@ -611,7 +635,10 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
611
635
|
if (!this.peers[peer.id]) {
|
|
612
636
|
return false;
|
|
613
637
|
}
|
|
614
|
-
|
|
638
|
+
if (this.peers[peer.id][peer.channelName]) {
|
|
639
|
+
this.peers[peer.id][peer.channelName].destroy();
|
|
640
|
+
delete this.peers[peer.id][peer.channelName];
|
|
641
|
+
}
|
|
615
642
|
// All data channels are gone. Peer lost
|
|
616
643
|
if (Object.keys(this.peers[peer.id]).length === 0) {
|
|
617
644
|
this.emit('peerclose', peer);
|
|
@@ -665,8 +692,13 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
665
692
|
* Array should atleast have one channel, otherwise peer connection is closed
|
|
666
693
|
*/
|
|
667
694
|
if (!peer.connected) {
|
|
668
|
-
for (const index in this.peers[peer.id]) {
|
|
695
|
+
for (const index in { ...this.peers[peer.id] }) {
|
|
669
696
|
peer = this.peers[peer.id][index];
|
|
697
|
+
/**
|
|
698
|
+
* directly cleanup channels
|
|
699
|
+
*/
|
|
700
|
+
if (!peer.connected)
|
|
701
|
+
this._removePeer(peer);
|
|
670
702
|
if (peer.connected)
|
|
671
703
|
break;
|
|
672
704
|
}
|
|
@@ -687,7 +719,7 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
687
719
|
* Request more peers
|
|
688
720
|
*/
|
|
689
721
|
requestMorePeers() {
|
|
690
|
-
return new Promise(resolve => {
|
|
722
|
+
return new Promise((resolve) => {
|
|
691
723
|
for (const key in this.trackers) {
|
|
692
724
|
this.trackers[key].announce(this._defaultAnnounceOpts());
|
|
693
725
|
}
|
|
@@ -729,7 +761,7 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
729
761
|
* @param integer msgID Message ID
|
|
730
762
|
*/
|
|
731
763
|
_peerRespond(peer, msgID) {
|
|
732
|
-
return msg => {
|
|
764
|
+
return (msg) => {
|
|
733
765
|
return this.send(peer, msg, msgID);
|
|
734
766
|
};
|
|
735
767
|
}
|
|
@@ -763,7 +795,7 @@ let P2PT$1 = class P2PT extends EventEmitter {
|
|
|
763
795
|
*/
|
|
764
796
|
_defaultAnnounceOpts(options = {}) {
|
|
765
797
|
if (options.numwant === undefined)
|
|
766
|
-
options.numwant =
|
|
798
|
+
options.numwant = 5;
|
|
767
799
|
if (options.uploaded === undefined)
|
|
768
800
|
options.uploaded = 0;
|
|
769
801
|
if (options.downloaded === undefined)
|
|
@@ -1231,7 +1263,7 @@ class WebSocketTracker extends Tracker {
|
|
|
1231
1263
|
if (data.complete != null) {
|
|
1232
1264
|
const response = Object.assign({}, data, {
|
|
1233
1265
|
announce: this.announceUrl,
|
|
1234
|
-
infoHash: data.info_hash
|
|
1266
|
+
infoHash: common.binaryToHex(data.info_hash)
|
|
1235
1267
|
});
|
|
1236
1268
|
this.client.emit('update', response);
|
|
1237
1269
|
}
|
|
@@ -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-34c93510.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));
|
|
@@ -27280,7 +27280,7 @@ class Peernet {
|
|
|
27280
27280
|
this.root = options.root;
|
|
27281
27281
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
27282
27282
|
// FolderMessageResponse
|
|
27283
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
27283
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-b7f41cba.js');
|
|
27284
27284
|
/**
|
|
27285
27285
|
* proto Object containing protos
|
|
27286
27286
|
* @type {Object}
|
|
@@ -27371,7 +27371,7 @@ class Peernet {
|
|
|
27371
27371
|
if (this.#starting || this.#started)
|
|
27372
27372
|
return;
|
|
27373
27373
|
this.#starting = true;
|
|
27374
|
-
const importee = await import('./client-
|
|
27374
|
+
const importee = await import('./client-493cbd83.js');
|
|
27375
27375
|
/**
|
|
27376
27376
|
* @access public
|
|
27377
27377
|
* @type {PeernetClient}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { P as default } from './peernet-
|
|
1
|
+
export { P as default } from './peernet-72528dd9.js';
|
|
2
2
|
import './value-4e80eeeb.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/peernet.js",
|
|
6
6
|
"exports": {
|
|
@@ -33,9 +33,10 @@
|
|
|
33
33
|
"@leofcoin/generate-account": "^2.0.0",
|
|
34
34
|
"@leofcoin/identity-utils": "^1.0.2",
|
|
35
35
|
"@leofcoin/multi-wallet": "^3.1.4",
|
|
36
|
+
"@leofcoin/p2pt": "^1.7.6",
|
|
36
37
|
"@leofcoin/peernet-swarm": "^1.1.0",
|
|
37
38
|
"@leofcoin/storage": "^3.0.0",
|
|
38
|
-
"@netpeer/p2pt-swarm": "^1.3.
|
|
39
|
+
"@netpeer/p2pt-swarm": "^1.3.5",
|
|
39
40
|
"@types/node": "^18.11.18",
|
|
40
41
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
41
42
|
"@vandeurenglenn/base58": "^1.1.0",
|