summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-22 10:41:15 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-22 10:41:15 -0700
commit1bc451ed10b43e7c1113c9d8129ad468821ab0cb (patch)
tree173122796efd1adab89c9b142a162140905d206e
parente07bae2525c21002b8e61a2ecc57fa1e17764241 (diff)
downloadinfinitytier-1bc451ed10b43e7c1113c9d8129ad468821ab0cb.tar.gz
infinitytier-1bc451ed10b43e7c1113c9d8129ad468821ab0cb.zip
GeoIP cluster service works.
-rwxr-xr-xcluster-geo/cluster-geo.exe2
-rw-r--r--cluster-geo/cluster-geo/cluster-geo.js28
-rw-r--r--service/ClusterGeoIpService.cpp3
3 files changed, 19 insertions, 14 deletions
diff --git a/cluster-geo/cluster-geo.exe b/cluster-geo/cluster-geo.exe
index 20bc487a..7ca791af 100755
--- a/cluster-geo/cluster-geo.exe
+++ b/cluster-geo/cluster-geo.exe
@@ -3,7 +3,7 @@
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
cd `dirname $0`
-if [ ! -d cluster-geo -o ! -f cluster-geo/index.js ]; then
+if [ ! -d cluster-geo -o ! -f cluster-geo/cluster-geo.js ]; then
echo 'Cannot find ./cluster-geo containing NodeJS script files.'
exit 1
fi
diff --git a/cluster-geo/cluster-geo/cluster-geo.js b/cluster-geo/cluster-geo/cluster-geo.js
index 0e903ade..44af8492 100644
--- a/cluster-geo/cluster-geo/cluster-geo.js
+++ b/cluster-geo/cluster-geo/cluster-geo.js
@@ -1,3 +1,5 @@
+"use strict";
+
//
// GeoIP lookup service
//
@@ -20,10 +22,10 @@ function lookup(ip,callback)
cache.get(ip,function(err,cachedEntryJson) {
if ((!err)&&(cachedEntryJson)) {
try {
- var cachedEntry = JSON.parse(cachedEntryJson.toString());
+ let cachedEntry = JSON.parse(cachedEntryJson.toString());
if (cachedEntry) {
- var ts = cachedEntry.ts;
- var r = cachedEntry.r;
+ let ts = cachedEntry.ts;
+ let r = cachedEntry.r;
if ((ts)&&(r)) {
if ((Date.now() - ts) < CACHE_TTL) {
r._cached = true;
@@ -57,24 +59,24 @@ process.stdin.on('readable',function() {
var chunk;
while (null !== (chunk = process.stdin.read())) {
for(var i=0;i<chunk.length;++i) {
- var c = chunk[i];
+ let c = chunk[i];
if ((c == 0x0d)||(c == 0x0a)) {
if (linebuf.length > 0) {
- var ip = linebuf;
+ let ip = linebuf;
lookup(ip,function(err,result) {
if ((err)||(!result)||(!result.location)) {
return process.stdout.write(ip+',0,0,0,0,0,0\n');
} else {
- var lat = parseFloat(result.location.latitude);
- var lon = parseFloat(result.location.longitude);
+ let lat = parseFloat(result.location.latitude);
+ let lon = parseFloat(result.location.longitude);
// Convert to X,Y,Z coordinates from Earth's origin, Earth-as-sphere approximation.
- var latRadians = lat * 0.01745329251994; // PI / 180
- var lonRadians = lon * 0.01745329251994; // PI / 180
- var cosLat = Math.cos(latRadians);
- var x = Math.round((-6371.0) * cosLat * Math.cos(lonRadians)); // 6371 == Earth's approximate radius in kilometers
- var y = Math.round(6371.0 * Math.sin(latRadians));
- var z = Math.round(6371.0 * cosLat * Math.sin(lonRadians));
+ let latRadians = lat * 0.01745329251994; // PI / 180
+ let lonRadians = lon * 0.01745329251994; // PI / 180
+ let cosLat = Math.cos(latRadians);
+ let x = Math.round((-6371.0) * cosLat * Math.cos(lonRadians)); // 6371 == Earth's approximate radius in kilometers
+ let y = Math.round(6371.0 * Math.sin(latRadians));
+ let z = Math.round(6371.0 * cosLat * Math.sin(lonRadians));
return process.stdout.write(ip+',1,'+lat+','+lon+','+x+','+y+','+z+'\n');
}
diff --git a/service/ClusterGeoIpService.cpp b/service/ClusterGeoIpService.cpp
index 00d95d7e..83afe770 100644
--- a/service/ClusterGeoIpService.cpp
+++ b/service/ClusterGeoIpService.cpp
@@ -37,6 +37,8 @@
#include <signal.h>
#include <errno.h>
+#include <iostream>
+
#include "ClusterGeoIpService.hpp"
#include "../node/Utils.hpp"
#include "../osdep/OSUtils.hpp"
@@ -163,6 +165,7 @@ void ClusterGeoIpService::threadMain()
{
Mutex::Lock _l2(_cache_m);
_cache[rip] = ce;
+ std::cout << ">> " << linebuf << std::endl;
}
}
}