allow tracker to reject outdated servers

This commit is contained in:
CoolElectronics 2023-08-20 10:09:54 -04:00
parent 55dece7bc3
commit c6f06d9724
No known key found for this signature in database
GPG key ID: F63593D168636C50
5 changed files with 19 additions and 9 deletions

3
pnpm-lock.yaml generated
View file

@ -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

View file

@ -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);
setTimeout(start, 2000);
});
})

View file

@ -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,7 +51,7 @@ 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 (_) { }

View file

@ -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"

View file

@ -10,6 +10,8 @@ import { WebSocket } from "ws";
import { v4 as uuid } from "uuid";
import { PROTOCOL_VERSION } from "protocol";
dotenv.config();
let members: Record<string, WebSocket> = {};
@ -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(() => {