[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [collector/release] Prevent weird values in cut-off time calculation.
commit 9d8a0ae6ece69746d17e4255a67cf50700018d6a
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date: Mon Mar 26 11:01:56 2018 +0000
Prevent weird values in cut-off time calculation.
Rename variable to include the unit (which is days).
Log cut-off date on info level.
Implements task-20224.
---
CHANGELOG.md | 3 ++
.../bridgedescs/SanitizedBridgesWriter.java | 32 ++++++++++++++--------
2 files changed, 24 insertions(+), 11 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e914f2f..31788f1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@
org.torproject.metrics.collector and ..index to ..indexer.
- Fix a bug in the tarball-creation script where tarballs might not
have been compressed in a run following an aborted run.
+ - Prevent weird values when calculating the cut-off date for
+ storing bridge sanitizer secrets using inf as the default value
+ of BridgeDescriptorMappingsLimit.
# Changes in version 1.6.0 - 2018-05-23
diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
index 23b91ad..8f28a2b 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -3,6 +3,8 @@
package org.torproject.metrics.collector.bridgedescs;
+import static java.time.ZoneOffset.UTC;
+
import org.torproject.descriptor.BridgeExtraInfoDescriptor;
import org.torproject.descriptor.BridgeNetworkStatus;
import org.torproject.descriptor.BridgeServerDescriptor;
@@ -32,6 +34,8 @@ import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -192,21 +196,27 @@ public class SanitizedBridgesWriter extends CollecTorMain {
}
}
- long limitBridgeSanitizingInterval =
- config.getInt(Key.BridgeDescriptorMappingsLimit);
+ long limitBridgeSanitizingIntervalDays
+ = config.getInt(Key.BridgeDescriptorMappingsLimit);
/* If we're configured to keep secrets only for a limited time, define
* the cut-off day and time. */
- if (limitBridgeSanitizingInterval >= 0L) {
- SimpleDateFormat formatter = new SimpleDateFormat(
- "yyyy-MM-dd HH:mm:ss");
- formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
- this.bridgeSanitizingCutOffTimestamp = formatter.format(
- System.currentTimeMillis() - 24L * 60L * 60L * 1000L
- * limitBridgeSanitizingInterval);
- } else {
- this.bridgeSanitizingCutOffTimestamp = "1999-12-31 23:59:59";
+ LocalDateTime bridgeSanitizingCutOffDateTime
+ = LocalDateTime.of(1999, 12, 31, 23, 59, 59);
+ if (limitBridgeSanitizingIntervalDays >= 0L) {
+ LocalDateTime configuredBridgeSanitizingCutOffDateTime
+ = LocalDateTime.now(UTC).minusDays(limitBridgeSanitizingIntervalDays);
+ if (configuredBridgeSanitizingCutOffDateTime.isAfter(
+ bridgeSanitizingCutOffDateTime)) {
+ bridgeSanitizingCutOffDateTime
+ = configuredBridgeSanitizingCutOffDateTime;
+ }
}
+ this.bridgeSanitizingCutOffTimestamp = bridgeSanitizingCutOffDateTime
+ .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+
+ logger.info("Using cut-off datetime '{}' for secrets.",
+ this.bridgeSanitizingCutOffTimestamp);
// Prepare bridge descriptor parser
BridgeDescriptorParser bdp = new BridgeDescriptorParser(this);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits