From eeaffe1f617add92580c6b0240074887a04b8a3a Mon Sep 17 00:00:00 2001 From: calzoneman Date: Wed, 6 Jan 2016 21:42:48 -0800 Subject: [PATCH] Update socket.io to version 1.4.0 --- NEWS.md | 10 ++++++++++ config.template.yaml | 5 +++++ package.json | 4 ++-- src/config.js | 3 ++- src/counters.js | 11 ++++++++++- src/database.js | 2 +- src/io/ioserver.js | 7 +++++-- 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4ad698a4..aec341ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +2016-01-06 +========== + +This release updates socket.io to version 1.4.0. The updates to socket.io +include a few security-related fixes, so please be sure to run `npm install` +to ensure the updated version is installed before restarting your CyTube server. + + * https://nodesecurity.io/advisories/67 + * https://github.com/socketio/engine.io/commit/391ce0dc8b88a6609d88db83ea064040a05ab803 + 2015-10-25 ========== diff --git a/config.template.yaml b/config.template.yaml index f50e2a20..5930aec4 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -105,6 +105,11 @@ io: default-port: 1337 # limit the number of concurrent socket connections per IP address ip-connection-limit: 10 + # Whether or not to use zlib to compress each socket message (this option is + # passed through to socket.io/engine.io). + # Note that while this may save a little bandwidth, it also consumes a lot + # more CPU and will bottleneck pretty quickly under heavy load. + per-message-deflate: false # Mailer details (used for sending password reset links) # see https://github.com/andris9/Nodemailer diff --git a/package.json b/package.json index 27969620..a27b0ab8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.12.1", + "version": "3.13.0", "repository": { "url": "http://github.com/calzoneman/sync" }, @@ -33,7 +33,7 @@ "q": "^1.4.1", "sanitize-html": "git://github.com/calzoneman/sanitize-html", "serve-static": "^1.10.0", - "socket.io": "^1.3.7", + "socket.io": "^1.4.0", "source-map-support": "^0.3.2", "status-message-polyfill": "calzoneman/status-message-polyfill", "yamljs": "^0.1.6" diff --git a/src/config.js b/src/config.js index 5fa5a93b..e437efb8 100644 --- a/src/config.js +++ b/src/config.js @@ -50,7 +50,8 @@ var defaults = { io: { domain: "http://localhost", "default-port": 1337, - "ip-connection-limit": 10 + "ip-connection-limit": 10, + "per-message-deflate": false }, mail: { enabled: false, diff --git a/src/counters.js b/src/counters.js index 21f679a4..7945fe8b 100644 --- a/src/counters.js +++ b/src/counters.js @@ -25,11 +25,20 @@ Socket.prototype.packet = function () { exports.add('socket.io:packet'); }; +function getConnectedSockets() { + var sockets = io.instance.sockets.sockets; + if (typeof sockets.length === 'number') { + return sockets.length; + } else { + return Object.keys(sockets).length; + } +} + setInterval(function () { try { counters['memory:rss'] = process.memoryUsage().rss / 1048576; counters['load:1min'] = os.loadavg()[0]; - counters['socket.io:count'] = io.instance.sockets.sockets.length; + counters['socket.io:count'] = getConnectedSockets(); counterLog.log(JSON.stringify(counters)); } catch (e) { Logger.errlog.log(e.stack); diff --git a/src/database.js b/src/database.js index c26883ee..cfdf14e0 100644 --- a/src/database.js +++ b/src/database.js @@ -583,7 +583,7 @@ module.exports.loadAnnouncement = function () { var sv = Server.getServer(); sv.announcement = announcement; for (var id in sv.ioServers) { - sv.ioServers[id].sockets.emit("announcement", announcement); + sv.ioServers[id].emit("announcement", announcement); } }); }; diff --git a/src/io/ioserver.js b/src/io/ioserver.js index 0f625783..d2e95a87 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -242,6 +242,9 @@ function handleConnection(sock) { module.exports = { init: function (srv, webConfig) { var bound = {}; + const ioOptions = { + perMessageDeflate: Config.get("io.per-message-deflate") + }; var io = sio.instance = sio(); io.use(handleAuth); @@ -259,7 +262,7 @@ module.exports = { } if (id in srv.servers) { - io.attach(srv.servers[id]); + io.attach(srv.servers[id], ioOptions); } else { var server = require("http").createServer().listen(bind.port, bind.ip); server.on("clientError", function (err, socket) { @@ -268,7 +271,7 @@ module.exports = { } catch (e) { } }); - io.attach(server); + io.attach(server, ioOptions); } bound[id] = null;