@leofcoin/peernet 0.11.1 → 0.11.2
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/326.peernet.js +29 -0
- package/dist/browser/peernet.js +27457 -47738
- package/dist/commonjs/{http-7bbac90a.js → http-4bc6caeb.js} +1 -1
- package/dist/commonjs/peernet-message.js +2 -2
- package/dist/commonjs/peernet.js +12 -12
- package/dist/module/peernet.js +13 -13
- package/index.html +1 -1
- package/package.json +2 -2
- package/src/handlers/message.js +0 -2
- package/src/peernet.js +11 -9
- package/src/proto/peernet.proto.js +2 -2
- package/webpack.config.js +7 -1
|
@@ -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.1";
|
|
14
14
|
|
|
15
15
|
var api$1 = {
|
|
16
16
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -1447,8 +1447,6 @@ class MessageHandler {
|
|
|
1447
1447
|
* or the messageNode itself
|
|
1448
1448
|
*/
|
|
1449
1449
|
async prepareMessage(from, to, data, id) {
|
|
1450
|
-
if (!Buffer.isBuffer(from)) from = new Buffer.from(from);
|
|
1451
|
-
if (!Buffer.isBuffer(to)) to = new Buffer.from(to);
|
|
1452
1450
|
if (data.encoded) data = data.encoded;
|
|
1453
1451
|
|
|
1454
1452
|
const message = {
|
|
@@ -1542,7 +1540,7 @@ class Peernet {
|
|
|
1542
1540
|
if (this.hasDaemon) {
|
|
1543
1541
|
Storage = LeofcoinStorageClient;
|
|
1544
1542
|
} else {
|
|
1545
|
-
Storage = LeofcoinStorage__default["default"];
|
|
1543
|
+
Storage = globalThis.LeofcoinStorage?.default ? globalThis.LeofcoinStorage.default : LeofcoinStorage__default["default"];
|
|
1546
1544
|
}
|
|
1547
1545
|
globalThis[`${name}Store`] = globalThis[`${name}Store`] ||
|
|
1548
1546
|
await new Storage(`${prefix}-${name}`, root);
|
|
@@ -1630,7 +1628,7 @@ class Peernet {
|
|
|
1630
1628
|
protocol: 'peernet-v0.1.0', host: '127.0.0.1', port: options.port
|
|
1631
1629
|
});
|
|
1632
1630
|
} else {
|
|
1633
|
-
const http = await Promise.resolve().then(function () { return require('./http-
|
|
1631
|
+
const http = await Promise.resolve().then(function () { return require('./http-4bc6caeb.js'); });
|
|
1634
1632
|
if (environment !== 'browser') http.default(options);
|
|
1635
1633
|
}
|
|
1636
1634
|
|
|
@@ -1681,7 +1679,7 @@ class Peernet {
|
|
|
1681
1679
|
message = new peernetMessage(uint8Array);
|
|
1682
1680
|
const proto = protoFor(message.decoded.data);
|
|
1683
1681
|
|
|
1684
|
-
const from =
|
|
1682
|
+
const from = message.decoded.from;
|
|
1685
1683
|
this._protoHandler({id, proto}, this.client.connections[from], from);
|
|
1686
1684
|
});
|
|
1687
1685
|
|
|
@@ -1732,7 +1730,7 @@ class Peernet {
|
|
|
1732
1730
|
const data = new dhtResponse({hash, has});
|
|
1733
1731
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1734
1732
|
|
|
1735
|
-
peer.send(
|
|
1733
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
1736
1734
|
this.bw.up += node.encoded.length;
|
|
1737
1735
|
} else if (proto.name === 'peernet-data') {
|
|
1738
1736
|
let { hash, store } = proto.decoded;
|
|
@@ -1746,10 +1744,10 @@ class Peernet {
|
|
|
1746
1744
|
data = await store.get(hash);
|
|
1747
1745
|
|
|
1748
1746
|
if (data) {
|
|
1749
|
-
data = new DataMessageResponse({hash, data: data.decoded ?
|
|
1747
|
+
data = new DataMessageResponse({hash, data: data.decoded ? new TextEncoder().encode(JSON.stringify(data.decoded)) : data});
|
|
1750
1748
|
|
|
1751
1749
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1752
|
-
peer.send(
|
|
1750
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
1753
1751
|
this.bw.up += node.encoded.length;
|
|
1754
1752
|
}
|
|
1755
1753
|
}
|
|
@@ -1762,6 +1760,7 @@ class Peernet {
|
|
|
1762
1760
|
const data = await method();
|
|
1763
1761
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1764
1762
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
1763
|
+
|
|
1765
1764
|
this.bw.up += node.encoded.length;
|
|
1766
1765
|
}
|
|
1767
1766
|
} else if (proto.name === 'peernet-ps' &&
|
|
@@ -1894,7 +1893,8 @@ class Peernet {
|
|
|
1894
1893
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
1895
1894
|
}
|
|
1896
1895
|
if (data.data) {
|
|
1897
|
-
|
|
1896
|
+
console.log(data.data);
|
|
1897
|
+
let proto = protoFor(data.data);
|
|
1898
1898
|
proto = protoFor(proto.decoded.data);
|
|
1899
1899
|
return proto.decoded.data
|
|
1900
1900
|
}
|
|
@@ -2025,15 +2025,15 @@ class Peernet {
|
|
|
2025
2025
|
*/
|
|
2026
2026
|
async publish(topic, data) {
|
|
2027
2027
|
// globalSub.publish(topic, data)
|
|
2028
|
-
if (
|
|
2029
|
-
if (
|
|
2028
|
+
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
|
|
2029
|
+
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
2030
2030
|
const id = Math.random().toString(36).slice(-12);
|
|
2031
2031
|
data = new PsMessage({data, topic});
|
|
2032
2032
|
for (const peer of this.peers) {
|
|
2033
2033
|
if (peer.connection._connected) {
|
|
2034
2034
|
if (peer.id.toString() !== this.peerId.toString()) {
|
|
2035
2035
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2036
|
-
peer.send(
|
|
2036
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2037
2037
|
}
|
|
2038
2038
|
} else {
|
|
2039
2039
|
this.removePeer(peer);
|
package/dist/module/peernet.js
CHANGED
|
@@ -621,8 +621,8 @@ var proto$a = `
|
|
|
621
621
|
message PeernetMessage {
|
|
622
622
|
required bytes data = 1;
|
|
623
623
|
required bytes signature = 2;
|
|
624
|
-
optional
|
|
625
|
-
optional
|
|
624
|
+
optional string from = 3;
|
|
625
|
+
optional string to = 4;
|
|
626
626
|
optional string id = 5;
|
|
627
627
|
}`;
|
|
628
628
|
|
|
@@ -2025,8 +2025,6 @@ class MessageHandler {
|
|
|
2025
2025
|
* or the messageNode itself
|
|
2026
2026
|
*/
|
|
2027
2027
|
async prepareMessage(from, to, data, id) {
|
|
2028
|
-
if (!Buffer.isBuffer(from)) from = new Buffer.from(from);
|
|
2029
|
-
if (!Buffer.isBuffer(to)) to = new Buffer.from(to);
|
|
2030
2028
|
if (data.encoded) data = data.encoded;
|
|
2031
2029
|
|
|
2032
2030
|
const message = {
|
|
@@ -2120,7 +2118,7 @@ class Peernet {
|
|
|
2120
2118
|
if (this.hasDaemon) {
|
|
2121
2119
|
Storage = LeofcoinStorageClient;
|
|
2122
2120
|
} else {
|
|
2123
|
-
Storage = LeofcoinStorage;
|
|
2121
|
+
Storage = globalThis.LeofcoinStorage?.default ? globalThis.LeofcoinStorage.default : LeofcoinStorage;
|
|
2124
2122
|
}
|
|
2125
2123
|
globalThis[`${name}Store`] = globalThis[`${name}Store`] ||
|
|
2126
2124
|
await new Storage(`${prefix}-${name}`, root);
|
|
@@ -2251,7 +2249,7 @@ class Peernet {
|
|
|
2251
2249
|
message = new PeernetMessage(uint8Array);
|
|
2252
2250
|
const proto = protoFor(message.decoded.data);
|
|
2253
2251
|
|
|
2254
|
-
const from =
|
|
2252
|
+
const from = message.decoded.from;
|
|
2255
2253
|
this._protoHandler({id, proto}, this.client.connections[from], from);
|
|
2256
2254
|
});
|
|
2257
2255
|
|
|
@@ -2302,7 +2300,7 @@ class Peernet {
|
|
|
2302
2300
|
const data = new DHTMessageResponse({hash, has});
|
|
2303
2301
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2304
2302
|
|
|
2305
|
-
peer.send(
|
|
2303
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2306
2304
|
this.bw.up += node.encoded.length;
|
|
2307
2305
|
} else if (proto.name === 'peernet-data') {
|
|
2308
2306
|
let { hash, store } = proto.decoded;
|
|
@@ -2316,10 +2314,10 @@ class Peernet {
|
|
|
2316
2314
|
data = await store.get(hash);
|
|
2317
2315
|
|
|
2318
2316
|
if (data) {
|
|
2319
|
-
data = new DataMessageResponse({hash, data: data.decoded ?
|
|
2317
|
+
data = new DataMessageResponse({hash, data: data.decoded ? new TextEncoder().encode(JSON.stringify(data.decoded)) : data});
|
|
2320
2318
|
|
|
2321
2319
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2322
|
-
peer.send(
|
|
2320
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2323
2321
|
this.bw.up += node.encoded.length;
|
|
2324
2322
|
}
|
|
2325
2323
|
}
|
|
@@ -2332,6 +2330,7 @@ class Peernet {
|
|
|
2332
2330
|
const data = await method();
|
|
2333
2331
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2334
2332
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2333
|
+
|
|
2335
2334
|
this.bw.up += node.encoded.length;
|
|
2336
2335
|
}
|
|
2337
2336
|
} else if (proto.name === 'peernet-ps' &&
|
|
@@ -2464,7 +2463,8 @@ class Peernet {
|
|
|
2464
2463
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
2465
2464
|
}
|
|
2466
2465
|
if (data.data) {
|
|
2467
|
-
|
|
2466
|
+
console.log(data.data);
|
|
2467
|
+
let proto = protoFor(data.data);
|
|
2468
2468
|
proto = protoFor(proto.decoded.data);
|
|
2469
2469
|
return proto.decoded.data
|
|
2470
2470
|
}
|
|
@@ -2595,15 +2595,15 @@ class Peernet {
|
|
|
2595
2595
|
*/
|
|
2596
2596
|
async publish(topic, data) {
|
|
2597
2597
|
// globalSub.publish(topic, data)
|
|
2598
|
-
if (
|
|
2599
|
-
if (
|
|
2598
|
+
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
|
|
2599
|
+
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
2600
2600
|
const id = Math.random().toString(36).slice(-12);
|
|
2601
2601
|
data = new PsMessage({data, topic});
|
|
2602
2602
|
for (const peer of this.peers) {
|
|
2603
2603
|
if (peer.connection._connected) {
|
|
2604
2604
|
if (peer.id.toString() !== this.peerId.toString()) {
|
|
2605
2605
|
const node = await this.prepareMessage(peer.id, data.encoded);
|
|
2606
|
-
peer.send(
|
|
2606
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})));
|
|
2607
2607
|
}
|
|
2608
2608
|
} else {
|
|
2609
2609
|
this.removePeer(peer);
|
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/commonjs/peernet.js",
|
|
6
6
|
"module": "dist/module/peernet.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@leofcoin/generate-account": "^1.0.2",
|
|
27
27
|
"@leofcoin/multi-wallet": "^2.1.1",
|
|
28
28
|
"@leofcoin/peernet-swarm": "^0.1.9",
|
|
29
|
-
"@leofcoin/storage": "^2.
|
|
29
|
+
"@leofcoin/storage": "^2.2.0",
|
|
30
30
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
31
31
|
"@vandeurenglenn/base58": "^1.1.0",
|
|
32
32
|
"@vandeurenglenn/is-hex": "^1.0.0",
|
package/src/handlers/message.js
CHANGED
|
@@ -32,8 +32,6 @@ export default class MessageHandler {
|
|
|
32
32
|
* or the messageNode itself
|
|
33
33
|
*/
|
|
34
34
|
async prepareMessage(from, to, data, id) {
|
|
35
|
-
if (!Buffer.isBuffer(from)) from = new Buffer.from(from)
|
|
36
|
-
if (!Buffer.isBuffer(to)) to = new Buffer.from(to)
|
|
37
35
|
if (data.encoded) data = data.encoded
|
|
38
36
|
|
|
39
37
|
const message = {
|
package/src/peernet.js
CHANGED
|
@@ -85,7 +85,7 @@ export default class Peernet {
|
|
|
85
85
|
if (this.hasDaemon) {
|
|
86
86
|
Storage = LeofcoinStorageClient
|
|
87
87
|
} else {
|
|
88
|
-
Storage = LeofcoinStorage
|
|
88
|
+
Storage = globalThis.LeofcoinStorage?.default ? globalThis.LeofcoinStorage.default : LeofcoinStorage
|
|
89
89
|
}
|
|
90
90
|
globalThis[`${name}Store`] = globalThis[`${name}Store`] ||
|
|
91
91
|
await new Storage(`${prefix}-${name}`, root)
|
|
@@ -216,7 +216,7 @@ export default class Peernet {
|
|
|
216
216
|
message = new PeernetMessage(uint8Array)
|
|
217
217
|
const proto = protoFor(message.decoded.data)
|
|
218
218
|
|
|
219
|
-
const from =
|
|
219
|
+
const from = message.decoded.from
|
|
220
220
|
this._protoHandler({id, proto}, this.client.connections[from], from)
|
|
221
221
|
})
|
|
222
222
|
|
|
@@ -267,7 +267,7 @@ export default class Peernet {
|
|
|
267
267
|
const data = new DHTMessageResponse({hash, has})
|
|
268
268
|
const node = await this.prepareMessage(from, data.encoded)
|
|
269
269
|
|
|
270
|
-
peer.send(
|
|
270
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})))
|
|
271
271
|
this.bw.up += node.encoded.length
|
|
272
272
|
} else if (proto.name === 'peernet-data') {
|
|
273
273
|
let { hash, store } = proto.decoded
|
|
@@ -281,10 +281,10 @@ export default class Peernet {
|
|
|
281
281
|
data = await store.get(hash)
|
|
282
282
|
|
|
283
283
|
if (data) {
|
|
284
|
-
data = new DataMessageResponse({hash, data: data.decoded ?
|
|
284
|
+
data = new DataMessageResponse({hash, data: data.decoded ? new TextEncoder().encode(JSON.stringify(data.decoded)) : data});
|
|
285
285
|
|
|
286
286
|
const node = await this.prepareMessage(from, data.encoded)
|
|
287
|
-
peer.send(
|
|
287
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})))
|
|
288
288
|
this.bw.up += node.encoded.length
|
|
289
289
|
}
|
|
290
290
|
} else {
|
|
@@ -299,6 +299,7 @@ export default class Peernet {
|
|
|
299
299
|
const data = await method()
|
|
300
300
|
const node = await this.prepareMessage(from, data.encoded)
|
|
301
301
|
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})))
|
|
302
|
+
|
|
302
303
|
this.bw.up += node.encoded.length
|
|
303
304
|
}
|
|
304
305
|
} else if (proto.name === 'peernet-ps' &&
|
|
@@ -431,7 +432,8 @@ export default class Peernet {
|
|
|
431
432
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
432
433
|
}
|
|
433
434
|
if (data.data) {
|
|
434
|
-
|
|
435
|
+
console.log(data.data);
|
|
436
|
+
let proto = protoFor(data.data)
|
|
435
437
|
proto = protoFor(proto.decoded.data)
|
|
436
438
|
return proto.decoded.data
|
|
437
439
|
}
|
|
@@ -563,15 +565,15 @@ export default class Peernet {
|
|
|
563
565
|
*/
|
|
564
566
|
async publish(topic, data) {
|
|
565
567
|
// globalSub.publish(topic, data)
|
|
566
|
-
if (
|
|
567
|
-
if (
|
|
568
|
+
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic)
|
|
569
|
+
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data))
|
|
568
570
|
const id = Math.random().toString(36).slice(-12)
|
|
569
571
|
data = new PsMessage({data, topic})
|
|
570
572
|
for (const peer of this.peers) {
|
|
571
573
|
if (peer.connection._connected) {
|
|
572
574
|
if (peer.id.toString() !== this.peerId.toString()) {
|
|
573
575
|
const node = await this.prepareMessage(peer.id, data.encoded)
|
|
574
|
-
peer.send(
|
|
576
|
+
peer.send(new TextEncoder().encode(JSON.stringify({id, data: node.encoded})))
|
|
575
577
|
}
|
|
576
578
|
} else {
|
|
577
579
|
this.removePeer(peer)
|
package/webpack.config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const webpack = require('webpack');
|
|
3
3
|
module.exports = {
|
|
4
|
-
entry: './
|
|
4
|
+
entry: './src/peernet.js',
|
|
5
5
|
plugins: [
|
|
6
6
|
// Work around for Buffer is undefined:
|
|
7
7
|
// https://github.com/webpack/changelog-v5/issues/10
|
|
@@ -10,6 +10,10 @@ module.exports = {
|
|
|
10
10
|
}),
|
|
11
11
|
new webpack.ProvidePlugin({
|
|
12
12
|
process: 'process/browser',
|
|
13
|
+
}),
|
|
14
|
+
new webpack.DefinePlugin({
|
|
15
|
+
HTTP_IMPORT: '',
|
|
16
|
+
"import fetch from 'node-fetch'": ''
|
|
13
17
|
})
|
|
14
18
|
],
|
|
15
19
|
optimization: {
|
|
@@ -18,6 +22,8 @@ optimization: {
|
|
|
18
22
|
resolve: {
|
|
19
23
|
extensions: [ '.ts', '.js' ],
|
|
20
24
|
fallback: {
|
|
25
|
+
fs: false,
|
|
26
|
+
util: false,
|
|
21
27
|
"stream": require.resolve("stream-browserify"),
|
|
22
28
|
"buffer": require.resolve("buffer"),
|
|
23
29
|
"path": require.resolve("path-browserify"),
|