summaryrefslogtreecommitdiff
path: root/attic/big-http-test/server.js
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-01-06 11:06:47 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-01-06 11:06:47 -0800
commit0a3ef38cade03c9b6a4f94611bd3df620ce1f4e6 (patch)
treefeaa8fb701c0822ec43afafc4deb156f4c76bd96 /attic/big-http-test/server.js
parent9aee72099e518636acb243237042049c50dcf483 (diff)
downloadinfinitytier-0a3ef38cade03c9b6a4f94611bd3df620ce1f4e6.tar.gz
infinitytier-0a3ef38cade03c9b6a4f94611bd3df620ce1f4e6.zip
Put old test code in attic.
Diffstat (limited to 'attic/big-http-test/server.js')
-rw-r--r--attic/big-http-test/server.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/attic/big-http-test/server.js b/attic/big-http-test/server.js
new file mode 100644
index 00000000..629784da
--- /dev/null
+++ b/attic/big-http-test/server.js
@@ -0,0 +1,53 @@
+// ZeroTier distributed HTTP test coordinator and result-reporting server
+
+// ---------------------------------------------------------------------------
+// Customizable parameters:
+
+var SERVER_PORT = 18080;
+
+// ---------------------------------------------------------------------------
+
+var fs = require('fs');
+
+var express = require('express');
+var app = express();
+
+app.use(function(req,res,next) {
+ req.rawBody = '';
+ req.on('data', function(chunk) { req.rawBody += chunk.toString(); });
+ req.on('end', function() { return next(); });
+});
+
+var knownAgents = {};
+
+app.post('/:agentId',function(req,res) {
+ var agentId = req.params.agentId;
+ if ((!agentId)||(agentId.length !== 32))
+ return res.status(404).send('');
+
+ if (req.rawBody) {
+ var receiveTime = Date.now();
+ var resultData = null;
+ try {
+ resultData = JSON.parse(req.rawBody);
+ console.log(Date.now().toString()+','+resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
+ } catch (e) {}
+ }
+
+ knownAgents[agentId] = true;
+ var thisUpdate = [];
+ var agents = Object.keys(knownAgents);
+ if (agents.length < 100)
+ thisUpdate = agents;
+ else {
+ for(var xx=0;xx<100;++xx)
+ thisUpdate.push(agents[Math.floor(Math.random() * agents.length)]);
+ }
+
+ return res.status(200).send(JSON.stringify(thisUpdate));
+});
+
+var expressServer = app.listen(SERVER_PORT,function () {
+ console.log('LISTENING ON '+SERVER_PORT);
+ console.log('');
+});