Skip to content

Commit

Permalink
Current time is now passed to intervalHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow-rt committed Mar 15, 2018
1 parent 30a21c3 commit 5e93d2f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions scripts/ddos.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ setEventHandler(function(evt) {
block(ip,info,false);
},['ddos_blackhole_attack']);

setIntervalHandler(function() {
var now = (new Date()).getTime();
setIntervalHandler(function(now) {
var threshMs = block_minutes * 60000;
for(var addr in controls) {
if(now - controls[addr].time > threshMs) allow(addr,{},false);
Expand Down
4 changes: 2 additions & 2 deletions scripts/inc/trend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function Trend(maxPoints, stepSize) {
for(i = maxPoints - 1; i >= 0; i--) { t -= stepMs; this.times[i] = t; }
}

Trend.prototype.addPoints = function(values) {
this.times.push((new Date).getTime());
Trend.prototype.addPoints = function(now,values) {
this.times.push(now);

var name, i;
for (name in values) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function calculateTopN(metric,n,minVal,total_pps) {
return topN;
}

setIntervalHandler(function() {
setIntervalHandler(function(now) {
points = {};
var counts = sharedGet('ddos_blackhole_controls_counts') || {};
points['controls'] = counts.n || 0;
Expand All @@ -36,7 +36,7 @@ setIntervalHandler(function() {
points['routes'] = sharedGet('ddos_blackhole_routes') || 0;
points['top-5-targets'] = calculateTopN('ddos_blackhole_target',5,1,0);
points['top-5-protocols'] = calculateTopN('ddos_blackhole_protocol',5,1,0);
trend.addPoints(points);
trend.addPoints(now,points);
}, 1);

setHttpHandler(function(req) {
Expand Down

0 comments on commit 5e93d2f

Please sign in to comment.