From 261c0276f8bf6f53d8eb80cd3d330100f9b4d44a Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 2 Oct 2024 12:49:33 +0200 Subject: [PATCH] track client versions to avoid problems during upgrades --- faucet-client/src/common/FaucetApi.ts | 4 +++- faucet-client/src/pow/PoWClient.ts | 2 +- src/modules/pow/PoWModule.ts | 4 ++++ src/webserv/FaucetWebApi.ts | 7 +++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/faucet-client/src/common/FaucetApi.ts b/faucet-client/src/common/FaucetApi.ts index 927cf18e1..8b5ea3522 100644 --- a/faucet-client/src/common/FaucetApi.ts +++ b/faucet-client/src/common/FaucetApi.ts @@ -104,7 +104,9 @@ export class FaucetApi { } public startSession(inputData: any): Promise { - return this.apiPost("/startSession", {}, inputData); + return this.apiPost("/startSession", { + cliver: FAUCET_CLIENT_VERSION, + }, inputData); } public claimReward(inputData: any): Promise { diff --git a/faucet-client/src/pow/PoWClient.ts b/faucet-client/src/pow/PoWClient.ts index d1f1fd1d8..d72aa84fc 100644 --- a/faucet-client/src/pow/PoWClient.ts +++ b/faucet-client/src/pow/PoWClient.ts @@ -64,7 +64,7 @@ export class PoWClient extends TypedEmitter { private startClient() { this.clientStatus = PoWClientStatus.CONNECTING; - this.clientSocket = new WebSocket(this.options.powApiUrl + "?session=" + this.options.sessionId); + this.clientSocket = new WebSocket(this.options.powApiUrl + "?session=" + this.options.sessionId + "&cliver=" + FAUCET_CLIENT_VERSION); this.clientSocket.addEventListener("open", (evt) => { console.log("[PoWClient] faucet websocket opened"); this.clientStatus = PoWClientStatus.READY; diff --git a/src/modules/pow/PoWModule.ts b/src/modules/pow/PoWModule.ts index f26468db4..e530c7921 100644 --- a/src/modules/pow/PoWModule.ts +++ b/src/modules/pow/PoWModule.ts @@ -167,12 +167,14 @@ export class PoWModule extends BaseModule { private async processPoWClientWebSocket(req: IncomingMessage, ws: WebSocket, remoteIp: string): Promise { let sessionId: string; + let clientVersion: string; try { let urlParts = req.url.split("?"); let url = new URLSearchParams(urlParts[1]); if(!(sessionId = url.get("session"))) { throw "session id missing"; } + clientVersion = url.get("cliver"); } catch(ex) { ws.send(JSON.stringify({ action: "error", @@ -209,6 +211,8 @@ export class PoWModule extends BaseModule { return; } + session.setSessionData("cliver", clientVersion); + let powSession = this.getPoWSession(session); let powClient: PoWClient; if((powClient = powSession.activeClient)) { diff --git a/src/webserv/FaucetWebApi.ts b/src/webserv/FaucetWebApi.ts index d2136f234..e4bdaccf9 100644 --- a/src/webserv/FaucetWebApi.ts +++ b/src/webserv/FaucetWebApi.ts @@ -81,7 +81,7 @@ export class FaucetWebApi { case "getFaucetConfig".toLowerCase(): return this.onGetFaucetConfig(apiUrl.query['cliver'] as string, apiUrl.query['session'] as string); case "startSession".toLowerCase(): - return this.onStartSession(req, body); + return this.onStartSession(req, body, apiUrl.query['cliver'] as string); case "getSession".toLowerCase(): return this.onGetSession(apiUrl.query['session'] as string); case "claimReward".toLowerCase(): @@ -184,7 +184,7 @@ export class FaucetWebApi { }; } - public async onStartSession(req: IncomingMessage, body: Buffer): Promise { + public async onStartSession(req: IncomingMessage, body: Buffer, clientVersion: string): Promise { if(req.method !== "POST") return new FaucetHttpResponse(405, "Method Not Allowed"); @@ -204,6 +204,9 @@ export class FaucetWebApi { } } + if(clientVersion) + session.setSessionData("cliver", clientVersion); + sessionInfo = await session.getSessionInfo(); } catch(ex) { if(ex instanceof FaucetError) {