[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [ernie/master 2/2] Warn if local cached-* files are stale.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon, 12 Apr 2010 15:57:44 +0200
Subject: Warn if local cached-* files are stale.
Commit: 0ed7a26e59b9a61d730a6c0c29a54749cefb66e4
---
src/CachedRelayDescriptorReader.java | 29 +++++++++++++++++++++++++++++
1 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/CachedRelayDescriptorReader.java b/src/CachedRelayDescriptorReader.java
index 89fa3fe..80cfca9 100644
--- a/src/CachedRelayDescriptorReader.java
+++ b/src/CachedRelayDescriptorReader.java
@@ -1,4 +1,6 @@
import java.io.*;
+import java.text.*;
+import java.util.*;
import java.util.logging.*;
/**
@@ -29,6 +31,30 @@ public class CachedRelayDescriptorReader {
bis.close();
byte[] allData = baos.toByteArray();
if (f.getName().equals("cached-consensus")) {
+ /* Check if directory information is stale. */
+ BufferedReader br = new BufferedReader(new StringReader(
+ new String(allData, "US-ASCII")));
+ String line = null;
+ while ((line = br.readLine()) != null) {
+ if (line.startsWith("valid-after ")) {
+ SimpleDateFormat dateTimeFormat =
+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ if (dateTimeFormat.parse(line.substring("valid-after ".
+ length())).getTime() < System.currentTimeMillis()
+ - 6L * 60L * 60L * 1000L) {
+ logger.warning("Cached descriptor files in "
+ + cachedDescDir.getAbsolutePath() + " are stale. "
+ + "The valid-after line in cached-consensus is '"
+ + line + "'.");
+ }
+ break;
+ }
+ }
+ br.close();
+
+ /* Parse the cached consensus (regardless of whether it's
+ * stale or not. */
if (rdp != null) {
rdp.parse(allData);
}
@@ -67,6 +93,9 @@ public class CachedRelayDescriptorReader {
} catch (IOException e) {
logger.log(Level.WARNING, "Failed reading cacheddesc/ "
+ "directory.", e);
+ } catch (ParseException e) {
+ logger.log(Level.WARNING, "Failed reading cacheddesc/ "
+ + "directory.", e);
}
}
}
--
1.6.5