chore: reformat all code with prettier
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Logger } from "@cvmts/shared";
|
||||
import { Logger } from '@cvmts/shared';
|
||||
|
||||
export class IPData {
|
||||
tempMuteExpireTimeout?: NodeJS.Timeout;
|
||||
@@ -15,19 +15,17 @@ export class IPData {
|
||||
|
||||
// Call when a connection is closed to "release" the ip data
|
||||
Unref() {
|
||||
if(this.refCount - 1 < 0)
|
||||
this.refCount = 0;
|
||||
if (this.refCount - 1 < 0) this.refCount = 0;
|
||||
this.refCount--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class IPDataManager {
|
||||
static ipDatas = new Map<string, IPData>();
|
||||
static logger = new Logger("CVMTS.IPDataManager");
|
||||
static logger = new Logger('CVMTS.IPDataManager');
|
||||
|
||||
static GetIPData(address: string) {
|
||||
if(IPDataManager.ipDatas.has(address)) {
|
||||
if (IPDataManager.ipDatas.has(address)) {
|
||||
// Note: We already check for if it exists, so we use ! here
|
||||
// because TypeScript can't exactly tell that in this case,
|
||||
// only in explicit null or undefined checks
|
||||
@@ -35,16 +33,15 @@ export class IPDataManager {
|
||||
ref.refCount++;
|
||||
return ref;
|
||||
}
|
||||
|
||||
|
||||
let data = new IPData(address);
|
||||
data.refCount++;
|
||||
IPDataManager.ipDatas.set(address, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
static ForEachIPData(callback: (d: IPData) => void) {
|
||||
for(let tuple of IPDataManager.ipDatas)
|
||||
callback(tuple[1]);
|
||||
for (let tuple of IPDataManager.ipDatas) callback(tuple[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +49,10 @@ export class IPDataManager {
|
||||
// Strictly speaking this will just allow the v8 GC to finally
|
||||
// delete the objects, but same difference.
|
||||
setInterval(() => {
|
||||
for(let tuple of IPDataManager.ipDatas) {
|
||||
if(tuple[1].refCount == 0) {
|
||||
IPDataManager.logger.Info("Deleted ipdata for IP {0}", tuple[0]);
|
||||
for (let tuple of IPDataManager.ipDatas) {
|
||||
if (tuple[1].refCount == 0) {
|
||||
IPDataManager.logger.Info('Deleted ipdata for IP {0}', tuple[0]);
|
||||
IPDataManager.ipDatas.delete(tuple[0]);
|
||||
}
|
||||
}
|
||||
}, 15000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user