Skip to content

Commit

Permalink
hash instead of full key
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Gottfried committed Feb 19, 2020
1 parent f9267ea commit 5e2eb13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ class WebSockProxyClient extends Object {
console.log("Client connection openned.");

ws.send({data:"Hallo."});
ws.on("message", function (message) {
request_forwarder.on_message(message);
});
ws.on("message", request_forwarder.on_message(message).bind(request_forwarder));
ws.on("close", function onClose() {
console.log("Client connection closed.");
});
Expand Down
11 changes: 6 additions & 5 deletions server/clients-manager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
//-- vim: ft=javascript tabstop=2 softtabstop=2 expandtab shiftwidth=2
'use strict';

const checksum = require('../lib').checksum;
const {BadRequest, Unauthorized} = require('./HttpError');

class ClientsManager extends Object {
Expand All @@ -23,20 +24,20 @@ class ClientsManager extends Object {
if (this.clientFromId(match.groups.client_key)) return callback(new BadRequest("The key is already used by another client."));
if (this.allowed_keys === true || this.allowed_keys.has(match.groups.client_key)) {
console.log(`Key ${match.groups.client_key} accepted`);
callback(null, {"key": match.groups.client_key});
callback(null, {"id": checksum(match.groups.client_key)});
} else {
console.log('Invalid key');
callback(new Unauthorized("Invalid key."), null);
}
}

onConnected (ws, client) {
this._clients_by_id[client.key] = ws;
ws.id = client.key;
this._clients_by_id[client.id] = ws;
ws.id = client.id;
}

onClose (ws, client) {
delete this._clients_by_id[client.key];
delete this._clients_by_id[client.id];
}

clientFromId (id) {
Expand Down

0 comments on commit 5e2eb13

Please sign in to comment.