From 99e0c078adcc0111d8212ef899a7fe054b28ceaf Mon Sep 17 00:00:00 2001 From: AndreaIannoli Date: Fri, 3 Nov 2023 17:27:19 +0100 Subject: [PATCH 1/2] MultiBroker setup w/o counter Complete multibroker setup that fully work in a context with 3 brokers --- .DS_Store | Bin 8196 -> 8196 bytes app/.DS_Store | Bin 6148 -> 6148 bytes backend/.idea/.gitignore | 0 backend/.idea/backend.iml | 0 backend/.idea/jsLibraryMappings.xml | 0 backend/.idea/modules.xml | 0 backend/.idea/vcs.xml | 6 + backend/App.js | 118 +++++++++++++++++- backend/App.ts | 56 ++++++++- backend/BackEndService.js | 54 -------- backend/BackEndService.ts | 7 -- backend/backend_configuration/backend_0.json | 3 + backend/backend_configuration/backend_1.json | 3 + backend/backend_configuration/backend_2.json | 3 + backend/la-mqtt/backend/backend.js | 107 ++++++++++++---- backend/la-mqtt/backend/backend.ts | 38 +++++- backend/la-mqtt/backend/dto/iwatcher.js | 0 backend/la-mqtt/backend/dto/iwatcher.ts | 0 backend/la-mqtt/backend/geoprocesser.js | 0 backend/la-mqtt/backend/geoprocesser.ts | 0 backend/la-mqtt/backend/ipersister.js | 0 backend/la-mqtt/backend/ipersister.ts | 0 backend/la-mqtt/backend/log.txt | 0 backend/la-mqtt/backend/logwatcher.js | 0 backend/la-mqtt/backend/logwatcher.ts | 0 backend/la-mqtt/backend/mempersister.js | 0 backend/la-mqtt/backend/mempersister.ts | 0 backend/la-mqtt/backend/model/geofence.js | 0 backend/la-mqtt/backend/model/geofence.ts | 0 backend/la-mqtt/backend/model/subscription.js | 0 backend/la-mqtt/backend/model/subscription.ts | 0 backend/la-mqtt/backend/model/user.js | 0 backend/la-mqtt/backend/model/user.ts | 0 backend/la-mqtt/backend/persister.js | 0 backend/la-mqtt/backend/persister.ts | 0 backend/la-mqtt/common/client.js | 0 backend/la-mqtt/common/client.ts | 0 backend/la-mqtt/common/direction.ts | 0 backend/la-mqtt/common/iconnector.js | 0 backend/la-mqtt/common/iconnector.ts | 0 backend/la-mqtt/common/ireceiver.js | 0 backend/la-mqtt/common/ireceiver.ts | 0 backend/la-mqtt/common/messages.js | 1 + backend/la-mqtt/common/messages.ts | 7 +- backend/la-mqtt/common/mosquittoConnector.js | 0 backend/la-mqtt/common/mosquittoConnector.ts | 0 backend/la-mqtt/common/position.js | 0 backend/la-mqtt/common/position.ts | 0 backend/package-lock.json | 6 + backend/package.json | 1 + lds/.idea/.gitignore | 0 lds/.idea/jsLibraryMappings.xml | 0 lds/.idea/lds.iml | 0 lds/.idea/modules.xml | 0 lds/.idea/vcs.xml | 6 + lds/App.js | 49 ++++---- lds/App.ts | 25 ++-- lds/LDSClientService.js | 14 +-- lds/LDSClientService.ts | 7 +- lds/LDSReceiver.js | 0 lds/LDSReceiver.ts | 0 lds/demo_configuaration/lds_via_irnerio.json | 0 lds/demo_configuaration/lds_via_irnerio1.json | 0 .../lds_via_mascarella.json | 0 .../lds_via_mascarella1.json | 0 lds/la-mqtt/client/measurer.js | 0 lds/la-mqtt/client/measurer.ts | 0 lds/la-mqtt/client/privacy/dist.js | 0 lds/la-mqtt/client/privacy/dist.ts | 0 lds/la-mqtt/client/privacy/entropy.js | 0 lds/la-mqtt/client/privacy/entropy.ts | 0 lds/la-mqtt/client/privacy/imetrics.js | 0 lds/la-mqtt/client/privacy/imetrics.ts | 0 lds/la-mqtt/client/privacy/iprivacy.js | 0 lds/la-mqtt/client/privacy/iprivacy.ts | 0 lds/la-mqtt/client/privacy/learning.js | 0 lds/la-mqtt/client/privacy/learning.ts | 0 lds/la-mqtt/client/privacy/percolation.js | 0 lds/la-mqtt/client/privacy/percolation.ts | 0 lds/la-mqtt/client/privacy/perturbation.js | 0 lds/la-mqtt/client/privacy/perturbation.ts | 0 lds/la-mqtt/client/smqttclient.js | 11 +- lds/la-mqtt/client/smqttclient.ts | 4 +- lds/la-mqtt/common/client.js | 0 lds/la-mqtt/common/client.ts | 0 lds/la-mqtt/common/direction.js | 0 lds/la-mqtt/common/direction.ts | 0 lds/la-mqtt/common/iconnector.js | 0 lds/la-mqtt/common/iconnector.ts | 0 lds/la-mqtt/common/ireceiver.js | 0 lds/la-mqtt/common/ireceiver.ts | 0 lds/la-mqtt/common/messages.js | 0 lds/la-mqtt/common/messages.ts | 0 lds/la-mqtt/common/mosquittoConnector.js | 0 lds/la-mqtt/common/mosquittoConnector.ts | 0 lds/la-mqtt/common/position.js | 0 lds/la-mqtt/common/position.ts | 0 lds/la-mqtt/simulator/god.js | 0 lds/la-mqtt/simulator/god.ts | 0 lds/la-mqtt/simulator/random.js | 0 lds/la-mqtt/simulator/random.ts | 0 lds/la-mqtt/simulator/simulator.ts | 0 lds/package-lock.json | 0 lds/package.json | 0 104 files changed, 378 insertions(+), 148 deletions(-) mode change 100644 => 100755 backend/.idea/.gitignore mode change 100644 => 100755 backend/.idea/backend.iml mode change 100644 => 100755 backend/.idea/jsLibraryMappings.xml mode change 100644 => 100755 backend/.idea/modules.xml create mode 100644 backend/.idea/vcs.xml mode change 100644 => 100755 backend/App.js mode change 100644 => 100755 backend/App.ts delete mode 100644 backend/BackEndService.js delete mode 100644 backend/BackEndService.ts create mode 100644 backend/backend_configuration/backend_0.json create mode 100644 backend/backend_configuration/backend_1.json create mode 100644 backend/backend_configuration/backend_2.json mode change 100644 => 100755 backend/la-mqtt/backend/backend.js mode change 100644 => 100755 backend/la-mqtt/backend/backend.ts mode change 100644 => 100755 backend/la-mqtt/backend/dto/iwatcher.js mode change 100644 => 100755 backend/la-mqtt/backend/dto/iwatcher.ts mode change 100644 => 100755 backend/la-mqtt/backend/geoprocesser.js mode change 100644 => 100755 backend/la-mqtt/backend/geoprocesser.ts mode change 100644 => 100755 backend/la-mqtt/backend/ipersister.js mode change 100644 => 100755 backend/la-mqtt/backend/ipersister.ts mode change 100644 => 100755 backend/la-mqtt/backend/log.txt mode change 100644 => 100755 backend/la-mqtt/backend/logwatcher.js mode change 100644 => 100755 backend/la-mqtt/backend/logwatcher.ts mode change 100644 => 100755 backend/la-mqtt/backend/mempersister.js mode change 100644 => 100755 backend/la-mqtt/backend/mempersister.ts mode change 100644 => 100755 backend/la-mqtt/backend/model/geofence.js mode change 100644 => 100755 backend/la-mqtt/backend/model/geofence.ts mode change 100644 => 100755 backend/la-mqtt/backend/model/subscription.js mode change 100644 => 100755 backend/la-mqtt/backend/model/subscription.ts mode change 100644 => 100755 backend/la-mqtt/backend/model/user.js mode change 100644 => 100755 backend/la-mqtt/backend/model/user.ts mode change 100644 => 100755 backend/la-mqtt/backend/persister.js mode change 100644 => 100755 backend/la-mqtt/backend/persister.ts mode change 100644 => 100755 backend/la-mqtt/common/client.js mode change 100644 => 100755 backend/la-mqtt/common/client.ts mode change 100644 => 100755 backend/la-mqtt/common/direction.ts mode change 100644 => 100755 backend/la-mqtt/common/iconnector.js mode change 100644 => 100755 backend/la-mqtt/common/iconnector.ts mode change 100644 => 100755 backend/la-mqtt/common/ireceiver.js mode change 100644 => 100755 backend/la-mqtt/common/ireceiver.ts mode change 100644 => 100755 backend/la-mqtt/common/messages.js mode change 100644 => 100755 backend/la-mqtt/common/messages.ts mode change 100644 => 100755 backend/la-mqtt/common/mosquittoConnector.js mode change 100644 => 100755 backend/la-mqtt/common/mosquittoConnector.ts mode change 100644 => 100755 backend/la-mqtt/common/position.js mode change 100644 => 100755 backend/la-mqtt/common/position.ts mode change 100644 => 100755 backend/package-lock.json mode change 100644 => 100755 backend/package.json mode change 100644 => 100755 lds/.idea/.gitignore mode change 100644 => 100755 lds/.idea/jsLibraryMappings.xml mode change 100644 => 100755 lds/.idea/lds.iml mode change 100644 => 100755 lds/.idea/modules.xml create mode 100644 lds/.idea/vcs.xml mode change 100644 => 100755 lds/App.js mode change 100644 => 100755 lds/App.ts mode change 100644 => 100755 lds/LDSClientService.js mode change 100644 => 100755 lds/LDSClientService.ts mode change 100644 => 100755 lds/LDSReceiver.js mode change 100644 => 100755 lds/LDSReceiver.ts mode change 100644 => 100755 lds/demo_configuaration/lds_via_irnerio.json mode change 100644 => 100755 lds/demo_configuaration/lds_via_irnerio1.json mode change 100644 => 100755 lds/demo_configuaration/lds_via_mascarella.json mode change 100644 => 100755 lds/demo_configuaration/lds_via_mascarella1.json mode change 100644 => 100755 lds/la-mqtt/client/measurer.js mode change 100644 => 100755 lds/la-mqtt/client/measurer.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/dist.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/dist.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/entropy.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/entropy.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/imetrics.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/imetrics.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/iprivacy.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/iprivacy.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/learning.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/learning.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/percolation.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/percolation.ts mode change 100644 => 100755 lds/la-mqtt/client/privacy/perturbation.js mode change 100644 => 100755 lds/la-mqtt/client/privacy/perturbation.ts mode change 100644 => 100755 lds/la-mqtt/client/smqttclient.js mode change 100644 => 100755 lds/la-mqtt/client/smqttclient.ts mode change 100644 => 100755 lds/la-mqtt/common/client.js mode change 100644 => 100755 lds/la-mqtt/common/client.ts mode change 100644 => 100755 lds/la-mqtt/common/direction.js mode change 100644 => 100755 lds/la-mqtt/common/direction.ts mode change 100644 => 100755 lds/la-mqtt/common/iconnector.js mode change 100644 => 100755 lds/la-mqtt/common/iconnector.ts mode change 100644 => 100755 lds/la-mqtt/common/ireceiver.js mode change 100644 => 100755 lds/la-mqtt/common/ireceiver.ts mode change 100644 => 100755 lds/la-mqtt/common/messages.js mode change 100644 => 100755 lds/la-mqtt/common/messages.ts mode change 100644 => 100755 lds/la-mqtt/common/mosquittoConnector.js mode change 100644 => 100755 lds/la-mqtt/common/mosquittoConnector.ts mode change 100644 => 100755 lds/la-mqtt/common/position.js mode change 100644 => 100755 lds/la-mqtt/common/position.ts mode change 100644 => 100755 lds/la-mqtt/simulator/god.js mode change 100644 => 100755 lds/la-mqtt/simulator/god.ts mode change 100644 => 100755 lds/la-mqtt/simulator/random.js mode change 100644 => 100755 lds/la-mqtt/simulator/random.ts mode change 100644 => 100755 lds/la-mqtt/simulator/simulator.ts mode change 100644 => 100755 lds/package-lock.json mode change 100644 => 100755 lds/package.json diff --git a/.DS_Store b/.DS_Store index e031f60faa1acd7a4566135a61e4bf0f5ca2bc4b..5c40462eabc5eae319baef1d9715b418deb8c233 100644 GIT binary patch delta 44 zcmZp1XmOa}&nUVvU^hRb=w==PCzj16B9oaXHmGf8m-xmq*;B}AbE@bfril&8072Xi AeE8&z$_^q@4UD1_lNJ1_s7%Ag%Ww3>X+T Xdy33p-pnrXjb*Zfu+rwAB2SqB3vU;H diff --git a/app/.DS_Store b/app/.DS_Store index 172e8fe3d1bdf66d2d59e851b9cda760cccd47c4..7be623edddd595227a793b94feeb7bf84d68afe6 100644 GIT binary patch delta 69 zcmZoMXffE}&cwK5vIkS4xIH?wm5=LZ0M;S(|d diff --git a/backend/.idea/.gitignore b/backend/.idea/.gitignore old mode 100644 new mode 100755 diff --git a/backend/.idea/backend.iml b/backend/.idea/backend.iml old mode 100644 new mode 100755 diff --git a/backend/.idea/jsLibraryMappings.xml b/backend/.idea/jsLibraryMappings.xml old mode 100644 new mode 100755 diff --git a/backend/.idea/modules.xml b/backend/.idea/modules.xml old mode 100644 new mode 100755 diff --git a/backend/.idea/vcs.xml b/backend/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/backend/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/backend/App.js b/backend/App.js old mode 100644 new mode 100755 index fb5ec16..339df44 --- a/backend/App.js +++ b/backend/App.js @@ -1,4 +1,118 @@ "use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; exports.__esModule = true; -var BackEndService_1 = require("./BackEndService"); -BackEndService_1.clientConnection(); +exports.clientConnection = void 0; +var backend_1 = require("./la-mqtt/backend/backend"); +var fs = require("fs"); +if (process.argv.length !== 4) { + console.error('Usage: npm start '); + process.exit(1); +} +else if (!process.argv[2].split(':')[1]) { + console.error('You must specify the port in the address'); + process.exit(1); +} +var brokerAddress = process.argv[2]; +var filePath = process.argv[3]; +function readFileAsJSON(filePath) { + return new Promise(function (resolve, reject) { + fs.readFile(filePath, 'utf8', function (err, data) { + if (err) { + reject(err); + return; + } + try { + var jsonContent = JSON.parse(data); + resolve(jsonContent); + } + catch (error) { + reject(error); + } + }); + }); +} +function start() { + return __awaiter(this, void 0, void 0, function () { + var configuration, lamqttBackEnd; + var _this = this; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () { + var jsonContent, error_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + return [4 /*yield*/, readFileAsJSON(filePath)]; + case 1: + jsonContent = _a.sent(); + console.log(jsonContent); + return [2 /*return*/, jsonContent]; + case 2: + error_1 = _a.sent(); + console.error('Error:', error_1); + return [3 /*break*/, 3]; + case 3: return [2 /*return*/]; + } + }); + }); })()]; + case 1: + configuration = _a.sent(); + lamqttBackEnd = new backend_1.SpatialMQTTBackEnd('', '', brokerAddress.split(':')[0], parseInt(brokerAddress.split(':')[1]), configuration); + return [4 /*yield*/, clientConnection(lamqttBackEnd)]; + case 2: + _a.sent(); + return [2 /*return*/]; + } + }); + }); +} +start(); +function clientConnection(lamqttBackEnd) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, lamqttBackEnd.start()]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); +} +exports.clientConnection = clientConnection; diff --git a/backend/App.ts b/backend/App.ts old mode 100644 new mode 100755 index bc7c156..490991a --- a/backend/App.ts +++ b/backend/App.ts @@ -1,3 +1,55 @@ -import {clientConnection} from "./BackEndService"; +import {SpatialMQTTBackEnd} from "./la-mqtt/backend/backend"; +import fs = require('fs'); + +if (process.argv.length !== 4) { + console.error('Usage: npm start '); + process.exit(1); +} else if(!process.argv[2].split(':')[1]) { + console.error('You must specify the port in the address'); + process.exit(1); +} + +const brokerAddress = process.argv[2]; + +const filePath = process.argv[3]; + +function readFileAsJSON(filePath) { + return new Promise((resolve, reject) => { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) { + reject(err); + return; + } + + try { + const jsonContent = JSON.parse(data); + resolve(jsonContent); + } catch (error) { + reject(error); + } + }); + }); +} + +async function start() { + const configuration = await (async () => { + try { + const jsonContent = await readFileAsJSON(filePath); + console.log(jsonContent); + return jsonContent; + } catch (error) { + console.error('Error:', error); + } + })(); + const lamqttBackEnd = new SpatialMQTTBackEnd('', '', brokerAddress.split(':')[0], parseInt(brokerAddress.split(':')[1]), configuration); + await clientConnection(lamqttBackEnd); +} +start(); + + + +export async function clientConnection(lamqttBackEnd) { + await lamqttBackEnd.start(); +} + -clientConnection(); diff --git a/backend/BackEndService.js b/backend/BackEndService.js deleted file mode 100644 index badd447..0000000 --- a/backend/BackEndService.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -exports.__esModule = true; -exports.clientConnection = exports.lamqttBackEnd = void 0; -var backend_1 = require("./la-mqtt/backend/backend"); -exports.lamqttBackEnd = new backend_1.SpatialMQTTBackEnd('', '', 'ws://127.0.0.1:9001/', 9001); -function clientConnection() { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, exports.lamqttBackEnd.start()]; - case 1: - _a.sent(); - return [2 /*return*/]; - } - }); - }); -} -exports.clientConnection = clientConnection; diff --git a/backend/BackEndService.ts b/backend/BackEndService.ts deleted file mode 100644 index 8ddc464..0000000 --- a/backend/BackEndService.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {SpatialMQTTBackEnd} from "./la-mqtt/backend/backend"; -export const lamqttBackEnd = new SpatialMQTTBackEnd('', '', 'ws://127.0.0.1:9001/', 9001); - -export async function clientConnection() { - await lamqttBackEnd.start(); -} - diff --git a/backend/backend_configuration/backend_0.json b/backend/backend_configuration/backend_0.json new file mode 100644 index 0000000..bbfed7d --- /dev/null +++ b/backend/backend_configuration/backend_0.json @@ -0,0 +1,3 @@ +{ + "bridgedBrokers": ["127.0.0.1:9002", "127.0.0.1:9003"] +} diff --git a/backend/backend_configuration/backend_1.json b/backend/backend_configuration/backend_1.json new file mode 100644 index 0000000..63ec688 --- /dev/null +++ b/backend/backend_configuration/backend_1.json @@ -0,0 +1,3 @@ +{ + "bridgedBrokers": ["127.0.0.1:9001", "127.0.0.1:9003"] +} diff --git a/backend/backend_configuration/backend_2.json b/backend/backend_configuration/backend_2.json new file mode 100644 index 0000000..ab8efe2 --- /dev/null +++ b/backend/backend_configuration/backend_2.json @@ -0,0 +1,3 @@ +{ + "bridgedBrokers": ["127.0.0.1:9001", "127.0.0.1:9002"] +} diff --git a/backend/la-mqtt/backend/backend.js b/backend/la-mqtt/backend/backend.js old mode 100644 new mode 100755 index 3aed901..3747fdc --- a/backend/la-mqtt/backend/backend.js +++ b/backend/la-mqtt/backend/backend.js @@ -58,14 +58,14 @@ var geoprocesser_1 = require("./geoprocesser"); var ipersister_1 = require("./ipersister"); var SpatialMQTTBackEnd = /** @class */ (function (_super) { __extends(SpatialMQTTBackEnd, _super); - function SpatialMQTTBackEnd(username, password, host, port) { - var _this = _super.call(this, username, password, host, port, SpatialMQTTBackEnd.DEFAULT_NAME) || this; + function SpatialMQTTBackEnd(username, password, host, port, brokerConf) { + var _this = _super.call(this, username, password, 'ws://' + host + ':' + port + '/', port, SpatialMQTTBackEnd.DEFAULT_NAME + '-' + host.split('.').join('') + "-" + port) || this; _this.persisterType = ipersister_1.PersisterType.MONGODB; // @ts-ignore if (_this.persisterType == ipersister_1.PersisterType.MEMORY) _this.persister = new mempersister_1.MemPersister(); else - _this.persister = new persister_1.Persister(SpatialMQTTBackEnd.STORAGE_NAME); + _this.persister = new persister_1.Persister(SpatialMQTTBackEnd.STORAGE_NAME + '-' + host.split('.').join('') + "-" + port); //this.logWatcher=new MosquittoWatcher('/Users/marcodifelice/Documents/Lavoro/ProgettiSW/SpatialMQTT/src/backend','log.txt'); _this.geoProcessor = new geoprocesser_1.GeoProcessor(_this.persister, _this); // @ts-ignore @@ -73,33 +73,48 @@ var SpatialMQTTBackEnd = /** @class */ (function (_super) { // @ts-ignore _this.historyNotificationSent = new Map(); _this.verboseMode = true; + // @ts-ignore + _this.adjacentBrokers = brokerConf.bridgedBrokers; + _this.host = host + ':' + port; return _this; } SpatialMQTTBackEnd.prototype.start = function () { return __awaiter(this, void 0, void 0, function () { - var res; - return __generator(this, function (_a) { - switch (_a.label) { + var res, _i, _a, aBroker; + return __generator(this, function (_b) { + switch (_b.label) { case 0: return [4 /*yield*/, this.connect()]; case 1: - res = _a.sent(); + res = _b.sent(); console.log("CONNECTION RESULT: ", res); - if (!(res == true)) return [3 /*break*/, 6]; + if (!(res == true)) return [3 /*break*/, 10]; this.setCallback(this); return [4 /*yield*/, this.subscribe(messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_POSITION)]; case 2: - _a.sent(); + _b.sent(); return [4 /*yield*/, this.subscribe(messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_GEOFENCE)]; case 3: - _a.sent(); + _b.sent(); return [4 /*yield*/, this.subscribe(messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_SUBSCRIPTION)]; case 4: - _a.sent(); - return [4 /*yield*/, this.persister.connect()]; + _b.sent(); + _i = 0, _a = this.adjacentBrokers; + _b.label = 5; case 5: - _a.sent(); - _a.label = 6; - case 6: return [2 /*return*/]; + if (!(_i < _a.length)) return [3 /*break*/, 8]; + aBroker = _a[_i]; + return [4 /*yield*/, this.subscribe('bridgeFrom' + aBroker + 'To' + this.host)]; + case 6: + _b.sent(); + _b.label = 7; + case 7: + _i++; + return [3 /*break*/, 5]; + case 8: return [4 /*yield*/, this.persister.connect()]; + case 9: + _b.sent(); + _b.label = 10; + case 10: return [2 /*return*/]; } }); }); @@ -130,20 +145,43 @@ var SpatialMQTTBackEnd = /** @class */ (function (_super) { return [4 /*yield*/, this.handlePositionUpdate(msg.message)]; case 1: _a.sent(); - return [3 /*break*/, 6]; + return [3 /*break*/, 8]; case 2: if (!(msg.topic == messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_GEOFENCE)) return [3 /*break*/, 4]; return [4 /*yield*/, this.handleGeofenceUpdate(msg.message)]; case 3: _a.sent(); - return [3 /*break*/, 6]; + return [3 /*break*/, 8]; case 4: if (!(msg.topic == messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_SUBSCRIPTION)) return [3 /*break*/, 6]; return [4 /*yield*/, this.handleSubscriptionUpdate(msg.message)]; case 5: _a.sent(); - _a.label = 6; - case 6: return [2 /*return*/]; + return [3 /*break*/, 8]; + case 6: + if (!(msg.topic.substring(0, 6) == messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_BRIDGE)) return [3 /*break*/, 8]; + return [4 /*yield*/, this.handleBridgeUpdate(msg.message)]; + case 7: + _a.sent(); + _a.label = 8; + case 8: return [2 /*return*/]; + } + }); + }); + }; + // @ts-ignore + SpatialMQTTBackEnd.prototype.handleBridgeUpdate = function (payload) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (this.verboseMode == true) { + console.log("[BACKEND] Received UPDATE FROM BRIDGE: " + payload); + } + return [4 /*yield*/, this.handleGeofenceUpdate(payload)]; + case 1: + _a.sent(); + return [2 /*return*/]; } }); }); @@ -175,9 +213,9 @@ var SpatialMQTTBackEnd = /** @class */ (function (_super) { // @ts-ignore SpatialMQTTBackEnd.prototype.handleGeofenceUpdate = function (payload) { return __awaiter(this, void 0, void 0, function () { - var objJSON, seqNo; - return __generator(this, function (_a) { - switch (_a.label) { + var objJSON, seqNo, alreadyNotifiedBroker, _i, _a, aBroker; + return __generator(this, function (_b) { + switch (_b.label) { case 0: if (this.verboseMode == true) { console.log("[BACKEND] Received UPDATE GEOFENCE: " + payload); @@ -192,8 +230,29 @@ var SpatialMQTTBackEnd = /** @class */ (function (_super) { console.log("SEQUENTIAL:", this.historyGeofence.get(objJSON["id"])); return [4 /*yield*/, this.persister.addGeofence(objJSON["topicGeofence"], objJSON["id"], objJSON["latitude"], objJSON["longitude"], objJSON["radius"], objJSON["message"])]; case 1: - _a.sent(); - return [2 /*return*/]; + _b.sent(); + alreadyNotifiedBroker = objJSON['notifiedBrokers']; + // This if should be run only by the first backend + if (!objJSON['notifiedBrokers'].includes(this.host)) { + objJSON['notifiedBrokers'].push(this.host); + } + objJSON['notifiedBrokers'] = objJSON['notifiedBrokers'].concat(this.adjacentBrokers).filter(function (value, index, self) { + return self.indexOf(value) === index; + }); + _i = 0, _a = this.adjacentBrokers; + _b.label = 2; + case 2: + if (!(_i < _a.length)) return [3 /*break*/, 5]; + aBroker = _a[_i]; + if (!!alreadyNotifiedBroker.includes(aBroker)) return [3 /*break*/, 4]; + return [4 /*yield*/, this.publish(messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_BRIDGE + 'From' + this.host + 'To' + aBroker, JSON.stringify(objJSON))]; + case 3: + _b.sent(); + _b.label = 4; + case 4: + _i++; + return [3 /*break*/, 2]; + case 5: return [2 /*return*/]; } }); }); diff --git a/backend/la-mqtt/backend/backend.ts b/backend/la-mqtt/backend/backend.ts old mode 100644 new mode 100755 index 4c3d634..4595f76 --- a/backend/la-mqtt/backend/backend.ts +++ b/backend/la-mqtt/backend/backend.ts @@ -27,15 +27,18 @@ export class SpatialMQTTBackEnd extends MQTTClient implements MQTTReceiver, ILog private historyGeofence: Map; // @ts-ignore private historyNotificationSent: Map; + // @ts-ignore + private adjacentBrokers: []; + private host: String; - constructor (username: string, password: string, host: string, port: number) { - super(username,password,host,port,SpatialMQTTBackEnd.DEFAULT_NAME); + constructor (username: string, password: string, host: string, port: number, brokerConf: any) { + super(username,password,'ws://' + host + ':' + port + '/', port,SpatialMQTTBackEnd.DEFAULT_NAME + '-' + host.split('.').join('') + "-" + port); this.persisterType=PersisterType.MONGODB; // @ts-ignore if (this.persisterType==PersisterType.MEMORY) this.persister=new MemPersister(); else - this.persister=new Persister(SpatialMQTTBackEnd.STORAGE_NAME); + this.persister=new Persister(SpatialMQTTBackEnd.STORAGE_NAME + '-' + host.split('.').join('') + "-" + port); //this.logWatcher=new MosquittoWatcher('/Users/marcodifelice/Documents/Lavoro/ProgettiSW/SpatialMQTT/src/backend','log.txt'); this.geoProcessor=new GeoProcessor(this.persister, this); @@ -44,6 +47,9 @@ export class SpatialMQTTBackEnd extends MQTTClient implements MQTTReceiver, ILog // @ts-ignore this.historyNotificationSent=new Map(); this.verboseMode=true; + // @ts-ignore + this.adjacentBrokers = brokerConf.bridgedBrokers; + this.host = host + ':' + port; } @@ -55,6 +61,9 @@ export class SpatialMQTTBackEnd extends MQTTClient implements MQTTReceiver, ILog await this.subscribe(MQTTSpatialMessages.TOPIC_PUBLISH_POSITION); await this.subscribe(MQTTSpatialMessages.TOPIC_PUBLISH_GEOFENCE); await this.subscribe(MQTTSpatialMessages.TOPIC_PUBLISH_SUBSCRIPTION); + for(let aBroker of this.adjacentBrokers) { + await this.subscribe('bridgeFrom' + aBroker + 'To' + this.host); + } await this.persister.connect(); //await this.logWatcher.start(this); } @@ -74,6 +83,16 @@ export class SpatialMQTTBackEnd extends MQTTClient implements MQTTReceiver, ILog await this.handleGeofenceUpdate(msg.message); else if (msg.topic==MQTTSpatialMessages.TOPIC_PUBLISH_SUBSCRIPTION) await this.handleSubscriptionUpdate(msg.message); + else if (msg.topic.substring(0, 6) == MQTTSpatialMessages.TOPIC_PUBLISH_BRIDGE) + await this.handleBridgeUpdate(msg.message); + } + + // @ts-ignore + private async handleBridgeUpdate(payload: string) { + if (this.verboseMode==true) { + console.log("[BACKEND] Received UPDATE FROM BRIDGE: "+payload); + } + await this.handleGeofenceUpdate(payload) } // @ts-ignore @@ -101,6 +120,19 @@ export class SpatialMQTTBackEnd extends MQTTClient implements MQTTReceiver, ILog this.historyGeofence.set(objJSON["id"],seqNo); console.log("SEQUENTIAL:", this.historyGeofence.get(objJSON["id"])); await this.persister.addGeofence(objJSON["topicGeofence"],objJSON["id"],objJSON["latitude"],objJSON["longitude"],objJSON["radius"],objJSON["message"]); + const alreadyNotifiedBroker = objJSON['notifiedBrokers']; + // This if should be run only by the first backend + if(!objJSON['notifiedBrokers'].includes(this.host)) { + objJSON['notifiedBrokers'].push(this.host); + } + objJSON['notifiedBrokers'] = objJSON['notifiedBrokers'].concat(this.adjacentBrokers).filter((value, index, self) => { + return self.indexOf(value) === index; + }); + for(let aBroker of this.adjacentBrokers) { + if(!alreadyNotifiedBroker.includes(aBroker)) { + await this.publish(MQTTSpatialMessages.TOPIC_PUBLISH_BRIDGE + 'From' + this.host + 'To' + aBroker, JSON.stringify(objJSON)); + } + } } // @ts-ignore diff --git a/backend/la-mqtt/backend/dto/iwatcher.js b/backend/la-mqtt/backend/dto/iwatcher.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/dto/iwatcher.ts b/backend/la-mqtt/backend/dto/iwatcher.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/geoprocesser.js b/backend/la-mqtt/backend/geoprocesser.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/geoprocesser.ts b/backend/la-mqtt/backend/geoprocesser.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/ipersister.js b/backend/la-mqtt/backend/ipersister.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/ipersister.ts b/backend/la-mqtt/backend/ipersister.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/log.txt b/backend/la-mqtt/backend/log.txt old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/logwatcher.js b/backend/la-mqtt/backend/logwatcher.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/logwatcher.ts b/backend/la-mqtt/backend/logwatcher.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/mempersister.js b/backend/la-mqtt/backend/mempersister.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/mempersister.ts b/backend/la-mqtt/backend/mempersister.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/geofence.js b/backend/la-mqtt/backend/model/geofence.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/geofence.ts b/backend/la-mqtt/backend/model/geofence.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/subscription.js b/backend/la-mqtt/backend/model/subscription.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/subscription.ts b/backend/la-mqtt/backend/model/subscription.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/user.js b/backend/la-mqtt/backend/model/user.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/model/user.ts b/backend/la-mqtt/backend/model/user.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/persister.js b/backend/la-mqtt/backend/persister.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/backend/persister.ts b/backend/la-mqtt/backend/persister.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/client.js b/backend/la-mqtt/common/client.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/client.ts b/backend/la-mqtt/common/client.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/direction.ts b/backend/la-mqtt/common/direction.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/iconnector.js b/backend/la-mqtt/common/iconnector.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/iconnector.ts b/backend/la-mqtt/common/iconnector.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/ireceiver.js b/backend/la-mqtt/common/ireceiver.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/ireceiver.ts b/backend/la-mqtt/common/ireceiver.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/messages.js b/backend/la-mqtt/common/messages.js old mode 100644 new mode 100755 index 945d1b1..dd411fb --- a/backend/la-mqtt/common/messages.js +++ b/backend/la-mqtt/common/messages.js @@ -6,4 +6,5 @@ var MQTTSpatialMessages; MQTTSpatialMessages["TOPIC_PUBLISH_POSITION"] = "PUBLISH_POSITION"; MQTTSpatialMessages["TOPIC_PUBLISH_GEOFENCE"] = "PUBLISH_GEOFENCE"; MQTTSpatialMessages["TOPIC_PUBLISH_SUBSCRIPTION"] = "PUBLISH_SUB"; + MQTTSpatialMessages["TOPIC_PUBLISH_BRIDGE"] = "bridge"; })(MQTTSpatialMessages = exports.MQTTSpatialMessages || (exports.MQTTSpatialMessages = {})); diff --git a/backend/la-mqtt/common/messages.ts b/backend/la-mqtt/common/messages.ts old mode 100644 new mode 100755 index 10b93e4..8a4b3cc --- a/backend/la-mqtt/common/messages.ts +++ b/backend/la-mqtt/common/messages.ts @@ -1,10 +1,11 @@ export enum MQTTSpatialMessages { - + TOPIC_PUBLISH_POSITION="PUBLISH_POSITION", TOPIC_PUBLISH_GEOFENCE="PUBLISH_GEOFENCE", - TOPIC_PUBLISH_SUBSCRIPTION="PUBLISH_SUB" - + TOPIC_PUBLISH_SUBSCRIPTION="PUBLISH_SUB", + + TOPIC_PUBLISH_BRIDGE="bridge" } diff --git a/backend/la-mqtt/common/mosquittoConnector.js b/backend/la-mqtt/common/mosquittoConnector.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/mosquittoConnector.ts b/backend/la-mqtt/common/mosquittoConnector.ts old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/position.js b/backend/la-mqtt/common/position.js old mode 100644 new mode 100755 diff --git a/backend/la-mqtt/common/position.ts b/backend/la-mqtt/common/position.ts old mode 100644 new mode 100755 diff --git a/backend/package-lock.json b/backend/package-lock.json old mode 100644 new mode 100755 index 11a5fb5..afc91d8 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "@types/node": "^14.14.14", + "fs": "^0.0.1-security", "geolib": "^3.3.1", "mongoose": "^5.11.8", "mqtt": "^4.2.6", @@ -286,6 +287,11 @@ "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", diff --git a/backend/package.json b/backend/package.json old mode 100644 new mode 100755 index 5e8dde7..bae0aa2 --- a/backend/package.json +++ b/backend/package.json @@ -12,6 +12,7 @@ "license": "ISC", "dependencies": { "@types/node": "^14.14.14", + "fs": "^0.0.1-security", "geolib": "^3.3.1", "mongoose": "^5.11.8", "mqtt": "^4.2.6", diff --git a/lds/.idea/.gitignore b/lds/.idea/.gitignore old mode 100644 new mode 100755 diff --git a/lds/.idea/jsLibraryMappings.xml b/lds/.idea/jsLibraryMappings.xml old mode 100644 new mode 100755 diff --git a/lds/.idea/lds.iml b/lds/.idea/lds.iml old mode 100644 new mode 100755 diff --git a/lds/.idea/modules.xml b/lds/.idea/modules.xml old mode 100644 new mode 100755 diff --git a/lds/.idea/vcs.xml b/lds/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/lds/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lds/App.js b/lds/App.js old mode 100644 new mode 100755 index 10cdd47..b887d0f --- a/lds/App.js +++ b/lds/App.js @@ -40,11 +40,14 @@ var LDSClientService_1 = require("./LDSClientService"); var LDSReceiver_1 = require("./LDSReceiver"); var readline = require("readline"); var fs = require("fs"); -if (process.argv.length !== 3) { - console.error('Usage: npm start '); +var uuid_1 = require("uuid"); +var smqttclient_1 = require("./la-mqtt/client/smqttclient"); +if (process.argv.length !== 4) { + console.error('Usage: npm start '); process.exit(1); } -var filePath = process.argv[2]; +var brokerAddress = process.argv[2]; +var filePath = process.argv[3]; function readFileAsJSON(filePath) { return new Promise(function (resolve, reject) { fs.readFile(filePath, 'utf8', function (err, data) { @@ -68,7 +71,7 @@ var rl = readline.createInterface({ }); function start() { return __awaiter(this, void 0, void 0, function () { - var configuration; + var configuration, clientId, lamqttClient; var _this = this; return __generator(this, function (_a) { switch (_a.label) { @@ -93,28 +96,27 @@ function start() { }); })()]; case 1: configuration = _a.sent(); - return [4 /*yield*/, (0, LDSClientService_1.clientConnection)() - //await lamqttClient.publicGeofence(44.49987328047904, 11.350508941159259, 300, "parking", "Via Irnerio-free", clientId); - // @ts-ignore - ]; + clientId = 'LDS-CLIENT-' + (0, uuid_1.v4)(); + lamqttClient = new smqttclient_1.SpatialMQTTClient('', '', 'ws://' + brokerAddress + '/', parseInt(brokerAddress.split(':')[1]), clientId); + return [4 /*yield*/, (0, LDSClientService_1.clientConnection)(lamqttClient)]; case 2: _a.sent(); //await lamqttClient.publicGeofence(44.49987328047904, 11.350508941159259, 300, "parking", "Via Irnerio-free", clientId); // @ts-ignore - LDSClientService_1.lamqttClient.setCallback(LDSReceiver_1.LDSReceiver); - askForParkingInput(configuration); + lamqttClient.setCallback(LDSReceiver_1.LDSReceiver); + askForParkingInput(configuration, lamqttClient, clientId); return [2 /*return*/]; } }); }); } start(); -function askForParkingInput(configuration) { +function askForParkingInput(configuration, lamqttClient, clientId) { var _this = this; rl.question('Take an action as LDS:\n1 - Notify free parking area\n2 - Notify almost full parking area\n3 - Notify full parking area\n', function (choice) { return __awaiter(_this, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { + var _a, _b, _c; + return __generator(this, function (_d) { + switch (_d.label) { case 0: _a = choice; switch (_a) { @@ -123,23 +125,26 @@ function askForParkingInput(configuration) { case "3": return [3 /*break*/, 5]; } return [3 /*break*/, 7]; - case 1: return [4 /*yield*/, LDSClientService_1.lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-free", LDSClientService_1.clientId)]; + case 1: + _c = (_b = console).log; + return [4 /*yield*/, lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-free", clientId)]; case 2: - _b.sent(); + _c.apply(_b, [_d.sent()]); + console.log('published'); return [3 /*break*/, 8]; - case 3: return [4 /*yield*/, LDSClientService_1.lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-almost full", LDSClientService_1.clientId)]; + case 3: return [4 /*yield*/, lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-almost full", clientId)]; case 4: - _b.sent(); + _d.sent(); return [3 /*break*/, 8]; - case 5: return [4 /*yield*/, LDSClientService_1.lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-full", LDSClientService_1.clientId)]; + case 5: return [4 /*yield*/, lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-full", clientId)]; case 6: - _b.sent(); + _d.sent(); return [3 /*break*/, 8]; case 7: console.error("Command not found"); - _b.label = 8; + _d.label = 8; case 8: - askForParkingInput(configuration); + askForParkingInput(configuration, lamqttClient, clientId); return [2 /*return*/]; } }); diff --git a/lds/App.ts b/lds/App.ts old mode 100644 new mode 100755 index 55bcfe1..e0879c0 --- a/lds/App.ts +++ b/lds/App.ts @@ -1,16 +1,20 @@ -import {clientConnection, clientId, lamqttClient} from "./LDSClientService"; +import {clientConnection} from "./LDSClientService"; import {LDSReceiver} from "./LDSReceiver"; import * as readline from "readline"; import fs = require('fs'); import path = require('path'); +import {v4 as uuidv4} from "uuid"; +import {SpatialMQTTClient} from "./la-mqtt/client/smqttclient"; -if (process.argv.length !== 3) { - console.error('Usage: npm start '); +if (process.argv.length !== 4) { + console.error('Usage: npm start '); process.exit(1); } -const filePath = process.argv[2]; +const brokerAddress = process.argv[2]; + +const filePath = process.argv[3]; function readFileAsJSON(filePath) { return new Promise((resolve, reject) => { @@ -46,20 +50,23 @@ async function start() { console.error('Error:', error); } })(); - await clientConnection() + const clientId = 'LDS-CLIENT-' + uuidv4(); + const lamqttClient = new SpatialMQTTClient('', '', 'ws://' + brokerAddress + '/', parseInt(brokerAddress.split(':')[1]), clientId); + await clientConnection(lamqttClient); //await lamqttClient.publicGeofence(44.49987328047904, 11.350508941159259, 300, "parking", "Via Irnerio-free", clientId); // @ts-ignore lamqttClient.setCallback(LDSReceiver); - askForParkingInput(configuration) + askForParkingInput(configuration, lamqttClient, clientId) } start(); -function askForParkingInput(configuration) { +function askForParkingInput(configuration, lamqttClient, clientId) { rl.question('Take an action as LDS:\n1 - Notify free parking area\n2 - Notify almost full parking area\n3 - Notify full parking area\n', async (choice) => { switch(choice) { case "1": - await lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-free", clientId); + console.log(await lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-free", clientId)); + console.log('published'); break; case "2": await lamqttClient.publicGeofence(configuration.latCenter, configuration.lngCenter, 300, "parking", configuration.streetName + "-" + configuration.latStart + "-" + configuration.lngStart + "-" + configuration.latEnd + "-" + configuration.lngEnd + "-almost full", clientId); @@ -70,7 +77,7 @@ function askForParkingInput(configuration) { default: console.error("Command not found"); } - askForParkingInput(configuration); + askForParkingInput(configuration, lamqttClient, clientId); }) } diff --git a/lds/LDSClientService.js b/lds/LDSClientService.js old mode 100644 new mode 100755 index 4995f13..b1775f0 --- a/lds/LDSClientService.js +++ b/lds/LDSClientService.js @@ -36,23 +36,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) { } }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.clientConnection = exports.lamqttClient = exports.clientId = void 0; -var smqttclient_1 = require("./la-mqtt/client/smqttclient"); -var uuid_1 = require("uuid"); -exports.clientId = 'LDS-CLIENT-' + (0, uuid_1.v4)(); -exports.lamqttClient = new smqttclient_1.SpatialMQTTClient('', '', 'ws://127.0.0.1:9001/', 9001, exports.clientId); -function clientConnection() { +exports.clientConnection = void 0; +function clientConnection(lamqttClient) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: - if (!exports.lamqttClient) { + if (!lamqttClient) { throw new Error("LAMQTT Client not initialized"); } console.log("CHECK CONNECTION..."); - if (!!exports.lamqttClient.getMConnector().isConnected()) return [3 /*break*/, 2]; + if (!!lamqttClient.getMConnector().isConnected()) return [3 /*break*/, 2]; console.log("CONNECTING..."); - return [4 /*yield*/, exports.lamqttClient.connect()]; + return [4 /*yield*/, lamqttClient.connect()]; case 1: return [2 /*return*/, _a.sent()]; case 2: console.log("ALREADY CONNECTED"); diff --git a/lds/LDSClientService.ts b/lds/LDSClientService.ts old mode 100644 new mode 100755 index 1d6d6dc..02f3fa7 --- a/lds/LDSClientService.ts +++ b/lds/LDSClientService.ts @@ -1,12 +1,7 @@ import {SpatialMQTTClient} from "./la-mqtt/client/smqttclient"; import {v4 as uuidv4} from 'uuid'; - - -export const clientId = 'LDS-CLIENT-' + uuidv4(); -export const lamqttClient = new SpatialMQTTClient('', '', 'ws://127.0.0.1:9001/', 9001, clientId); - -export async function clientConnection() { +export async function clientConnection(lamqttClient) { if(!lamqttClient) { throw new Error("LAMQTT Client not initialized"); } diff --git a/lds/LDSReceiver.js b/lds/LDSReceiver.js old mode 100644 new mode 100755 diff --git a/lds/LDSReceiver.ts b/lds/LDSReceiver.ts old mode 100644 new mode 100755 diff --git a/lds/demo_configuaration/lds_via_irnerio.json b/lds/demo_configuaration/lds_via_irnerio.json old mode 100644 new mode 100755 diff --git a/lds/demo_configuaration/lds_via_irnerio1.json b/lds/demo_configuaration/lds_via_irnerio1.json old mode 100644 new mode 100755 diff --git a/lds/demo_configuaration/lds_via_mascarella.json b/lds/demo_configuaration/lds_via_mascarella.json old mode 100644 new mode 100755 diff --git a/lds/demo_configuaration/lds_via_mascarella1.json b/lds/demo_configuaration/lds_via_mascarella1.json old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/measurer.js b/lds/la-mqtt/client/measurer.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/measurer.ts b/lds/la-mqtt/client/measurer.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/dist.js b/lds/la-mqtt/client/privacy/dist.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/dist.ts b/lds/la-mqtt/client/privacy/dist.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/entropy.js b/lds/la-mqtt/client/privacy/entropy.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/entropy.ts b/lds/la-mqtt/client/privacy/entropy.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/imetrics.js b/lds/la-mqtt/client/privacy/imetrics.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/imetrics.ts b/lds/la-mqtt/client/privacy/imetrics.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/iprivacy.js b/lds/la-mqtt/client/privacy/iprivacy.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/iprivacy.ts b/lds/la-mqtt/client/privacy/iprivacy.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/learning.js b/lds/la-mqtt/client/privacy/learning.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/learning.ts b/lds/la-mqtt/client/privacy/learning.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/percolation.js b/lds/la-mqtt/client/privacy/percolation.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/percolation.ts b/lds/la-mqtt/client/privacy/percolation.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/perturbation.js b/lds/la-mqtt/client/privacy/perturbation.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/privacy/perturbation.ts b/lds/la-mqtt/client/privacy/perturbation.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/client/smqttclient.js b/lds/la-mqtt/client/smqttclient.js old mode 100644 new mode 100755 index 7a058ff..187e5ab --- a/lds/la-mqtt/client/smqttclient.js +++ b/lds/la-mqtt/client/smqttclient.js @@ -116,21 +116,22 @@ var SpatialMQTTClient = /** @class */ (function (_super) { */ SpatialMQTTClient.prototype.publicGeofence = function (latitude, longitude, radius, topic, message, geofenceId) { return __awaiter(this, void 0, void 0, function () { - var position, topicN, messageN; - return __generator(this, function (_a) { - switch (_a.label) { + var position, topicN, messageN, _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { case 0: position = new position_1.Position(latitude, longitude); topicN = messages_1.MQTTSpatialMessages.TOPIC_PUBLISH_GEOFENCE; messageN = "{ " + position.toString() + ", \"id\": \"" + geofenceId + "\""; - messageN = messageN + ", \"radius\": " + radius + ", \"message\": \"" + message + "\", \"topicGeofence\": \"" + topic + '\" }'; + messageN = messageN + ", \"radius\": " + radius + ", \"message\": \"" + message + "\", \"topicGeofence\": \"" + topic + '\", \"notifiedBrokers\": []}'; //await this.publish(topic, messageN); //HHH + _b = (_a = console).log; return [4 /*yield*/, this.publish(topicN, messageN)]; case 1: //await this.publish(topic, messageN); //HHH - _a.sent(); + _b.apply(_a, [_c.sent()]); return [2 /*return*/]; } }); diff --git a/lds/la-mqtt/client/smqttclient.ts b/lds/la-mqtt/client/smqttclient.ts old mode 100644 new mode 100755 index ac1fe80..99216be --- a/lds/la-mqtt/client/smqttclient.ts +++ b/lds/la-mqtt/client/smqttclient.ts @@ -71,10 +71,10 @@ export class SpatialMQTTClient extends MQTTClient { let position: Position=new Position(latitude, longitude); const topicN: string = MQTTSpatialMessages.TOPIC_PUBLISH_GEOFENCE; let messageN: string= "{ "+position.toString()+", \"id\": \""+geofenceId+"\""; - messageN=messageN+", \"radius\": "+radius+", \"message\": \""+message+"\", \"topicGeofence\": \""+topic+'\" }'; + messageN=messageN+", \"radius\": "+radius+", \"message\": \""+message+"\", \"topicGeofence\": \""+topic+'\", \"notifiedBrokers\": []}'; //await this.publish(topic, messageN); //HHH - await this.publish(topicN, messageN); + console.log(await this.publish(topicN, messageN)); //this.mqttMeasurer.trackGeofencePublish(); } diff --git a/lds/la-mqtt/common/client.js b/lds/la-mqtt/common/client.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/client.ts b/lds/la-mqtt/common/client.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/direction.js b/lds/la-mqtt/common/direction.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/direction.ts b/lds/la-mqtt/common/direction.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/iconnector.js b/lds/la-mqtt/common/iconnector.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/iconnector.ts b/lds/la-mqtt/common/iconnector.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/ireceiver.js b/lds/la-mqtt/common/ireceiver.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/ireceiver.ts b/lds/la-mqtt/common/ireceiver.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/messages.js b/lds/la-mqtt/common/messages.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/messages.ts b/lds/la-mqtt/common/messages.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/mosquittoConnector.js b/lds/la-mqtt/common/mosquittoConnector.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/mosquittoConnector.ts b/lds/la-mqtt/common/mosquittoConnector.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/position.js b/lds/la-mqtt/common/position.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/common/position.ts b/lds/la-mqtt/common/position.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/simulator/god.js b/lds/la-mqtt/simulator/god.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/simulator/god.ts b/lds/la-mqtt/simulator/god.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/simulator/random.js b/lds/la-mqtt/simulator/random.js old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/simulator/random.ts b/lds/la-mqtt/simulator/random.ts old mode 100644 new mode 100755 diff --git a/lds/la-mqtt/simulator/simulator.ts b/lds/la-mqtt/simulator/simulator.ts old mode 100644 new mode 100755 diff --git a/lds/package-lock.json b/lds/package-lock.json old mode 100644 new mode 100755 diff --git a/lds/package.json b/lds/package.json old mode 100644 new mode 100755 From 01b8b5fbfd2086081c3f0608ddf839755f09598d Mon Sep 17 00:00:00 2001 From: AndreaIannoli Date: Fri, 3 Nov 2023 18:10:49 +0100 Subject: [PATCH 2/2] Mosquitto brokers demo configurations --- .DS_Store | Bin 8196 -> 8196 bytes broker/.DS_Store | Bin 6148 -> 6148 bytes broker/broker_conf/.DS_Store | Bin 0 -> 6148 bytes broker/broker_conf/broker1/mosquitto.conf | 17 +++++++++++++++++ broker/broker_conf/broker2/mosquitto.conf | 17 +++++++++++++++++ broker/broker_conf/broker3/mosquitto.conf | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+) create mode 100644 broker/broker_conf/.DS_Store create mode 100644 broker/broker_conf/broker1/mosquitto.conf create mode 100644 broker/broker_conf/broker2/mosquitto.conf create mode 100644 broker/broker_conf/broker3/mosquitto.conf diff --git a/.DS_Store b/.DS_Store index 5c40462eabc5eae319baef1d9715b418deb8c233..a0055a4dc59732d9acfee1693032a8a7019c5877 100644 GIT binary patch delta 87 zcmZp1XmOa}&nUJrU^hRb*k&GqFlKfma}yl}OT$T`_LEl#FH`hlaAffH%*jtq%E?b+ nU|`c$ZYdtCPh&IMgImI diff --git a/broker/broker_conf/.DS_Store b/broker/broker_conf/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..8e3de3f90a74e7eb60e8edb8380df7858c764d60 GIT binary patch literal 6148 zcmeHK%}T>S5dKCh76j?hi?B~nsJ=if_29WLAgx-&m|(S@bN69}IgGoG-) zJzn_K7-Px4!d*KT7oA)VLxO=|AQ%V+f`QC{?pKuIkzw?~Krj#td@-QwLt;}b92>*D zbg;`;0OEk=EY$VTtU1ZCaBK|ep@^jtEmi!AA(l>i^0>mWF|>4uUp~a&yuG|gemm=@ z91bZAqYnmxfi?sCHXP~xf5~5__mbaEiBT{R4E!?&WH6i0ru-=1TX#NB_u9mE&8DJp pjVcuCtwR6@x{jP=r}>lWj4K=)L#?9roKB2`Kqe%*VBi-R_ynM5Nbvvw literal 0 HcmV?d00001 diff --git a/broker/broker_conf/broker1/mosquitto.conf b/broker/broker_conf/broker1/mosquitto.conf new file mode 100644 index 0000000..5a33d20 --- /dev/null +++ b/broker/broker_conf/broker1/mosquitto.conf @@ -0,0 +1,17 @@ +port 1990 +protocol mqtt +allow_anonymous true + + +# Websockets + +listener 9001 +protocol websockets + +connection bridgeFrom1To2 +address 127.0.0.1:1991 +remote_username jam +remote_password password +try_private true +topic bridgeFrom127.0.0.1:9001To127.0.0.1:9002 out 0 +topic bridgeFrom127.0.0.1:9002To127.0.0.1:9001 in 0 diff --git a/broker/broker_conf/broker2/mosquitto.conf b/broker/broker_conf/broker2/mosquitto.conf new file mode 100644 index 0000000..399dba9 --- /dev/null +++ b/broker/broker_conf/broker2/mosquitto.conf @@ -0,0 +1,17 @@ +port 1991 +protocol mqtt +allow_anonymous true + + +# Websockets + +listener 9002 +protocol websockets + +connection bridgeFrom2To3 +address 127.0.0.1:1992 +remote_username jam +remote_password password +try_private true +topic bridgeFrom127.0.0.1:9002To127.0.0.1:9003 out 0 +topic bridgeFrom127.0.0.1:9003To127.0.0.1:9002 in 0 \ No newline at end of file diff --git a/broker/broker_conf/broker3/mosquitto.conf b/broker/broker_conf/broker3/mosquitto.conf new file mode 100644 index 0000000..4c28116 --- /dev/null +++ b/broker/broker_conf/broker3/mosquitto.conf @@ -0,0 +1,18 @@ +port 1992 +protocol mqtt +allow_anonymous true + + +# Websockets + +listener 9003 +protocol websockets + +connection bridgeFrom3To1 +address 127.0.0.1:1990 +remote_username jam +remote_password password +try_private true +topic bridgeFrom127.0.0.1:9003To127.0.0.1:9001 out 0 +topic bridgeFrom127.0.0.1:9001To127.0.0.1:9003 in 0 +