Giant refactoring (or at least the start)

In short:
- cvmts is now bundled/built via parcel and inside of a npm/yarn workspace with multiple nodejs projects
- cvmts now uses the crusttest QEMU management and RFB library (or a fork, if you so prefer).
- cvmts does NOT use node-canvas anymore, instead we opt for the same route crusttest took and just encode jpegs ourselves from the RFB provoded framebuffer via jpeg-turbo. this means funnily enough sharp is back for more for thumbnails, but actually seems to WORK this time
- IPData is now managed in a very similar way to the original cvm 1.2 implementation where a central manager and reference count exist. tbh it wouldn't be that hard to implement multinode either, but for now, I'm not going to take much time on doing that.

this refactor is still incomplete. please do not treat it as generally available while it's not on the default branch. if you want to use it (and report bugs or send fixes) feel free to, but while it may "just work" in certain situations it may be very broken in others.

(yes, I know windows support is partially totaled by this; it's something that can and will be fixed)
This commit is contained in:
modeco80
2024-04-23 09:57:02 -04:00
parent 28dddfc363
commit cb297e15c4
46 changed files with 5661 additions and 1011 deletions

62
cvmts/src/IPData.ts Normal file
View File

@@ -0,0 +1,62 @@
import { Logger } from "@cvmts/shared";
export class IPData {
tempMuteExpireTimeout?: NodeJS.Timeout;
muted: Boolean;
vote: boolean | null;
address: string;
refCount: number = 0;
constructor(address: string) {
this.address = address;
this.muted = false;
this.vote = null;
}
// Call when a connection is closed to "release" the ip data
Unref() {
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 GetIPData(address: string) {
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
let ref = IPDataManager.ipDatas.get(address)!;
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]);
}
}
// Garbage collect unreferenced IPDatas every 15 seconds.
// 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]);
IPDataManager.ipDatas.delete(tuple[0]);
}
}
}, 15000);