-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscannor.js
47 lines (41 loc) · 1.1 KB
/
scannor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
const Tools = require("./tools.js");
const archive = require("./archive.js");
const scannor = require("./scannor-oe3.js");
const DO_ARCHIVE = true;
function accountPotentialBlockage(reactor) {
fetchTraffic(decider, reactor);
function decider(data) {
if(!data) {
Tools.log("Could not fetch data.");
return false; // end handling
}
const traffic = scannor.fetch(data);
for(const test of [ scannor.isTunnelBlocked, scannor.isExpresswayBlocked ]) {
const report = test(traffic);
if(report) {
reactor(report);
return true; // done on first encounter and signal handled
} else {
Tools.trace("No current blockage detected.");
return false;
}
}
return false;
}
}
function fetchTraffic(decider) {
scannor.loader.get(scannor.SOURCE, resp => {
let data = "";
resp.on("data", (chunk) => data += chunk);
resp.on("end", () => {
var incidentFound = decider(data);
if(DO_ARCHIVE && incidentFound) {
archive.store(data);
}
});
}).on("error", () => decider(null));
}
if(typeof module !== "undefined") {
module.exports = accountPotentialBlockage;
}