cvmts: rip out raw tcp transport

it's really just a tech debt that nothing uses, these is pretty much no point keeping it
This commit is contained in:
Elijah R
2025-03-21 19:13:15 -04:00
parent e1e5f4a352
commit ab63420075
5 changed files with 0 additions and 141 deletions

View File

@@ -20,13 +20,6 @@ directory = "geoip/"
accountID = ""
licenseKey = ""
[tcp]
# Enabled the raw TCP socket server
# You usually want to leave this disabled
enabled = false
host = "0.0.0.0"
port = 6014
[auth]
# Enables the CollabVM account authentication system
# Requires an authentication server (https://git.computernewb.com/collabvm/CollabVMAuthServer)

View File

@@ -16,11 +16,6 @@ export default interface IConfig {
accountID: string;
licenseKey: string;
};
tcp: {
enabled: boolean;
host: string;
port: number;
};
auth: {
enabled: boolean;
apiEndpoint: string;

View File

@@ -8,7 +8,6 @@ import { QemuVmDefinition } from '@computernewb/superqemu';
import AuthManager from './AuthManager.js';
import WSServer from './net/ws/WSServer.js';
import { User } from './User.js';
import TCPServer from './net/tcp/TCPServer.js';
import VM from './vm/interface.js';
import VNCVM from './vm/vnc/VNCVM.js';
import GeoIPDownloader from './GeoIPDownloader.js';
@@ -111,11 +110,5 @@ async function start() {
var WS = new WSServer(Config, banmgr);
WS.on('connect', (client: User) => CVM.connectionOpened(client));
WS.start();
if (Config.tcp.enabled) {
var TCP = new TCPServer(Config, banmgr);
TCP.on('connect', (client: User) => CVM.connectionOpened(client));
TCP.start();
}
}
start();

View File

@@ -1,72 +0,0 @@
import EventEmitter from 'events';
import { NetworkClient } from '../NetworkClient.js';
import { Socket } from 'net';
const TextHeader = 0;
const BinaryHeader = 1;
export default class TCPClient extends EventEmitter implements NetworkClient {
private socket: Socket;
private cache: string;
constructor(socket: Socket) {
super();
this.socket = socket;
this.cache = '';
this.socket.on('end', () => {
this.emit('disconnect');
});
this.socket.on('data', (data) => {
var msg = data.toString('utf-8');
if (msg[msg.length - 1] === '\n') msg = msg.slice(0, -1);
this.cache += msg;
this.readCache();
});
}
private readCache() {
for (var index = this.cache.indexOf(';'); index !== -1; index = this.cache.indexOf(';')) {
this.emit('msg', this.cache.slice(0, index + 1));
this.cache = this.cache.slice(index + 1);
}
}
getIP(): string {
return this.socket.remoteAddress!;
}
send(msg: string): Promise<void> {
return new Promise((res, rej) => {
let _msg = new Uint32Array([TextHeader, ...Buffer.from(msg, 'utf-8')]);
this.socket.write(Buffer.from(_msg), (err) => {
if (err) {
rej(err);
return;
}
res();
});
});
}
sendBinary(msg: Uint8Array): Promise<void> {
return new Promise((res, rej) => {
let _msg = new Uint32Array([BinaryHeader, msg.length, ...msg]);
this.socket.write(Buffer.from(_msg), (err) => {
if (err) {
rej(err);
return;
}
res();
});
});
}
close(): void {
this.emit('disconnect');
this.socket.end();
}
isOpen(): boolean {
return this.socket.writable;
}
}

View File

@@ -1,50 +0,0 @@
// TODO: replace tcp protocol with smth like
// struct msg { beu32 len; char data[len] }
// (along with a length cap obviously)
import EventEmitter from 'events';
import { NetworkServer } from '../NetworkServer.js';
import { Server, Socket } from 'net';
import IConfig from '../../IConfig.js';
import TCPClient from './TCPClient.js';
import { IPDataManager } from '../../IPData.js';
import { User } from '../../User.js';
import pino from 'pino';
import { BanManager } from '../../BanManager.js';
export default class TCPServer extends EventEmitter implements NetworkServer {
listener: Server;
Config: IConfig;
logger = pino({ name: 'CVMTS.TCPServer' });
clients: TCPClient[];
private banmgr: BanManager;
constructor(config: IConfig, banmgr: BanManager) {
super();
this.Config = config;
this.listener = new Server();
this.clients = [];
this.listener.on('connection', (socket) => this.onConnection(socket));
this.banmgr = banmgr;
}
private async onConnection(socket: Socket) {
this.logger.info(`New TCP connection from ${socket.remoteAddress}`);
if (await this.banmgr.isIPBanned(socket.remoteAddress!)) {
socket.write('6.banned;');
socket.destroy();
return;
}
var client = new TCPClient(socket);
this.clients.push(client);
this.emit('connect', new User(client, IPDataManager.GetIPData(client.getIP()), this.Config));
}
start(): void {
this.listener.listen(this.Config.tcp.port, this.Config.tcp.host, () => {
this.logger.info(`TCP server listening on ${this.Config.tcp.host}:${this.Config.tcp.port}`);
});
}
stop(): void {
this.listener.close();
}
}