add command line arg to collect all neighbour info
This commit is contained in:
33
src/mqtt.js
33
src/mqtt.js
@ -46,6 +46,11 @@ const optionsList = [
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
description: "This option will save all received waypoints to the database.",
|
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",
|
name: "collect-map-reports",
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -96,6 +101,7 @@ const mqttPassword = options["mqtt-password"] ?? "large4cats";
|
|||||||
const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false;
|
const collectServiceEnvelopes = options["collect-service-envelopes"] ?? false;
|
||||||
const collectTextMessages = options["collect-text-messages"] ?? false;
|
const collectTextMessages = options["collect-text-messages"] ?? false;
|
||||||
const collectWaypoints = options["collect-waypoints"] ?? true;
|
const collectWaypoints = options["collect-waypoints"] ?? true;
|
||||||
|
const collectNeighbourInfo = options["collect-neighbour-info"] ?? false;
|
||||||
const collectMapReports = options["collect-map-reports"] ?? false;
|
const collectMapReports = options["collect-map-reports"] ?? false;
|
||||||
const decryptionKeys = options["decryption-keys"] ?? [
|
const decryptionKeys = options["decryption-keys"] ?? [
|
||||||
"1PG7OiApB1nwvP+rz05pAQ==", // add default "AQ==" decryption key
|
"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 {
|
try {
|
||||||
await prisma.neighbourInfo.create({
|
await prisma.node.updateMany({
|
||||||
data: {
|
where: {
|
||||||
node_id: envelope.packet.from,
|
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) => {
|
neighbours: neighbourInfo.neighbors.map((neighbour) => {
|
||||||
return {
|
return {
|
||||||
node_id: neighbour.nodeId,
|
node_id: neighbour.nodeId,
|
||||||
@ -435,15 +444,17 @@ client.on("message", async (topic, message) => {
|
|||||||
console.error(e);
|
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 {
|
try {
|
||||||
await prisma.node.updateMany({
|
await prisma.neighbourInfo.create({
|
||||||
where: {
|
|
||||||
node_id: envelope.packet.from,
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
neighbours_updated_at: new Date(),
|
node_id: envelope.packet.from,
|
||||||
neighbour_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs,
|
node_broadcast_interval_secs: neighbourInfo.nodeBroadcastIntervalSecs,
|
||||||
neighbours: neighbourInfo.neighbors.map((neighbour) => {
|
neighbours: neighbourInfo.neighbors.map((neighbour) => {
|
||||||
return {
|
return {
|
||||||
node_id: neighbour.nodeId,
|
node_id: neighbour.nodeId,
|
||||||
|
Reference in New Issue
Block a user