Skip to content

Commit

Permalink
track client versions to avoid problems during upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Oct 2, 2024
1 parent 1756fc3 commit 261c027
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion faucet-client/src/common/FaucetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export class FaucetApi {
}

public startSession(inputData: any): Promise<IFaucetSessionInfo> {
return this.apiPost("/startSession", {}, inputData);
return this.apiPost("/startSession", {
cliver: FAUCET_CLIENT_VERSION,
}, inputData);
}

public claimReward(inputData: any): Promise<IFaucetSessionStatus> {
Expand Down
2 changes: 1 addition & 1 deletion faucet-client/src/pow/PoWClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class PoWClient extends TypedEmitter<PoWClientEvents> {

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;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/pow/PoWModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ export class PoWModule extends BaseModule<IPoWConfig> {

private async processPoWClientWebSocket(req: IncomingMessage, ws: WebSocket, remoteIp: string): Promise<void> {
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",
Expand Down Expand Up @@ -209,6 +211,8 @@ export class PoWModule extends BaseModule<IPoWConfig> {
return;
}

session.setSessionData("cliver", clientVersion);

let powSession = this.getPoWSession(session);
let powClient: PoWClient;
if((powClient = powSession.activeClient)) {
Expand Down
7 changes: 5 additions & 2 deletions src/webserv/FaucetWebApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -184,7 +184,7 @@ export class FaucetWebApi {
};
}

public async onStartSession(req: IncomingMessage, body: Buffer): Promise<any> {
public async onStartSession(req: IncomingMessage, body: Buffer, clientVersion: string): Promise<any> {
if(req.method !== "POST")
return new FaucetHttpResponse(405, "Method Not Allowed");

Expand All @@ -204,6 +204,9 @@ export class FaucetWebApi {
}
}

if(clientVersion)
session.setSessionData("cliver", clientVersion);

sessionInfo = await session.getSessionInfo();
} catch(ex) {
if(ex instanceof FaucetError) {
Expand Down

0 comments on commit 261c027

Please sign in to comment.