2015-10-30 17:55:05 +00:00
|
|
|
// ZeroTier distributed HTTP test coordinator and result-reporting server
|
|
|
|
|
2015-10-28 19:50:48 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
// Customizable parameters:
|
|
|
|
|
|
|
|
var SERVER_PORT = 18080;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2015-10-28 20:14:53 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
|
2015-10-28 19:50:48 +00:00
|
|
|
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 = {};
|
|
|
|
|
2015-11-02 21:17:11 +00:00
|
|
|
app.post('/:agentId',function(req,res) {
|
2015-10-28 19:50:48 +00:00
|
|
|
var agentId = req.params.agentId;
|
|
|
|
if ((!agentId)||(agentId.length !== 32))
|
|
|
|
return res.status(404).send('');
|
2015-10-28 20:14:53 +00:00
|
|
|
|
2015-11-02 21:17:11 +00:00
|
|
|
if (req.rawBody) {
|
|
|
|
var receiveTime = Date.now();
|
|
|
|
var resultData = null;
|
|
|
|
try {
|
|
|
|
resultData = JSON.parse(req.rawBody);
|
2015-11-10 02:01:23 +00:00
|
|
|
console.log(Date.now()+','+resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
|
2015-11-02 21:17:11 +00:00
|
|
|
} catch (e) {}
|
2015-10-28 19:50:48 +00:00
|
|
|
}
|
2015-10-28 20:14:53 +00:00
|
|
|
|
2015-11-02 21:17:11 +00:00
|
|
|
knownAgents[agentId] = Date.now();
|
|
|
|
return res.status(200).send(JSON.stringify(Object.keys(knownAgents)));
|
2015-10-28 19:50:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var expressServer = app.listen(SERVER_PORT,function () {
|
|
|
|
console.log('LISTENING ON '+SERVER_PORT);
|
|
|
|
console.log('');
|
|
|
|
});
|