[tor-commits] [metrics-lib/master] Parse three new lines in snowflake statistics.

karsten at torproject.org karsten at torproject.org
Thu Jan 9 12:08:54 UTC 2020


commit 5fb36b70c884073963af8e9cb3a37fa907eb35b8
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Mon Dec 9 10:16:29 2019 +0100

    Parse three new lines in snowflake statistics.
    
    Implements #32665.
---
 CHANGELOG.md                                       |  5 ++-
 .../org/torproject/descriptor/SnowflakeStats.java  | 30 +++++++++++++
 .../java/org/torproject/descriptor/impl/Key.java   |  3 ++
 .../descriptor/impl/SnowflakeStatsImpl.java        | 51 +++++++++++++++++++++-
 .../descriptor/impl/SnowflakeStatsImplTest.java    | 12 +++++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ad91d5d..8d3ab12 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,7 @@
-# Changes in version 2.?.? - 2019-1?-??
+# Changes in version 2.10.0 - 2019-1?-??
+
+ * Medium changes
+   - Parse three newly added lines in snowflake statistics files.
 
  * Minor changes
    - Fix a NullPointerException when parsing an invalid crypto block
diff --git a/src/main/java/org/torproject/descriptor/SnowflakeStats.java b/src/main/java/org/torproject/descriptor/SnowflakeStats.java
index 379a0f7..5c464df 100644
--- a/src/main/java/org/torproject/descriptor/SnowflakeStats.java
+++ b/src/main/java/org/torproject/descriptor/SnowflakeStats.java
@@ -52,6 +52,36 @@ public interface SnowflakeStats extends Descriptor {
   Optional<Long> snowflakeIpsTotal();
 
   /**
+   * Return a count of the total number of unique IP addresses of snowflake
+   * proxies of type "standalone" that have polled.
+   *
+   * @return Count of the total number of unique IP addresses of snowflake
+   *     proxies of type "standalone" that have polled.
+   * @since 2.10.0
+   */
+  Optional<Long> snowflakeIpsStandalone();
+
+  /**
+   * Return a count of the total number of unique IP addresses of snowflake
+   * proxies of type "badge" that have polled.
+   *
+   * @return Count of the total number of unique IP addresses of snowflake
+   *     proxies of type "badge" that have polled.
+   * @since 2.10.0
+   */
+  Optional<Long> snowflakeIpsBadge();
+
+  /**
+   * Return a count of the total number of unique IP addresses of snowflake
+   * proxies of type "webext" that have polled.
+   *
+   * @return Count of the total number of unique IP addresses of snowflake
+   *     proxies of type "webext" that have polled.
+   * @since 2.10.0
+   */
+  Optional<Long> snowflakeIpsWebext();
+
+  /**
    * Return a count of the number of times a proxy has polled but received no
    * client offer, rounded up to the nearest multiple of 8.
    *
diff --git a/src/main/java/org/torproject/descriptor/impl/Key.java b/src/main/java/org/torproject/descriptor/impl/Key.java
index ac12992..10839dd 100644
--- a/src/main/java/org/torproject/descriptor/impl/Key.java
+++ b/src/main/java/org/torproject/descriptor/impl/Key.java
@@ -139,7 +139,10 @@ public enum Key {
   SIGNING_KEY("signing-key"),
   SNOWFLAKE_IDLE_COUNT("snowflake-idle-count"),
   SNOWFLAKE_IPS("snowflake-ips"),
+  SNOWFLAKE_IPS_BADGE("snowflake-ips-badge"),
+  SNOWFLAKE_IPS_STANDALONE("snowflake-ips-standalone"),
   SNOWFLAKE_IPS_TOTAL("snowflake-ips-total"),
+  SNOWFLAKE_IPS_WEBEXT("snowflake-ips-webext"),
   SNOWFLAKE_STATS_END("snowflake-stats-end"),
   TRANSPORT("transport"),
   TUNNELLED_DIR_SERVER("tunnelled-dir-server"),
diff --git a/src/main/java/org/torproject/descriptor/impl/SnowflakeStatsImpl.java b/src/main/java/org/torproject/descriptor/impl/SnowflakeStatsImpl.java
index 9922756..daaa933 100644
--- a/src/main/java/org/torproject/descriptor/impl/SnowflakeStatsImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/SnowflakeStatsImpl.java
@@ -20,8 +20,10 @@ public class SnowflakeStatsImpl extends DescriptorImpl
     implements SnowflakeStats {
 
   private static final Set<Key> atMostOnce = EnumSet.of(
-      Key.SNOWFLAKE_IPS, Key.SNOWFLAKE_IPS_TOTAL, Key.SNOWFLAKE_IDLE_COUNT,
-      Key.CLIENT_DENIED_COUNT, Key.CLIENT_SNOWFLAKE_MATCH_COUNT);
+      Key.SNOWFLAKE_IPS, Key.SNOWFLAKE_IPS_TOTAL, Key.SNOWFLAKE_IPS_STANDALONE,
+      Key.SNOWFLAKE_IPS_BADGE, Key.SNOWFLAKE_IPS_WEBEXT,
+      Key.SNOWFLAKE_IDLE_COUNT, Key.CLIENT_DENIED_COUNT,
+      Key.CLIENT_SNOWFLAKE_MATCH_COUNT);
 
   private static final Set<Key> exactlyOnce = EnumSet.of(
       Key.SNOWFLAKE_STATS_END);
@@ -61,6 +63,15 @@ public class SnowflakeStatsImpl extends DescriptorImpl
         case SNOWFLAKE_IPS_TOTAL:
           this.parseSnowflakeIpsTotal(line, parts);
           break;
+        case SNOWFLAKE_IPS_STANDALONE:
+          this.parseSnowflakeIpsStandalone(line, parts);
+          break;
+        case SNOWFLAKE_IPS_BADGE:
+          this.parseSnowflakeIpsBadge(line, parts);
+          break;
+        case SNOWFLAKE_IPS_WEBEXT:
+          this.parseSnowflakeIpsWebext(line, parts);
+          break;
         case SNOWFLAKE_IDLE_COUNT:
           this.parseSnowflakeIdleCount(line, parts);
           break;
@@ -104,6 +115,21 @@ public class SnowflakeStatsImpl extends DescriptorImpl
     this.snowflakeIpsTotal = ParseHelper.parseLong(line, parts, 1);
   }
 
+  private void parseSnowflakeIpsStandalone(String line, String[] parts)
+      throws DescriptorParseException {
+    this.snowflakeIpsStandalone = ParseHelper.parseLong(line, parts, 1);
+  }
+
+  private void parseSnowflakeIpsBadge(String line, String[] parts)
+      throws DescriptorParseException {
+    this.snowflakeIpsBadge = ParseHelper.parseLong(line, parts, 1);
+  }
+
+  private void parseSnowflakeIpsWebext(String line, String[] parts)
+      throws DescriptorParseException {
+    this.snowflakeIpsWebext = ParseHelper.parseLong(line, parts, 1);
+  }
+
   private void parseSnowflakeIdleCount(String line, String[] parts)
       throws DescriptorParseException {
     this.snowflakeIdleCount = ParseHelper.parseLong(line, parts, 1);
@@ -147,6 +173,27 @@ public class SnowflakeStatsImpl extends DescriptorImpl
     return Optional.ofNullable(this.snowflakeIpsTotal);
   }
 
+  private Long snowflakeIpsStandalone;
+
+  @Override
+  public Optional<Long> snowflakeIpsStandalone() {
+    return Optional.ofNullable(this.snowflakeIpsStandalone);
+  }
+
+  private Long snowflakeIpsBadge;
+
+  @Override
+  public Optional<Long> snowflakeIpsBadge() {
+    return Optional.ofNullable(this.snowflakeIpsBadge);
+  }
+
+  private Long snowflakeIpsWebext;
+
+  @Override
+  public Optional<Long> snowflakeIpsWebext() {
+    return Optional.ofNullable(this.snowflakeIpsWebext);
+  }
+
   private Long snowflakeIdleCount;
 
   @Override
diff --git a/src/test/java/org/torproject/descriptor/impl/SnowflakeStatsImplTest.java b/src/test/java/org/torproject/descriptor/impl/SnowflakeStatsImplTest.java
index 6d0e50b..0378fbc 100644
--- a/src/test/java/org/torproject/descriptor/impl/SnowflakeStatsImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/SnowflakeStatsImplTest.java
@@ -35,6 +35,9 @@ public class SnowflakeStatsImplTest {
           + "PK=4,ID=9,IR=7,JO=2,CR=2,US=265,DE=92,LV=1,MY=8,AR=5,NZ=10,BG=2,"
           + "UY=1,TW=5,SI=3,LU=2,GE=2,BN=1,JP=15,ES=9,SG=7,EC=1",
       "snowflake-ips-total 937",
+      "snowflake-ips-standalone 3",
+      "snowflake-ips-badge 0",
+      "snowflake-ips-webext 4118",
       "snowflake-idle-count 660976",
       "client-denied-count 0",
       "client-snowflake-match-count 864" };
@@ -51,6 +54,12 @@ public class SnowflakeStatsImplTest {
     assertEquals(68, snowflakeStats.snowflakeIps().get().size());
     assertTrue(snowflakeStats.snowflakeIpsTotal().isPresent());
     assertEquals((Long) 937L, snowflakeStats.snowflakeIpsTotal().get());
+    assertTrue(snowflakeStats.snowflakeIpsStandalone().isPresent());
+    assertEquals((Long) 3L, snowflakeStats.snowflakeIpsStandalone().get());
+    assertTrue(snowflakeStats.snowflakeIpsBadge().isPresent());
+    assertEquals((Long) 0L, snowflakeStats.snowflakeIpsBadge().get());
+    assertTrue(snowflakeStats.snowflakeIpsWebext().isPresent());
+    assertEquals((Long) 4118L, snowflakeStats.snowflakeIpsWebext().get());
     assertTrue(snowflakeStats.snowflakeIdleCount().isPresent());
     assertEquals((Long) 660976L, snowflakeStats.snowflakeIdleCount().get());
     assertTrue(snowflakeStats.clientDeniedCount().isPresent());
@@ -69,6 +78,9 @@ public class SnowflakeStatsImplTest {
         snowflakeStats.snowflakeStatsIntervalLength());
     assertFalse(snowflakeStats.snowflakeIps().isPresent());
     assertFalse(snowflakeStats.snowflakeIpsTotal().isPresent());
+    assertFalse(snowflakeStats.snowflakeIpsStandalone().isPresent());
+    assertFalse(snowflakeStats.snowflakeIpsBadge().isPresent());
+    assertFalse(snowflakeStats.snowflakeIpsWebext().isPresent());
     assertFalse(snowflakeStats.snowflakeIdleCount().isPresent());
     assertFalse(snowflakeStats.clientDeniedCount().isPresent());
     assertFalse(snowflakeStats.clientSnowflakeMatchCount().isPresent());



More information about the tor-commits mailing list