Commit 1c3bcae7 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

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.
parent 037f4637
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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 + "'.");