@leofcoin/peernet 0.11.3 → 0.11.6
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/dist/browser/peernet.js +1 -1
- package/dist/commonjs/codec-format-interface.js +22 -0
- package/dist/commonjs/{http-e088ccdb.js → http-1600124a.js} +1 -1
- package/dist/commonjs/peernet.js +20 -12
- package/dist/module/peernet.js +41 -11
- package/package.json +1 -1
- package/src/codec/codec-format-interface.js +22 -0
- package/src/peernet.js +19 -11
|
@@ -102,6 +102,28 @@ class FormatInterface {
|
|
|
102
102
|
else this.decode();
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
toString() {
|
|
106
|
+
return this.encoded.toString()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async toArray() {
|
|
110
|
+
const array = [];
|
|
111
|
+
for await (const value of this.encoded.values()) {
|
|
112
|
+
array.push(value);
|
|
113
|
+
}
|
|
114
|
+
return array
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fromString(string) {
|
|
118
|
+
this.encoded = new Uint8Array(string.split(','));
|
|
119
|
+
this.decode();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
fromArray(array) {
|
|
123
|
+
this.encoded = new Uint8Array([...array]);
|
|
124
|
+
this.decode();
|
|
125
|
+
}
|
|
126
|
+
|
|
105
127
|
/**
|
|
106
128
|
* @param {Buffer} encoded
|
|
107
129
|
*/
|
|
@@ -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.5";
|
|
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
|
|
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-1600124a.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
|
}
|
|
@@ -2055,7 +2063,7 @@ class Peernet {
|
|
|
2055
2063
|
}
|
|
2056
2064
|
|
|
2057
2065
|
async removePeer(peer) {
|
|
2058
|
-
connections
|
|
2066
|
+
delete this.client.connections[peer.id];
|
|
2059
2067
|
}
|
|
2060
2068
|
|
|
2061
2069
|
get Buffer() {
|
package/dist/module/peernet.js
CHANGED
|
@@ -1062,6 +1062,28 @@ class FormatInterface {
|
|
|
1062
1062
|
else this.decode();
|
|
1063
1063
|
}
|
|
1064
1064
|
|
|
1065
|
+
toString() {
|
|
1066
|
+
return this.encoded.toString()
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
async toArray() {
|
|
1070
|
+
const array = [];
|
|
1071
|
+
for await (const value of this.encoded.values()) {
|
|
1072
|
+
array.push(value);
|
|
1073
|
+
}
|
|
1074
|
+
return array
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
fromString(string) {
|
|
1078
|
+
this.encoded = new Uint8Array(string.split(','));
|
|
1079
|
+
this.decode();
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
fromArray(array) {
|
|
1083
|
+
this.encoded = new Uint8Array([...array]);
|
|
1084
|
+
this.decode();
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1065
1087
|
/**
|
|
1066
1088
|
* @param {Buffer} encoded
|
|
1067
1089
|
*/
|
|
@@ -2141,7 +2163,15 @@ class Peernet {
|
|
|
2141
2163
|
* @return {Array} peerId
|
|
2142
2164
|
*/
|
|
2143
2165
|
get peers() {
|
|
2144
|
-
return
|
|
2166
|
+
return Object.keys(this.client.connections)
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
get connections() {
|
|
2170
|
+
return Object.values(this.client.connections)
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
get peerEntries() {
|
|
2174
|
+
return Object.entries(this.client.connections)
|
|
2145
2175
|
}
|
|
2146
2176
|
|
|
2147
2177
|
/**
|
|
@@ -2347,7 +2377,7 @@ class Peernet {
|
|
|
2347
2377
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
2348
2378
|
const data = new DHTMessage({hash});
|
|
2349
2379
|
this.client.id;
|
|
2350
|
-
for (const peer of this.
|
|
2380
|
+
for (const peer of this.connections) {
|
|
2351
2381
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2352
2382
|
|
|
2353
2383
|
const result = await peer.request(node.encoded);
|
|
@@ -2445,9 +2475,9 @@ class Peernet {
|
|
|
2445
2475
|
if (!closestPeer || !closestPeer.id) return this.requestData(hash, store.name ? store.name : store)
|
|
2446
2476
|
|
|
2447
2477
|
const id = closestPeer.id.toString();
|
|
2448
|
-
if (this.
|
|
2449
|
-
let closest = this.
|
|
2450
|
-
if (
|
|
2478
|
+
if (this.connections) {
|
|
2479
|
+
let closest = this.connections.filter((peer) => {
|
|
2480
|
+
if (peer.id === id) return peer
|
|
2451
2481
|
});
|
|
2452
2482
|
|
|
2453
2483
|
let data = new DataMessage({hash, store: store.name ? store.name : store});
|
|
@@ -2455,8 +2485,8 @@ class Peernet {
|
|
|
2455
2485
|
const node = await this.prepareMessage(id, data.encoded);
|
|
2456
2486
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
2457
2487
|
else {
|
|
2458
|
-
closest = this.
|
|
2459
|
-
if (peer.id
|
|
2488
|
+
closest = this.connections.filter((peer) => {
|
|
2489
|
+
if (peer.id === id) return peer
|
|
2460
2490
|
});
|
|
2461
2491
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
2462
2492
|
}
|
|
@@ -2597,9 +2627,9 @@ class Peernet {
|
|
|
2597
2627
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
2598
2628
|
const id = Math.random().toString(36).slice(-12);
|
|
2599
2629
|
data = new PsMessage({data, topic});
|
|
2600
|
-
for (const peer of this.
|
|
2601
|
-
if (peer.
|
|
2602
|
-
if (peer.id
|
|
2630
|
+
for (const peer of this.connections) {
|
|
2631
|
+
if (peer.connected) {
|
|
2632
|
+
if (peer.id !== this.peerId) {
|
|
2603
2633
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2604
2634
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2605
2635
|
}
|
|
@@ -2625,7 +2655,7 @@ class Peernet {
|
|
|
2625
2655
|
}
|
|
2626
2656
|
|
|
2627
2657
|
async removePeer(peer) {
|
|
2628
|
-
connections
|
|
2658
|
+
delete this.client.connections[peer.id];
|
|
2629
2659
|
}
|
|
2630
2660
|
|
|
2631
2661
|
get Buffer() {
|
package/package.json
CHANGED
|
@@ -92,6 +92,28 @@ export default class FormatInterface {
|
|
|
92
92
|
else this.decode()
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
toString() {
|
|
96
|
+
return this.encoded.toString()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async toArray() {
|
|
100
|
+
const array = []
|
|
101
|
+
for await (const value of this.encoded.values()) {
|
|
102
|
+
array.push(value)
|
|
103
|
+
}
|
|
104
|
+
return array
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fromString(string) {
|
|
108
|
+
this.encoded = new Uint8Array(string.split(','))
|
|
109
|
+
this.decode()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
fromArray(array) {
|
|
113
|
+
this.encoded = new Uint8Array([...array])
|
|
114
|
+
this.decode()
|
|
115
|
+
}
|
|
116
|
+
|
|
95
117
|
/**
|
|
96
118
|
* @param {Buffer} encoded
|
|
97
119
|
*/
|
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
|
|
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
|
}
|
|
@@ -596,7 +604,7 @@ export default class Peernet {
|
|
|
596
604
|
}
|
|
597
605
|
|
|
598
606
|
async removePeer(peer) {
|
|
599
|
-
connections
|
|
607
|
+
delete this.client.connections[peer.id]
|
|
600
608
|
}
|
|
601
609
|
|
|
602
610
|
get Buffer() {
|