mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
user agents
This commit is contained in:
@@ -14,9 +14,12 @@ export class ClientEntity extends TrackedEntity {
|
|||||||
@Column({ length: 62, type: 'varchar' })
|
@Column({ length: 62, type: 'varchar' })
|
||||||
address: string;
|
address: string;
|
||||||
|
|
||||||
@Column()
|
@Column({ length: 64, type: 'varchar' })
|
||||||
clientName: string;
|
clientName: string;
|
||||||
|
|
||||||
|
@Column({ length: 128, type: 'varchar', nullable: true })
|
||||||
|
userAgent: string;
|
||||||
|
|
||||||
@Column({ length: 8, type: 'varchar' })
|
@Column({ length: 8, type: 'varchar' })
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
|
|
||||||
@@ -24,7 +27,6 @@ export class ClientEntity extends TrackedEntity {
|
|||||||
startTime: Date;
|
startTime: Date;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Column({ type: 'real', default: 0 })
|
@Column({ type: 'real', default: 0 })
|
||||||
bestDifficulty: number
|
bestDifficulty: number
|
||||||
|
|
||||||
|
|||||||
@@ -76,4 +76,14 @@ export class ClientService {
|
|||||||
public async deleteAll() {
|
public async deleteAll() {
|
||||||
return await this.clientRepository.softDelete({})
|
return await this.clientRepository.softDelete({})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getUserAgents() {
|
||||||
|
const result = await this.clientRepository.createQueryBuilder('client')
|
||||||
|
.select('client.userAgent as userAgent')
|
||||||
|
.addSelect('COUNT(client.userAgent)', 'count')
|
||||||
|
.groupBy('client.userAgent')
|
||||||
|
.orderBy('count', 'DESC')
|
||||||
|
.getRawMany();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,11 +18,16 @@ export class AppController {
|
|||||||
@Get('info')
|
@Get('info')
|
||||||
public async info() {
|
public async info() {
|
||||||
|
|
||||||
|
const blockData = await this.blocksService.getFoundBlocks();
|
||||||
|
const userAgents = await this.clientService.getUserAgents();
|
||||||
|
|
||||||
const CACHE_KEY = 'SITE_HASHRATE_GRAPH';
|
const CACHE_KEY = 'SITE_HASHRATE_GRAPH';
|
||||||
const cachedResult = await this.cacheManager.get(CACHE_KEY);
|
const cachedResult = await this.cacheManager.get(CACHE_KEY);
|
||||||
if (cachedResult != null) {
|
if (cachedResult != null) {
|
||||||
return {
|
return {
|
||||||
chartData: cachedResult
|
chartData: cachedResult,
|
||||||
|
blockData,
|
||||||
|
userAgents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,11 +35,11 @@ export class AppController {
|
|||||||
|
|
||||||
await this.cacheManager.set(CACHE_KEY, chartData, 600);
|
await this.cacheManager.set(CACHE_KEY, chartData, 600);
|
||||||
|
|
||||||
const blockData = await this.blocksService.getFoundBlocks();
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
chartData,
|
chartData,
|
||||||
blockData
|
blockData,
|
||||||
|
userAgents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ export class StratumV1Client extends EasyUnsubscribe {
|
|||||||
sessionId: this.extraNonceAndSessionId,
|
sessionId: this.extraNonceAndSessionId,
|
||||||
address: this.clientAuthorization.address,
|
address: this.clientAuthorization.address,
|
||||||
clientName: this.clientAuthorization.worker,
|
clientName: this.clientAuthorization.worker,
|
||||||
|
userAgent: this.clientSubscription.userAgent,
|
||||||
startTime: new Date(),
|
startTime: new Date(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { IsArray } from 'class-validator';
|
import { Expose, Transform } from 'class-transformer';
|
||||||
|
import { IsArray, IsString, MaxLength } from 'class-validator';
|
||||||
|
|
||||||
import { eRequestMethod } from '../enums/eRequestMethod';
|
import { eRequestMethod } from '../enums/eRequestMethod';
|
||||||
import { StratumBaseMessage } from './StratumBaseMessage';
|
import { StratumBaseMessage } from './StratumBaseMessage';
|
||||||
@@ -9,6 +10,14 @@ export class SubscriptionMessage extends StratumBaseMessage {
|
|||||||
@IsArray()
|
@IsArray()
|
||||||
params: string[];
|
params: string[];
|
||||||
|
|
||||||
|
@Expose()
|
||||||
|
@IsString()
|
||||||
|
@MaxLength(128)
|
||||||
|
@Transform(({ value, key, obj, type }) => {
|
||||||
|
return obj.params[0] == null ? 'default' : obj.params[0]
|
||||||
|
})
|
||||||
|
public userAgent: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.method = eRequestMethod.SUBSCRIBE;
|
this.method = eRequestMethod.SUBSCRIBE;
|
||||||
|
|||||||
Reference in New Issue
Block a user