nep-cli 0.1.9 → 0.2.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/bin/index.js +41 -69
- package/package.json +3 -3
package/bin/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const { version } = require('../package.json');
|
|
|
5
5
|
const os = require('os');
|
|
6
6
|
const zmq = require("zeromq");
|
|
7
7
|
var nep = require('nep-js');
|
|
8
|
-
var nep_configuration = { current_port:
|
|
8
|
+
var nep_configuration = { current_port: 50200, IP: "0.0.0.0", brokers: {} }
|
|
9
9
|
const { exec } = require('child_process');
|
|
10
10
|
const { AutoComplete } = require('enquirer');
|
|
11
11
|
|
|
@@ -17,37 +17,23 @@ const socketIo = require('socket.io');
|
|
|
17
17
|
const fs = require('fs');
|
|
18
18
|
const zmqc = require("zeromq/v5-compat");
|
|
19
19
|
|
|
20
|
+
const PORT_MASTER_INFO = 50001; // Default port for master info
|
|
21
|
+
const PORT_IMAGES = [];
|
|
22
|
+
for (let i = 50050; i <= 50060; i++) {
|
|
23
|
+
PORT_IMAGES.push(i);
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
|
|
21
27
|
program
|
|
22
28
|
.version(version)
|
|
23
29
|
.description('NEP-CLI')
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
function getIPAddress(interfaceName) {
|
|
27
|
-
const interfaces = os.networkInterfaces();
|
|
28
|
-
const networkInterface = interfaces[interfaceName];
|
|
29
|
-
|
|
30
|
-
if (networkInterface) {
|
|
31
|
-
const ipAddressInfo = networkInterface.find(info => info.family === 'IPv4');
|
|
32
|
-
return ipAddressInfo ? ipAddressInfo.address : null;
|
|
33
|
-
} else {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function printIPAddress(interfaceName, ipAddress) {
|
|
39
|
-
if (ipAddress) {
|
|
40
|
-
console.log(`${interfaceName} IP Address: ${ipAddress}`);
|
|
41
|
-
} else {
|
|
42
|
-
console.log(`No ${interfaceName} IPv4 address found.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
31
|
program
|
|
47
32
|
.command('ip')
|
|
48
33
|
.description('Display current Wi-Fi and Ethernet IP addresses of this computer')
|
|
49
34
|
.action(() => {
|
|
50
35
|
try {
|
|
36
|
+
// subsitude by interfaces = nep.getNetworkInterfaces --> {"wifi":wifiInterfaces, "eth":ethernetInterface}
|
|
51
37
|
const platform = os.platform();
|
|
52
38
|
let wifiInterfaces, ethernetInterface;
|
|
53
39
|
|
|
@@ -66,11 +52,11 @@ program
|
|
|
66
52
|
}
|
|
67
53
|
|
|
68
54
|
wifiInterfaces.forEach(wifiInterface => {
|
|
69
|
-
const ipAddress = getIPAddress(wifiInterface);
|
|
70
|
-
printIPAddress(`Wi-Fi (${wifiInterface})`, ipAddress);
|
|
55
|
+
const ipAddress = nep.getIPAddress(wifiInterface);
|
|
56
|
+
nep.printIPAddress(`Wi-Fi (${wifiInterface})`, ipAddress);
|
|
71
57
|
});
|
|
72
58
|
|
|
73
|
-
printIPAddress('Ethernet', getIPAddress(ethernetInterface));
|
|
59
|
+
nep.printIPAddress('Ethernet', nep.getIPAddress(ethernetInterface));
|
|
74
60
|
} catch (error) {
|
|
75
61
|
console.error('An error occurred:', error.message);
|
|
76
62
|
}
|
|
@@ -85,7 +71,7 @@ var nodes_register = {};
|
|
|
85
71
|
var topic_register = {};
|
|
86
72
|
|
|
87
73
|
class MasterLocal {
|
|
88
|
-
constructor(IP = '0.0.0.0', port_ =
|
|
74
|
+
constructor(IP = '0.0.0.0', port_ = 50000) {
|
|
89
75
|
this.port = String(port_)
|
|
90
76
|
var address = "tcp://" + IP + ":" + this.port
|
|
91
77
|
console.log("New Master in: " + address)
|
|
@@ -266,60 +252,46 @@ var restartTopics = function (node_request) {
|
|
|
266
252
|
onUpdateTopicList(topic_register)
|
|
267
253
|
}
|
|
268
254
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
console.log(
|
|
255
|
+
const processMsg = (json_msg, nodes_register, topic_register) => {
|
|
256
|
+
const node_request = JSON.parse(json_msg);
|
|
257
|
+
const { node, socket, topic, pid } = node_request;
|
|
258
|
+
console.log(`NEP: Node request - node: ${node}, socket: ${socket}, topic: ${topic}`);
|
|
273
259
|
|
|
274
260
|
// Check node status
|
|
275
|
-
if (
|
|
276
|
-
|
|
261
|
+
if (node) {
|
|
277
262
|
// Kill previous node with the same name
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
console.log("Kill node: " + node_request['node'])
|
|
288
|
-
nep.killNode(current_pid)
|
|
263
|
+
if (node in nodes_register) {
|
|
264
|
+
console.log(`--- Node *${node}* already defined ---`);
|
|
265
|
+
const current_pid = nodes_register[node];
|
|
266
|
+
if (pid !== current_pid) {
|
|
267
|
+
if (!node.startsWith('nep-cli')) {
|
|
268
|
+
// TODO: Reset topics in node for graph
|
|
269
|
+
console.log(`Kill node: ${node}`);
|
|
270
|
+
nep.killNode(current_pid);
|
|
271
|
+
}
|
|
289
272
|
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
console.log("--- New Node *" + node_request['node'] + "* ---")
|
|
273
|
+
} else {
|
|
274
|
+
console.log(`--- New Node *${node}* ---`);
|
|
293
275
|
}
|
|
294
276
|
}
|
|
295
277
|
|
|
296
278
|
// Update node info
|
|
297
|
-
nodes_register[
|
|
298
|
-
|
|
299
|
-
var topic = String(node_request['topic'])
|
|
279
|
+
nodes_register[node] = pid;
|
|
280
|
+
|
|
300
281
|
// Check topic status
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
282
|
+
const topicStr = String(topic);
|
|
283
|
+
if (topicStr in topic_register) {
|
|
284
|
+
console.log(`--- Topic *${topicStr}* already registered ---`);
|
|
304
285
|
// Send information of topic already defined
|
|
305
|
-
|
|
306
|
-
return JSON.stringify(response)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
console.log(" --- New topic : *" + topic + "* ---")
|
|
286
|
+
const response = onRegisteredTopic(node_request, topic_register, topicStr);
|
|
287
|
+
return JSON.stringify(response);
|
|
288
|
+
} else {
|
|
289
|
+
console.log(`--- New topic: *${topicStr}* ---`);
|
|
310
290
|
// Create new broker
|
|
311
|
-
|
|
312
|
-
return JSON.stringify(response)
|
|
291
|
+
const response = onNewTopic(node_request, topic_register);
|
|
292
|
+
return JSON.stringify(response);
|
|
313
293
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
const PORT_MASTER_INFO = 7010; // Default port for master info
|
|
317
|
-
const PORT_IMAGE = 3000;
|
|
318
|
-
const PORT_IMAGES = [];
|
|
319
|
-
for (let i = 3020; i <= 3040; i++) {
|
|
320
|
-
PORT_IMAGES.push(i);
|
|
321
|
-
}
|
|
322
|
-
|
|
294
|
+
};
|
|
323
295
|
|
|
324
296
|
|
|
325
297
|
program
|
|
@@ -397,7 +369,7 @@ program
|
|
|
397
369
|
var node = new nep.Node("nep-cli");
|
|
398
370
|
console.log("Starting NEP master in terminal")
|
|
399
371
|
var master = new MasterLocal();
|
|
400
|
-
var info = new nep.MasterInfoServer(IP = '0.0.0.0', topics = topic_register);
|
|
372
|
+
var info = new nep.MasterInfoServer(IP = '0.0.0.0', topics = topic_register, port_=PORT_MASTER_INFO);
|
|
401
373
|
} catch (error) {
|
|
402
374
|
if (error.message.includes('EADDRINUSE')) {
|
|
403
375
|
console.error("Error: Address already in use. Another instance of NEP master might be running.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nep-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "./lib/nep.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"nep": "./bin/index.js"
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"express": "^4.18.2",
|
|
15
15
|
"fix-path": "^2.1.0",
|
|
16
16
|
"inquirer": "^9.2.10",
|
|
17
|
-
"nep-js": "0.3.
|
|
17
|
+
"nep-js": "0.3.7",
|
|
18
18
|
"open": "7.4.2",
|
|
19
19
|
"socket.io": "^4.7.2",
|
|
20
|
-
"zeromq": "6.0.0-beta.
|
|
20
|
+
"zeromq": "6.0.0-beta.19"
|
|
21
21
|
}
|
|
22
22
|
}
|