collect traceroutes
This commit is contained in:
@ -0,0 +1,13 @@
|
|||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE `traceroutes` (
|
||||||
|
`id` BIGINT NOT NULL AUTO_INCREMENT,
|
||||||
|
`node_id` BIGINT NOT NULL,
|
||||||
|
`route` JSON NOT NULL,
|
||||||
|
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||||
|
|
||||||
|
INDEX `traceroutes_created_at_idx`(`created_at`),
|
||||||
|
INDEX `traceroutes_updated_at_idx`(`updated_at`),
|
||||||
|
INDEX `traceroutes_node_id_idx`(`node_id`),
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
@ -52,3 +52,17 @@ model NeighbourInfo {
|
|||||||
@@index(updated_at)
|
@@index(updated_at)
|
||||||
@@map("neighbour_infos")
|
@@map("neighbour_infos")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model TraceRoute {
|
||||||
|
id BigInt @id @default(autoincrement())
|
||||||
|
node_id BigInt
|
||||||
|
route Json
|
||||||
|
|
||||||
|
created_at DateTime @default(now())
|
||||||
|
updated_at DateTime @default(now()) @updatedAt
|
||||||
|
|
||||||
|
@@index(created_at)
|
||||||
|
@@index(updated_at)
|
||||||
|
@@index(node_id)
|
||||||
|
@@map("traceroutes")
|
||||||
|
}
|
||||||
|
33
src/mqtt.js
33
src/mqtt.js
@ -21,6 +21,7 @@ const Data = root.lookupType("Data");
|
|||||||
const ServiceEnvelope = root.lookupType("ServiceEnvelope");
|
const ServiceEnvelope = root.lookupType("ServiceEnvelope");
|
||||||
const NeighborInfo = root.lookupType("NeighborInfo");
|
const NeighborInfo = root.lookupType("NeighborInfo");
|
||||||
const Position = root.lookupType("Position");
|
const Position = root.lookupType("Position");
|
||||||
|
const RouteDiscovery = root.lookupType("RouteDiscovery");
|
||||||
const Telemetry = root.lookupType("Telemetry");
|
const Telemetry = root.lookupType("Telemetry");
|
||||||
const User = root.lookupType("User");
|
const User = root.lookupType("User");
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(portnum === 4) {
|
else if(portnum === 4) {
|
||||||
|
|
||||||
const user = User.decode(envelope.packet.decoded.payload);
|
const user = User.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(portnum === 71) {
|
else if(portnum === 71) {
|
||||||
|
|
||||||
const neighbourInfo = NeighborInfo.decode(envelope.packet.decoded.payload);
|
const neighbourInfo = NeighborInfo.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(portnum === 67) {
|
else if(portnum === 67) {
|
||||||
|
|
||||||
const telemetry = Telemetry.decode(envelope.packet.decoded.payload);
|
const telemetry = Telemetry.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
@ -225,6 +226,32 @@ client.on("message", async (topic, message) => {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if(portnum === 70) {
|
||||||
|
|
||||||
|
const routeDiscovery = RouteDiscovery.decode(envelope.packet.decoded.payload);
|
||||||
|
|
||||||
|
console.log("TRACEROUTE_APP", {
|
||||||
|
from: envelope.packet.from.toString(16),
|
||||||
|
route_discovery: routeDiscovery,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await prisma.traceRoute.create({
|
||||||
|
data: {
|
||||||
|
node_id: envelope.packet.from,
|
||||||
|
route: routeDiscovery.route,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
// console.log(portnum, envelope);
|
||||||
|
}
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// ignore errors
|
// ignore errors
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user