From 47af3071845f43e40669a30e9c7c9121d03c164e Mon Sep 17 00:00:00 2001 From: liamcottle Date: Fri, 29 Mar 2024 20:10:07 +1300 Subject: [PATCH] add command line arg to collect all neighbour info --- src/mqtt.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/mqtt.js b/src/mqtt.js index d34c434..b84d60d 100644 --- a/src/mqtt.js +++ b/src/mqtt.js @@ -46,6 +46,11 @@ const optionsList = [ type: Boolean, description: "This option will save all received waypoints to the database.", }, + { + name: "collect-neighbour-info", + type: Boolean, + description: "This option will save all received neighbour infos to the database.", + }, { name: "collect-map-reports", type: Boolean, @@ -96,6 +101,7 @@ const mqttPassword = options["mqtt-password"] ?? "large4cats"; const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false; const collectTextMessages = options["collect-text-messages"] ?? false; const collectWaypoints = options["collect-waypoints"] ?? true; +const collectNeighbourInfo = options["collect-neighbour-info"] ?? false; const collectMapReports = options["collect-map-reports"] ?? false; const decryptionKeys = options["decryption-keys"] ?? [ "1PG7OiApB1nwvP+rz05pAQ==", // add default "AQ==" decryption key @@ -417,12 +423,15 @@ client.on("message", async (topic, message) => { }); } - // create neighbour info + // update node neighbour info in db try { - await prisma.neighbourInfo.create({ - data: { + await prisma.node.updateMany({ + where: { node_id: envelope.packet.from, - node_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, + }, + data: { + neighbours_updated_at: new Date(), + neighbour_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, neighbours: neighbourInfo.neighbors.map((neighbour) => { return { node_id: neighbour.nodeId, @@ -435,15 +444,17 @@ client.on("message", async (topic, message) => { console.error(e); } - // update node neighbour info in db + // don't store all neighbour infos, but we want to update the existing node above + if(!collectNeighbourInfo){ + return; + } + + // create neighbour info try { - await prisma.node.updateMany({ - where: { - node_id: envelope.packet.from, - }, + await prisma.neighbourInfo.create({ data: { - neighbours_updated_at: new Date(), - neighbour_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, + node_id: envelope.packet.from, + node_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs, neighbours: neighbourInfo.neighbors.map((neighbour) => { return { node_id: neighbour.nodeId,