[tor-commits] [metrics-lib/master] Parse exit lists with @type annotation and Downloaded line.
karsten at torproject.org
karsten at torproject.org
Thu May 31 14:00:41 UTC 2012
commit 194768b33ffd36a3690a714cdbccb3b27a762fb5
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Thu May 31 16:00:09 2012 +0200
Parse exit lists with @type annotation and Downloaded line.
---
src/org/torproject/descriptor/ExitList.java | 4 ++--
.../torproject/descriptor/impl/DescriptorImpl.java | 3 ++-
.../torproject/descriptor/impl/ExitListImpl.java | 20 ++++++++++++--------
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/src/org/torproject/descriptor/ExitList.java b/src/org/torproject/descriptor/ExitList.java
index 5372b8b..dc4a1f9 100644
--- a/src/org/torproject/descriptor/ExitList.java
+++ b/src/org/torproject/descriptor/ExitList.java
@@ -7,8 +7,8 @@ import java.util.Set;
/* Exit list containing all known exit scan results at a given time. */
public interface ExitList extends Descriptor {
- /* Return the publication time of the exit list. */
- public long getPublishedMillis();
+ /* Return the download time of the exit list. */
+ public long getDownloadedMillis();
/* Return the unordered set of exit scan results. */
public Set<ExitListEntry> getExitListEntries();
diff --git a/src/org/torproject/descriptor/impl/DescriptorImpl.java b/src/org/torproject/descriptor/impl/DescriptorImpl.java
index 00a4b16..c1c4a9a 100644
--- a/src/org/torproject/descriptor/impl/DescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/DescriptorImpl.java
@@ -70,7 +70,8 @@ public abstract class DescriptorImpl implements Descriptor {
parsedDescriptors.addAll(DirectoryKeyCertificateImpl.
parseDescriptors(rawDescriptorBytes,
failUnrecognizedDescriptorLines));
- } else if (firstLines.startsWith("ExitNode ") ||
+ } else if (firstLines.startsWith("@type tordnsel 1.") ||
+ firstLines.startsWith("ExitNode ") ||
firstLines.contains("\nExitNode ")) {
parsedDescriptors.add(new ExitListImpl(rawDescriptorBytes, fileName,
failUnrecognizedDescriptorLines));
diff --git a/src/org/torproject/descriptor/impl/ExitListImpl.java b/src/org/torproject/descriptor/impl/ExitListImpl.java
index 277112f..8683cce 100644
--- a/src/org/torproject/descriptor/impl/ExitListImpl.java
+++ b/src/org/torproject/descriptor/impl/ExitListImpl.java
@@ -21,24 +21,25 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
boolean failUnrecognizedDescriptorLines)
throws DescriptorParseException {
super(rawDescriptorBytes, failUnrecognizedDescriptorLines, false);
- this.setPublishedMillisFromFileName(fileName);
this.splitAndParseExitListEntries(rawDescriptorBytes);
+ this.setPublishedMillisFromFileName(fileName);
}
private void setPublishedMillisFromFileName(String fileName)
throws DescriptorParseException {
- if (fileName.length() == "2012-02-01-04-06-24".length()) {
+ if (this.downloadedMillis == 0L &&
+ fileName.length() == "2012-02-01-04-06-24".length()) {
try {
SimpleDateFormat fileNameFormat = new SimpleDateFormat(
"yyyy-MM-dd-HH-mm-ss");
fileNameFormat.setLenient(false);
fileNameFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- this.publishedMillis = fileNameFormat.parse(fileName).getTime();
+ this.downloadedMillis = fileNameFormat.parse(fileName).getTime();
} catch (ParseException e) {
/* Handle below. */
}
}
- if (this.publishedMillis == 0L) {
+ if (this.downloadedMillis == 0L) {
throw new DescriptorParseException("Unrecognized exit list file "
+ "name '" + fileName + "'.");
}
@@ -56,7 +57,10 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
String line = s.next();
String[] parts = line.split(" ");
String keyword = parts[0];
- if (keyword.equals("ExitNode")) {
+ if (keyword.equals("Downloaded")) {
+ this.downloadedMillis = ParseHelper.parseTimestampAtIndex(line,
+ parts, 1, 2);
+ } else if (keyword.equals("ExitNode")) {
sb = new StringBuilder();
sb.append(line + "\n");
} else if (keyword.equals("Published")) {
@@ -94,9 +98,9 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
}
}
- private long publishedMillis;
- public long getPublishedMillis() {
- return this.publishedMillis;
+ private long downloadedMillis;
+ public long getDownloadedMillis() {
+ return this.downloadedMillis;
}
private Set<ExitListEntry> exitListEntries =
More information about the tor-commits
mailing list