From c6f06d97248f9ee61407de1d2a4f249c26a6e577 Mon Sep 17 00:00:00 2001 From: CoolElectronics Date: Sun, 20 Aug 2023 10:09:54 -0400 Subject: [PATCH] allow tracker to reject outdated servers --- pnpm-lock.yaml | 3 +++ server/src/autoupdater.ts | 6 ++---- server/src/dev.ts | 5 +++-- tracker/package.json | 1 + tracker/src/main.ts | 13 ++++++++++--- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7aa9927..71ba16c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -480,6 +480,9 @@ importers: firebase-admin: specifier: ^11.10.1 version: 11.10.1 + protocol: + specifier: workspace:* + version: link:../protocol tracker-list: specifier: workspace:* version: link:../tracker-list diff --git a/server/src/autoupdater.ts b/server/src/autoupdater.ts index a6c72cb..400da0a 100644 --- a/server/src/autoupdater.ts +++ b/server/src/autoupdater.ts @@ -17,10 +17,8 @@ https.get( file.on("finish", () => { fs.chmodSync(`${dir}/${appname}`, "755"); - setTimeout(() => { - // this timeout shouldn't be needed, but it is - start(); - }, 2000); + // this timeout shouldn't be needed, but it is + setTimeout(start, 2000); }); }) diff --git a/server/src/dev.ts b/server/src/dev.ts index 6f589c3..20fadb4 100644 --- a/server/src/dev.ts +++ b/server/src/dev.ts @@ -6,6 +6,7 @@ import { AdriftServer, connectTracker } from "./server"; import WebSocket from "isomorphic-ws"; import { answerRtc, bufferToArrayBuffer } from "./rtc"; +import { PROTOCOL_VERSION } from "protocol"; dotenv.config(); @@ -50,9 +51,9 @@ app.ws("/dev-ws", (ws, _req) => { }); try { - let tracker = new WebSocket("ws://localhost:17776/join"); + let tracker = new WebSocket(`ws://localhost:17776/join?protocol=${PROTOCOL_VERSION}`); tracker.onerror = console.error; connectTracker(tracker); -} catch (_) {} +} catch (_) { } app.listen(3000, () => console.log("listening")); diff --git a/tracker/package.json b/tracker/package.json index 763310e..1656d8c 100644 --- a/tracker/package.json +++ b/tracker/package.json @@ -17,6 +17,7 @@ "firebase": "^10.1.0", "firebase-admin": "^11.10.1", "tracker-list": "workspace:*", + "protocol": "workspace:*", "ts-node": "^10.9.1", "typescript": "^5.1.6", "uuid": "^9.0.0" diff --git a/tracker/src/main.ts b/tracker/src/main.ts index 76e5060..42fec86 100644 --- a/tracker/src/main.ts +++ b/tracker/src/main.ts @@ -10,6 +10,8 @@ import { WebSocket } from "ws"; import { v4 as uuid } from "uuid"; +import { PROTOCOL_VERSION } from "protocol"; + dotenv.config(); let members: Record = {}; @@ -70,16 +72,21 @@ reff.on("value", snapshot => { }); -app.ws("/join", (ws, _req) => { +app.ws("/join", (ws, req) => { + let ver = new URL(`https://a/${req.url}`).searchParams.get("protocol"); + + if (ver != PROTOCOL_VERSION) { + ws.close(); + } let id = uuid(); - console.log(_req.ip); + console.log(req.ip); console.log(`ws connect of id ${id}`); members[id] = ws; ws.onclose = () => { - console.log(`${_req.ip} disconnected`); + console.log(`${req.ip} disconnected`); delete members[id]; }; setInterval(() => {