@leofcoin/peernet 1.1.31 → 1.1.33

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 { g as getDefaultExportFromCjs, c as commonjsGlobal } from './peernet-ad3ca002.js';
1
+ import { g as getDefaultExportFromCjs, c as commonjsGlobal } from './peernet-d2274ccd.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  function commonjsRequire(path) {
@@ -1,30 +1,19 @@
1
1
  export default class DhtEarth {
2
- providerMap: Map<any, any>;
2
+ providerMap: Map<string, Set<string>>;
3
3
  /**
4
- * @param {Object} address
5
- * @return {Object} {latitude: lat, longitude: lon}
4
+ *
6
5
  */
7
- getCoordinates(address: any): any;
6
+ constructor();
7
+ getCoordinates(address: string): Promise<object>;
8
8
  /**
9
9
  * @param {Object} peer
10
10
  * @param {Object} provider
11
11
  * @return {Object} {provider, distance}
12
12
  */
13
- getDistance(peer: any, provider: any): any;
14
- /**
15
- * @param {Array} providers
16
- * @return {Object} closestPeer
17
- */
18
- closestPeer(providers: any[]): any;
19
- /**
20
- * @param {String} hash
21
- * @return {Array} providers
22
- */
23
- providersFor(hash: string): any[];
24
- /**
25
- * @param {String} address
26
- * @param {String} hash
27
- * @return {Array} providers
28
- */
29
- addProvider(address: string, hash: string): any[];
13
+ getDistance(peer: object, provider: object): object;
14
+ closestPeer(providers: Array<any>): object;
15
+ hasProvider(hash: string): boolean;
16
+ providersFor(hash: string): Set<string>;
17
+ addProvider(address: string, hash: string): void;
18
+ removeProvider(address: string, hash: string): true | undefined;
30
19
  }
@@ -1,4 +1,4 @@
1
- import { M as MultiWallet, e as encrypt, b as base58$1 } from './peernet-ad3ca002.js';
1
+ import { M as MultiWallet, e as encrypt, b as base58$1 } from './peernet-d2274ccd.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-ad3ca002.js';
1
+ import { F as FormatInterface } from './peernet-d2274ccd.js';
2
2
  import './value-157ab062.js';
3
3
 
4
4
  var proto$b = {
@@ -6226,16 +6226,13 @@ const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
6226
6226
  return earthRadiusKm * c;
6227
6227
  };
6228
6228
  class DhtEarth {
6229
+ providerMap = new Map;
6229
6230
  /**
6230
6231
  *
6231
6232
  */
6232
6233
  constructor() {
6233
6234
  this.providerMap = new Map();
6234
6235
  }
6235
- /**
6236
- * @param {Object} address
6237
- * @return {Object} {latitude: lat, longitude: lon}
6238
- */
6239
6236
  async getCoordinates(address) {
6240
6237
  if (!fetchedCoordinates[address]) {
6241
6238
  const request = `https://whereis.leofcoin.org/?ip=${address}`;
@@ -6255,10 +6252,6 @@ class DhtEarth {
6255
6252
  const { latitude, longitude } = await this.getCoordinates(provider.address);
6256
6253
  return { provider, distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude) };
6257
6254
  }
6258
- /**
6259
- * @param {Array} providers
6260
- * @return {Object} closestPeer
6261
- */
6262
6255
  async closestPeer(providers) {
6263
6256
  let all = [];
6264
6257
  const address = await getAddress();
@@ -6273,26 +6266,32 @@ class DhtEarth {
6273
6266
  all = all.sort((previous, current) => previous.distance - current.distance);
6274
6267
  return all[0].provider;
6275
6268
  }
6276
- /**
6277
- * @param {String} hash
6278
- * @return {Array} providers
6279
- */
6280
- providersFor(hash) {
6281
- return this.providerMap.get(hash);
6269
+ hasProvider(hash) {
6270
+ return this.providerMap.has(hash);
6282
6271
  }
6283
- /**
6284
- * @param {String} address
6285
- * @param {String} hash
6286
- * @return {Array} providers
6287
- */
6288
- async addProvider(address, hash) {
6289
- let providers = [];
6272
+ providersFor(hash) {
6273
+ let providers;
6290
6274
  if (this.providerMap.has(hash))
6291
6275
  providers = this.providerMap.get(hash);
6292
- providers = new Set([...providers, address]);
6293
- this.providerMap.set(hash, providers);
6294
6276
  return providers;
6295
6277
  }
6278
+ addProvider(address, hash) {
6279
+ let providers = new Set();
6280
+ if (this.providerMap.has(hash)) {
6281
+ providers = this.providerMap.get(hash);
6282
+ }
6283
+ providers.add(address);
6284
+ this.providerMap.set(hash, providers);
6285
+ }
6286
+ removeProvider(address, hash) {
6287
+ let deleted = undefined;
6288
+ if (this.providerMap.has(hash)) {
6289
+ const providers = this.providerMap.get(hash);
6290
+ deleted = providers.delete(address);
6291
+ deleted && this.providerMap.set(hash, providers);
6292
+ }
6293
+ return deleted;
6294
+ }
6296
6295
  }
6297
6296
 
6298
6297
  class MessageHandler {
@@ -20184,7 +20183,7 @@ class Identity {
20184
20183
  globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
20185
20184
  }
20186
20185
  else {
20187
- const importee = await import(/* webpackChunkName: "generate-account" */ './index-904b9f85.js');
20186
+ const importee = await import(/* webpackChunkName: "generate-account" */ './index-4464b87e.js');
20188
20187
  const { identity, accounts } = await importee.default(password, this.network);
20189
20188
  await globalThis.accountStore.put('public', JSON.stringify({ walletId: identity.walletId }));
20190
20189
  await globalThis.walletStore.put('version', String(1));
@@ -20355,7 +20354,7 @@ class Peernet {
20355
20354
  this.root = options.root;
20356
20355
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
20357
20356
  // FolderMessageResponse
20358
- } = await import(/* webpackChunkName: "messages" */ './messages-de2c5670.js');
20357
+ } = await import(/* webpackChunkName: "messages" */ './messages-27279443.js');
20359
20358
  /**
20360
20359
  * proto Object containing protos
20361
20360
  * @type {Object}
@@ -20434,7 +20433,7 @@ class Peernet {
20434
20433
  if (this.#starting || this.#started)
20435
20434
  return;
20436
20435
  this.#starting = true;
20437
- const importee = await import('./client-d1c29e20.js');
20436
+ const importee = await import('./client-4d80940e.js');
20438
20437
  /**
20439
20438
  * @access public
20440
20439
  * @type {PeernetClient}
@@ -20624,8 +20623,8 @@ class Peernet {
20624
20623
  if (!closestPeer || !closestPeer.id)
20625
20624
  return this.requestData(hash, store?.name || store);
20626
20625
  const id = closestPeer.id;
20627
- if (this.#connections[id]) {
20628
- const peer = this.#connections[id];
20626
+ const peer = this.#connections[id];
20627
+ if (peer?.connected) {
20629
20628
  let data = await new globalThis.peernet.protos['peernet-data']({ hash, store: store?.name || store });
20630
20629
  const node = await this.prepareMessage(data);
20631
20630
  if (peer)
@@ -20648,6 +20647,9 @@ class Peernet {
20648
20647
  return BufferToUint8Array(proto.decoded.data);
20649
20648
  // this.put(hash, proto.decoded.data)
20650
20649
  }
20650
+ else {
20651
+ this.dht.removeProvider(id, hash);
20652
+ }
20651
20653
  return;
20652
20654
  }
20653
20655
  get message() {
@@ -1,2 +1,2 @@
1
- export { P as default } from './peernet-ad3ca002.js';
1
+ export { P as default } from './peernet-d2274ccd.js';
2
2
  import './value-157ab062.js';
@@ -1,30 +1,19 @@
1
1
  export default class DhtEarth {
2
- providerMap: Map<any, any>;
2
+ providerMap: Map<string, Set<string>>;
3
3
  /**
4
- * @param {Object} address
5
- * @return {Object} {latitude: lat, longitude: lon}
4
+ *
6
5
  */
7
- getCoordinates(address: any): any;
6
+ constructor();
7
+ getCoordinates(address: string): Promise<object>;
8
8
  /**
9
9
  * @param {Object} peer
10
10
  * @param {Object} provider
11
11
  * @return {Object} {provider, distance}
12
12
  */
13
- getDistance(peer: any, provider: any): any;
14
- /**
15
- * @param {Array} providers
16
- * @return {Object} closestPeer
17
- */
18
- closestPeer(providers: any[]): any;
19
- /**
20
- * @param {String} hash
21
- * @return {Array} providers
22
- */
23
- providersFor(hash: string): any[];
24
- /**
25
- * @param {String} address
26
- * @param {String} hash
27
- * @return {Array} providers
28
- */
29
- addProvider(address: string, hash: string): any[];
13
+ getDistance(peer: object, provider: object): object;
14
+ closestPeer(providers: Array<any>): object;
15
+ hasProvider(hash: string): boolean;
16
+ providersFor(hash: string): Set<string>;
17
+ addProvider(address: string, hash: string): void;
18
+ removeProvider(address: string, hash: string): true | undefined;
30
19
  }
@@ -187,16 +187,13 @@ const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
187
187
  return earthRadiusKm * c;
188
188
  };
189
189
  class DhtEarth {
190
+ providerMap = new Map;
190
191
  /**
191
192
  *
192
193
  */
193
194
  constructor() {
194
195
  this.providerMap = new Map();
195
196
  }
196
- /**
197
- * @param {Object} address
198
- * @return {Object} {latitude: lat, longitude: lon}
199
- */
200
197
  async getCoordinates(address) {
201
198
  if (!fetchedCoordinates[address]) {
202
199
  const request = `https://whereis.leofcoin.org/?ip=${address}`;
@@ -216,10 +213,6 @@ class DhtEarth {
216
213
  const { latitude, longitude } = await this.getCoordinates(provider.address);
217
214
  return { provider, distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude) };
218
215
  }
219
- /**
220
- * @param {Array} providers
221
- * @return {Object} closestPeer
222
- */
223
216
  async closestPeer(providers) {
224
217
  let all = [];
225
218
  const address = await getAddress();
@@ -234,26 +227,32 @@ class DhtEarth {
234
227
  all = all.sort((previous, current) => previous.distance - current.distance);
235
228
  return all[0].provider;
236
229
  }
237
- /**
238
- * @param {String} hash
239
- * @return {Array} providers
240
- */
241
- providersFor(hash) {
242
- return this.providerMap.get(hash);
230
+ hasProvider(hash) {
231
+ return this.providerMap.has(hash);
243
232
  }
244
- /**
245
- * @param {String} address
246
- * @param {String} hash
247
- * @return {Array} providers
248
- */
249
- async addProvider(address, hash) {
250
- let providers = [];
233
+ providersFor(hash) {
234
+ let providers;
251
235
  if (this.providerMap.has(hash))
252
236
  providers = this.providerMap.get(hash);
253
- providers = new Set([...providers, address]);
254
- this.providerMap.set(hash, providers);
255
237
  return providers;
256
238
  }
239
+ addProvider(address, hash) {
240
+ let providers = new Set();
241
+ if (this.providerMap.has(hash)) {
242
+ providers = this.providerMap.get(hash);
243
+ }
244
+ providers.add(address);
245
+ this.providerMap.set(hash, providers);
246
+ }
247
+ removeProvider(address, hash) {
248
+ let deleted = undefined;
249
+ if (this.providerMap.has(hash)) {
250
+ const providers = this.providerMap.get(hash);
251
+ deleted = providers.delete(address);
252
+ deleted && this.providerMap.set(hash, providers);
253
+ }
254
+ return deleted;
255
+ }
257
256
  }
258
257
 
259
258
  class MessageHandler {
@@ -782,8 +781,8 @@ class Peernet {
782
781
  if (!closestPeer || !closestPeer.id)
783
782
  return this.requestData(hash, store?.name || store);
784
783
  const id = closestPeer.id;
785
- if (this.#connections[id]) {
786
- const peer = this.#connections[id];
784
+ const peer = this.#connections[id];
785
+ if (peer?.connected) {
787
786
  let data = await new globalThis.peernet.protos['peernet-data']({ hash, store: store?.name || store });
788
787
  const node = await this.prepareMessage(data);
789
788
  if (peer)
@@ -806,6 +805,9 @@ class Peernet {
806
805
  return BufferToUint8Array(proto.decoded.data);
807
806
  // this.put(hash, proto.decoded.data)
808
807
  }
808
+ else {
809
+ this.dht.removeProvider(id, hash);
810
+ }
809
811
  return;
810
812
  }
811
813
  get message() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.31",
3
+ "version": "1.1.33",
4
4
  "description": "",
5
5
  "main": "src/peernet.js",
6
6
  "exports": {
@@ -47,18 +47,15 @@ const distanceInKmBetweenEarthCoordinates = (lat1, lon1, lat2, lon2) => {
47
47
  }
48
48
 
49
49
  export default class DhtEarth {
50
+ providerMap = new Map<string, Set<string>>
51
+
50
52
  /**
51
53
  *
52
54
  */
53
55
  constructor() {
54
56
  this.providerMap = new Map();
55
57
  }
56
-
57
- /**
58
- * @param {Object} address
59
- * @return {Object} {latitude: lat, longitude: lon}
60
- */
61
- async getCoordinates(address) {
58
+ async getCoordinates(address: string): Promise<object> {
62
59
  if (!fetchedCoordinates[address]) {
63
60
  const request = `https://whereis.leofcoin.org/?ip=${address}`
64
61
  let response = await fetch(request)
@@ -74,16 +71,12 @@ export default class DhtEarth {
74
71
  * @param {Object} provider
75
72
  * @return {Object} {provider, distance}
76
73
  */
77
- async getDistance(peer, provider) {
74
+ async getDistance(peer: object, provider: object): object {
78
75
  const {latitude, longitude} = await this.getCoordinates(provider.address)
79
76
  return {provider, distance: distanceInKmBetweenEarthCoordinates(peer.latitude, peer.longitude, latitude, longitude)}
80
77
  }
81
78
 
82
- /**
83
- * @param {Array} providers
84
- * @return {Object} closestPeer
85
- */
86
- async closestPeer(providers) {
79
+ async closestPeer(providers: Array<any>): object {
87
80
  let all = []
88
81
  const address = await getAddress();
89
82
  const peerLoc = await this.getCoordinates(address)
@@ -97,25 +90,32 @@ export default class DhtEarth {
97
90
  return all[0].provider;
98
91
  }
99
92
 
100
- /**
101
- * @param {String} hash
102
- * @return {Array} providers
103
- */
104
- providersFor(hash) {
105
- return this.providerMap.get(hash);
93
+ hasProvider(hash: string): boolean {
94
+ return this.providerMap.has(hash)
106
95
  }
107
96
 
108
- /**
109
- * @param {String} address
110
- * @param {String} hash
111
- * @return {Array} providers
112
- */
113
- async addProvider(address, hash) {
114
- let providers = [];
97
+ providersFor(hash: string): Set<string> {
98
+ let providers
115
99
  if (this.providerMap.has(hash)) providers = this.providerMap.get(hash)
100
+ return providers
101
+ }
116
102
 
117
- providers = new Set([...providers, address])
103
+ addProvider(address: string, hash: string) {
104
+ let providers:Set<string> = new Set()
105
+ if (this.providerMap.has(hash)) {
106
+ providers = this.providerMap.get(hash)
107
+ }
108
+ providers.add(address)
118
109
  this.providerMap.set(hash, providers)
119
- return providers;
110
+ }
111
+
112
+ removeProvider(address: string, hash: string): true | undefined {
113
+ let deleted = undefined
114
+ if (this.providerMap.has(hash)) {
115
+ const providers = this.providerMap.get(hash)
116
+ deleted = providers.delete(address)
117
+ deleted && this.providerMap.set(hash, providers)
118
+ }
119
+ return deleted;
120
120
  }
121
121
  }
package/src/peernet.ts CHANGED
@@ -480,9 +480,9 @@ export default class Peernet {
480
480
  if (!closestPeer || !closestPeer.id) return this.requestData(hash, store?.name || store)
481
481
 
482
482
  const id = closestPeer.id
483
-
484
- if (this.#connections[id]) {
485
- const peer = this.#connections[id]
483
+ const peer = this.#connections[id]
484
+
485
+ if (peer?.connected) {
486
486
 
487
487
  let data = await new globalThis.peernet.protos['peernet-data']({hash, store: store?.name || store});
488
488
 
@@ -508,6 +508,8 @@ export default class Peernet {
508
508
  return BufferToUint8Array(proto.decoded.data)
509
509
 
510
510
  // this.put(hash, proto.decoded.data)
511
+ } else {
512
+ this.dht.removeProvider(id, hash)
511
513
  }
512
514
  return
513
515
  }