@leofcoin/peernet 0.10.6 → 0.11.0
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/LICENSE +1 -1
- package/README.md +49 -49
- package/dist/browser/peernet.js +101814 -92947
- package/dist/commonjs/client-bd0caeb7.js +324 -0
- package/dist/commonjs/{codec-6367213c.js → codec-4a768e5e.js} +99 -89
- package/dist/commonjs/codec-format-interface.js +41 -24
- package/dist/commonjs/codec.js +3 -3
- package/dist/commonjs/dht-response.js +3 -3
- package/dist/commonjs/dht.js +23 -23
- package/dist/commonjs/hash.js +17 -7
- package/dist/commonjs/{http-42a6e555.js → http-2b0735ef.js} +19 -15
- package/dist/commonjs/peernet-message.js +12 -12
- package/dist/commonjs/peernet.js +1164 -966
- package/dist/commonjs/request.js +12 -12
- package/dist/commonjs/response.js +12 -12
- package/dist/module/peernet.js +1325 -1120
- package/index.html +4 -6
- package/package.json +31 -7
- package/rollup.config.js +33 -5
- package/rollup0.config.js +7 -0
- package/src/codec/codec-format-interface.js +40 -23
- package/src/codec/codec.js +21 -11
- package/src/codec/codecs.js +79 -79
- package/src/handlers/message.js +52 -52
- package/src/hash/hash.js +16 -6
- package/src/http/client/http-client.js +1 -1
- package/src/messages/chat-message.js +14 -14
- package/src/messages/data-response.js +14 -14
- package/src/messages/data.js +18 -18
- package/src/messages/dht-response.js +0 -1
- package/src/messages/dht.js +25 -25
- package/src/messages/peer-response.js +14 -14
- package/src/messages/peer.js +14 -14
- package/src/messages/peernet-message.js +14 -14
- package/src/messages/ps.js +14 -14
- package/src/messages/request.js +14 -14
- package/src/messages/response.js +14 -14
- package/src/peernet.js +31 -116
- package/test/codec.js +3 -2
- package/test/messages.js +7 -4
- package/test.js +11 -4
- package/webpack.config.js +35 -0
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/codec-format-interface.js.html +0 -533
- package/coverage/lcov-report/codec.js.html +0 -677
- package/coverage/lcov-report/dht-response.js.html +0 -188
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/hash.js.html +0 -551
- package/coverage/lcov-report/index.html +0 -156
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov.info +0 -459
- package/debug.log +0 -3
- package/dist/browser/peernet.js.tmp-browserify-14074318104595318069 +0 -0
- package/dist/browser/peernet.js.tmp-browserify-45407634493269122267 +0 -0
- package/dist/browser/peernet.js.tmp-browserify-53722389064799025427 +0 -0
- package/dist/browser/peernet.js.tmp-browserify-96323030449218949300 +0 -0
- package/dist/codec/codec-format-interface.js +0 -433
- package/dist/codec/codec.js +0 -199
- package/dist/commonjs/codec-73adfc0f.js +0 -205
- package/dist/commonjs/http-2c603501.js +0 -324
- package/dist/commonjs/http-43f4fafe.js +0 -324
- package/dist/commonjs/http-a94c5a81.js +0 -324
- package/dist/commonjs/peernet-message-b6925673.js +0 -32
- package/dist/hash/hash.js +0 -340
- package/dist/messages/dht-response.js +0 -454
- package/dist/messages/dht.js +0 -453
- package/dist/messages/peernet.js +0 -456
- package/dist/module/http-273664bd.js +0 -317
- package/dist/module/http-8fe3c0d7.js +0 -317
- package/dist/module/http-c780c991.js +0 -317
- package/dist/module/http-f13e0d77.js +0 -317
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var protons = require('protons');
|
|
4
|
-
require('bs32');
|
|
5
4
|
var codecFormatInterface = require('./codec-format-interface.js');
|
|
6
|
-
require('
|
|
5
|
+
require('@vandeurenglenn/base32');
|
|
6
|
+
require('@vandeurenglenn/base58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-4a768e5e.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
package/dist/commonjs/dht.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var protons = require('protons');
|
|
4
4
|
var codecFormatInterface = require('./codec-format-interface.js');
|
|
5
|
-
require('
|
|
6
|
-
require('
|
|
5
|
+
require('@vandeurenglenn/base32');
|
|
6
|
+
require('@vandeurenglenn/base58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-4a768e5e.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -22,26 +22,26 @@ message PeernetDHTMessage {
|
|
|
22
22
|
}
|
|
23
23
|
`;
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* @example `
|
|
27
|
-
new DHTMessage(hash, store)
|
|
28
|
-
// store = optional if not set, peernet checks every store
|
|
29
|
-
let message = new DHTMessage('hashmvbs124xcfd...', 'transaction')
|
|
30
|
-
message = new DHTMessage('hashmvbs124xcfd...', 'block')
|
|
31
|
-
`
|
|
32
|
-
*/
|
|
33
|
-
class DHTMessage extends codecFormatInterface {
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
get keys() {
|
|
38
|
-
return ['hash', 'store']
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
constructor(data) {
|
|
42
|
-
const name = 'peernet-dht';
|
|
43
|
-
super(data, protons__default["default"](proto).PeernetDHTMessage, {name});
|
|
44
|
-
}
|
|
25
|
+
/**
|
|
26
|
+
* @example `
|
|
27
|
+
new DHTMessage(hash, store)
|
|
28
|
+
// store = optional if not set, peernet checks every store
|
|
29
|
+
let message = new DHTMessage('hashmvbs124xcfd...', 'transaction')
|
|
30
|
+
message = new DHTMessage('hashmvbs124xcfd...', 'block')
|
|
31
|
+
`
|
|
32
|
+
*/
|
|
33
|
+
class DHTMessage extends codecFormatInterface {
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
get keys() {
|
|
38
|
+
return ['hash', 'store']
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
constructor(data) {
|
|
42
|
+
const name = 'peernet-dht';
|
|
43
|
+
super(data, protons__default["default"](proto).PeernetDHTMessage, {name});
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
module.exports = DHTMessage;
|
package/dist/commonjs/hash.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var createKeccakHash = require('keccak');
|
|
4
4
|
var varint = require('varint');
|
|
5
|
-
var bs32 = require('
|
|
6
|
-
var bs58 = require('
|
|
5
|
+
var bs32 = require('@vandeurenglenn/base32');
|
|
6
|
+
var bs58 = require('@vandeurenglenn/base58');
|
|
7
7
|
var isHex = require('is-hex');
|
|
8
|
-
var codec = require('./codec-
|
|
8
|
+
var codec = require('./codec-4a768e5e.js');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
11
|
|
|
@@ -35,18 +35,28 @@ class PeernetHash {
|
|
|
35
35
|
|
|
36
36
|
if (typeof buffer === 'string') {
|
|
37
37
|
if (isHex__default["default"](buffer)) this.fromHex(buffer);
|
|
38
|
-
if (bs32__default["default"].
|
|
39
|
-
else this.fromBs58(buffer);
|
|
38
|
+
if (bs32__default["default"].isBase32(buffer)) this.fromBs32(buffer);
|
|
39
|
+
else if (bs58__default["default"].isBase58(buffer)) this.fromBs58(buffer);
|
|
40
|
+
else throw new Error(`unsupported string ${buffer}`)
|
|
40
41
|
} else if (typeof buffer === 'object') this.fromJSON(buffer);
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
get prefix() {
|
|
45
|
-
|
|
46
|
+
const length = this.length;
|
|
47
|
+
const uint8Array = new Uint8Array(length.length + this.discoCodec.codecBuffer.length);
|
|
48
|
+
for (let i = 0; i < this.discoCodec.codecBuffer.length; i++) {
|
|
49
|
+
uint8Array[i] = this.discoCodec.codecBuffer[i];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (let i = uint8Array.length - 1; i < length.length; i++) {
|
|
53
|
+
uint8Array[i] = length[i];
|
|
54
|
+
}
|
|
55
|
+
return uint8Array
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
get length() {
|
|
49
|
-
return
|
|
59
|
+
return varint__default["default"].encode(this.size)
|
|
50
60
|
}
|
|
51
61
|
|
|
52
62
|
get buffer() {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var Pubsub = require('@vandeurenglenn/little-pubsub');
|
|
4
3
|
var websocket = require('websocket');
|
|
4
|
+
var PubSub = require('@vandeurenglenn/little-pubsub');
|
|
5
5
|
var http$1 = require('http');
|
|
6
6
|
var Koa = require('koa');
|
|
7
7
|
|
|
8
8
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
11
11
|
var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
|
|
12
12
|
|
|
13
|
-
var version = "0.
|
|
13
|
+
var version = "0.10.8";
|
|
14
14
|
|
|
15
15
|
var api$1 = {
|
|
16
16
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -173,12 +173,15 @@ var socketResponse = (connection, url, id, customEvent) => {
|
|
|
173
173
|
}
|
|
174
174
|
};
|
|
175
175
|
|
|
176
|
+
if (!globalThis.PubSub) globalThis.PubSub = PubSub__default["default"];
|
|
177
|
+
if (!globalThis.pubsub) globalThis.pubsub = new PubSub__default["default"]();
|
|
178
|
+
|
|
176
179
|
const socketRequestServer = (options, routes = {}) => {
|
|
177
180
|
// if (!routes && !routes.port && options) routes = options;
|
|
178
181
|
// else if (!options && !routes) return console.error('no routes defined');
|
|
179
182
|
|
|
180
183
|
let {httpServer, httpsServer, port, protocol, credentials, origin, pubsub } = options;
|
|
181
|
-
if (!pubsub) pubsub = new
|
|
184
|
+
if (!pubsub) pubsub = new PubSub__default["default"]({verbose: false});
|
|
182
185
|
if (!port) port = 6000;
|
|
183
186
|
const connections = [];
|
|
184
187
|
let connection;
|
|
@@ -195,12 +198,12 @@ const socketRequestServer = (options, routes = {}) => {
|
|
|
195
198
|
response = params;
|
|
196
199
|
params = {};
|
|
197
200
|
}
|
|
198
|
-
|
|
201
|
+
|
|
199
202
|
if (!params.topic) params.topic = 'pubsub';
|
|
200
|
-
|
|
203
|
+
|
|
201
204
|
const topic = params.topic;
|
|
202
205
|
delete params.topic;
|
|
203
|
-
|
|
206
|
+
|
|
204
207
|
if (params.subscribe) {
|
|
205
208
|
pubsub.subscribe(topic, message => {
|
|
206
209
|
response.connection.send(JSON.stringify({url: topic, status: 200, value: message}));
|
|
@@ -225,7 +228,7 @@ const socketRequestServer = (options, routes = {}) => {
|
|
|
225
228
|
pubsub.publish(topic, params.value);
|
|
226
229
|
response.send('ok', 200);
|
|
227
230
|
};
|
|
228
|
-
|
|
231
|
+
|
|
229
232
|
}
|
|
230
233
|
globalThis.peerMap = new Map();
|
|
231
234
|
if (!routes.peernet) {
|
|
@@ -282,10 +285,10 @@ const socketRequestServer = (options, routes = {}) => {
|
|
|
282
285
|
// ignore api when customEvent is defined
|
|
283
286
|
if (customEvent) return;
|
|
284
287
|
if (routes[url]) {
|
|
285
|
-
if (!params) return routes[url](socketResponse(connection, url, id));
|
|
286
|
-
return routes[url](params, socketResponse(connection, url, id));
|
|
288
|
+
if (!params) return routes[url](socketResponse(connection, url, id), connections);
|
|
289
|
+
return routes[url](params, socketResponse(connection, url, id), connections);
|
|
287
290
|
}
|
|
288
|
-
else return socketResponse(connection, url, id).error(`
|
|
291
|
+
else return socketResponse(connection, url, id).error(`no handler found for '${message.url}'`);
|
|
289
292
|
};
|
|
290
293
|
|
|
291
294
|
connection.on('message', routeHandler);
|
|
@@ -295,7 +298,8 @@ const socketRequestServer = (options, routes = {}) => {
|
|
|
295
298
|
close: () => socketServer.shutDown(),
|
|
296
299
|
connections
|
|
297
300
|
};
|
|
298
|
-
};
|
|
301
|
+
};
|
|
302
|
+
var server = socketRequestServer;
|
|
299
303
|
|
|
300
304
|
var http = (config = {}) => {
|
|
301
305
|
if (typeof config !== 'object') config = {};
|
|
@@ -303,7 +307,7 @@ var http = (config = {}) => {
|
|
|
303
307
|
if (!config.port) config.port = 2000;
|
|
304
308
|
if (!config.host) config.host = '127.0.0.1';
|
|
305
309
|
|
|
306
|
-
const app = new Koa__default[
|
|
310
|
+
const app = new Koa__default["default"]();
|
|
307
311
|
|
|
308
312
|
app.use(async (ctx) => {
|
|
309
313
|
const url = ctx.url.split('/api/')[1];
|
|
@@ -318,7 +322,7 @@ var http = (config = {}) => {
|
|
|
318
322
|
console.log(`listening on ${config.port}`);
|
|
319
323
|
});
|
|
320
324
|
|
|
321
|
-
return
|
|
325
|
+
return server(config, api$1)
|
|
322
326
|
};
|
|
323
327
|
|
|
324
|
-
exports
|
|
328
|
+
exports["default"] = http;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var protons = require('protons');
|
|
4
4
|
var codecFormatInterface = require('./codec-format-interface.js');
|
|
5
|
-
require('
|
|
6
|
-
require('
|
|
5
|
+
require('@vandeurenglenn/base32');
|
|
6
|
+
require('@vandeurenglenn/base58');
|
|
7
7
|
require('is-hex');
|
|
8
|
-
require('./codec-
|
|
8
|
+
require('./codec-4a768e5e.js');
|
|
9
9
|
require('varint');
|
|
10
10
|
require('./hash.js');
|
|
11
11
|
require('keccak');
|
|
@@ -24,15 +24,15 @@ message PeernetMessage {
|
|
|
24
24
|
optional string id = 5;
|
|
25
25
|
}`;
|
|
26
26
|
|
|
27
|
-
class PeernetMessage extends codecFormatInterface {
|
|
28
|
-
get keys() {
|
|
29
|
-
return ['data', 'signature', 'from', 'to', 'id']
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor(buffer) {
|
|
33
|
-
const name = 'peernet-message';
|
|
34
|
-
super(buffer, protons__default["default"](proto).PeernetMessage, {name});
|
|
35
|
-
}
|
|
27
|
+
class PeernetMessage extends codecFormatInterface {
|
|
28
|
+
get keys() {
|
|
29
|
+
return ['data', 'signature', 'from', 'to', 'id']
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
constructor(buffer) {
|
|
33
|
+
const name = 'peernet-message';
|
|
34
|
+
super(buffer, protons__default["default"](proto).PeernetMessage, {name});
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
module.exports = PeernetMessage;
|