Implement HostInfo as a class

Replace POJO definition of HostInfo with a class that properly manages
its own serialisation to JSON.
This commit is contained in:
Hornwitser committed 2023-12-09 17:23:24 +01:00
1 parent 20330bc2c3
commit c248363895
6 files changed
+137 -60

No files matched your search

+2 -4
View File
@@ -9,7 +9,7 @@ import * as lib from "@clusterio/lib";
const { logger } = lib;
import ControlConnection from "./ControlConnection";
import HostConnection, { HostInfo } from "./HostConnection";
import HostConnection from "./HostConnection";
import WsServerConnector from "./WsServerConnector";
import { version as packageVersion } from "../package.json";
@@ -243,7 +243,7 @@ ${err.stack}`
}
let host = this.controller.hosts.get(data.id);
if (!tokenPayload.iat || tokenPayload.iat < (host?.token_valid_after??0)) {
if (!tokenPayload.iat || tokenPayload.iat < (host?.tokenValidAfter ?? 0)) {
throw new Error("invalid token");
}
} catch (err: any) {
@@ -274,13 +274,11 @@ ${err.stack}`
connector.on("close", () => {
if (this.hostConnections.get(data.id) === connection) {
this.hostConnections.delete(data.id);
this.controller.hostsUpdated([this.controller.hosts.get(data.id)!]);
} else {
logger.warn("Unlisted HostConnection closed");
}
});
this.hostConnections.set(data.id, connection);
this.controller.hostsUpdated([this.controller.hosts.get(data.id)!]);
let src = new lib.Address(lib.Address.host, data.id);
connector.ready(socket, src, sessionToken, undefined);
}