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

58
cvmts/src/index.ts Normal file
View File

@@ -0,0 +1,58 @@
import * as toml from 'toml';
import IConfig from './IConfig.js';
import * as fs from "fs";
import WSServer from './WSServer.js';
import { QemuVM, QemuVmDefinition } from '@cvmts/qemu';
import * as Shared from '@cvmts/shared';
import AuthManager from './AuthManager.js';
let logger = new Shared.Logger("CVMTS.Init");
logger.Info("CollabVM Server starting up");
// Parse the config file
var Config : IConfig;
if (!fs.existsSync("config.toml")) {
logger.Error("Fatal error: Config.toml not found. Please copy config.example.toml and fill out fields")
process.exit(1);
}
try {
var configRaw = fs.readFileSync("config.toml").toString();
Config = toml.parse(configRaw);
} catch (e) {
logger.Error("Fatal error: Failed to read or parse the config file: {0}", (e as Error).message);
process.exit(1);
}
async function start() {
// Print a warning if qmpSockDir is set
// and the host OS is Windows, as this
// configuration will very likely not work.
if(process.platform === "win32" && Config.vm.qmpSockDir) {
logger.Warning("You appear to have the option 'qmpSockDir' enabled in the config.")
logger.Warning("This is not supported on Windows, and you will likely run into issues.");
logger.Warning("To remove this warning, use the qmpHost and qmpPort options instead.");
}
// Init the auth manager if enabled
let auth = Config.auth.enabled ? new AuthManager(Config.auth.apiEndpoint, Config.auth.secretKey) : null;
// Fire up the VM
let def: QemuVmDefinition = {
id: Config.collabvm.node,
command: Config.vm.qemuArgs
}
var VM = new QemuVM(def);
await VM.Start();
// Start up the websocket server
var WS = new WSServer(Config, VM, auth);
WS.listen();
}
start();