Commit 668788a9 authored by Iain Learmonth's avatar Iain Learmonth
Browse files

Overload lines in extra info descriptors.

* Checks that the overload keys are seen at most once
* Exposes the version fields from each line
* Exposes the rate and burst limits from overload-ratelimit
* Checks that the line has all the fields present
parent 0f79ef2d
Pipeline #10148 passed with stage
in 2 minutes and 32 seconds
......@@ -122,6 +122,13 @@ public interface ExtraInfoDescriptor extends Descriptor {
*/
BandwidthHistory getIpv6ReadHistory();
/**
* Return the version number in the overload-ratelimits line.
*
* @since 2.18.0
*/
long getOverloadRatelimitsVersion();
/**
* Return the server's history exhausted bandwidth as a timestamp of the
* last time this happened, or -1 if the descriptor does not
......@@ -131,6 +138,22 @@ public interface ExtraInfoDescriptor extends Descriptor {
*/
long getOverloadRatelimitsTimestamp();
/**
* Return the server's rate-limit, or -1 if the descriptor does not
* contain a bandwidth overload rate limit.
*
* @since 2.18.0
*/
long getOverloadRatelimitsRateLimit();
/**
* Return the server's burst-limit, or -1 if the descriptor does not
* contain a bandwidth overload rate limit.
*
* @since 2.18.0
*/
long getOverloadRatelimitsBurstLimit();
/**
* Return the server's read-overload-count, or -1 if the descriptor does not
* contain a bandwidth overload rate limit.
......@@ -147,12 +170,19 @@ public interface ExtraInfoDescriptor extends Descriptor {
*/
int getOverloadRatelimitsWriteCount();
/**
* Return the version number in the overload-fd-exhausted line.
*
* @since 2.18.0
*/
int getOverloadFdExhaustedVersion();
/**
* Return 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.
*
* -1 is returned if the descriptor does not contain a file descriptor
* <p>-1 is returned if the descriptor does not contain a file descriptor
* exhaustion.
*
* @since 2.18.0
......
......@@ -33,7 +33,7 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
Key.WRITE_HISTORY, Key.DIRREQ_READ_HISTORY, Key.DIRREQ_WRITE_HISTORY,
Key.GEOIP_DB_DIGEST, Key.GEOIP6_DB_DIGEST, Key.ROUTER_SIG_ED25519,
Key.ROUTER_SIGNATURE, Key.ROUTER_DIGEST_SHA256, Key.ROUTER_DIGEST,
Key.PADDING_COUNTS);
Key.PADDING_COUNTS, Key.OVERLOAD_RATELIMITS, Key.OVERLOAD_FD_EXHAUSTED);
protected ExtraInfoDescriptorImpl(byte[] descriptorBytes,
int[] offsetAndLimit, File descriptorFile)
......@@ -340,24 +340,35 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
private void parseOverloadRatelimits(String line,
String[] partsNoOpt) throws DescriptorParseException {
int version = Integer.parseInt(partsNoOpt[1]);
if (version != 1) {
throw new DescriptorParseException("Illegal version number for line '"
this.overloadRatelimitsVersion = Integer.parseInt(partsNoOpt[1]);
if (this.overloadRatelimitsVersion != 1) {
throw new DescriptorParseException("Unknown version number for line '"
+ line + "' in extra-info descriptor.");
}
if (partsNoOpt.length < 8) {
throw new DescriptorParseException("Missing fields for line '"
+ line + "' in extra-info descriptor.");
}
this.overloadRatelimitsTimestamp = ParseHelper.parseTimestampAtIndex(line,
partsNoOpt, 2, 3);
this.overloadRatelimitsRateLimit = Long.parseLong(partsNoOpt[4]);
this.overloadRatelimitsBurstLimit = Long.parseLong(partsNoOpt[5]);
this.overloadRatelimitsReadCount = Integer.parseInt(partsNoOpt[6]);
this.overloadRatelimitsWriteCount = Integer.parseInt(partsNoOpt[7]);
}
private void parseOverloadFdExhausted(String line,
String[] partsNoOpt) throws DescriptorParseException {
int version = Integer.parseInt(partsNoOpt[1]);
if (version != 1) {
throw new DescriptorParseException("Illegal version number for line '"
String[] partsNoOpt)
throws DescriptorParseException {
this.overloadFdExhaustedVersion = Integer.parseInt(partsNoOpt[1]);
if (this.overloadFdExhaustedVersion != 1) {
throw new DescriptorParseException("Unknown version number for line '"
+ line + "' in extra-info descriptor.");
}
if (partsNoOpt.length < 4) {
throw new DescriptorParseException("Missing fields for line '"
+ line + "' in extra-info descriptor.");
}
this.overloadFdExhaustedTimestamp = ParseHelper.parseTimestampAtIndex(line,
partsNoOpt, 2, 3);
}
......@@ -983,6 +994,13 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.geoip6DbDigest;
}
private int overloadRatelimitsVersion = 0;
@Override
public long getOverloadRatelimitsVersion() {
return this.overloadRatelimitsVersion;
}
private long overloadRatelimitsTimestamp = -1L;
@Override
......@@ -990,6 +1008,20 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.overloadRatelimitsTimestamp;
}
private long overloadRatelimitsRateLimit = -1L;
@Override
public long getOverloadRatelimitsRateLimit() {
return this.overloadRatelimitsRateLimit;
}
private long overloadRatelimitsBurstLimit = -1L;
@Override
public long getOverloadRatelimitsBurstLimit() {
return this.overloadRatelimitsBurstLimit;
}
private int overloadRatelimitsReadCount = -1;
@Override
......@@ -1004,6 +1036,13 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.overloadRatelimitsWriteCount;
}
private int overloadFdExhaustedVersion = 0;
@Override
public int getOverloadFdExhaustedVersion() {
return this.overloadFdExhaustedVersion;
}
private long overloadFdExhaustedTimestamp = -1L;
@Override
......
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