some nodes are spamming map reports at a high rate. we don't need them

This commit is contained in:
liamcottle
2024-03-23 21:35:29 +13:00
parent 7aa53718f7
commit 45988cee12

View File

@ -406,6 +406,21 @@ client.on("message", async (topic, message) => {
} }
try { try {
// find an existing map with duplicate information created in the last 60 seconds
const existingDuplicateMapReport = await prisma.mapReport.findFirst({
where: {
node_id: envelope.packet.from,
long_name: mapReport.longName,
short_name: mapReport.shortName,
created_at: {
gte: new Date(Date.now() - 60000), // created in the last 60 seconds
},
}
});
// create map report if no duplicates found
if(!existingDuplicateMapReport){
await prisma.mapReport.create({ await prisma.mapReport.create({
data: { data: {
node_id: envelope.packet.from, node_id: envelope.packet.from,
@ -424,6 +439,8 @@ client.on("message", async (topic, message) => {
num_online_local_nodes: mapReport.numOnlineLocalNodes, num_online_local_nodes: mapReport.numOnlineLocalNodes,
}, },
}); });
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }