Skip to content

Commit 36d380b

Browse files
committed
bugfix
1 parent 266b786 commit 36d380b

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

v3/opt_togetherjs/server.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ var server = http.createServer(function(request, response) {
305305
request.connection.remoteAddress ||
306306
request.socket.remoteAddress ||
307307
(request.connection.socket ? request.connection.socket.remoteAddress : null);
308+
var ipBasedId = 'IP_' + ip;
308309

309310
// if we don't have a user_uuid, use IP address as the next best proxy for unique user identity
310311
var uniqueId = url.query.user_uuid;
311312
if (!uniqueId) {
312-
uniqueId = 'IP_' + ip;
313+
uniqueId = ipBasedId;
313314
}
315+
314316
allRecentHelpQueueQueries.set(uniqueId, Object.assign({ip: ip}, url.query));
315317

316318
response.writeHead(200, {
@@ -320,7 +322,7 @@ var server = http.createServer(function(request, response) {
320322
// don't forget to pass in uniqueId since we want to know whether to
321323
// hide some entries on the queue based on whether uniqueId has been
322324
// banned from those sessions:
323-
response.end(JSON.stringify(getPHRStats(uniqueId)));
325+
response.end(JSON.stringify(getPHRStats(uniqueId, ipBasedId)));
324326
} else if (url.pathname == '/getNumObservers') { // pgbovine
325327
if (request.method == "OPTIONS") {
326328
// CORS preflight
@@ -398,7 +400,7 @@ var server = http.createServer(function(request, response) {
398400
var nowTime = Date.now();
399401
response.end(JSON.stringify({
400402
curTime: nowTime,
401-
queue: getPHRStats(undefined),
403+
queue: getPHRStats(undefined, undefined),
402404
freem: {errcode: err ? err.code : null, stdout: stdout, stderr: stderr},
403405
connectionStats: connectionStats}));
404406
});
@@ -1014,7 +1016,7 @@ function removeFromPHRQueue(id) {
10141016
}
10151017
}
10161018

1017-
function getPHRStats(uniqueId) {
1019+
function getPHRStats(uniqueId, ipBasedId) {
10181020
var ret = [];
10191021
publicHelpRequestQueue.forEach(function(e) {
10201022
var timeSinceCreation;
@@ -1034,11 +1036,14 @@ function getPHRStats(uniqueId) {
10341036
numClients = stat.numClients;
10351037
numChatters = stat.chatters.length;
10361038

1037-
// only enforce if uniqueId has been passed in ...
1038-
if (uniqueId && stat.bannedUsers) {
1039+
// 2019-03-26: since we are always enforcing bannedUsers by IP
1040+
// addresses now, DON'T use uniqueId inside here; use ipBasedId
1041+
1042+
// only enforce if ipBasedId has been passed in ...
1043+
if (ipBasedId && stat.bannedUsers) {
10391044
for (var i=0; i < stat.bannedUsers.length; i++) {
10401045
var elt = stat.bannedUsers[i];
1041-
if (elt === uniqueId) {
1046+
if (elt === ipBasedId) {
10421047
return; // GET OUTTA HERE EARLY! we've been banned from this session, so don't add this to the list
10431048
}
10441049
}
@@ -1068,7 +1073,7 @@ function logPHRStats() {
10681073
var logObj = {};
10691074
logObj.date = (new Date()).toISOString();
10701075
logObj.type = 'PHRStats';
1071-
logObj.queue = getPHRStats(undefined);
1076+
logObj.queue = getPHRStats(undefined, undefined);
10721077
logObj.recentQueries = [...allRecentHelpQueueQueries]; // spread operator
10731078
pgLogWrite(logObj);
10741079
//console.log(logObj);

0 commit comments

Comments
 (0)