diff options
| author | iwakeh <iwakeh@torproject.org> | 2018-03-26 11:01:56 +0000 |
|---|---|---|
| committer | iwakeh <iwakeh@torproject.org> | 2018-03-26 11:01:57 +0000 |
| commit | 8175766daa48babef45fbe2de2221e5f5c1d6a17 (patch) | |
| tree | 12b635f03619af48f7f320812d739d603b7014cf | |
| parent | 970dd3d1e1757d01b485fe05b1869cfc244e82f2 (diff) | |
Prevent weird values in cut-off time calculation.task-20224
Rename variable to include the unit (which is days).
Log cut-off date on info level.
Implements task-20224.
| -rw-r--r-- | src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java index af54e03..f174474 100644 --- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java +++ b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java @@ -3,6 +3,8 @@ package org.torproject.collector.bridgedescs; +import static java.time.ZoneOffset.UTC; + import org.torproject.collector.conf.Annotation; import org.torproject.collector.conf.Configuration; import org.torproject.collector.conf.ConfigurationException; @@ -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,22 +196,22 @@ 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); + if (limitBridgeSanitizingIntervalDays >= 0L) { + this.bridgeSanitizingCutOffTimestamp = LocalDateTime.now(UTC) + .minusDays(limitBridgeSanitizingIntervalDays) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); } else { this.bridgeSanitizingCutOffTimestamp = "1999-12-31 23:59:59"; } + logger.info("Using cut-off datetime '{}' for secrets.", + this.bridgeSanitizingCutOffTimestamp); + // Prepare bridge descriptor parser BridgeDescriptorParser bdp = new BridgeDescriptorParser(this); |
