Fix `BridgeDescriptorMappingsLimit` config option
The BridgeDescriptorMappingsLimit
option doesn't work as expected with its default value inf
or with other sufficiently large values. Here's where that configuration value is used (https://gitweb.torproject.org/collector.git/tree/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java#n183):
this.bridgeSanitizingCutOffTimestamp = formatter.format(
System.currentTimeMillis() - 24L * 60L * 60L * 1000L
* limitBridgeSanitizingInterval);
For limitBridgeSanitizingInterval = Integer.MAX_VALUE
, we'd try to format 1474617184667 - 86400000 * 2147483647 = -1.855E+017
milliseconds since the epoch. In theory, that large negative value should still fit into the long
, but somehow it gets formatted as 5877475-11-25 07:53:04
, which is in the future rather than in the past.
Anyway, I stopped digging what the exact bug might be, and instead suggest this possible fix:
diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
index b61cd30..b8674a3 100644
--- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -180,9 +180,9 @@ public class SanitizedBridgesWriter extends CollecTorMain {
SimpleDateFormat formatter = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
- this.bridgeSanitizingCutOffTimestamp = formatter.format(
+ this.bridgeSanitizingCutOffTimestamp = formatter.format(Math.max(-1L,
System.currentTimeMillis() - 24L * 60L * 60L * 1000L
- * limitBridgeSanitizingInterval);
+ * limitBridgeSanitizingInterval));
} else {
this.bridgeSanitizingCutOffTimestamp = "1999-12-31 23:59:59";
}