diff --git a/src/index.js b/src/index.js index bc2d386..3eca755 100644 --- a/src/index.js +++ b/src/index.js @@ -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); }