mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
undo stratum changes
This commit is contained in:
@@ -48,6 +48,7 @@ const ORMModules = [
|
|||||||
logging: false,
|
logging: false,
|
||||||
enableWAL: true,
|
enableWAL: true,
|
||||||
busyTimeout: 30 * 1000,
|
busyTimeout: 30 * 1000,
|
||||||
|
|
||||||
}),
|
}),
|
||||||
CacheModule.register(),
|
CacheModule.register(),
|
||||||
ScheduleModule.forRoot(),
|
ScheduleModule.forRoot(),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { Interval } from '@nestjs/schedule';
|
|
||||||
import { Server, Socket } from 'net';
|
import { Server, Socket } from 'net';
|
||||||
|
|
||||||
import { StratumV1Client } from '../models/StratumV1Client';
|
import { StratumV1Client } from '../models/StratumV1Client';
|
||||||
@@ -16,9 +15,6 @@ import { StratumV1JobsService } from './stratum-v1-jobs.service';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class StratumV1Service implements OnModuleInit {
|
export class StratumV1Service implements OnModuleInit {
|
||||||
|
|
||||||
private maxConnections = 50;
|
|
||||||
private currentConnections = 0;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly bitcoinRpcService: BitcoinRpcService,
|
private readonly bitcoinRpcService: BitcoinRpcService,
|
||||||
private readonly clientService: ClientService,
|
private readonly clientService: ClientService,
|
||||||
@@ -32,20 +28,13 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Interval(1000 * 30)
|
|
||||||
public async incrementConnections() {
|
|
||||||
this.maxConnections += 50;
|
|
||||||
}
|
|
||||||
|
|
||||||
async onModuleInit(): Promise<void> {
|
async onModuleInit(): Promise<void> {
|
||||||
console.log(`Enable Solo: ${process.env.ENABLE_SOLO}`)
|
|
||||||
if (process.env.ENABLE_SOLO == 'true') {
|
if (process.env.ENABLE_SOLO == 'true') {
|
||||||
//await this.clientStatisticsService.deleteAll();
|
//await this.clientStatisticsService.deleteAll();
|
||||||
console.log(`NODE_APP_INSTANCE: ${process.env.NODE_APP_INSTANCE}`)
|
|
||||||
if (process.env.NODE_APP_INSTANCE == '0') {
|
if (process.env.NODE_APP_INSTANCE == '0') {
|
||||||
await this.clientService.deleteAll();
|
await this.clientService.deleteAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.startSocketServer();
|
this.startSocketServer();
|
||||||
}, 1000 * 10)
|
}, 1000 * 10)
|
||||||
@@ -56,15 +45,6 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
private startSocketServer() {
|
private startSocketServer() {
|
||||||
const server = new Server(async (socket: Socket) => {
|
const server = new Server(async (socket: Socket) => {
|
||||||
|
|
||||||
this.currentConnections++;
|
|
||||||
|
|
||||||
if (this.currentConnections > this.maxConnections) {
|
|
||||||
// If the maximum number of connections is reached, reject the new connection
|
|
||||||
console.log('Connection limit reached. Rejecting new connection.');
|
|
||||||
socket.end(); // Close the socket immediately
|
|
||||||
this.currentConnections--; // Decrement the count as the connection is rejected
|
|
||||||
}
|
|
||||||
|
|
||||||
//5 min
|
//5 min
|
||||||
socket.setTimeout(1000 * 60 * 5);
|
socket.setTimeout(1000 * 60 * 5);
|
||||||
|
|
||||||
@@ -95,11 +75,6 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
socket.destroy();
|
socket.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
socket.on('end', () => {
|
|
||||||
this.currentConnections--;
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('error', async (error: Error) => { });
|
socket.on('error', async (error: Error) => { });
|
||||||
|
|
||||||
// //console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}`);
|
// //console.log(`Client disconnected, socket error, ${client.extraNonceAndSessionId}`);
|
||||||
@@ -107,7 +82,6 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
server.listen(process.env.STRATUM_PORT, () => {
|
server.listen(process.env.STRATUM_PORT, () => {
|
||||||
console.log(`Stratum server is listening on port ${process.env.STRATUM_PORT}`);
|
console.log(`Stratum server is listening on port ${process.env.STRATUM_PORT}`);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user