Commit d357a5f8 authored by Hiro's avatar Hiro 🏄
Browse files

Define OverloadRatelimitsVersion and OverloadFdExhaustedVersion as long

OverloadRatelimitsVersion and OverloadFdExhaustedVersion were defined as int
but parsed as long.

Also include test for OverloadRatelimitsVersion.
parent 04e17004
......@@ -48,8 +48,7 @@ public interface ExtraInfoDescriptor extends Descriptor {
* characters, that is used to reference this descriptor from a server
* descriptor.
*
* @return SHA-1 descriptor digest or upper-case (bridge descriptors)
* hexadecimal characters
* @return SHA-1 descriptor digest or bridge descriptor
*
* @since 1.7.0
*/
......@@ -183,8 +182,8 @@ public interface ExtraInfoDescriptor extends Descriptor {
long getOverloadRatelimitsBurstLimit();
/**
* Get the server's read-overload-count, or {@code -1L} if the descriptor does not
* contain a bandwidth overload rate limit.
* Get the server's read-overload-count, or {@code -1L} if the descriptor
* does not contain a bandwidth overload rate limit.
*
* @return burst-limit or {@code -1L}
*
......@@ -205,19 +204,19 @@ public interface ExtraInfoDescriptor extends Descriptor {
/**
* Get the version number in the overload-fd-exhausted line.
*
* @return version or {@code -1}
* @return version or {@code -1L}
*
* @since 2.18.0
*/
int getOverloadFdExhaustedVersion();
long getOverloadFdExhaustedVersion();
/**
* Get the server's descriptor exhaustion as a timestamp.
* The timestamp indicates that the maximum was reached between the
* timestamp and the "published" timestamp of the document.
*
* {@code -1L} is returned if the descriptor does not contain a file descriptor
* exhaustion.
* {@code -1L} is returned if the descriptor does not contain a
* file descriptor exhaustion.
*
* @return timestamp or {@code -1L}
*
......@@ -274,8 +273,8 @@ public interface ExtraInfoDescriptor extends Descriptor {
* Get statistics on unique IP addresses requesting v2 network
* statuses with map keys being country codes and map values being
* numbers of unique IP addresses rounded up to the nearest multiple of
* 8, or {@code null} if no such statistics are included (which is the case with
* recent Tor versions).
* 8, or {@code null} if no such statistics are included (which is the
* case with recent Tor versions).
*
* @return SortedMap ("contry code", "number of unique IPs"} or {@code null}
*
......@@ -516,8 +515,8 @@ public interface ExtraInfoDescriptor extends Descriptor {
/**
* Get the mean times in milliseconds that cells spend in circuit
* queues by circuit decile starting with the loudest decile at index 0
* and the quietest decile at index 8, or {@code null} if no such statistics are
* included.
* and the quietest decile at index 8, or {@code null} if no such
* statistics are included.
*
* @return mean of time or {@code null}
*
......@@ -892,8 +891,8 @@ public interface ExtraInfoDescriptor extends Descriptor {
/**
* Get the time in milliseconds since the epoch when the included version 3
* onion service statistics interval ended, or {@code -1L} if no such statistics are
* included.
* onion service statistics interval ended, or {@code -1L} if no such
* statistics are included.
*
* @return time or {@code -1L}
*
......@@ -959,7 +958,8 @@ public interface ExtraInfoDescriptor extends Descriptor {
/**
* Get the time in milliseconds since the epoch when the included
* padding-counts statistics ended, or {@code -1L} if no such statistics are included.
* padding-counts statistics ended, or {@code -1L} if no such statistics
* are included.
*
* @return time or {@code -1L}
*
......@@ -990,8 +990,9 @@ public interface ExtraInfoDescriptor extends Descriptor {
/**
* Get the RSA-1024 signature of the PKCS1-padded descriptor digest,
* taken from the beginning of the router line through the newline after
* the router-signature line, or {@code null} if the descriptor doesn't contain
* a signature (which is the case in sanitized bridge descriptors).
* the router-signature line, or {@code null} if the descriptor
* doesn't contain a signature (which is the case in sanitized bridge
* descriptors).
*
* @return RSA-1024 signature or {@code null}
*
......
......@@ -3,7 +3,10 @@
package org.torproject.descriptor.impl;
import org.torproject.descriptor.*;
import org.torproject.descriptor.BandwidthHistory;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.ExtraInfoDescriptor;
import java.io.File;
import java.util.ArrayList;
......@@ -21,23 +24,23 @@ import java.util.TreeMap;
/**
* Contains logic to work with extra-info descriptor files.
*
* The extra-info document format is defined in the dir-spec
* document.
* <p>The extra-info document format is defined in the dir-spec
* document.</p>
*
* @see <a href="https://github.com/torproject/torspec/blob/main/dir-spec.txt#L893">dir-spec.txt</a>
*
* Descriptor keys are defined and their occurency is checked to
* make sure the descriptor file format is valid.
* <p>Descriptor keys are defined and their occurency is checked to
* make sure the descriptor file format is valid.</p>
*
* Descriptor lines are parsed and their values can be accessed through the
* defined methods.
* <p>Descriptor lines are parsed and their values can be accessed
* through the defined methods.</p>
*
* When metrics library learns how to parse a new line for extra-info
* descriptor files all its fields, from the dir-spec document, are parsed in
* this class.
* <p>When metrics library learns how to parse a new line for extra-info
* descriptor files all its fields, from the dir-spec document, are
* parsed in this class.</p>
*
* The new key is added to {@link Key} and its occurence is checked in
* {@link ExtraInfoDescriptorImpl} constructor.
* <p>The new key is added to {@link Key} and its occurence is checked in
* {@link ExtraInfoDescriptorImpl} constructor.</p>
*
* @since 1.0.0
*/
......@@ -113,8 +116,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
/**
* Parse the descriptor file.
*
* @throws DescriptorParseException if any of the desriptor lines
* is not valid.
* @throws DescriptorParseException
*
*/
private void parseDescriptorBytes() throws DescriptorParseException {
......@@ -383,8 +385,8 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseOverloadRatelimits(String line,
String[] partsNoOpt) throws DescriptorParseException {
this.overloadRatelimitsVersion = Integer.parseInt(partsNoOpt[1]);
if (this.overloadRatelimitsVersion != 1) {
this.overloadRatelimitsVersion = Long.parseLong(partsNoOpt[1]);
if (this.overloadRatelimitsVersion != 1.0) {
throw new DescriptorParseException("Unknown version number for line '"
+ line + "' in extra-info descriptor.");
}
......@@ -403,8 +405,8 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseOverloadFdExhausted(String line,
String[] partsNoOpt)
throws DescriptorParseException {
this.overloadFdExhaustedVersion = Integer.parseInt(partsNoOpt[1]);
if (this.overloadFdExhaustedVersion != 1) {
this.overloadFdExhaustedVersion = Long.parseLong(partsNoOpt[1]);
if (this.overloadFdExhaustedVersion != 1.0) {
throw new DescriptorParseException("Unknown version number for line '"
+ line + "' in extra-info descriptor.");
}
......@@ -1037,7 +1039,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.geoip6DbDigest;
}
private int overloadRatelimitsVersion = 0;
private long overloadRatelimitsVersion = -1L;
@Override
public long getOverloadRatelimitsVersion() {
......@@ -1079,10 +1081,10 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.overloadRatelimitsWriteCount;
}
private int overloadFdExhaustedVersion = 0;
private long overloadFdExhaustedVersion = -1;
@Override
public int getOverloadFdExhaustedVersion() {
public long getOverloadFdExhaustedVersion() {
return this.overloadFdExhaustedVersion;
}
......
......@@ -6,12 +6,13 @@ import java.util.Map;
/**
* Define keys from descriptor document files
*
* The extra-info document format is defined in the dir-spec
* document.
* <p>The extra-info document format is defined in the dir-spec
* document.</p>
*
* @see <a href="https://github.com/torproject/torspec/blob/main/dir-spec.txt#L893">dir-spec.txt</a>
*
* Occurence of each key is checked in the respective implementation class.
* <p>Occurence of each key is checked in the respective
* implementation class.</p>
*/
public enum Key {
......
......@@ -1238,6 +1238,8 @@ public class ExtraInfoDescriptorImplTest {
String expectedDate = "Sat Jul 24 03:00:00 UTC 2021";
assertEquals(expectedDate,
new Date(descriptor.getOverloadRatelimitsTimestamp()).toString());
assertEquals("1",
Long.toString(descriptor.getOverloadRatelimitsVersion()));
assertEquals(824,
descriptor.getOverloadRatelimitsReadCount());
assertEquals(650,
......
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