@leofcoin/chain 1.7.92 → 1.7.94
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/chain.js +13 -17
- package/exports/browser/{client-BScgNzXE-Vdpk0JDu.js → client-BGaLaHk2-CA-9lfx-.js} +1 -1
- package/exports/browser/{messages-B9TrXtD1-B5p-nLLO.js → messages-BqTna7yM-sC5s4kYG.js} +4 -1
- package/exports/browser/{node-browser-D4im-c4V.js → node-browser-DwZGtboN.js} +20 -11
- package/exports/browser/node-browser.js +1 -1
- package/exports/chain.js +13 -17
- package/package.json +2 -2
package/exports/browser/chain.js
CHANGED
|
@@ -5312,7 +5312,6 @@ class VersionControl extends State {
|
|
|
5312
5312
|
class ConnectionMonitor {
|
|
5313
5313
|
#isMonitoring = false;
|
|
5314
5314
|
#checkInterval = null;
|
|
5315
|
-
#reconnectAttempts = 0;
|
|
5316
5315
|
#peerReconnectAttempts = {};
|
|
5317
5316
|
#maxReconnectAttempts = 10;
|
|
5318
5317
|
#reconnectDelay = 5000;
|
|
@@ -5366,10 +5365,6 @@ class ConnectionMonitor {
|
|
|
5366
5365
|
await this.#attemptReconnection();
|
|
5367
5366
|
// Could attempt to find compatible peers or trigger version negotiation
|
|
5368
5367
|
}
|
|
5369
|
-
else {
|
|
5370
|
-
// Reset reconnect attempts on successful connection
|
|
5371
|
-
this.#reconnectAttempts = 0;
|
|
5372
|
-
}
|
|
5373
5368
|
// Log disconnected peers
|
|
5374
5369
|
const disconnectedPeers = this.disconnectedPeers;
|
|
5375
5370
|
if (disconnectedPeers.length > 0) {
|
|
@@ -5392,7 +5387,6 @@ class ConnectionMonitor {
|
|
|
5392
5387
|
if (this.#peerReconnectAttempts[peer.peerId] >= this.#maxReconnectAttempts) {
|
|
5393
5388
|
console.error('❌ Max reconnection attempts reached');
|
|
5394
5389
|
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
5395
|
-
return;
|
|
5396
5390
|
}
|
|
5397
5391
|
if (!this.#peerReconnectAttempts[peer.peerId]) {
|
|
5398
5392
|
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
@@ -5418,24 +5412,26 @@ class ConnectionMonitor {
|
|
|
5418
5412
|
// }
|
|
5419
5413
|
}
|
|
5420
5414
|
async #attemptReconnection() {
|
|
5421
|
-
|
|
5422
|
-
console.error('❌ Max reconnection attempts reached');
|
|
5423
|
-
return;
|
|
5424
|
-
}
|
|
5425
|
-
this.#reconnectAttempts++;
|
|
5426
|
-
console.log(`🔄 Attempting reconnection ${this.#reconnectAttempts}/${this.#maxReconnectAttempts}`);
|
|
5415
|
+
console.warn('⚠️ Attempting to reconnect to peers...');
|
|
5427
5416
|
try {
|
|
5428
5417
|
// Try to restart the network
|
|
5429
|
-
if (globalThis.peernet?.start) {
|
|
5430
|
-
|
|
5431
|
-
}
|
|
5418
|
+
// if (globalThis.peernet?.start) {
|
|
5419
|
+
// await globalThis.peernet.start()
|
|
5420
|
+
// }
|
|
5432
5421
|
// Wait a bit before next check
|
|
5433
5422
|
await new Promise((resolve) => setTimeout(resolve, this.#reconnectDelay));
|
|
5434
5423
|
}
|
|
5435
5424
|
catch (error) {
|
|
5436
5425
|
console.error('❌ Reconnection failed:', error.message);
|
|
5437
|
-
|
|
5438
|
-
|
|
5426
|
+
if (this.#reconnectDelay >= 30000) {
|
|
5427
|
+
console.warn('⚠️ Reconnection delay reached maximum, resetting to 5 seconds');
|
|
5428
|
+
this.#reconnectDelay = 5000;
|
|
5429
|
+
}
|
|
5430
|
+
else {
|
|
5431
|
+
// Exponential backoff
|
|
5432
|
+
this.#reconnectDelay = Math.min(this.#reconnectDelay * 1.5, 30000);
|
|
5433
|
+
console.warn(`⚠️ Increasing reconnection delay to ${this.#reconnectDelay} ms`);
|
|
5434
|
+
}
|
|
5439
5435
|
}
|
|
5440
5436
|
}
|
|
5441
5437
|
async waitForPeers(timeoutMs = 30000) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FormatInterface } from './node-browser-
|
|
1
|
+
import { F as FormatInterface } from './node-browser-DwZGtboN.js';
|
|
2
2
|
import './identity-Cn0iQbY3-CeW0giQS.js';
|
|
3
3
|
import './index-DUfUgiQY.js';
|
|
4
4
|
|
|
@@ -50,6 +50,9 @@ var proto$9 = {
|
|
|
50
50
|
has: Boolean()
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @extends typeof {FormatInterface}
|
|
55
|
+
*/
|
|
53
56
|
class DHTMessageResponse extends FormatInterface {
|
|
54
57
|
get messageName() {
|
|
55
58
|
return 'PeernetDHTMessageResponse'
|
|
@@ -8496,7 +8496,7 @@ class Peernet {
|
|
|
8496
8496
|
this.root = options.root;
|
|
8497
8497
|
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
|
|
8498
8498
|
// FolderMessageResponse
|
|
8499
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
8499
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-BqTna7yM-sC5s4kYG.js');
|
|
8500
8500
|
/**
|
|
8501
8501
|
* proto Object containing protos
|
|
8502
8502
|
* @type {Object}
|
|
@@ -8590,7 +8590,7 @@ class Peernet {
|
|
|
8590
8590
|
if (this.#starting || this.#started)
|
|
8591
8591
|
return;
|
|
8592
8592
|
this.#starting = true;
|
|
8593
|
-
const importee = await import('./client-
|
|
8593
|
+
const importee = await import('./client-BGaLaHk2-CA-9lfx-.js');
|
|
8594
8594
|
/**
|
|
8595
8595
|
* @access public
|
|
8596
8596
|
* @type {PeernetClient}
|
|
@@ -8738,7 +8738,7 @@ class Peernet {
|
|
|
8738
8738
|
if (proto.name !== 'peernet-dht-response')
|
|
8739
8739
|
throw dhtError(proto.name);
|
|
8740
8740
|
const peerInfo = {
|
|
8741
|
-
|
|
8741
|
+
address: peer.remoteAddress,
|
|
8742
8742
|
id: peerId
|
|
8743
8743
|
};
|
|
8744
8744
|
if (proto.decoded.has)
|
|
@@ -8746,6 +8746,7 @@ class Peernet {
|
|
|
8746
8746
|
}
|
|
8747
8747
|
catch (error) {
|
|
8748
8748
|
console.error(`Error while walking ${peerId}`, error);
|
|
8749
|
+
return undefined;
|
|
8749
8750
|
}
|
|
8750
8751
|
};
|
|
8751
8752
|
let walks = [];
|
|
@@ -8754,7 +8755,7 @@ class Peernet {
|
|
|
8754
8755
|
walks.push(walk(peer, peerId));
|
|
8755
8756
|
}
|
|
8756
8757
|
}
|
|
8757
|
-
return Promise.
|
|
8758
|
+
return Promise.race(walks);
|
|
8758
8759
|
}
|
|
8759
8760
|
/**
|
|
8760
8761
|
* Override DHT behavior, try's finding the content three times
|
|
@@ -8811,18 +8812,26 @@ class Peernet {
|
|
|
8811
8812
|
throw nothingFoundError(hash);
|
|
8812
8813
|
debug(`found ${Object.keys(providers).length} provider(s) for ${hash}`);
|
|
8813
8814
|
// get closest peer on earth
|
|
8814
|
-
|
|
8815
|
+
let closestPeer = await this.dht.closestPeer(Object.values(providers));
|
|
8816
|
+
// fallback to first provider if no closest peer found
|
|
8817
|
+
if (!closestPeer || !closestPeer.id)
|
|
8818
|
+
closestPeer = Object.values(providers)[0];
|
|
8819
|
+
debug(`closest peer for ${hash} is ${closestPeer?.address}`);
|
|
8815
8820
|
// get peer instance by id
|
|
8816
8821
|
if (!closestPeer || !closestPeer.id)
|
|
8817
8822
|
return this.requestData(hash, store?.name || store);
|
|
8818
8823
|
const id = closestPeer.id;
|
|
8819
8824
|
const peer = this.connections[id];
|
|
8825
|
+
if (!peer || !peer?.connected) {
|
|
8826
|
+
this.dht.removeProvider(id, hash);
|
|
8827
|
+
return this.requestData(hash, store?.name || store);
|
|
8828
|
+
}
|
|
8829
|
+
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
8830
|
+
hash,
|
|
8831
|
+
store: store?.name || store
|
|
8832
|
+
});
|
|
8833
|
+
const node = await this.prepareMessage(data);
|
|
8820
8834
|
if (peer?.connected) {
|
|
8821
|
-
let data = await new globalThis.peernet.protos['peernet-data']({
|
|
8822
|
-
hash,
|
|
8823
|
-
store: store?.name || store
|
|
8824
|
-
});
|
|
8825
|
-
const node = await this.prepareMessage(data);
|
|
8826
8835
|
try {
|
|
8827
8836
|
if (peer)
|
|
8828
8837
|
data = await peer.request(node.encoded);
|
|
@@ -8848,10 +8857,10 @@ class Peernet {
|
|
|
8848
8857
|
catch (error) {
|
|
8849
8858
|
debug(`Error while requesting data from ${id}`, error);
|
|
8850
8859
|
// if error, remove provider
|
|
8851
|
-
this.dht.removeProvider(id, hash);
|
|
8852
8860
|
if (this.#peerAttempts[id] > 1) {
|
|
8853
8861
|
this.#peerAttempts[id] = 0;
|
|
8854
8862
|
debug(`Removed provider ${id} for ${hash} after 3 attempts`);
|
|
8863
|
+
this.dht.removeProvider(id, hash);
|
|
8855
8864
|
console.error(nothingFoundError(hash));
|
|
8856
8865
|
return undefined;
|
|
8857
8866
|
}
|
package/exports/chain.js
CHANGED
|
@@ -1458,7 +1458,6 @@ class VersionControl extends State {
|
|
|
1458
1458
|
class ConnectionMonitor {
|
|
1459
1459
|
#isMonitoring = false;
|
|
1460
1460
|
#checkInterval = null;
|
|
1461
|
-
#reconnectAttempts = 0;
|
|
1462
1461
|
#peerReconnectAttempts = {};
|
|
1463
1462
|
#maxReconnectAttempts = 10;
|
|
1464
1463
|
#reconnectDelay = 5000;
|
|
@@ -1512,10 +1511,6 @@ class ConnectionMonitor {
|
|
|
1512
1511
|
await this.#attemptReconnection();
|
|
1513
1512
|
// Could attempt to find compatible peers or trigger version negotiation
|
|
1514
1513
|
}
|
|
1515
|
-
else {
|
|
1516
|
-
// Reset reconnect attempts on successful connection
|
|
1517
|
-
this.#reconnectAttempts = 0;
|
|
1518
|
-
}
|
|
1519
1514
|
// Log disconnected peers
|
|
1520
1515
|
const disconnectedPeers = this.disconnectedPeers;
|
|
1521
1516
|
if (disconnectedPeers.length > 0) {
|
|
@@ -1538,7 +1533,6 @@ class ConnectionMonitor {
|
|
|
1538
1533
|
if (this.#peerReconnectAttempts[peer.peerId] >= this.#maxReconnectAttempts) {
|
|
1539
1534
|
console.error('❌ Max reconnection attempts reached');
|
|
1540
1535
|
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
1541
|
-
return;
|
|
1542
1536
|
}
|
|
1543
1537
|
if (!this.#peerReconnectAttempts[peer.peerId]) {
|
|
1544
1538
|
this.#peerReconnectAttempts[peer.peerId] = 0;
|
|
@@ -1564,24 +1558,26 @@ class ConnectionMonitor {
|
|
|
1564
1558
|
// }
|
|
1565
1559
|
}
|
|
1566
1560
|
async #attemptReconnection() {
|
|
1567
|
-
|
|
1568
|
-
console.error('❌ Max reconnection attempts reached');
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
|
-
this.#reconnectAttempts++;
|
|
1572
|
-
console.log(`🔄 Attempting reconnection ${this.#reconnectAttempts}/${this.#maxReconnectAttempts}`);
|
|
1561
|
+
console.warn('⚠️ Attempting to reconnect to peers...');
|
|
1573
1562
|
try {
|
|
1574
1563
|
// Try to restart the network
|
|
1575
|
-
if (globalThis.peernet?.start) {
|
|
1576
|
-
|
|
1577
|
-
}
|
|
1564
|
+
// if (globalThis.peernet?.start) {
|
|
1565
|
+
// await globalThis.peernet.start()
|
|
1566
|
+
// }
|
|
1578
1567
|
// Wait a bit before next check
|
|
1579
1568
|
await new Promise((resolve) => setTimeout(resolve, this.#reconnectDelay));
|
|
1580
1569
|
}
|
|
1581
1570
|
catch (error) {
|
|
1582
1571
|
console.error('❌ Reconnection failed:', error.message);
|
|
1583
|
-
|
|
1584
|
-
|
|
1572
|
+
if (this.#reconnectDelay >= 30000) {
|
|
1573
|
+
console.warn('⚠️ Reconnection delay reached maximum, resetting to 5 seconds');
|
|
1574
|
+
this.#reconnectDelay = 5000;
|
|
1575
|
+
}
|
|
1576
|
+
else {
|
|
1577
|
+
// Exponential backoff
|
|
1578
|
+
this.#reconnectDelay = Math.min(this.#reconnectDelay * 1.5, 30000);
|
|
1579
|
+
console.warn(`⚠️ Increasing reconnection delay to ${this.#reconnectDelay} ms`);
|
|
1580
|
+
}
|
|
1585
1581
|
}
|
|
1586
1582
|
}
|
|
1587
1583
|
async waitForPeers(timeoutMs = 30000) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.94",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"@leofcoin/messages": "^1.4.40",
|
|
70
70
|
"@leofcoin/multi-wallet": "^3.1.8",
|
|
71
71
|
"@leofcoin/networks": "^1.1.25",
|
|
72
|
-
"@leofcoin/peernet": "^1.1.
|
|
72
|
+
"@leofcoin/peernet": "^1.1.95",
|
|
73
73
|
"@leofcoin/storage": "^3.5.38",
|
|
74
74
|
"@leofcoin/utils": "^1.1.40",
|
|
75
75
|
"@leofcoin/workers": "^1.5.27",
|