From 0adcc41fc407d5da18f404074037344a8366acbb Mon Sep 17 00:00:00 2001 From: netop Date: Thu, 18 May 2017 10:52:39 +0300 Subject: [PATCH 1/7] Update server.js to fix ws@3.0.0 breaking changes --- lib/server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 00480ddf6..7fa86f0c1 100644 --- a/lib/server.js +++ b/lib/server.js @@ -20,7 +20,8 @@ app._initializeWSS = function(server) { // Create WebSocket server as well. this._wss = new WebSocketServer({ path: path, server: server}); - this._wss.on('connection', function(socket) { + this._wss.on('connection', function(socket, req) { + socket.upgradeReq = req; var query = url.parse(socket.upgradeReq.url, true).query; var id = query.id; var token = query.token; From d65790a9f19a861e8c3a3bb35eee147ff9befda6 Mon Sep 17 00:00:00 2001 From: netop Date: Thu, 18 May 2017 11:26:30 +0300 Subject: [PATCH 2/7] Update ws version number to ^3.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0276a9eb2..438898ef4 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "body-parser": "^1.9.0", "express": "^4.9.8", "optimist": "~0.6.1", - "ws": "*", + "ws": "^3.0.0", "cors": "~2.5.0" }, "devDependencies": { From 114dd281b13ecdc384e112243373107e6ae0ff89 Mon Sep 17 00:00:00 2001 From: casi Date: Mon, 26 Mar 2018 15:45:35 +0300 Subject: [PATCH 3/7] [feat]: added more error logging --- lib/server.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/server.js b/lib/server.js index 7fa86f0c1..ea48563f7 100644 --- a/lib/server.js +++ b/lib/server.js @@ -28,12 +28,12 @@ app._initializeWSS = function(server) { var key = query.key; var ip = socket.upgradeReq.socket.remoteAddress; - socket.on("error", function(e) { - console.log("Error in WS socket."); - console.log(e); + socket.on('error', function(e) { + self._log('Error in WS socket.', e); }); if (!id || !token || !key) { + self._warn('No id, token, or key supplied to websocket server', id, token, key); socket.send(JSON.stringify({ type: 'ERROR', payload: { msg: 'No id, token, or key supplied to websocket server' } })); socket.close(); return; @@ -49,6 +49,7 @@ app._initializeWSS = function(server) { } self._configureWS(socket, key, id, token); } else { + self._warn('Client key check failure for wss: ' + err, key, ip); socket.send(JSON.stringify({ type: 'ERROR', payload: { msg: err } })); } }); @@ -72,6 +73,7 @@ app._configureWS = function(socket, key, id, token) { } } else { // ID-taken, invalid token + self._warn('Client token already taken: ', key, id, token); socket.send(JSON.stringify({ type: 'ID-TAKEN', payload: { msg: 'ID is taken' } })); socket.close(); return; @@ -102,7 +104,7 @@ app._configureWS = function(socket, key, id, token) { } else if(message.type === 'PING') { // Do nothing } else { - util.prettyError('Message unrecognized'); + self._warn('Message unrecognized:', message && message.type); } } catch(e) { self._log('Invalid message', data); @@ -175,6 +177,7 @@ app._initializeHTTP = function() { self._ips[ip]++; self._startStreaming(res, key, id, token, true); } else { + self._warn('Client key check failure for XHR: ' + err, key, ip, id); res.send(JSON.stringify({ type: 'HTTP-ERROR' })); } }); @@ -206,6 +209,7 @@ app._initializeHTTP = function() { var client; if (!self._clients[key] || !(client = self._clients[key][id])) { if (req.params.retry) { + self._warn('Client check failure on retry for: ', key, id); res.sendStatus(401); return; } else { @@ -218,6 +222,7 @@ app._initializeHTTP = function() { // Auth the req if (typeof client === 'undefined' || req.params.token !== client.token) { + self._warn('Client check failure on request for: ', key, id); res.sendStatus(401); return; } else { @@ -275,6 +280,7 @@ app._startStreaming = function(res, key, id, token, open) { client.res = res; this._processOutstanding(key, id); } else { + self._warn('Client token check failure for streaming: ', key, id, token); // ID-taken, invalid token res.end(JSON.stringify({ type: 'HTTP-ERROR' })); } @@ -408,3 +414,9 @@ app._log = function() { console.log.apply(console, arguments); } }; + +app._warn = function() { + if (this._options.debug > 2 ) { + console.warn.apply(console, arguments); + } +}; From 1effbcac7bc280ef14de71eab1440b68d1c0f1f8 Mon Sep 17 00:00:00 2001 From: casi Date: Mon, 26 Mar 2018 15:49:49 +0300 Subject: [PATCH 4/7] [version]: bump PeerServer version to 0.2.10 --- changelog.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f19f5c2d3..d990c99d9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # PeerServer Changelog +### 0.2.10 + +* Added some more error logging + ### 0.2.6 * Ensure 16 character IDs. diff --git a/package.json b/package.json index 438898ef4..b8eeed33e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peer", - "version": "0.2.9", + "version": "0.2.10", "description": "PeerJS server component", "main": "lib/index.js", "bin": { From 565812677f7126207bf7885479847851e5be2368 Mon Sep 17 00:00:00 2001 From: casi Date: Mon, 26 Mar 2018 16:05:59 +0300 Subject: [PATCH 5/7] [fix]: updated log level evaluation --- lib/server.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/server.js b/lib/server.js index ea48563f7..9408abd3c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -409,14 +409,21 @@ app._generateClientId = function(key) { return clientId; }; + +// logging methods + +var _logLevels = { + ERROR: 1, WARN: 2, INFO: 3, DEBUG: 4 +} + app._log = function() { - if (this._options.debug) { + if (this._options.debug === true || this._options.debug >= _logLevels.DEBUG) { console.log.apply(console, arguments); } }; app._warn = function() { - if (this._options.debug > 2 ) { + if (this._options.debug === true || this._options.debug >= _logLevels.WARN ) { console.warn.apply(console, arguments); } }; From b17565f9a0660ce71246cd0e0af3aa8ae5dc1731 Mon Sep 17 00:00:00 2001 From: casi Date: Thu, 17 May 2018 10:46:02 +0300 Subject: [PATCH 6/7] [log]: decreased log level for client check failure --- lib/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/server.js b/lib/server.js index 9408abd3c..a6e8ef063 100644 --- a/lib/server.js +++ b/lib/server.js @@ -209,7 +209,7 @@ app._initializeHTTP = function() { var client; if (!self._clients[key] || !(client = self._clients[key][id])) { if (req.params.retry) { - self._warn('Client check failure on retry for: ', key, id); + self._log('Client check failure on retry for: ', key, id); res.sendStatus(401); return; } else { From f4318bce60923017f023d3ff09fe5736e05a4344 Mon Sep 17 00:00:00 2001 From: casi Date: Thu, 17 May 2018 11:01:41 +0300 Subject: [PATCH 7/7] [version]: bumped module version --- changelog.md | 6 +++++- package.json | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index d990c99d9..b4343de44 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,12 @@ # PeerServer Changelog +### 0.2.11 + +* Decreased error logging for missing peer event. + ### 0.2.10 -* Added some more error logging +* Added some more error logging. ### 0.2.6 diff --git a/package.json b/package.json index b8eeed33e..a54684d6b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peer", - "version": "0.2.10", + "version": "0.2.11", "description": "PeerJS server component", "main": "lib/index.js", "bin": {