cvmts: Move initial protocol selection to transport layer
This commit is contained in:
@@ -37,7 +37,7 @@ export class User {
|
|||||||
|
|
||||||
private logger = pino({ name: 'CVMTS.User' });
|
private logger = pino({ name: 'CVMTS.User' });
|
||||||
|
|
||||||
constructor(socket: NetworkClient, ip: IPData, config: IConfig, username?: string, node?: string) {
|
constructor(socket: NetworkClient, protocol: string, ip: IPData, config: IConfig, username?: string, node?: string) {
|
||||||
this.IP = ip;
|
this.IP = ip;
|
||||||
this.connectedToNode = false;
|
this.connectedToNode = false;
|
||||||
this.viewMode = -1;
|
this.viewMode = -1;
|
||||||
@@ -47,7 +47,7 @@ export class User {
|
|||||||
this.Capabilities = new CollabVMCapabilities();
|
this.Capabilities = new CollabVMCapabilities();
|
||||||
|
|
||||||
// All clients default to the Guacamole protocol.
|
// All clients default to the Guacamole protocol.
|
||||||
this.protocol = TheProtocolManager.createProtocol('guacamole', this);
|
this.protocol = TheProtocolManager.createProtocol(protocol, this);
|
||||||
|
|
||||||
this.socket.on('disconnect', () => {
|
this.socket.on('disconnect', () => {
|
||||||
// Unref the ip data for this connection
|
// Unref the ip data for this connection
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import { User } from '../../User.js';
|
|||||||
import pino from 'pino';
|
import pino from 'pino';
|
||||||
import { BanManager } from '../../BanManager.js';
|
import { BanManager } from '../../BanManager.js';
|
||||||
|
|
||||||
|
const kAllowedProtocols = [
|
||||||
|
"guacamole" // Regular ol' collabvm1 protocol
|
||||||
|
]
|
||||||
|
|
||||||
export default class WSServer extends EventEmitter implements NetworkServer {
|
export default class WSServer extends EventEmitter implements NetworkServer {
|
||||||
private httpServer: http.Server;
|
private httpServer: http.Server;
|
||||||
private wsServer: WebSocketServer;
|
private wsServer: WebSocketServer;
|
||||||
@@ -50,7 +54,9 @@ export default class WSServer extends EventEmitter implements NetworkServer {
|
|||||||
socket.destroy();
|
socket.destroy();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (req.headers['sec-websocket-protocol'] !== 'guacamole') {
|
let protocol = req.headers['sec-websocket-protocol'];
|
||||||
|
|
||||||
|
if (!protocol || kAllowedProtocols.indexOf(protocol) === -1) {
|
||||||
killConnection();
|
killConnection();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -131,14 +137,14 @@ export default class WSServer extends EventEmitter implements NetworkServer {
|
|||||||
|
|
||||||
this.wsServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
|
this.wsServer.handleUpgrade(req, socket, head, (ws: WebSocket) => {
|
||||||
this.wsServer.emit('connection', ws, req);
|
this.wsServer.emit('connection', ws, req);
|
||||||
this.onConnection(ws, req, ip);
|
this.onConnection(ws, req, ip, protocol);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private onConnection(ws: WebSocket, req: http.IncomingMessage, ip: string) {
|
private onConnection(ws: WebSocket, req: http.IncomingMessage, ip: string, protocol: string) {
|
||||||
let client = new WSClient(ws, ip);
|
let client = new WSClient(ws, ip);
|
||||||
this.clients.push(client);
|
this.clients.push(client);
|
||||||
let user = new User(client, IPDataManager.GetIPData(ip), this.Config);
|
let user = new User(client, protocol, IPDataManager.GetIPData(ip), this.Config);
|
||||||
|
|
||||||
this.emit('connect', user);
|
this.emit('connect', user);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user