collect waypoints

This commit is contained in:
liamcottle
2024-03-15 16:11:51 +13:00
parent 8cda474f13
commit bb7fa83d94
3 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,28 @@
-- CreateTable
CREATE TABLE `waypoints` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`from` BIGINT NOT NULL,
`to` BIGINT NOT NULL,
`waypoint_id` BIGINT NOT NULL,
`latitude` INTEGER NOT NULL,
`longitude` INTEGER NOT NULL,
`expire` BIGINT NULL,
`locked_to` BIGINT NULL,
`name` VARCHAR(191) NULL,
`description` VARCHAR(191) NULL,
`icon` INTEGER NULL,
`channel` INTEGER NOT NULL,
`packet_id` BIGINT NOT NULL,
`channel_id` VARCHAR(191) NOT NULL,
`gateway_id` BIGINT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
INDEX `waypoints_created_at_idx`(`created_at`),
INDEX `waypoints_updated_at_idx`(`updated_at`),
INDEX `waypoints_from_idx`(`from`),
INDEX `waypoints_waypoint_id_idx`(`waypoint_id`),
INDEX `waypoints_packet_id_idx`(`packet_id`),
INDEX `waypoints_gateway_id_idx`(`gateway_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

View File

@ -141,3 +141,34 @@ model TraceRoute {
@@index(node_id)
@@map("traceroutes")
}
model Waypoint {
id BigInt @id @default(autoincrement())
from BigInt
to BigInt
waypoint_id BigInt
latitude Int
longitude Int
expire BigInt?
locked_to BigInt?
name String?
description String?
icon Int?
channel Int
packet_id BigInt
channel_id String
gateway_id BigInt?
created_at DateTime @default(now())
updated_at DateTime @default(now()) @updatedAt
@@index(created_at)
@@index(updated_at)
@@index(to)
@@index(from)
@@index(waypoint_id)
@@index(packet_id)
@@index(gateway_id)
@@map("waypoints")
}

View File

@ -25,6 +25,7 @@ const Position = root.lookupType("Position");
const RouteDiscovery = root.lookupType("RouteDiscovery");
const Telemetry = root.lookupType("Telemetry");
const User = root.lookupType("User");
const Waypoint = root.lookupType("Waypoint");
function createNonce(packetId, fromNode) {
@ -201,6 +202,43 @@ client.on("message", async (topic, message) => {
}
else if(portnum === 8) {
const waypoint = Waypoint.decode(envelope.packet.decoded.payload);
if(logKnownPacketTypes) {
console.log("WAYPOINT_APP", {
to: envelope.packet.to.toString(16),
from: envelope.packet.from.toString(16),
waypoint: waypoint,
});
}
try {
await prisma.waypoint.create({
data: {
to: envelope.packet.to,
from: envelope.packet.from,
waypoint_id: waypoint.id,
latitude: waypoint.latitudeI,
longitude: waypoint.longitudeI,
expire: waypoint.expire,
locked_to: waypoint.lockedTo,
name: waypoint.name,
description: waypoint.description,
icon: waypoint.icon,
channel: envelope.packet.channel,
packet_id: envelope.packet.id,
channel_id: envelope.channelId,
gateway_id: envelope.gatewayId ? BigInt('0x' + envelope.gatewayId.replaceAll("!", "")) : null, // convert hex id "!f96a92f0" to bigint
},
});
} catch (e) {
console.error(e);
}
}
else if(portnum === 71) {
const neighbourInfo = NeighborInfo.decode(envelope.packet.decoded.payload);
@ -370,11 +408,13 @@ client.on("message", async (topic, message) => {
// ignore packets we don't want to see for now
if(portnum === undefined // ignore failed to decrypt
|| portnum === 0 // ignore UNKNOWN_APP
|| portnum === 1 // ignore TEXT_MESSAGE_APP
|| portnum === 5 // ignore ROUTING_APP
|| portnum === 34 // ignore PAXCOUNTER_APP
|| portnum === 65 // ignore STORE_FORWARD_APP
|| portnum === 66 // ignore RANGE_TEST_APP
|| portnum === 72 // ignore ATAK_PLUGIN
){
return;
}