@leofcoin/chain 1.7.91 → 1.7.93

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.
@@ -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,12 +5412,7 @@ class ConnectionMonitor {
5418
5412
  // }
5419
5413
  }
5420
5414
  async #attemptReconnection() {
5421
- if (this.#reconnectAttempts >= this.#maxReconnectAttempts) {
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
5418
  if (globalThis.peernet?.start) {
@@ -5434,8 +5423,15 @@ class ConnectionMonitor {
5434
5423
  }
5435
5424
  catch (error) {
5436
5425
  console.error('❌ Reconnection failed:', error.message);
5437
- // Exponential backoff
5438
- this.#reconnectDelay = Math.min(this.#reconnectDelay * 1.5, 30000);
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 { L as LittlePubSub } from './node-browser-CsSAehTl.js';
1
+ import { L as LittlePubSub } from './node-browser-D4im-c4V.js';
2
2
  import './identity-Cn0iQbY3-CeW0giQS.js';
3
3
  import './index-DUfUgiQY.js';
4
4
 
@@ -42,7 +42,7 @@ class Api {
42
42
  if (state !== 'open')
43
43
  return reject(`coudn't send request to ${client.id}, no open connection found.`);
44
44
  request.id = Math.random().toString(36).slice(-12);
45
- const handler = result => {
45
+ const handler = (result) => {
46
46
  if (result && result.error)
47
47
  return reject(result.error);
48
48
  resolve({ result, id: request.id, handler });
@@ -62,11 +62,17 @@ class Api {
62
62
  },
63
63
  subscribe: (topic = 'pubsub', cb) => {
64
64
  this.subscribe(topic, cb);
65
- return this.send(client, { url: 'pubsub', params: { topic, subscribe: true } });
65
+ return this.send(client, {
66
+ url: 'pubsub',
67
+ params: { topic, subscribe: true }
68
+ });
66
69
  },
67
70
  unsubscribe: (topic = 'pubsub', cb) => {
68
71
  this.unsubscribe(topic, cb);
69
- return this.send(client, { url: 'pubsub', params: { topic, unsubscribe: true } });
72
+ return this.send(client, {
73
+ url: 'pubsub',
74
+ params: { topic, unsubscribe: true }
75
+ });
70
76
  },
71
77
  subscribers: this._pubsub.subscribers
72
78
  };
@@ -75,7 +81,9 @@ class Api {
75
81
  return {
76
82
  uptime: async () => {
77
83
  try {
78
- const { result, id, handler } = await this.request(client, { url: 'uptime' });
84
+ const { result, id, handler } = await this.request(client, {
85
+ url: 'uptime'
86
+ });
79
87
  this.unsubscribe(id, handler);
80
88
  return result;
81
89
  }
@@ -86,9 +94,11 @@ class Api {
86
94
  ping: async () => {
87
95
  try {
88
96
  const now = new Date().getTime();
89
- const { result, id, handler } = await this.request(client, { url: 'ping' });
97
+ const { result, id, handler } = await this.request(client, {
98
+ url: 'ping'
99
+ });
90
100
  this.unsubscribe(id, handler);
91
- return (Number(result) - now);
101
+ return Number(result) - now;
92
102
  }
93
103
  catch (e) {
94
104
  throw e;
@@ -121,6 +131,18 @@ class Api {
121
131
  catch (e) {
122
132
  throw e;
123
133
  }
134
+ },
135
+ peers: async (params) => {
136
+ try {
137
+ params.peers = true;
138
+ const requested = { url: 'peernet', params };
139
+ const { result, id, handler } = await this.request(client, requested);
140
+ this.unsubscribe(id, handler);
141
+ return result;
142
+ }
143
+ catch (e) {
144
+ throw e;
145
+ }
124
146
  }
125
147
  };
126
148
  }
@@ -475,7 +497,7 @@ class Client {
475
497
  });
476
498
  }
477
499
  else {
478
- globalThis.addEventListener('beforeunload', async () => this.close());
500
+ globalThis.addEventListener('beforeunload', this.close.bind(this));
479
501
  }
480
502
  }
481
503
  setupStarListeners(star) {
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './node-browser-CsSAehTl.js';
1
+ import { F as FormatInterface } from './node-browser-D4im-c4V.js';
2
2
  import './identity-Cn0iQbY3-CeW0giQS.js';
3
3
  import './index-DUfUgiQY.js';
4
4
 
@@ -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-BYZZUpuv-MiKV0Pk4.js');
8499
+ } = await import(/* webpackChunkName: "messages" */ './messages-B9TrXtD1-B5p-nLLO.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-Vbt0C3YZ-BSi2TKqM.js');
8593
+ const importee = await import('./client-BScgNzXE-Vdpk0JDu.js');
8594
8594
  /**
8595
8595
  * @access public
8596
8596
  * @type {PeernetClient}
@@ -1,3 +1,3 @@
1
- export { N as default } from './node-browser-CsSAehTl.js';
1
+ export { N as default } from './node-browser-D4im-c4V.js';
2
2
  import './identity-Cn0iQbY3-CeW0giQS.js';
3
3
  import './index-DUfUgiQY.js';
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,12 +1558,7 @@ class ConnectionMonitor {
1564
1558
  // }
1565
1559
  }
1566
1560
  async #attemptReconnection() {
1567
- if (this.#reconnectAttempts >= this.#maxReconnectAttempts) {
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
1564
  if (globalThis.peernet?.start) {
@@ -1580,8 +1569,15 @@ class ConnectionMonitor {
1580
1569
  }
1581
1570
  catch (error) {
1582
1571
  console.error('❌ Reconnection failed:', error.message);
1583
- // Exponential backoff
1584
- this.#reconnectDelay = Math.min(this.#reconnectDelay * 1.5, 30000);
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.91",
3
+ "version": "1.7.93",
4
4
  "description": "Official javascript implementation",
5
5
  "private": false,
6
6
  "exports": {
@@ -55,7 +55,7 @@
55
55
  "@rollup/plugin-typescript": "^12.1.4",
56
56
  "@types/semver": "^7.7.0",
57
57
  "@vandeurenglenn/debug": "^1.2.6",
58
- "rollup": "^4.45.1",
58
+ "rollup": "^4.46.2",
59
59
  "rollup-plugin-modify": "^3.0.0",
60
60
  "tape": "^5.9.0",
61
61
  "tslib": "^2.8.1"
@@ -71,7 +71,7 @@
71
71
  "@leofcoin/networks": "^1.1.25",
72
72
  "@leofcoin/peernet": "^1.1.92",
73
73
  "@leofcoin/storage": "^3.5.38",
74
- "@leofcoin/utils": "^1.1.39",
74
+ "@leofcoin/utils": "^1.1.40",
75
75
  "@leofcoin/workers": "^1.5.27",
76
76
  "@vandeurenglenn/base58": "^1.1.9",
77
77
  "@vandeurenglenn/easy-worker": "^1.0.2",