Fix frontend not updating publicConfig.json

This changes the handshake sequence to use “bootTime” (a unique key
based off the time) to make sure the frontend configuration matches the
current one. If not, the client pulls the update and validates before
requesting the listing.
This commit is contained in:
Cryptkeeper
2016-02-06 18:26:29 -06:00
parent 143e99876a
commit 798dda8f12
5 changed files with 86 additions and 44 deletions

View File

@ -4,6 +4,7 @@ var url = require('url');
var mime = require('mime');
var io = require('socket.io');
var util = require('./util');
var logger = require('./logger');
var config = require('../config.json');
@ -65,7 +66,8 @@ function handleRequest(req, res) {
var publicConfig = {
categories: categories,
graphDuration: config.graphDuration,
servers: servers
servers: servers,
bootTime: util.getBootTime()
};
res.write('setPublicConfig(' + JSON.stringify(publicConfig) + ');');

View File

@ -3,7 +3,9 @@ var logger = require('./logger');
var config = require('../config.json');
var servers = require('../servers.json');
var serverNameLookup = {};
var serverNameLookup = [];
var bootTime;
// Finds a server in servers.json with a matching IP.
// If it finds one, it caches the result for faster future lookups.
@ -136,4 +138,14 @@ exports.convertPingsToGraph = function(sqlData) {
logger.info('Converted data structure in ' + (exports.getCurrentTimeMs() - startTime) + 'ms');
return graphData;
};
exports.getBootTime = function() {
if (!bootTime) {
bootTime = exports.getCurrentTimeMs();
logger.info('Selected %d as boot time.', bootTime);
}
return bootTime;
};