[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Add support for parsing geoip6-db-digest lines.
commit 43b939025031706ab1eeca9d1a72fc9ce9554e45
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed Nov 7 13:55:23 2012 -0500
Add support for parsing geoip6-db-digest lines.
---
.../torproject/descriptor/ExtraInfoDescriptor.java | 4 ++++
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 17 +++++++++++++++++
.../impl/ExtraInfoDescriptorImplTest.java | 19 +++++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/src/org/torproject/descriptor/ExtraInfoDescriptor.java b/src/org/torproject/descriptor/ExtraInfoDescriptor.java
index 05707a5..0e19425 100644
--- a/src/org/torproject/descriptor/ExtraInfoDescriptor.java
+++ b/src/org/torproject/descriptor/ExtraInfoDescriptor.java
@@ -32,6 +32,10 @@ public interface ExtraInfoDescriptor extends Descriptor {
* null if no GeoIP database digest is included. */
public String getGeoipDbDigest();
+ /* Return the SHA1 digest of the GeoIPv6 database used by this relay, or
+ * null if no GeoIPv6 database digest is included. */
+ public String getGeoip6DbDigest();
+
/* Return the end of the included directory request statistics interval,
* or -1 if no directory request statistics are included. */
public long getDirreqStatsEndMillis();
diff --git a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 45848d2..d84a5e2 100644
--- a/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -104,6 +104,8 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
this.parseWriteHistoryLine(line, lineNoOpt, partsNoOpt);
} else if (keyword.equals("geoip-db-digest")) {
this.parseGeoipDbDigestLine(line, lineNoOpt, partsNoOpt);
+ } else if (keyword.equals("geoip6-db-digest")) {
+ this.parseGeoip6DbDigestLine(line, lineNoOpt, partsNoOpt);
} else if (keyword.equals("geoip-start-time")) {
this.parseGeoipStartTimeLine(line, lineNoOpt, partsNoOpt);
} else if (keyword.equals("geoip-client-origins")) {
@@ -229,6 +231,16 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
partsNoOpt[1]);
}
+ private void parseGeoip6DbDigestLine(String line, String lineNoOpt,
+ String[] partsNoOpt) throws DescriptorParseException {
+ if (partsNoOpt.length != 2) {
+ throw new DescriptorParseException("Illegal line '" + line
+ + "' in extra-info descriptor.");
+ }
+ this.geoip6DbDigest = ParseHelper.parseTwentyByteHexString(line,
+ partsNoOpt[1]);
+ }
+
private void parseGeoipStartTimeLine(String line, String lineNoOpt,
String[] partsNoOpt) throws DescriptorParseException {
if (partsNoOpt.length != 3) {
@@ -656,6 +668,11 @@ public class ExtraInfoDescriptorImpl extends DescriptorImpl
return this.geoipDbDigest;
}
+ private String geoip6DbDigest;
+ public String getGeoip6DbDigest() {
+ return this.geoip6DbDigest;
+ }
+
private long dirreqStatsEndMillis = -1L;
public long getDirreqStatsEndMillis() {
return this.dirreqStatsEndMillis;
diff --git a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
index c8df3ce..a2becd2 100644
--- a/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
+++ b/test/org/torproject/descriptor/impl/ExtraInfoDescriptorImplTest.java
@@ -77,6 +77,13 @@ public class ExtraInfoDescriptorImplTest {
db.geoipDbDigestLine = line;
return new ExtraInfoDescriptorImpl(db.buildDescriptor(), true);
}
+ private String geoip6DbDigestLine = null;
+ private static ExtraInfoDescriptor createWithGeoip6DbDigestLine(
+ String line) throws DescriptorParseException {
+ DescriptorBuilder db = new DescriptorBuilder();
+ db.geoip6DbDigestLine = line;
+ return new ExtraInfoDescriptorImpl(db.buildDescriptor(), true);
+ }
private String geoipStatsLines = null;
private static ExtraInfoDescriptor createWithGeoipStatsLines(
String lines) throws DescriptorParseException {
@@ -170,6 +177,9 @@ public class ExtraInfoDescriptorImplTest {
if (this.geoipDbDigestLine != null) {
sb.append(this.geoipDbDigestLine + "\n");
}
+ if (this.geoip6DbDigestLine != null) {
+ sb.append(this.geoip6DbDigestLine + "\n");
+ }
if (this.geoipStatsLines != null) {
sb.append(this.geoipStatsLines + "\n");
}
@@ -832,6 +842,15 @@ public class ExtraInfoDescriptorImplTest {
}
@Test()
+ public void testGeoip6DbDigestValid() throws DescriptorParseException {
+ ExtraInfoDescriptor descriptor = DescriptorBuilder.
+ createWithGeoip6DbDigestLine("geoip6-db-digest "
+ + "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8");
+ assertEquals("916A3CA8B7DF61473D5AE5B21711F35F301CE9E8",
+ descriptor.getGeoip6DbDigest());
+ }
+
+ @Test()
public void testGeoipStatsValid() throws DescriptorParseException {
ExtraInfoDescriptor descriptor = GeoipStatsBuilder.
createWithDefaultLines();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits