[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Change order of detecting descriptor types.
commit 1c3bcae76d92781fa7f7de86a3dcb6449bd3579d
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Thu Apr 30 22:06:53 2020 +0200
Change order of detecting descriptor types.
We are detecting descriptor types of parsed descriptors by either
content or file name. In some cases, if we downloaded descriptors from
web servers, there is no file name. In other cases the file name can
match more than one descriptor type. It seems most robust to move the
file name checks to the end, which includes web server access logs and
OnionPerf analysis files.
---
.../torproject/descriptor/impl/DescriptorParserImpl.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
index 7dcd9d2..e008e7a 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorParserImpl.java
@@ -131,9 +131,6 @@ public class DescriptorParserImpl implements DescriptorParser {
} else if (firstLines.startsWith("@type torperf 1.")) {
return TorperfResultImpl.parseTorperfResults(rawDescriptorBytes,
sourceFile);
- } else if (fileName.endsWith(".onionperf.analysis.json.xz")) {
- return new OnionPerfAnalysisConverter(rawDescriptorBytes, sourceFile)
- .asTorperfResults();
} else if (firstLines.startsWith("@type snowflake-stats 1.")
|| firstLines.startsWith(Key.SNOWFLAKE_STATS_END.keyword + SP)
|| firstLines.contains(NL + Key.SNOWFLAKE_STATS_END.keyword + SP)) {
@@ -144,8 +141,6 @@ public class DescriptorParserImpl implements DescriptorParser {
|| firstLines.contains(NL + Key.BRIDGEDB_METRICS_END.keyword + SP)) {
return this.parseOneOrMoreDescriptors(rawDescriptorBytes, sourceFile,
Key.BRIDGEDB_METRICS_END, BridgedbMetricsImpl.class);
- } else if (fileName.contains(LogDescriptorImpl.MARKER)) {
- return LogDescriptorImpl.parse(rawDescriptorBytes, sourceFile, fileName);
} else if (firstLines.startsWith("@type bandwidth-file 1.")
|| firstLines.matches("(?s)[0-9]{10}\\n.*")) {
/* Identifying bandwidth files by a 10-digit timestamp in the first line
@@ -156,6 +151,14 @@ public class DescriptorParserImpl implements DescriptorParser {
parsedDescriptors.add(new BandwidthFileImpl(rawDescriptorBytes,
sourceFile));
return parsedDescriptors;
+ } else if (null != fileName
+ && fileName.contains(LogDescriptorImpl.MARKER)) {
+ return LogDescriptorImpl.parse(rawDescriptorBytes, sourceFile,
+ fileName);
+ } else if (null != fileName
+ && fileName.endsWith(".onionperf.analysis.json.xz")) {
+ return new OnionPerfAnalysisConverter(rawDescriptorBytes, sourceFile)
+ .asTorperfResults();
} else {
throw new DescriptorParseException("Could not detect descriptor "
+ "type in descriptor starting with '" + firstLines + "'.");
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits