@leofcoin/peernet 1.1.89 → 1.1.91

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.
@@ -1,4 +1,4 @@
1
- import { L as LittlePubSub } from './peernet-CZhvkXXp.js';
1
+ import { L as LittlePubSub } from './peernet-DwOQKkjc.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -526,6 +526,22 @@ class Client {
526
526
  }
527
527
  debug(`peer ${id} left`);
528
528
  };
529
+ connect(peerId, star, initiator = true) {
530
+ if (this.#connections[peerId]) {
531
+ debug(`peer ${peerId} already connected`);
532
+ return;
533
+ }
534
+ if (this.#stars[star]?.connectionState() !== 'open') {
535
+ console.warn(`Star ${star} is not connected, cannot reconnect to peer ${peerId}`);
536
+ return;
537
+ }
538
+ this.#createRTCPeerConnection(peerId, star, this.version, initiator);
539
+ }
540
+ reconnect(peerId, star, initiator = true) {
541
+ delete this.#connections[peerId];
542
+ debug(`reconnecting to peer ${peerId}`);
543
+ return this.connect(peerId, star, initiator);
544
+ }
529
545
  #createRTCPeerConnection = (peerId, star, version, initiator = false) => {
530
546
  const peer = new Peer({
531
547
  initiator: initiator,
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-CZhvkXXp.js';
1
+ import { F as FormatInterface } from './peernet-DwOQKkjc.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -8261,6 +8261,7 @@ class Peernet {
8261
8261
  _peerHandler;
8262
8262
  protos;
8263
8263
  version;
8264
+ #peerAttempts = {};
8264
8265
  /**
8265
8266
  * @access public
8266
8267
  * @param {Object} options
@@ -8371,7 +8372,7 @@ class Peernet {
8371
8372
  this.root = options.root;
8372
8373
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
8373
8374
  // FolderMessageResponse
8374
- } = await import(/* webpackChunkName: "messages" */ './messages-D9OyBKBu.js');
8375
+ } = await import(/* webpackChunkName: "messages" */ './messages-PrGKIaCz.js');
8375
8376
  /**
8376
8377
  * proto Object containing protos
8377
8378
  * @type {Object}
@@ -8465,7 +8466,7 @@ class Peernet {
8465
8466
  if (this.#starting || this.#started)
8466
8467
  return;
8467
8468
  this.#starting = true;
8468
- const importee = await import('./client-D7CuvpPv.js');
8469
+ const importee = await import('./client-CWo3zJ1j.js');
8469
8470
  /**
8470
8471
  * @access public
8471
8472
  * @type {PeernetClient}
@@ -8724,7 +8725,14 @@ class Peernet {
8724
8725
  debug(`Error while requesting data from ${id}`, error);
8725
8726
  // if error, remove provider
8726
8727
  this.dht.removeProvider(id, hash);
8727
- // and try again
8728
+ if (this.#peerAttempts[id] > 3) {
8729
+ this.#peerAttempts[id] = 0;
8730
+ debug(`Removed provider ${id} for ${hash} after 3 attempts`);
8731
+ throw nothingFoundError(hash);
8732
+ }
8733
+ if (this.#peerAttempts[id] === undefined)
8734
+ this.#peerAttempts[id] = 0;
8735
+ this.#peerAttempts[id]++;
8728
8736
  return this.requestData(hash, store?.name || store);
8729
8737
  }
8730
8738
  // this.put(hash, proto.decoded.data)
@@ -1,3 +1,3 @@
1
- export { P as default } from './peernet-CZhvkXXp.js';
1
+ export { P as default } from './peernet-DwOQKkjc.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
@@ -342,6 +342,7 @@ class Peernet {
342
342
  _peerHandler;
343
343
  protos;
344
344
  version;
345
+ #peerAttempts = {};
345
346
  /**
346
347
  * @access public
347
348
  * @param {Object} options
@@ -805,7 +806,14 @@ class Peernet {
805
806
  debug(`Error while requesting data from ${id}`, error);
806
807
  // if error, remove provider
807
808
  this.dht.removeProvider(id, hash);
808
- // and try again
809
+ if (this.#peerAttempts[id] > 3) {
810
+ this.#peerAttempts[id] = 0;
811
+ debug(`Removed provider ${id} for ${hash} after 3 attempts`);
812
+ throw nothingFoundError(hash);
813
+ }
814
+ if (this.#peerAttempts[id] === undefined)
815
+ this.#peerAttempts[id] = 0;
816
+ this.#peerAttempts[id]++;
809
817
  return this.requestData(hash, store?.name || store);
810
818
  }
811
819
  // this.put(hash, proto.decoded.data)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.89",
3
+ "version": "1.1.91",
4
4
  "description": "",
5
5
  "browser": "./exports/browser/peernet.js",
6
6
  "exports": {
package/src/peernet.ts CHANGED
@@ -66,6 +66,7 @@ export default class Peernet {
66
66
  protos: {}
67
67
  version
68
68
 
69
+ #peerAttempts: { [key: string]: number } = {}
69
70
  /**
70
71
  * @access public
71
72
  * @param {Object} options
@@ -583,7 +584,14 @@ export default class Peernet {
583
584
  debug(`Error while requesting data from ${id}`, error)
584
585
  // if error, remove provider
585
586
  this.dht.removeProvider(id, hash)
586
- // and try again
587
+ if (this.#peerAttempts[id] > 3) {
588
+ this.#peerAttempts[id] = 0
589
+ debug(`Removed provider ${id} for ${hash} after 3 attempts`)
590
+ throw nothingFoundError(hash)
591
+ }
592
+
593
+ if (this.#peerAttempts[id] === undefined) this.#peerAttempts[id] = 0
594
+ this.#peerAttempts[id]++
587
595
  return this.requestData(hash, store?.name || store)
588
596
  }
589
597