[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Update to metrics-lib 1.9.0.



commit ccd5a7e58ca459ef3ed5ce168e815efedb147e0b
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Sat Jun 17 08:49:16 2017 +0200

    Update to metrics-lib 1.9.0.
    
    Implements #22681.
---
 build.xml                                          |  2 +-
 .../onionoo/updater/DescriptorQueue.java           | 62 ++++++++--------------
 .../onionoo/updater/DummyBridgeStatus.java         |  9 ++++
 .../torproject/onionoo/updater/DummyConsensus.java |  9 ++++
 4 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/build.xml b/build.xml
index c498a5d..e6f3c2b 100644
--- a/build.xml
+++ b/build.xml
@@ -11,7 +11,7 @@
   <property name="onionoo.protocol.version" value="4.0"/>
   <property name="release.version"
             value="${onionoo.protocol.version}-1.2.0-dev"/>
-  <property name="descriptorversion" value="1.8.2"/>
+  <property name="descriptorversion" value="1.9.0"/>
   <property name="jetty.version" value="-8.1.16.v20140903" />
   <property name="warfile"
             value="onionoo-${release.version}.war"/>
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
index e2657c9..ae68b41 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
@@ -4,9 +4,9 @@
 package org.torproject.onionoo.updater;
 
 import org.torproject.descriptor.Descriptor;
-import org.torproject.descriptor.DescriptorFile;
 import org.torproject.descriptor.DescriptorReader;
 import org.torproject.descriptor.DescriptorSourceFactory;
+import org.torproject.descriptor.UnparseableDescriptor;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -18,7 +18,6 @@ import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -34,9 +33,9 @@ class DescriptorQueue {
 
   private File historyFile;
 
-  private Iterator<DescriptorFile> descriptorFiles;
+  private File directory;
 
-  private List<Descriptor> descriptors;
+  private Iterator<Descriptor> descriptors;
 
   private int historySizeBefore;
 
@@ -64,28 +63,14 @@ class DescriptorQueue {
 
   public DescriptorQueue(File inDir, DescriptorType descriptorType,
       File statusDir) {
-    File directory = inDir;
+    this.directory = inDir;
     if (descriptorType != null) {
-      directory = new File(inDir, descriptorType.getDir());
+      this.directory = new File(inDir, descriptorType.getDir());
     }
     this.statusDir = statusDir;
     this.descriptorReader =
         DescriptorSourceFactory.createDescriptorReader();
-    this.addDirectory(directory);
-  }
-
-  private void addDirectory(File directory) {
-    if (directory == null) {
-      return;
-    }
-    if (directory.exists() && directory.isDirectory()) {
-      this.descriptorReader.addDirectory(directory);
-      this.descriptorReader.setMaxDescriptorFilesInQueue(1);
-    } else {
-      log.error("Directory " + directory.getAbsolutePath()
-          + " either does not exist or is not a directory.  Not adding "
-          + "to descriptor reader.");
-    }
+    this.descriptorReader.setMaxDescriptorsInQueue(20);
   }
 
   public void readHistoryFile(DescriptorHistory descriptorHistory) {
@@ -146,27 +131,26 @@ class DescriptorQueue {
 
   public Descriptor nextDescriptor() {
     Descriptor nextDescriptor = null;
-    if (this.descriptorFiles == null) {
-      this.descriptorFiles = this.descriptorReader.readDescriptors();
-    }
-    while (this.descriptors == null && this.descriptorFiles.hasNext()) {
-      DescriptorFile descriptorFile = this.descriptorFiles.next();
-      if (descriptorFile.getException() != null) {
-        log.error("Could not parse " + descriptorFile.getFileName(), 
-            descriptorFile.getException());
-      }
-      if (descriptorFile.getDescriptors() != null
-          && !descriptorFile.getDescriptors().isEmpty()) {
-        this.descriptors = descriptorFile.getDescriptors();
+    if (null == this.descriptors) {
+      if (this.directory.exists()
+          && directory.isDirectory()) {
+        this.descriptors = this.descriptorReader.readDescriptors(
+            this.directory).iterator();
+      } else {
+        log.error("Directory " + this.directory.getAbsolutePath()
+            + " either does not exist or is not a directory.  Not adding "
+            + "to descriptor reader.");
+        return null;
       }
     }
-    if (this.descriptors != null) {
-      nextDescriptor = this.descriptors.remove(0);
-      this.returnedDescriptors++;
-      this.returnedBytes += nextDescriptor.getRawDescriptorBytes().length;
-      if (this.descriptors.isEmpty()) {
-        this.descriptors = null;
+    while (null == nextDescriptor && this.descriptors.hasNext()) {
+      nextDescriptor = this.descriptors.next();
+      if (nextDescriptor instanceof UnparseableDescriptor) {
+        nextDescriptor = null;
+        continue;
       }
+      this.returnedDescriptors++;
+      this.returnedBytes += nextDescriptor.getRawDescriptorLength();
     }
     return nextDescriptor;
   }
diff --git a/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java b/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java
index 46f6371..4b06c99 100644
--- a/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java
+++ b/src/test/java/org/torproject/onionoo/updater/DummyBridgeStatus.java
@@ -6,6 +6,7 @@ package org.torproject.onionoo.updater;
 import org.torproject.descriptor.BridgeNetworkStatus;
 import org.torproject.descriptor.NetworkStatusEntry;
 
+import java.io.File;
 import java.util.List;
 import java.util.SortedMap;
 import java.util.TreeMap;
@@ -16,6 +17,10 @@ public class DummyBridgeStatus implements BridgeNetworkStatus {
     return null;
   }
 
+  public int getRawDescriptorLength() {
+    return 0;
+  }
+
   public List<String> getAnnotations() {
     return null;
   }
@@ -24,6 +29,10 @@ public class DummyBridgeStatus implements BridgeNetworkStatus {
     return null;
   }
 
+  public File getDescriptorFile() {
+    return null;
+  }
+
   private long publishedMillis;
 
   public void setPublishedMillis(long publishedMillis) {
diff --git a/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java b/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java
index 9147967..5faf709 100644
--- a/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java
+++ b/src/test/java/org/torproject/onionoo/updater/DummyConsensus.java
@@ -8,6 +8,7 @@ import org.torproject.descriptor.DirectorySignature;
 import org.torproject.descriptor.NetworkStatusEntry;
 import org.torproject.descriptor.RelayNetworkStatusConsensus;
 
+import java.io.File;
 import java.util.List;
 import java.util.SortedMap;
 import java.util.SortedSet;
@@ -20,6 +21,10 @@ public class DummyConsensus implements RelayNetworkStatusConsensus {
     return null;
   }
 
+  public int getRawDescriptorLength() {
+    return 0;
+  }
+
   public List<String> getAnnotations() {
     return null;
   }
@@ -28,6 +33,10 @@ public class DummyConsensus implements RelayNetworkStatusConsensus {
     return null;
   }
 
+  public File getDescriptorFile() {
+    return null;
+  }
+
   public int getNetworkStatusVersion() {
     return 0;
   }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits