defer session create

This commit is contained in:
Ben Wilson
2023-08-08 23:39:52 -04:00
parent 2e0b66577d
commit 10f6ffa91f
3 changed files with 12 additions and 10 deletions
+10 -6
View File
@@ -111,12 +111,7 @@ export class StratumV1Client {
return;
}
if (this.sessionStart == null) {
this.sessionStart = new Date();
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService, this.clientService);
this.extraNonceAndSessionId = this.getRandomHexString();
console.log(`New client ID: : ${this.extraNonceAndSessionId}, ${this.socket.remoteAddress}:${this.socket.remotePort}`);
}
switch (parsedMessage.method) {
case eRequestMethod.SUBSCRIBE: {
@@ -133,6 +128,14 @@ export class StratumV1Client {
const errors = await validate(subscriptionMessage, validatorOptions);
if (errors.length === 0) {
if (this.sessionStart == null) {
this.sessionStart = new Date();
this.statistics = new StratumV1ClientStatistics(this.clientStatisticsService, this.clientService);
this.extraNonceAndSessionId = this.getRandomHexString();
console.log(`New client ID: : ${this.extraNonceAndSessionId}, ${this.socket.remoteAddress}:${this.socket.remotePort}`);
}
this.clientSubscription = subscriptionMessage;
const success = await this.write(JSON.stringify(this.clientSubscription.response(this.extraNonceAndSessionId)) + '\n');
if (!success) {
@@ -274,6 +277,7 @@ export class StratumV1Client {
if (this.stratumInitialized == false) {
console.log('Submit before initalized');
await this.socket.end();
return;
}