[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [onionoo/release] Fix off-by-one bug in writing history documents.
commit bd2c7af771a64dd393970e2e483c59778b32dbfc
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon Jan 15 11:12:51 2018 +0100
Fix off-by-one bug in writing history documents.
When we consider a history interval from start to end, we really mean
the interval [start, end[. Fixing a few off-by-one bugs in the code.
---
.../java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java | 4 ++--
.../java/org/torproject/onionoo/writer/ClientsDocumentWriter.java | 4 ++--
src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java | 4 ++--
.../java/org/torproject/onionoo/writer/WeightsDocumentWriter.java | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
index 99a5a00..f1c5041 100644
--- a/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/BandwidthDocumentWriter.java
@@ -111,7 +111,7 @@ public class BandwidthDocumentWriter implements DocumentWriter {
long totalBandwidth = 0L;
for (long[] v : history.values()) {
long endMillis = v[1];
- if (endMillis < intervalStartMillis) {
+ if (endMillis <= intervalStartMillis) {
continue;
} else if (endMillis > graphEndMillis) {
break;
@@ -124,7 +124,7 @@ public class BandwidthDocumentWriter implements DocumentWriter {
continue;
}
while ((intervalStartMillis / dataPointInterval)
- != (endMillis / dataPointInterval)) {
+ != ((endMillis - 1L) / dataPointInterval)) {
dataPoints.add(totalMillis * 5L < dataPointInterval
? -1L : (totalBandwidth * DateTimeHelper.ONE_SECOND)
/ totalMillis);
diff --git a/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java
index 834df9c..81168f5 100644
--- a/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/ClientsDocumentWriter.java
@@ -140,13 +140,13 @@ public class ClientsDocumentWriter implements DocumentWriter {
long millis = 0L;
double responses = 0.0;
for (ClientsHistory hist : history) {
- if (hist.getEndMillis() < intervalStartMillis) {
+ if (hist.getEndMillis() <= intervalStartMillis) {
continue;
} else if (hist.getEndMillis() > graphEndMillis) {
break;
}
while ((intervalStartMillis / dataPointInterval)
- != (hist.getEndMillis() / dataPointInterval)) {
+ != ((hist.getEndMillis() - 1L) / dataPointInterval)) {
dataPoints.add(millis * 2L < dataPointInterval
? -1.0 : responses * ((double) DateTimeHelper.ONE_DAY)
/ (((double) millis) * 10.0));
diff --git a/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java
index f739b9e..2aee7a1 100644
--- a/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/UptimeDocumentWriter.java
@@ -175,7 +175,7 @@ public class UptimeDocumentWriter implements DocumentWriter {
}
long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR
* hist.getUptimeHours();
- if (histEndMillis < intervalStartMillis) {
+ if (histEndMillis <= intervalStartMillis) {
continue;
} else if (histEndMillis > graphEndMillis) {
histEndMillis = graphEndMillis;
@@ -218,7 +218,7 @@ public class UptimeDocumentWriter implements DocumentWriter {
}
long histEndMillis = hist.getStartMillis() + DateTimeHelper.ONE_HOUR
* hist.getUptimeHours();
- if (histEndMillis < intervalStartMillis) {
+ if (histEndMillis <= intervalStartMillis) {
continue;
} else if (histEndMillis > graphEndMillis) {
histEndMillis = graphEndMillis;
diff --git a/src/main/java/org/torproject/onionoo/writer/WeightsDocumentWriter.java b/src/main/java/org/torproject/onionoo/writer/WeightsDocumentWriter.java
index ad54fea..10d8a94 100644
--- a/src/main/java/org/torproject/onionoo/writer/WeightsDocumentWriter.java
+++ b/src/main/java/org/torproject/onionoo/writer/WeightsDocumentWriter.java
@@ -132,13 +132,13 @@ public class WeightsDocumentWriter implements DocumentWriter {
long startMillis = e.getKey()[0];
long endMillis = e.getKey()[1];
double weight = e.getValue()[graphTypeIndex];
- if (endMillis < intervalStartMillis) {
+ if (endMillis <= intervalStartMillis) {
continue;
} else if (endMillis > graphEndMillis) {
break;
}
while ((intervalStartMillis / dataPointInterval)
- != (endMillis / dataPointInterval)) {
+ != ((endMillis - 1L) / dataPointInterval)) {
dataPoints.add(totalMillis * 5L < dataPointInterval
? -1.0 : totalWeightTimesMillis / (double) totalMillis);
totalWeightTimesMillis = 0.0;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits