vrpc 3.4.0 → 3.5.1
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/browser/vrpc.js +7 -1
- package/browser/vrpc.js.LICENSE.txt +1 -5
- package/package.json +15 -15
- package/vrpc/VrpcAdapter.js +3 -22
- package/vrpc/VrpcAgent.js +26 -16
- package/vrpc/VrpcBrowserAdapter.js +0 -5
- package/vrpc/VrpcBrowserAgent.js +23 -10
- package/vrpc/VrpcClient.js +220 -83
- package/vrpc/vrpc-agent-js +1 -1
|
@@ -5,10 +5,6 @@
|
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
/*! https://mths.be/punycode v1.
|
|
8
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */
|
|
9
9
|
|
|
10
10
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
11
|
-
|
|
12
|
-
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
13
|
-
|
|
14
|
-
/** @license URI.js v4.4.1 (c) 2011 Gary Court. License: http://github.com/garycourt/uri-js */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vrpc",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Variadic Remote Procedure Calls",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"build:addon": "ln -sf binding.gyp.no-auto binding.gyp && node-gyp rebuild && rm binding.gyp",
|
|
13
13
|
"build:browser": "./node_modules/.bin/webpack --stats-error-details",
|
|
14
14
|
"build:doc": "./node_modules/.bin/jsdoc2md -f vrpc/VrpcAdapter.js vrpc/VrpcAgent.js vrpc/VrpcClient.js vrpc/VrpcNative.js --param-list-format=list --separators > docs/api.md",
|
|
15
|
-
"test": "npm run test:adapter && npm run test:
|
|
15
|
+
"test": "npm run test:adapter && npm run test:agent && npm run test:client && npm run test:persistor && npm run test:production",
|
|
16
16
|
"test:adapter": "./node_modules/.bin/mocha tests/adapter/*.js --exit",
|
|
17
17
|
"test:native": "./node_modules/.bin/mocha tests/native/*.js --exit",
|
|
18
|
-
"test:agent": "tests/agent/test.sh",
|
|
18
|
+
"test:agent": "tests/agent/test.sh" ,
|
|
19
19
|
"test:client": "tests/client/test.sh",
|
|
20
20
|
"test:performance": "tests/performance/test.sh",
|
|
21
|
-
"test:persistor": "./node_modules/.bin/mocha tests/persistor/*.js --exit",
|
|
21
|
+
"test:persistor": "./node_modules/.bin/mocha tests/persistor/*.js --timeout 30000 --exit",
|
|
22
22
|
"test:production": "./node_modules/.bin/mocha tests/production/lifeCycleTest.js --timeout 30000 --exit && tests/production/test.sh"
|
|
23
23
|
},
|
|
24
24
|
"bin": {
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
"homepage": "https://vrpc.io",
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@heisenware/storage": "^1.2.2",
|
|
51
|
-
"chai": "^4.
|
|
52
|
-
"crypto-browserify": "^3.12.
|
|
53
|
-
"dockerode": "^
|
|
51
|
+
"chai": "^4.3.10",
|
|
52
|
+
"crypto-browserify": "^3.12.1",
|
|
53
|
+
"dockerode": "^4.0.9",
|
|
54
54
|
"fs-extra": "^11.3.1",
|
|
55
55
|
"jsdoc-to-markdown": "^7.0.1",
|
|
56
|
-
"mocha": "^9.
|
|
56
|
+
"mocha": "^9.2.2",
|
|
57
57
|
"os-browserify": "^0.3.0",
|
|
58
|
-
"sinon": "^
|
|
58
|
+
"sinon": "^21.0.0",
|
|
59
59
|
"stream-browserify": "^3.0.0",
|
|
60
60
|
"url": "^0.11.0",
|
|
61
|
-
"webpack": "^5.
|
|
62
|
-
"webpack-cli": "^
|
|
61
|
+
"webpack": "^5.102.0",
|
|
62
|
+
"webpack-cli": "^6.0.1"
|
|
63
63
|
},
|
|
64
64
|
"files": [
|
|
65
65
|
"vrpc/",
|
|
@@ -68,13 +68,13 @@
|
|
|
68
68
|
],
|
|
69
69
|
"browser": "./browser/vrpc.js",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"ajv": "^
|
|
71
|
+
"ajv": "^8.17.1",
|
|
72
72
|
"argparse": "^2.0.1",
|
|
73
73
|
"buffer": "^6.0.3",
|
|
74
|
-
"caller": "^1.0
|
|
74
|
+
"caller": "^1.1.0",
|
|
75
75
|
"json-stringify-safe": "^5.0.1",
|
|
76
|
-
"mqtt": "^4.
|
|
77
|
-
"nanoid": "^3.
|
|
76
|
+
"mqtt": "^4.3.7",
|
|
77
|
+
"nanoid": "^3.3.8",
|
|
78
78
|
"process": "^0.11.10"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
package/vrpc/VrpcAdapter.js
CHANGED
|
@@ -37,7 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
37
37
|
SOFTWARE.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
const crypto = require('crypto')
|
|
41
40
|
const path = require('path')
|
|
42
41
|
const fs = require('fs')
|
|
43
42
|
const Ajv = require('ajv')
|
|
@@ -548,11 +547,6 @@ class VrpcAdapter {
|
|
|
548
547
|
return
|
|
549
548
|
}
|
|
550
549
|
const unwrapped = VrpcAdapter._unwrapArguments(json)
|
|
551
|
-
if (!unwrapped) {
|
|
552
|
-
// this call must be skipped (event emitter stuff)
|
|
553
|
-
json.r = true
|
|
554
|
-
return
|
|
555
|
-
}
|
|
556
550
|
// Check whether context is a registered class
|
|
557
551
|
const entry = VrpcAdapter._functionRegistry.get(json.c)
|
|
558
552
|
if (entry !== undefined) {
|
|
@@ -681,9 +675,6 @@ class VrpcAdapter {
|
|
|
681
675
|
eventId: arg,
|
|
682
676
|
event: args[0]
|
|
683
677
|
})
|
|
684
|
-
if (!listener) {
|
|
685
|
-
return null // skip call as listener is already registered
|
|
686
|
-
}
|
|
687
678
|
unwrapped.push(listener)
|
|
688
679
|
// event un-registration
|
|
689
680
|
} else if (func === 'off' || func === 'removeListener') {
|
|
@@ -692,9 +683,6 @@ class VrpcAdapter {
|
|
|
692
683
|
instanceId: context,
|
|
693
684
|
eventId: arg
|
|
694
685
|
})
|
|
695
|
-
if (!listener) {
|
|
696
|
-
return null // skip call as others are still interested
|
|
697
|
-
}
|
|
698
686
|
unwrapped.push(listener)
|
|
699
687
|
} else {
|
|
700
688
|
this._mustTrackClient = true
|
|
@@ -760,7 +748,7 @@ class VrpcAdapter {
|
|
|
760
748
|
return VrpcAdapter._listeners[instanceId][eventId].listener
|
|
761
749
|
}
|
|
762
750
|
VrpcAdapter._listeners[instanceId][eventId].clients.push(clientId)
|
|
763
|
-
return
|
|
751
|
+
return VrpcAdapter._listeners[instanceId][eventId].listener
|
|
764
752
|
}
|
|
765
753
|
|
|
766
754
|
static _generateListener ({ eventId, instanceId, isCallAll }) {
|
|
@@ -783,8 +771,8 @@ class VrpcAdapter {
|
|
|
783
771
|
if (Object.keys(VrpcAdapter._listeners[instanceId]).length === 0) {
|
|
784
772
|
delete VrpcAdapter._listeners[instanceId]
|
|
785
773
|
}
|
|
786
|
-
return listener
|
|
787
774
|
}
|
|
775
|
+
return listener
|
|
788
776
|
}
|
|
789
777
|
}
|
|
790
778
|
|
|
@@ -794,11 +782,8 @@ class VrpcAdapter {
|
|
|
794
782
|
Object.entries(eventIds).forEach(([ek, ev]) => {
|
|
795
783
|
if (ev.event === event && ev.clients.includes(clientId)) {
|
|
796
784
|
ev.clients = ev.clients.filter(x => x !== clientId)
|
|
785
|
+
VrpcAdapter.getInstance(instanceId).removeAllListeners(ev.event)
|
|
797
786
|
if (ev.clients.length === 0) {
|
|
798
|
-
VrpcAdapter.getInstance(instanceId).removeListener(
|
|
799
|
-
ev.event,
|
|
800
|
-
ev.listener
|
|
801
|
-
)
|
|
802
787
|
delete VrpcAdapter._listeners[instanceId][ek]
|
|
803
788
|
}
|
|
804
789
|
}
|
|
@@ -825,10 +810,6 @@ class VrpcAdapter {
|
|
|
825
810
|
}
|
|
826
811
|
}
|
|
827
812
|
|
|
828
|
-
static _generateId (object) {
|
|
829
|
-
return crypto.createHash('md5').update(JSON.stringify(object)).digest('hex')
|
|
830
|
-
}
|
|
831
|
-
|
|
832
813
|
static _getClassEntry (className) {
|
|
833
814
|
const entry = VrpcAdapter._functionRegistry.get(className)
|
|
834
815
|
if (!entry) {
|
package/vrpc/VrpcAgent.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const os = require('os')
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const mqtt = require('mqtt')
|
|
4
|
-
const
|
|
4
|
+
const { nanoid } = require('nanoid')
|
|
5
5
|
const { ArgumentParser } = require('argparse')
|
|
6
6
|
const EventEmitter = require('events')
|
|
7
7
|
const jsonStringifySafe = require('json-stringify-safe')
|
|
@@ -57,7 +57,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
57
57
|
})
|
|
58
58
|
parser.add_argument('-b', '--broker', {
|
|
59
59
|
help: 'Broker url',
|
|
60
|
-
default: broker || 'mqtts://
|
|
60
|
+
default: broker || 'mqtts://broker.hivemq.com:8883'
|
|
61
61
|
})
|
|
62
62
|
parser.add_argument('-u', '--username', {
|
|
63
63
|
help: 'Username',
|
|
@@ -96,7 +96,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
96
96
|
* @param {String} [obj.token] Access token
|
|
97
97
|
* @param {String} [obj.domain='vrpc'] The domain under which the agent-provided code is reachable
|
|
98
98
|
* @param {String} [obj.agent='<user>-<pathId>@<hostname>-<platform>-js'] This agent's name
|
|
99
|
-
* @param {String} [obj.broker='mqtts://
|
|
99
|
+
* @param {String} [obj.broker='mqtts://broker.hivemq.com:8883'] Broker url in form: `<scheme>://<host>:<port>`
|
|
100
100
|
* @param {Object} [obj.log=console] Log object (must support debug, info, warn, and error level)
|
|
101
101
|
* @param {String} [obj.bestEffort=true] If true, message will be sent with best effort, i.e. no caching if offline
|
|
102
102
|
* @param {String} [obj.version=''] The (user-defined) version of this agent
|
|
@@ -114,7 +114,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
114
114
|
token,
|
|
115
115
|
domain = 'vrpc',
|
|
116
116
|
agent = VrpcAgent._generateAgentName(),
|
|
117
|
-
broker = 'mqtts://
|
|
117
|
+
broker = 'mqtts://broker.hivemq.com:8883',
|
|
118
118
|
log = 'console',
|
|
119
119
|
bestEffort = true,
|
|
120
120
|
version = '',
|
|
@@ -132,12 +132,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
132
132
|
this._qos = bestEffort ? 0 : 1
|
|
133
133
|
this._version = version
|
|
134
134
|
this._mqttClientId =
|
|
135
|
-
mqttClientId ||
|
|
136
|
-
`va3${crypto
|
|
137
|
-
.createHash('md5')
|
|
138
|
-
.update(this._domain + this._agent)
|
|
139
|
-
.digest('hex')
|
|
140
|
-
.substring(0, 20)}`
|
|
135
|
+
mqttClientId || `va3${VrpcAgent._createHash(this._domain + this._agent)}`
|
|
141
136
|
if (log === 'console') {
|
|
142
137
|
this._log = console
|
|
143
138
|
this._log.debug = () => {}
|
|
@@ -268,13 +263,28 @@ class VrpcAgent extends EventEmitter {
|
|
|
268
263
|
return obj
|
|
269
264
|
}
|
|
270
265
|
|
|
266
|
+
static _createHash (str, length = 20) {
|
|
267
|
+
// Extended DJB2 hash with two accumulators
|
|
268
|
+
let hash1 = 5381
|
|
269
|
+
let hash2 = 52711 // different seed
|
|
270
|
+
|
|
271
|
+
for (let i = 0; i < str.length; i++) {
|
|
272
|
+
const char = str.charCodeAt(i)
|
|
273
|
+
hash1 = (hash1 * 33) ^ char
|
|
274
|
+
hash2 = (hash2 * 33) ^ char
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Combine into longer hex string
|
|
278
|
+
const token =
|
|
279
|
+
(hash1 >>> 0).toString(16).padStart(8, '0') +
|
|
280
|
+
(hash2 >>> 0).toString(16).padStart(8, '0')
|
|
281
|
+
|
|
282
|
+
return token.slice(0, length)
|
|
283
|
+
}
|
|
284
|
+
|
|
271
285
|
static _generateAgentName () {
|
|
272
286
|
const { username } = os.userInfo()
|
|
273
|
-
const pathId =
|
|
274
|
-
.createHash('md5')
|
|
275
|
-
.update(path.resolve())
|
|
276
|
-
.digest('hex')
|
|
277
|
-
.substring(0, 4)
|
|
287
|
+
const pathId = VrpcAgent._createHash(path.resolve, 4)
|
|
278
288
|
return `${username}-${pathId}@${os.hostname()}-${os.platform()}-js`
|
|
279
289
|
}
|
|
280
290
|
|
|
@@ -293,7 +303,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
293
303
|
os.type() +
|
|
294
304
|
JSON.stringify(os.networkInterfaces()) +
|
|
295
305
|
JSON.stringify(os.cpus().map(({ model }) => model))
|
|
296
|
-
return
|
|
306
|
+
return VrpcAgent._createHash(uid)
|
|
297
307
|
}
|
|
298
308
|
|
|
299
309
|
_validateDomain (domain) {
|
|
@@ -37,7 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
37
37
|
SOFTWARE.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
-
const crypto = require('crypto')
|
|
41
40
|
const Ajv = require('ajv')
|
|
42
41
|
const EventEmitter = require('events')
|
|
43
42
|
const { nanoid } = require('nanoid')
|
|
@@ -727,10 +726,6 @@ class VrpcAdapter {
|
|
|
727
726
|
}
|
|
728
727
|
}
|
|
729
728
|
|
|
730
|
-
static _generateId (object) {
|
|
731
|
-
return crypto.createHash('md5').update(JSON.stringify(object)).digest('hex')
|
|
732
|
-
}
|
|
733
|
-
|
|
734
729
|
static _getClassEntry (className) {
|
|
735
730
|
const entry = VrpcAdapter._functionRegistry.get(className)
|
|
736
731
|
if (!entry) {
|
package/vrpc/VrpcBrowserAgent.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const os = require('os')
|
|
2
2
|
const mqtt = require('mqtt')
|
|
3
|
-
const crypto = require('crypto')
|
|
4
3
|
const VrpcAdapter = require('./VrpcBrowserAdapter')
|
|
5
4
|
const EventEmitter = require('events')
|
|
6
5
|
const { nanoid } = require('nanoid')
|
|
@@ -13,7 +12,6 @@ const VRPC_PROTOCOL_VERSION = 3
|
|
|
13
12
|
* @extends EventEmitter
|
|
14
13
|
*/
|
|
15
14
|
class VrpcAgent extends EventEmitter {
|
|
16
|
-
|
|
17
15
|
/**
|
|
18
16
|
* Constructs an agent instance
|
|
19
17
|
*
|
|
@@ -24,7 +22,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
24
22
|
* @param {String} [obj.token] Access token
|
|
25
23
|
* @param {String} [obj.domain='vrpc'] The domain under which the agent-provided code is reachable
|
|
26
24
|
* @param {String} [obj.agent='<user>-<pathId>@<hostname>-<platform>-js'] This agent's name
|
|
27
|
-
* @param {String} [obj.broker='mqtts://
|
|
25
|
+
* @param {String} [obj.broker='mqtts://broker.hivemq.com:8883'] Broker url in form: `<scheme>://<host>:<port>`
|
|
28
26
|
* @param {Object} [obj.log=console] Log object (must support debug, info, warn, and error level)
|
|
29
27
|
* @param {String} [obj.bestEffort=false] If true, message will be sent with best effort, i.e. no caching if offline
|
|
30
28
|
* @param {String} [obj.version=''] The (user-defined) version of this agent
|
|
@@ -42,7 +40,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
42
40
|
token,
|
|
43
41
|
domain = 'vrpc',
|
|
44
42
|
agent = nanoid(8),
|
|
45
|
-
broker = 'mqtts://
|
|
43
|
+
broker = 'mqtts://broker.hivemq.com:8883',
|
|
46
44
|
log = 'console',
|
|
47
45
|
bestEffort = false,
|
|
48
46
|
version = '',
|
|
@@ -61,11 +59,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
61
59
|
this._version = version
|
|
62
60
|
this._mqttClientId =
|
|
63
61
|
mqttClientId ||
|
|
64
|
-
`va3${
|
|
65
|
-
.createHash('md5')
|
|
66
|
-
.update(this._domain + this._agent)
|
|
67
|
-
.digest('hex')
|
|
68
|
-
.substring(0, 20)}`
|
|
62
|
+
`va3${VrpcAgent._createHash(this._domain + this._agent)}`
|
|
69
63
|
if (log === 'console') {
|
|
70
64
|
this._log = console
|
|
71
65
|
this._log.debug = () => {}
|
|
@@ -171,6 +165,25 @@ class VrpcAgent extends EventEmitter {
|
|
|
171
165
|
}
|
|
172
166
|
}
|
|
173
167
|
|
|
168
|
+
static _createHash (str, length = 20) {
|
|
169
|
+
// Extended DJB2 hash with two accumulators
|
|
170
|
+
let hash1 = 5381
|
|
171
|
+
let hash2 = 52711 // different seed
|
|
172
|
+
|
|
173
|
+
for (let i = 0; i < str.length; i++) {
|
|
174
|
+
const char = str.charCodeAt(i)
|
|
175
|
+
hash1 = (hash1 * 33) ^ char
|
|
176
|
+
hash2 = (hash2 * 33) ^ char
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Combine into longer hex string
|
|
180
|
+
const token =
|
|
181
|
+
(hash1 >>> 0).toString(16).padStart(8, '0') +
|
|
182
|
+
(hash2 >>> 0).toString(16).padStart(8, '0')
|
|
183
|
+
|
|
184
|
+
return token.slice(0, length)
|
|
185
|
+
}
|
|
186
|
+
|
|
174
187
|
_validateDomain (domain) {
|
|
175
188
|
if (!domain) throw new Error('The domain must be specified')
|
|
176
189
|
if (domain.match(/[+/#*]/)) {
|
|
@@ -373,7 +386,7 @@ class VrpcAgent extends EventEmitter {
|
|
|
373
386
|
|
|
374
387
|
_publishClassInfoMessage (className) {
|
|
375
388
|
const json = {
|
|
376
|
-
className
|
|
389
|
+
className,
|
|
377
390
|
instances: this._getInstances(className),
|
|
378
391
|
memberFunctions: this._getMemberFunctions(className),
|
|
379
392
|
staticFunctions: this._getStaticFunctions(className),
|