@leofcoin/peernet 0.11.4 → 0.11.5
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.
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
11
11
|
var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
|
|
12
12
|
|
|
13
|
-
var version = "0.11.
|
|
13
|
+
var version = "0.11.4";
|
|
14
14
|
|
|
15
15
|
var api$1 = {
|
|
16
16
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -1563,7 +1563,15 @@ class Peernet {
|
|
|
1563
1563
|
* @return {Array} peerId
|
|
1564
1564
|
*/
|
|
1565
1565
|
get peers() {
|
|
1566
|
-
return this.client.connections
|
|
1566
|
+
return Object.keys(this.client.connections)
|
|
1567
|
+
}
|
|
1568
|
+
|
|
1569
|
+
get connections() {
|
|
1570
|
+
return Object.values(this.client.connections)
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
get peerEntries() {
|
|
1574
|
+
return Object.entries(this.client.connections)
|
|
1567
1575
|
}
|
|
1568
1576
|
|
|
1569
1577
|
/**
|
|
@@ -1628,7 +1636,7 @@ class Peernet {
|
|
|
1628
1636
|
protocol: 'peernet-v0.1.0', host: '127.0.0.1', port: options.port
|
|
1629
1637
|
});
|
|
1630
1638
|
} else {
|
|
1631
|
-
const http = await Promise.resolve().then(function () { return require('./http-
|
|
1639
|
+
const http = await Promise.resolve().then(function () { return require('./http-ee1b2071.js'); });
|
|
1632
1640
|
if (environment !== 'browser') http.default(options);
|
|
1633
1641
|
}
|
|
1634
1642
|
|
|
@@ -1777,7 +1785,7 @@ class Peernet {
|
|
|
1777
1785
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
1778
1786
|
const data = new dht({hash});
|
|
1779
1787
|
this.client.id;
|
|
1780
|
-
for (const peer of this.
|
|
1788
|
+
for (const peer of this.connections) {
|
|
1781
1789
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
1782
1790
|
|
|
1783
1791
|
const result = await peer.request(node.encoded);
|
|
@@ -1875,9 +1883,9 @@ class Peernet {
|
|
|
1875
1883
|
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store.name ? store.name : store)
|
|
1876
1884
|
|
|
1877
1885
|
const id = closestPeer.id.toString();
|
|
1878
|
-
if (this.
|
|
1879
|
-
let closest = this.
|
|
1880
|
-
if (
|
|
1886
|
+
if (this.connections) {
|
|
1887
|
+
let closest = this.connections.filter((peer) => {
|
|
1888
|
+
if (peer.id === id) return peer
|
|
1881
1889
|
});
|
|
1882
1890
|
|
|
1883
1891
|
let data = new DataMessage({hash, store: store.name ? store.name : store});
|
|
@@ -1885,8 +1893,8 @@ class Peernet {
|
|
|
1885
1893
|
const node = await this.prepareMessage(id, data.encoded);
|
|
1886
1894
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
1887
1895
|
else {
|
|
1888
|
-
closest = this.
|
|
1889
|
-
if (peer.id
|
|
1896
|
+
closest = this.connections.filter((peer) => {
|
|
1897
|
+
if (peer.id === id) return peer
|
|
1890
1898
|
});
|
|
1891
1899
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
1892
1900
|
}
|
|
@@ -2027,9 +2035,9 @@ class Peernet {
|
|
|
2027
2035
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
2028
2036
|
const id = Math.random().toString(36).slice(-12);
|
|
2029
2037
|
data = new PsMessage({data, topic});
|
|
2030
|
-
for (const peer of this.
|
|
2031
|
-
if (peer.
|
|
2032
|
-
if (peer.id
|
|
2038
|
+
for (const peer of this.connections) {
|
|
2039
|
+
if (peer.connected) {
|
|
2040
|
+
if (peer.id !== this.peerId) {
|
|
2033
2041
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2034
2042
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2035
2043
|
}
|
package/dist/module/peernet.js
CHANGED
|
@@ -2141,7 +2141,15 @@ class Peernet {
|
|
|
2141
2141
|
* @return {Array} peerId
|
|
2142
2142
|
*/
|
|
2143
2143
|
get peers() {
|
|
2144
|
-
return this.client.connections
|
|
2144
|
+
return Object.keys(this.client.connections)
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
get connections() {
|
|
2148
|
+
return Object.values(this.client.connections)
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
get peerEntries() {
|
|
2152
|
+
return Object.entries(this.client.connections)
|
|
2145
2153
|
}
|
|
2146
2154
|
|
|
2147
2155
|
/**
|
|
@@ -2347,7 +2355,7 @@ class Peernet {
|
|
|
2347
2355
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
2348
2356
|
const data = new DHTMessage({hash});
|
|
2349
2357
|
this.client.id;
|
|
2350
|
-
for (const peer of this.
|
|
2358
|
+
for (const peer of this.connections) {
|
|
2351
2359
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2352
2360
|
|
|
2353
2361
|
const result = await peer.request(node.encoded);
|
|
@@ -2445,9 +2453,9 @@ class Peernet {
|
|
|
2445
2453
|
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store.name ? store.name : store)
|
|
2446
2454
|
|
|
2447
2455
|
const id = closestPeer.id.toString();
|
|
2448
|
-
if (this.
|
|
2449
|
-
let closest = this.
|
|
2450
|
-
if (
|
|
2456
|
+
if (this.connections) {
|
|
2457
|
+
let closest = this.connections.filter((peer) => {
|
|
2458
|
+
if (peer.id === id) return peer
|
|
2451
2459
|
});
|
|
2452
2460
|
|
|
2453
2461
|
let data = new DataMessage({hash, store: store.name ? store.name : store});
|
|
@@ -2455,8 +2463,8 @@ class Peernet {
|
|
|
2455
2463
|
const node = await this.prepareMessage(id, data.encoded);
|
|
2456
2464
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
2457
2465
|
else {
|
|
2458
|
-
closest = this.
|
|
2459
|
-
if (peer.id
|
|
2466
|
+
closest = this.connections.filter((peer) => {
|
|
2467
|
+
if (peer.id === id) return peer
|
|
2460
2468
|
});
|
|
2461
2469
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
2462
2470
|
}
|
|
@@ -2597,9 +2605,9 @@ class Peernet {
|
|
|
2597
2605
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
2598
2606
|
const id = Math.random().toString(36).slice(-12);
|
|
2599
2607
|
data = new PsMessage({data, topic});
|
|
2600
|
-
for (const peer of this.
|
|
2601
|
-
if (peer.
|
|
2602
|
-
if (peer.id
|
|
2608
|
+
for (const peer of this.connections) {
|
|
2609
|
+
if (peer.connected) {
|
|
2610
|
+
if (peer.id !== this.peerId) {
|
|
2603
2611
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2604
2612
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2605
2613
|
}
|
package/package.json
CHANGED
package/src/peernet.js
CHANGED
|
@@ -108,7 +108,15 @@ export default class Peernet {
|
|
|
108
108
|
* @return {Array} peerId
|
|
109
109
|
*/
|
|
110
110
|
get peers() {
|
|
111
|
-
return this.client.connections
|
|
111
|
+
return Object.keys(this.client.connections)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
get connections() {
|
|
115
|
+
return Object.values(this.client.connections)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
get peerEntries() {
|
|
119
|
+
return Object.entries(this.client.connections)
|
|
112
120
|
}
|
|
113
121
|
|
|
114
122
|
/**
|
|
@@ -317,7 +325,7 @@ export default class Peernet {
|
|
|
317
325
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
318
326
|
const data = new DHTMessage({hash})
|
|
319
327
|
const clientId = this.client.id
|
|
320
|
-
for (const peer of this.
|
|
328
|
+
for (const peer of this.connections) {
|
|
321
329
|
const node = await this.prepareMessage(peer.id, data.encoded)
|
|
322
330
|
|
|
323
331
|
const result = await peer.request(node.encoded)
|
|
@@ -415,9 +423,9 @@ export default class Peernet {
|
|
|
415
423
|
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store.name ? store.name : store)
|
|
416
424
|
|
|
417
425
|
const id = closestPeer.id.toString()
|
|
418
|
-
if (this.
|
|
419
|
-
let closest = this.
|
|
420
|
-
if (
|
|
426
|
+
if (this.connections) {
|
|
427
|
+
let closest = this.connections.filter((peer) => {
|
|
428
|
+
if (peer.id === id) return peer
|
|
421
429
|
})
|
|
422
430
|
|
|
423
431
|
let data = new DataMessage({hash, store: store.name ? store.name : store});
|
|
@@ -425,8 +433,8 @@ export default class Peernet {
|
|
|
425
433
|
const node = await this.prepareMessage(id, data.encoded)
|
|
426
434
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
427
435
|
else {
|
|
428
|
-
closest = this.
|
|
429
|
-
if (peer.id
|
|
436
|
+
closest = this.connections.filter((peer) => {
|
|
437
|
+
if (peer.id === id) return peer
|
|
430
438
|
})
|
|
431
439
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
432
440
|
}
|
|
@@ -568,9 +576,9 @@ export default class Peernet {
|
|
|
568
576
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data))
|
|
569
577
|
const id = Math.random().toString(36).slice(-12)
|
|
570
578
|
data = new PsMessage({data, topic})
|
|
571
|
-
for (const peer of this.
|
|
572
|
-
if (peer.
|
|
573
|
-
if (peer.id
|
|
579
|
+
for (const peer of this.connections) {
|
|
580
|
+
if (peer.connected) {
|
|
581
|
+
if (peer.id !== this.peerId) {
|
|
574
582
|
const node = await this.prepareMessage(peer.id, data.encoded)
|
|
575
583
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})))
|
|
576
584
|
}
|