vrpc 3.3.2 → 3.5.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.
@@ -1,14 +1 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <https://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*! https://mths.be/punycode v1.3.2 by @mathias */
9
-
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 */
1
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vrpc",
3
- "version": "3.3.2",
3
+ "version": "3.5.0",
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:native && npm run test:agent && npm run test:client && npm run test:production && npm run test:persistor",
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.2.0",
52
- "crypto-browserify": "^3.12.0",
53
- "dockerode": "^3.2.0",
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.1.3",
56
+ "mocha": "^9.2.2",
57
57
  "os-browserify": "^0.3.0",
58
- "sinon": "^7.3.2",
58
+ "sinon": "^21.0.0",
59
59
  "stream-browserify": "^3.0.0",
60
60
  "url": "^0.11.0",
61
- "webpack": "^5.24.2",
62
- "webpack-cli": "^4.5.0"
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": "^6.10.0",
71
+ "ajv": "^8.17.1",
72
72
  "argparse": "^2.0.1",
73
73
  "buffer": "^6.0.3",
74
- "caller": "^1.0.1",
74
+ "caller": "^1.1.0",
75
75
  "json-stringify-safe": "^5.0.1",
76
- "mqtt": "^4.2.6",
77
- "nanoid": "^3.1.23",
76
+ "mqtt": "^5.14.1",
77
+ "nanoid": "^3.3.8",
78
78
  "process": "^0.11.10"
79
79
  },
80
80
  "peerDependencies": {
@@ -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')
@@ -760,7 +759,9 @@ class VrpcAdapter {
760
759
  return VrpcAdapter._listeners[instanceId][eventId].listener
761
760
  }
762
761
  VrpcAdapter._listeners[instanceId][eventId].clients.push(clientId)
763
- return null
762
+ // if "event" is defined we are calling against a plain EventEmitter and
763
+ // have to skip this call as we have registered internally
764
+ return VrpcAdapter._listeners[instanceId][eventId].listener
764
765
  }
765
766
 
766
767
  static _generateListener ({ eventId, instanceId, isCallAll }) {
@@ -783,8 +784,8 @@ class VrpcAdapter {
783
784
  if (Object.keys(VrpcAdapter._listeners[instanceId]).length === 0) {
784
785
  delete VrpcAdapter._listeners[instanceId]
785
786
  }
786
- return listener
787
787
  }
788
+ return listener
788
789
  }
789
790
  }
790
791
 
@@ -794,11 +795,8 @@ class VrpcAdapter {
794
795
  Object.entries(eventIds).forEach(([ek, ev]) => {
795
796
  if (ev.event === event && ev.clients.includes(clientId)) {
796
797
  ev.clients = ev.clients.filter(x => x !== clientId)
798
+ VrpcAdapter.getInstance(instanceId).removeAllListeners(ev.event)
797
799
  if (ev.clients.length === 0) {
798
- VrpcAdapter.getInstance(instanceId).removeListener(
799
- ev.event,
800
- ev.listener
801
- )
802
800
  delete VrpcAdapter._listeners[instanceId][ek]
803
801
  }
804
802
  }
@@ -825,10 +823,6 @@ class VrpcAdapter {
825
823
  }
826
824
  }
827
825
 
828
- static _generateId (object) {
829
- return crypto.createHash('md5').update(JSON.stringify(object)).digest('hex')
830
- }
831
-
832
826
  static _getClassEntry (className) {
833
827
  const entry = VrpcAdapter._functionRegistry.get(className)
834
828
  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 crypto = require('crypto')
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://vrpc.io:8883'
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://vrpc.io:8883'] Broker url in form: `<scheme>://<host>:<port>`
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://vrpc.io:8883',
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 = crypto
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 crypto.createHash('md5').update(uid).digest('hex')
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) {
@@ -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://vrpc.io:8883'] Broker url in form: `<scheme>://<host>:<port>`
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://vrpc.io:8883',
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${crypto
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: className,
389
+ className,
377
390
  instances: this._getInstances(className),
378
391
  memberFunctions: this._getMemberFunctions(className),
379
392
  staticFunctions: this._getStaticFunctions(className),