diff --git a/lib/fsWatcher.js b/lib/fsWatcher.js index 44e6180..ecd9a65 100644 --- a/lib/fsWatcher.js +++ b/lib/fsWatcher.js @@ -1,6 +1,6 @@ var fs = require('fs'), path = require('path'), - FSWatcher = {}; + FSWatcher = {} /** * Takes a directory/file and watch for change. Upon change, call the @@ -14,44 +14,44 @@ var fs = require('fs'), * @param {Function} callback: function () : called when changes are detected **/ function makeFsWatchFilter(name, directory, filename, cooldownDelay, callback) { - var cooldownId = null; + var cooldownId = null //Delete the cooldownId and callback the outer function function timeoutCallback() { - cooldownId = null; - callback(); + cooldownId = null + callback() } //This function is called when there is a change in the data directory //It sets a timer to wait for the change to be completed function onWatchEvent(event, changedFile) { - var filePath = path.join(directory, changedFile); + var filePath = path.join(directory, changedFile) if (!filename || filename === changedFile) { - if(!fs.existsSync(filePath)) return; + if(!fs.existsSync(filePath)) return //If a cooldownId already exists, we delete it if (cooldownId !== null) { - clearTimeout(cooldownId); - cooldownId = null; + clearTimeout(cooldownId) + cooldownId = null } //Once the cooldownDelay has passed, the timeoutCallback function will be called - cooldownId = setTimeout(timeoutCallback, cooldownDelay); + cooldownId = setTimeout(timeoutCallback, cooldownDelay) } } //Manage the case where filename is missing (because it's optionnal) if (typeof cooldownDelay === 'function') { - callback = cooldownDelay; - cooldownDelay = filename; - filename = null; + callback = cooldownDelay + cooldownDelay = filename + filename = null } if (FSWatcher[name]) { - stopWatching(name); + stopWatching(name) } - FSWatcher[name] = fs.watch(directory, onWatchEvent); + FSWatcher[name] = fs.watch(directory, onWatchEvent) } /** @@ -61,8 +61,8 @@ function makeFsWatchFilter(name, directory, filename, cooldownDelay, callback) { * **/ function stopWatching(name) { - FSWatcher[name].close(); + FSWatcher[name].close() } -module.exports.makeFsWatchFilter = makeFsWatchFilter; -module.exports.stopWatching = stopWatching; +module.exports.makeFsWatchFilter = makeFsWatchFilter +module.exports.stopWatching = stopWatching diff --git a/lib/geoip.js b/lib/geoip.js index a310b36..a1fcf33 100644 --- a/lib/geoip.js +++ b/lib/geoip.js @@ -154,7 +154,7 @@ function lookup4(ip) { } } fline = cline * start / fastLookupNum | 0 - cline = cline * end / fastLookupNum | 0; + cline = cline * end / fastLookupNum | 0 for(;;) { line = fline + cline >> 1 @@ -208,7 +208,7 @@ function lookup6(ip) { } } fline = cline * start / fastLookupNum | 0 - cline = cline * end / fastLookupNum | 0; + cline = cline * end / fastLookupNum | 0 for(;;) { line = fline + cline >> 1 @@ -219,7 +219,7 @@ function lookup6(ip) { cline = line continue } - + if(buffer.readBigUInt64BE(offset + 8) < ip){ if(fline === line) { return null @@ -473,7 +473,7 @@ module.exports = { }) }, - // Start watching for data updates. The watcher waits one minute for file transfer to + // Start watching for data updates. The watcher waits one minute for file transfer to // completete before triggering the callback. startWatchingDataUpdate: function (callback) { fsWatcher.makeFsWatchFilter(watcherName, geodatadir, 60*1000, function () { diff --git a/lib/utils.js b/lib/utils.js index 56d3aae..ae19aaa 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,63 +1,63 @@ -var utils = module.exports = {}; +var utils = module.exports = {} utils.fieldsSize = function(types){ - var size = 0; + var size = 0 for(var type of types){ switch(type){ case 'postcode': size += 5 - break; + break case 'area': - size += 2; - break; + size += 2 + break default: - size += 4; - break; + size += 4 + break } } return size } utils.aton4 = function(a) { - a = a.split(/\./); - return ((parseInt(a[0], 10)<<24)>>>0) + ((parseInt(a[1], 10)<<16)>>>0) + ((parseInt(a[2], 10)<<8)>>>0) + (parseInt(a[3], 10)>>>0); -}; + a = a.split(/\./) + return ((parseInt(a[0], 10)<<24)>>>0) + ((parseInt(a[1], 10)<<16)>>>0) + ((parseInt(a[2], 10)<<8)>>>0) + (parseInt(a[3], 10)>>>0) +} utils.aton6 = function(a) { - a = a.replace(/"/g, '').split(/:/); + a = a.replace(/"/g, '').split(/:/) - var l = a.length - 1; - var i; + var l = a.length - 1 + var i - if (a[l] === '') a[l] = 0; + if (a[l] === '') a[l] = 0 if (l < 7) { - var omitted = 8 - a.length, omitStart = a.indexOf(''), omitEnd = omitStart + omitted; + var omitted = 8 - a.length, omitStart = a.indexOf(''), omitEnd = omitStart + omitted for(i = 7; i >= omitStart; i--){ - a[i] = i > omitEnd ? a[i - omitted] : 0; + a[i] = i > omitEnd ? a[i - omitted] : 0 } } - var r = 0n; + var r = 0n for (i = 0; i < 4; i++) { if(a[i]) { - r += BigInt(parseInt(a[i], 16)) << BigInt(16 * (3 - i)); + r += BigInt(parseInt(a[i], 16)) << BigInt(16 * (3 - i)) } } - return r; -}; + return r +} utils.isPrivateIP = function(addr) { - addr = addr.toString(); + addr = addr.toString() return addr.match(/^10\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) != null || addr.match(/^192\.168\.([0-9]{1,3})\.([0-9]{1,3})/) != null || addr.match(/^172\.16\.([0-9]{1,3})\.([0-9]{1,3})/) != null || addr.match(/^127\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/) != null || addr.match(/^169\.254\.([0-9]{1,3})\.([0-9]{1,3})/) != null || - addr.match(/^fc00:/) != null || addr.match(/^fe80:/) != null; -}; + addr.match(/^fc00:/) != null || addr.match(/^fe80:/) != null +} utils.ntoa4 = function(n) { - n = n.toString(); - n = '' + (n>>>24&0xff) + '.' + (n>>>16&0xff) + '.' + (n>>>8&0xff) + '.' + (n&0xff); - return n; -}; + n = n.toString() + n = '' + (n>>>24&0xff) + '.' + (n>>>16&0xff) + '.' + (n>>>8&0xff) + '.' + (n&0xff) + return n +} diff --git a/scripts/updatedb.js b/scripts/updatedb.js index 8c291a2..a470c6d 100644 --- a/scripts/updatedb.js +++ b/scripts/updatedb.js @@ -483,7 +483,6 @@ function processCountryDataIpLocationDb(src, fileName, srcUrl, cb) { if(!datFile.write(b)){ rl.pause() } - preCC = cc } } @@ -749,7 +748,7 @@ function processCityDataNamesEn(src, dest, cb) { } } var rl = readline.createInterface({ - input: fs.createReadStream(tmpDataFile), + input: fs.createReadStream(tmpDataFile), crlfDelay: Infinity }) rl.on('line', processLine) @@ -830,7 +829,7 @@ function processCityDataNames(src, dest, cb) { var datFile = fs.createWriteStream(dataFile, {highWaterMark: 1024 * 1024}) var rl = readline.createInterface({ - input: fs.createReadStream(tmpDataFile, {highWaterMark: 1024 * 1024}), + input: fs.createReadStream(tmpDataFile, {highWaterMark: 1024 * 1024}), crlfDelay: Infinity }) rl.on('line', processLine) @@ -942,7 +941,7 @@ if(ip_location_db){ console.log('Fetching new databases from MaxMind...') console.log('Storing files at ' + dataPath) - + async.eachSeries(databases, function(database, nextDatabase) { if(isDebug){ async.seq(processData)(database, nextDatabase)