Commit 45ad8a0d authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Make unrecognized keys of Torperf results available.

parent 6f561bef
......@@ -4,6 +4,8 @@
- Include the hostname in directory source entries of consensuses
and votes.
- Also accept \r\n as newline in Torperf results files.
- Make unrecognized keys of Torperf results available together with
the corresponding values, rather than just the whole line.
* Minor changes
- Include a Torperf results line with more than one unrecognized
......
/* Copyright 2012--2015 The Tor Project
/* Copyright 2012--2016 The Tor Project
* See LICENSE for licensing information */
package org.torproject.descriptor;
......@@ -7,6 +7,10 @@ import java.util.SortedMap;
public interface TorperfResult extends Descriptor {
/* Return all unrecognized keys together with their values, or null if
* all keys were recognized. */
public SortedMap<String, String> getUnrecognizedKeys();
/* Return the configured name of the data source. */
public String getSource();
......
......@@ -153,6 +153,10 @@ public class TorperfResultImpl extends DescriptorImpl
throw new DescriptorParseException("Unrecognized key '" + key
+ "' in line '" + line + "'.");
} else {
if (this.unrecognizedKeys == null) {
this.unrecognizedKeys = new TreeMap<>();
}
this.unrecognizedKeys.put(key, value);
if (this.unrecognizedLines == null) {
this.unrecognizedLines = new ArrayList<>();
}
......@@ -275,16 +279,19 @@ public class TorperfResultImpl extends DescriptorImpl
Arrays.asList("10,20,30,40,50,60,70,80,90".split(",")));
private void parseDataPercentile(String value, String keyValue,
String line) throws DescriptorParseException {
String percentileString = keyValue.substring("DATAPERC".length(),
keyValue.indexOf("="));
String key = keyValue.substring(0, keyValue.indexOf("="));
String percentileString = key.substring("DATAPERC".length());
if (!this.unparsedPercentiles.contains(percentileString)) {
throw new DescriptorParseException("Illegal value in '" + keyValue
+ "' in line '" + line + "'.");
if (this.unrecognizedKeys == null) {
this.unrecognizedKeys = new TreeMap<>();
}
this.unrecognizedKeys.put(key, value);
} else {
this.unparsedPercentiles.remove(percentileString);
int decileIndex = (Integer.parseInt(percentileString) / 10) - 1;
long timestamp = this.parseTimestamp(value, keyValue, line);
this.dataDeciles[decileIndex] = timestamp;
}
this.unparsedPercentiles.remove(percentileString);
int decileIndex = (Integer.parseInt(percentileString) / 10) - 1;
long timestamp = this.parseTimestamp(value, keyValue, line);
this.dataDeciles[decileIndex] = timestamp;
}
private void parseLaunch(String value, String keyValue, String line)
......@@ -383,6 +390,12 @@ public class TorperfResultImpl extends DescriptorImpl
}
}
private SortedMap<String, String> unrecognizedKeys;
public SortedMap<String, String> getUnrecognizedKeys() {
return this.unrecognizedKeys == null ? null
: new TreeMap<>(this.unrecognizedKeys);
}
private String source;
public String getSource() {
return this.source;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment