Only add nodes to pool after successful auth

This commit is contained in:
2023-07-31 23:03:59 +02:00
parent fc6647e873
commit 1ffeb082b6

View File

@@ -79,8 +79,6 @@ app.post("/jobs", async (req, res) => {
wss.on('connection', function connection(ws) {
var nodeID = uuid.v4();
ws.nodeID = nodeID;
nodes[nodeID] = ws
console.log("New connection from", nodeID)
ws.on('error', console.error);
@@ -89,11 +87,14 @@ wss.on('connection', function connection(ws) {
if(request["register"]){
if(request["register"]["auth_key"] !== process.env.NODE_AUTH_KEY) {
nodeID = `${nodeID}-${request["register"]["hostname"]}`;
console.log("INVALID AUTH KEY. Disconnecting ", nodeID);
ws.close(4000, "Invalid auth key");
return;
}
ws.send(JSON.stringify({"welcome": { "clientId": nodeID }}));
ws.nodeID = nodeID;
nodes[nodeID] = ws
console.log("Node registered", nodeID);
}