[tor-commits] [metrics-lib/master] Parse new ipv6-* lines in extra-info descriptors.
karsten at torproject.org
karsten at torproject.org
Fri Aug 7 18:53:27 UTC 2020
commit a7850a2dc0e8be8a7d9bc289c96dbeed6f204b00
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Fri Aug 7 20:48:57 2020 +0200
Parse new ipv6-* lines in extra-info descriptors.
---
CHANGELOG.md | 2 +
.../torproject/descriptor/ExtraInfoDescriptor.java | 72 ++++++++++++++++
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 95 ++++++++++++++++++++++
.../java/org/torproject/descriptor/impl/Key.java | 3 +
.../impl/ExtraInfoDescriptorImplTest.java | 74 +++++++++++++++++
5 files changed, 246 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4679688..bb55312 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,8 @@
* Medium changes
- Extend Torperf results to provide error codes.
- Parse OnionPerf analysis results format version 3.0.
+ - Parse new ipv6-{write,read}-history and ipv6-conn-bi-direct
+ lines in extra-info descriptors.
# Changes in version 2.13.0 - 2020-05-16
diff --git a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java
index a2c893b..e094fed 100644
--- a/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java
+++ b/src/main/java/org/torproject/descriptor/ExtraInfoDescriptor.java
@@ -106,6 +106,22 @@ public interface ExtraInfoDescriptor extends Descriptor {
*/
BandwidthHistory getWriteHistory();
+ /**
+ * Return the server's history of written IPv6 bytes, or {@code null} if the
+ * descriptor does not contain a bandwidth history.
+ *
+ * @since 2.14.0
+ */
+ BandwidthHistory getIpv6WriteHistory();
+
+ /**
+ * Return the server's history of read IPv6 bytes, or {@code null} if the
+ * descriptor does not contain a bandwidth history.
+ *
+ * @since 2.14.0
+ */
+ BandwidthHistory getIpv6ReadHistory();
+
/**
* Return a SHA-1 digest of the GeoIP database file used by this server
* to resolve client IP addresses to country codes, encoded as 40
@@ -419,6 +435,62 @@ public interface ExtraInfoDescriptor extends Descriptor {
*/
int getConnBiDirectBoth();
+ /**
+ * Return the time in milliseconds since the epoch when the included
+ * statistics on bi-directional IPv6 connection usage ended, or -1 if no such
+ * statistics are included.
+ *
+ * @since 2.14.0
+ */
+ long getIpv6ConnBiDirectStatsEndMillis();
+
+ /**
+ * Return the interval length of the included statistics on
+ * bi-directional IPv6 connection usage in seconds, or -1 if no such
+ * statistics are included.
+ *
+ * @since 2.14.0
+ */
+ long getIpv6ConnBiDirectStatsIntervalLength();
+
+ /**
+ * Return the number of IPv6 connections on which this server read and wrote
+ * less than 2 KiB/s in a 10-second interval, or -1 if no such
+ * statistics are included.
+ *
+ * @since 2.14.0
+ */
+ int getIpv6ConnBiDirectBelow();
+
+ /**
+ * Return the number of IPv6 connections on which this server read and wrote
+ * at least 2 KiB/s in a 10-second interval and at least 10 times more
+ * in read direction than in write direction, or -1 if no such
+ * statistics are included.
+ *
+ * @since 2.14.0
+ */
+ int getIpv6ConnBiDirectRead();
+
+ /**
+ * Return the number of IPv6 connections on which this server read and wrote
+ * at least 2 KiB/s in a 10-second interval and at least 10 times more
+ * in write direction than in read direction, or -1 if no such
+ * statistics are included.
+ *
+ * @since 2.14.0
+ */
+ int getIpv6ConnBiDirectWrite();
+
+ /**
+ * Return the number of IPv6 connections on which this server read and wrote
+ * at least 2 KiB/s in a 10-second interval but not 10 times more in
+ * either direction, or -1 if no such statistics are included.
+ *
+ * @since 2.14.0
+ */
+ int getIpv6ConnBiDirectBoth();
+
/**
* Return the time in milliseconds since the epoch when the included
* exit statistics interval ended, or -1 if no such statistics are
diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index f02b540..5cab6ab 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -97,6 +97,12 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
case WRITE_HISTORY:
this.parseWriteHistoryLine(line, partsNoOpt);
break;
+ case IPV6_READ_HISTORY:
+ this.parseIpv6ReadHistoryLine(line, partsNoOpt);
+ break;
+ case IPV6_WRITE_HISTORY:
+ this.parseIpv6WriteHistoryLine(line, partsNoOpt);
+ break;
case GEOIP_DB_DIGEST:
this.parseGeoipDbDigestLine(line, partsNoOpt);
break;
@@ -179,6 +185,9 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
case CONN_BI_DIRECT:
this.parseConnBiDirectLine(line, partsNoOpt);
break;
+ case IPV6_CONN_BI_DIRECT:
+ this.parseIpv6ConnBiDirectLine(line, partsNoOpt);
+ break;
case EXIT_STATS_END:
this.parseExitStatsEndLine(line, partsNoOpt);
break;
@@ -314,6 +323,18 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
partsNoOpt);
}
+ private void parseIpv6ReadHistoryLine(String line,
+ String[] partsNoOpt) throws DescriptorParseException {
+ this.ipv6ReadHistory = new BandwidthHistoryImpl(line,
+ partsNoOpt);
+ }
+
+ private void parseIpv6WriteHistoryLine(String line,
+ String[] partsNoOpt) throws DescriptorParseException {
+ this.ipv6WriteHistory = new BandwidthHistoryImpl(line,
+ partsNoOpt);
+ }
+
private void parseGeoipDbDigestLine(String line,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length < 2) {
@@ -573,6 +594,24 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
this.connBiDirectBoth = parsedConnBiDirectStats[3];
}
+ private void parseIpv6ConnBiDirectLine(String line,
+ String[] partsNoOpt) throws DescriptorParseException {
+ long[] parsedStatsEndData = this.parseStatsEndLine(line, partsNoOpt,
+ 6);
+ this.ipv6ConnBiDirectStatsEndMillis = parsedStatsEndData[0];
+ this.ipv6ConnBiDirectStatsIntervalLength = parsedStatsEndData[1];
+ Integer[] parsedIpv6ConnBiDirectStats = ParseHelper
+ .parseCommaSeparatedIntegerValueList(line, partsNoOpt, 5);
+ if (parsedIpv6ConnBiDirectStats.length != 4) {
+ throw new DescriptorParseException("Illegal line '" + line + "' in "
+ + "extra-info descriptor.");
+ }
+ this.ipv6ConnBiDirectBelow = parsedIpv6ConnBiDirectStats[0];
+ this.ipv6ConnBiDirectRead = parsedIpv6ConnBiDirectStats[1];
+ this.ipv6ConnBiDirectWrite = parsedIpv6ConnBiDirectStats[2];
+ this.ipv6ConnBiDirectBoth = parsedIpv6ConnBiDirectStats[3];
+ }
+
private void parseExitStatsEndLine(String line,
String[] partsNoOpt) throws DescriptorParseException {
long[] parsedStatsEndData = this.parseStatsEndLine(line, partsNoOpt,
@@ -837,6 +876,20 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.writeHistory;
}
+ private BandwidthHistory ipv6ReadHistory;
+
+ @Override
+ public BandwidthHistory getIpv6ReadHistory() {
+ return this.ipv6ReadHistory;
+ }
+
+ private BandwidthHistory ipv6WriteHistory;
+
+ @Override
+ public BandwidthHistory getIpv6WriteHistory() {
+ return this.ipv6WriteHistory;
+ }
+
private String geoipDbDigest;
@Override
@@ -1082,6 +1135,48 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.connBiDirectBoth;
}
+ private long ipv6ConnBiDirectStatsEndMillis = -1L;
+
+ @Override
+ public long getIpv6ConnBiDirectStatsEndMillis() {
+ return this.ipv6ConnBiDirectStatsEndMillis;
+ }
+
+ private long ipv6ConnBiDirectStatsIntervalLength = -1L;
+
+ @Override
+ public long getIpv6ConnBiDirectStatsIntervalLength() {
+ return this.ipv6ConnBiDirectStatsIntervalLength;
+ }
+
+ private int ipv6ConnBiDirectBelow = -1;
+
+ @Override
+ public int getIpv6ConnBiDirectBelow() {
+ return this.ipv6ConnBiDirectBelow;
+ }
+
+ private int ipv6ConnBiDirectRead = -1;
+
+ @Override
+ public int getIpv6ConnBiDirectRead() {
+ return this.ipv6ConnBiDirectRead;
+ }
+
+ private int ipv6ConnBiDirectWrite = -1;
+
+ @Override
+ public int getIpv6ConnBiDirectWrite() {
+ return this.ipv6ConnBiDirectWrite;
+ }
+
+ private int ipv6ConnBiDirectBoth = -1;
+
+ @Override
+ public int getIpv6ConnBiDirectBoth() {
+ return this.ipv6ConnBiDirectBoth;
+ }
+
private long exitStatsEndMillis = -1L;
@Override
diff --git a/src/main/java/org/torproject/descriptor/impl/Key.java b/src/main/java/org/torproject/descriptor/impl/Key.java
index a6202e4..70db350 100644
--- a/src/main/java/org/torproject/descriptor/impl/Key.java
+++ b/src/main/java/org/torproject/descriptor/impl/Key.java
@@ -94,7 +94,10 @@ public enum Key {
HIDSERV_STATS_END("hidserv-stats-end"),
ID("id"),
IDENTITY_ED25519("identity-ed25519"),
+ IPV6_CONN_BI_DIRECT("ipv6-conn-bi-direct"),
IPV6_POLICY("ipv6-policy"),
+ IPV6_READ_HISTORY("ipv6-read-history"),
+ IPV6_WRITE_HISTORY("ipv6-write-history"),
KNOWN_FLAGS("known-flags"),
LEGACY_DIR_KEY("legacy-dir-key"),
LEGACY_KEY("legacy-key"),
diff --git a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index 9750046..1233bd5 100644
--- a/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -75,6 +75,24 @@ public class ExtraInfoDescriptorImplTest {
return db.buildDescriptor();
}
+ private String ipv6WriteHistoryLine = null;
+
+ private static ExtraInfoDescriptor createWithIpv6WriteHistoryLine(
+ String line) throws DescriptorParseException {
+ DescriptorBuilder db = new DescriptorBuilder();
+ db.ipv6WriteHistoryLine = line;
+ return db.buildDescriptor();
+ }
+
+ private String ipv6ReadHistoryLine = null;
+
+ private static ExtraInfoDescriptor createWithIpv6ReadHistoryLine(
+ String line) throws DescriptorParseException {
+ DescriptorBuilder db = new DescriptorBuilder();
+ db.ipv6ReadHistoryLine = line;
+ return db.buildDescriptor();
+ }
+
private String dirreqWriteHistoryLine = "dirreq-write-history "
+ "2012-02-11 09:03:39 (900 s) 81281024,64996352,60625920,"
+ "67922944";
@@ -160,6 +178,15 @@ public class ExtraInfoDescriptorImplTest {
return db.buildDescriptor();
}
+ private String ipv6ConnBiDirectLine = null;
+
+ private static ExtraInfoDescriptor createWithIpv6ConnBiDirectLine(
+ String line) throws DescriptorParseException {
+ DescriptorBuilder db = new DescriptorBuilder();
+ db.ipv6ConnBiDirectLine = line;
+ return db.buildDescriptor();
+ }
+
private String exitStatsLines = null;
private static ExtraInfoDescriptor createWithExitStatsLines(
@@ -266,6 +293,12 @@ public class ExtraInfoDescriptorImplTest {
if (this.readHistoryLine != null) {
sb.append(this.readHistoryLine).append("\n");
}
+ if (this.ipv6WriteHistoryLine != null) {
+ sb.append(this.ipv6WriteHistoryLine).append("\n");
+ }
+ if (this.ipv6ReadHistoryLine != null) {
+ sb.append(this.ipv6ReadHistoryLine).append("\n");
+ }
if (this.dirreqWriteHistoryLine != null) {
sb.append(this.dirreqWriteHistoryLine).append("\n");
}
@@ -293,6 +326,9 @@ public class ExtraInfoDescriptorImplTest {
if (this.connBiDirectLine != null) {
sb.append(this.connBiDirectLine).append("\n");
}
+ if (this.ipv6ConnBiDirectLine != null) {
+ sb.append(this.ipv6ConnBiDirectLine).append("\n");
+ }
if (this.exitStatsLines != null) {
sb.append(this.exitStatsLines).append("\n");
}
@@ -1137,6 +1173,29 @@ public class ExtraInfoDescriptorImplTest {
+ "4707695616,4699666432,4650004480,4489718784");
}
+ @Test
+ public void testIpv6WriteHistory()
+ throws DescriptorParseException {
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithIpv6WriteHistoryLine("ipv6-write-history 2020-07-15 "
+ + "03:54:50 (86400 s) 1290676224,2538212352,6013477888");
+ assertNotNull(descriptor.getIpv6WriteHistory());
+ assertNull(descriptor.getIpv6ReadHistory());
+ assertEquals(86400L, descriptor.getIpv6WriteHistory().getIntervalLength());
+ }
+
+ @Test
+ public void testIpv6ReadHistory()
+ throws DescriptorParseException {
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithIpv6ReadHistoryLine("ipv6-read-history 2020-07-15 03:54:50 "
+ + "(86400 s) 55123875840,62352131072,69582769152");
+ assertNull(descriptor.getIpv6WriteHistory());
+ assertNotNull(descriptor.getIpv6ReadHistory());
+ assertEquals(3,
+ descriptor.getIpv6ReadHistory().getBandwidthValues().size());
+ }
+
@Test
public void testDirreqWriteHistoryMissingBytesBegin()
throws DescriptorParseException {
@@ -1724,6 +1783,21 @@ public class ExtraInfoDescriptorImplTest {
+ "2012-02-11 01:59:39 (86400 s) 42173,1591,1310,1744 +1");
}
+ @Test
+ public void testIpv6ConnBiDirectValid()
+ throws DescriptorParseException {
+ ExtraInfoDescriptor descriptor = DescriptorBuilder
+ .createWithIpv6ConnBiDirectLine("ipv6-conn-bi-direct 2020-02-11 "
+ + "01:59:39 (86400 s) 42173,1591,1310,1744");
+ assertEquals(1581386379000L,
+ descriptor.getIpv6ConnBiDirectStatsEndMillis());
+ assertEquals(86400L, descriptor.getIpv6ConnBiDirectStatsIntervalLength());
+ assertEquals(42173, descriptor.getIpv6ConnBiDirectBelow());
+ assertEquals(1591, descriptor.getIpv6ConnBiDirectRead());
+ assertEquals(1310, descriptor.getIpv6ConnBiDirectWrite());
+ assertEquals(1744, descriptor.getIpv6ConnBiDirectBoth());
+ }
+
@Test
public void testExitStatsValid() throws DescriptorParseException {
ExtraInfoDescriptor descriptor = ExitStatsBuilder
More information about the tor-commits
mailing list