Return the host record from verifyHostToken

Matches verifyUserToken returning the user. HostConnection._saveInfo is
renamed saveRecord to match User.saveRecord.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-04 00:37:37 +00:00
1 parent e6554e09c7
commit 4c6aed3cff
5 files changed
+13 -12

No files matched your search

+3 -3
View File
@@ -68,7 +68,7 @@ export default class HostConnection extends BaseConnection {
this._controller.instances.records.setMany(instances);
this.info.connected = false;
this._saveInfo();
this.saveRecord();
});
this.handle(lib.GetFactorioCredentialsRequest, this.handleGetFactorioCredentialsRequest.bind(this));
@@ -173,7 +173,7 @@ export default class HostConnection extends BaseConnection {
}
/** Store changes to the host record, unless the host was revoked */
private _saveInfo() {
saveRecord() {
if (this._controller.hosts.getMutable(this.id) === this.info) {
this._controller.hosts.records.set(this.info);
}
@@ -182,7 +182,7 @@ export default class HostConnection extends BaseConnection {
async handleHostInfoUpdateEvent(event: lib.HostInfoUpdateEvent) {
this.info.name = event.update.name;
this.info.publicAddress = event.update.publicAddress;
this._saveInfo();
this.saveRecord();
}
async handleInstanceStatusChangedEvent(request: lib.InstanceStatusChangedEvent) {
+4 -4
View File
@@ -127,23 +127,23 @@ export default class HostManager {
* Check a host token
*
* @param token - Host token to check.
* @returns ID of the host the token was issued to.
* @returns the host the token was issued to.
* @throws if the token is invalid, its host is not registered or it was issued before tokenValidAfter.
*/
verifyHostToken(token: string): number {
verifyHostToken(token: string): HostRecord {
// migrate: allow pre-rename tokens issued to hosts before alpha-14
const payload = jwt.verify(token, this._controller.authSecret, { audience: ["host", "slave"] });
if (typeof payload === "string") {
throw new Error("unexpected JsonWebToken type");
}
const hostId = payload.host !== undefined ? payload.host : payload.slave;
const host = this.records.get(hostId);
const host = this.records.getMutable(hostId);
if (!host) {
throw new Error("host is not registered, start the host again to request to join the cluster");
}
if (!payload.iat || payload.iat < host.tokenValidAfter) {
throw new Error("invalid token");
}
return hostId;
return host;
}
}
+1 -1
View File
@@ -252,7 +252,7 @@ ${err.stack}`
}
try {
if (this.controller.hosts.verifyHostToken(data.token) !== data.id) {
if (this.controller.hosts.verifyHostToken(data.token).id !== data.id) {
throw new Error("missmatched host id");
}
} catch (err: any) {