@leofcoin/peernet 1.1.87 → 1.1.88
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-MAPwcc7G.js → client-D7CuvpPv.js} +1 -1
- package/exports/browser/{messages-BkkXT6WO.js → messages-D9OyBKBu.js} +1 -1
- package/exports/browser/{peernet-P6qb1z0Q.js → peernet-CZhvkXXp.js} +45 -29
- package/exports/browser/peernet.js +1 -1
- package/exports/peernet.js +43 -27
- package/package.json +1 -1
- package/src/peernet.ts +36 -24
|
@@ -8371,7 +8371,7 @@ class Peernet {
|
|
|
8371
8371
|
this.root = options.root;
|
|
8372
8372
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
8373
8373
|
// FolderMessageResponse
|
|
8374
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8374
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-D9OyBKBu.js');
|
|
8375
8375
|
/**
|
|
8376
8376
|
* proto Object containing protos
|
|
8377
8377
|
* @type {Object}
|
|
@@ -8465,7 +8465,7 @@ class Peernet {
|
|
|
8465
8465
|
if (this.#starting || this.#started)
|
|
8466
8466
|
return;
|
|
8467
8467
|
this.#starting = true;
|
|
8468
|
-
const importee = await import('./client-
|
|
8468
|
+
const importee = await import('./client-D7CuvpPv.js');
|
|
8469
8469
|
/**
|
|
8470
8470
|
* @access public
|
|
8471
8471
|
* @type {PeernetClient}
|
|
@@ -8606,17 +8606,22 @@ class Peernet {
|
|
|
8606
8606
|
const data = await new globalThis.peernet.protos['peernet-dht']({ hash });
|
|
8607
8607
|
const walk = async (peer, peerId) => {
|
|
8608
8608
|
const node = await this.prepareMessage(data);
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8612
|
-
|
|
8613
|
-
|
|
8614
|
-
|
|
8615
|
-
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
8619
|
-
|
|
8609
|
+
try {
|
|
8610
|
+
let result = await peer.request(node.encoded);
|
|
8611
|
+
result = new Uint8Array(Object.values(result));
|
|
8612
|
+
const proto = await protoFor(result);
|
|
8613
|
+
if (proto.name !== 'peernet-dht-response')
|
|
8614
|
+
throw dhtError(proto.name);
|
|
8615
|
+
const peerInfo = {
|
|
8616
|
+
...peer.connectionStats,
|
|
8617
|
+
id: peerId
|
|
8618
|
+
};
|
|
8619
|
+
if (proto.decoded.has)
|
|
8620
|
+
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
8621
|
+
}
|
|
8622
|
+
catch (error) {
|
|
8623
|
+
console.error(`Error while walking ${peerId}`, error);
|
|
8624
|
+
}
|
|
8620
8625
|
};
|
|
8621
8626
|
let walks = [];
|
|
8622
8627
|
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
@@ -8693,24 +8698,35 @@ class Peernet {
|
|
|
8693
8698
|
store: store?.name || store
|
|
8694
8699
|
});
|
|
8695
8700
|
const node = await this.prepareMessage(data);
|
|
8696
|
-
|
|
8697
|
-
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
|
|
8703
|
-
const
|
|
8704
|
-
|
|
8705
|
-
|
|
8701
|
+
try {
|
|
8702
|
+
if (peer)
|
|
8703
|
+
data = await peer.request(node.encoded);
|
|
8704
|
+
else {
|
|
8705
|
+
// fallback and try every provider found
|
|
8706
|
+
const promises = [];
|
|
8707
|
+
const providers = await this.providersFor(hash, store);
|
|
8708
|
+
for (const provider of Object.values(providers)) {
|
|
8709
|
+
const peer = this.connections[provider.id];
|
|
8710
|
+
if (peer)
|
|
8711
|
+
promises.push(peer.request(node.encoded));
|
|
8712
|
+
}
|
|
8713
|
+
data = await Promise.race(promises);
|
|
8706
8714
|
}
|
|
8707
|
-
|
|
8715
|
+
if (data)
|
|
8716
|
+
data = new Uint8Array(Object.values(data));
|
|
8717
|
+
if (!data || data.length === 0)
|
|
8718
|
+
throw nothingFoundError(hash);
|
|
8719
|
+
const proto = await protoFor(data);
|
|
8720
|
+
// TODO: store data automaticly or not
|
|
8721
|
+
return BufferToUint8Array(proto.decoded.data);
|
|
8722
|
+
}
|
|
8723
|
+
catch (error) {
|
|
8724
|
+
debug(`Error while requesting data from ${id}`, error);
|
|
8725
|
+
// if error, remove provider
|
|
8726
|
+
this.dht.removeProvider(id, hash);
|
|
8727
|
+
// and try again
|
|
8728
|
+
return this.requestData(hash, store?.name || store);
|
|
8708
8729
|
}
|
|
8709
|
-
if (data)
|
|
8710
|
-
data = new Uint8Array(Object.values(data));
|
|
8711
|
-
const proto = await protoFor(data);
|
|
8712
|
-
// TODO: store data automaticly or not
|
|
8713
|
-
return BufferToUint8Array(proto.decoded.data);
|
|
8714
8730
|
// this.put(hash, proto.decoded.data)
|
|
8715
8731
|
}
|
|
8716
8732
|
else {
|
package/exports/peernet.js
CHANGED
|
@@ -687,17 +687,22 @@ class Peernet {
|
|
|
687
687
|
const data = await new globalThis.peernet.protos['peernet-dht']({ hash });
|
|
688
688
|
const walk = async (peer, peerId) => {
|
|
689
689
|
const node = await this.prepareMessage(data);
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
690
|
+
try {
|
|
691
|
+
let result = await peer.request(node.encoded);
|
|
692
|
+
result = new Uint8Array(Object.values(result));
|
|
693
|
+
const proto = await protoFor(result);
|
|
694
|
+
if (proto.name !== 'peernet-dht-response')
|
|
695
|
+
throw dhtError(proto.name);
|
|
696
|
+
const peerInfo = {
|
|
697
|
+
...peer.connectionStats,
|
|
698
|
+
id: peerId
|
|
699
|
+
};
|
|
700
|
+
if (proto.decoded.has)
|
|
701
|
+
this.dht.addProvider(peerInfo, proto.decoded.hash);
|
|
702
|
+
}
|
|
703
|
+
catch (error) {
|
|
704
|
+
console.error(`Error while walking ${peerId}`, error);
|
|
705
|
+
}
|
|
701
706
|
};
|
|
702
707
|
let walks = [];
|
|
703
708
|
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
@@ -774,24 +779,35 @@ class Peernet {
|
|
|
774
779
|
store: store?.name || store
|
|
775
780
|
});
|
|
776
781
|
const node = await this.prepareMessage(data);
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
782
|
+
try {
|
|
783
|
+
if (peer)
|
|
784
|
+
data = await peer.request(node.encoded);
|
|
785
|
+
else {
|
|
786
|
+
// fallback and try every provider found
|
|
787
|
+
const promises = [];
|
|
788
|
+
const providers = await this.providersFor(hash, store);
|
|
789
|
+
for (const provider of Object.values(providers)) {
|
|
790
|
+
const peer = this.connections[provider.id];
|
|
791
|
+
if (peer)
|
|
792
|
+
promises.push(peer.request(node.encoded));
|
|
793
|
+
}
|
|
794
|
+
data = await Promise.race(promises);
|
|
787
795
|
}
|
|
788
|
-
|
|
796
|
+
if (data)
|
|
797
|
+
data = new Uint8Array(Object.values(data));
|
|
798
|
+
if (!data || data.length === 0)
|
|
799
|
+
throw nothingFoundError(hash);
|
|
800
|
+
const proto = await protoFor(data);
|
|
801
|
+
// TODO: store data automaticly or not
|
|
802
|
+
return BufferToUint8Array(proto.decoded.data);
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
debug(`Error while requesting data from ${id}`, error);
|
|
806
|
+
// if error, remove provider
|
|
807
|
+
this.dht.removeProvider(id, hash);
|
|
808
|
+
// and try again
|
|
809
|
+
return this.requestData(hash, store?.name || store);
|
|
789
810
|
}
|
|
790
|
-
if (data)
|
|
791
|
-
data = new Uint8Array(Object.values(data));
|
|
792
|
-
const proto = await protoFor(data);
|
|
793
|
-
// TODO: store data automaticly or not
|
|
794
|
-
return BufferToUint8Array(proto.decoded.data);
|
|
795
811
|
// this.put(hash, proto.decoded.data)
|
|
796
812
|
}
|
|
797
813
|
else {
|
package/package.json
CHANGED
package/src/peernet.ts
CHANGED
|
@@ -467,17 +467,21 @@ export default class Peernet {
|
|
|
467
467
|
const data = await new globalThis.peernet.protos['peernet-dht']({ hash })
|
|
468
468
|
const walk = async (peer, peerId) => {
|
|
469
469
|
const node = await this.prepareMessage(data)
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
470
|
+
try {
|
|
471
|
+
let result = await peer.request(node.encoded)
|
|
472
|
+
result = new Uint8Array(Object.values(result))
|
|
473
|
+
const proto = await protoFor(result)
|
|
474
|
+
if (proto.name !== 'peernet-dht-response') throw dhtError(proto.name)
|
|
475
|
+
|
|
476
|
+
const peerInfo = {
|
|
477
|
+
...peer.connectionStats,
|
|
478
|
+
id: peerId
|
|
479
|
+
}
|
|
479
480
|
|
|
480
|
-
|
|
481
|
+
if (proto.decoded.has) this.dht.addProvider(peerInfo, proto.decoded.hash)
|
|
482
|
+
} catch (error) {
|
|
483
|
+
console.error(`Error while walking ${peerId}`, error)
|
|
484
|
+
}
|
|
481
485
|
}
|
|
482
486
|
let walks = []
|
|
483
487
|
for (const [peerId, peer] of Object.entries(this.connections)) {
|
|
@@ -557,23 +561,31 @@ export default class Peernet {
|
|
|
557
561
|
|
|
558
562
|
const node = await this.prepareMessage(data)
|
|
559
563
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
564
|
+
try {
|
|
565
|
+
if (peer) data = await peer.request(node.encoded)
|
|
566
|
+
else {
|
|
567
|
+
// fallback and try every provider found
|
|
568
|
+
const promises = []
|
|
569
|
+
const providers = await this.providersFor(hash, store)
|
|
570
|
+
for (const provider of Object.values(providers)) {
|
|
571
|
+
const peer = this.connections[provider.id]
|
|
567
572
|
|
|
568
|
-
|
|
573
|
+
if (peer) promises.push(peer.request(node.encoded))
|
|
574
|
+
}
|
|
575
|
+
data = await Promise.race(promises)
|
|
569
576
|
}
|
|
570
|
-
data =
|
|
577
|
+
if (data) data = new Uint8Array(Object.values(data))
|
|
578
|
+
if (!data || data.length === 0) throw nothingFoundError(hash)
|
|
579
|
+
const proto = await protoFor(data)
|
|
580
|
+
// TODO: store data automaticly or not
|
|
581
|
+
return BufferToUint8Array(proto.decoded.data)
|
|
582
|
+
} catch (error) {
|
|
583
|
+
debug(`Error while requesting data from ${id}`, error)
|
|
584
|
+
// if error, remove provider
|
|
585
|
+
this.dht.removeProvider(id, hash)
|
|
586
|
+
// and try again
|
|
587
|
+
return this.requestData(hash, store?.name || store)
|
|
571
588
|
}
|
|
572
|
-
if (data) data = new Uint8Array(Object.values(data))
|
|
573
|
-
|
|
574
|
-
const proto = await protoFor(data)
|
|
575
|
-
// TODO: store data automaticly or not
|
|
576
|
-
return BufferToUint8Array(proto.decoded.data)
|
|
577
589
|
|
|
578
590
|
// this.put(hash, proto.decoded.data)
|
|
579
591
|
} else {
|