[or-cvs] [ernie/master] Make use of values in config file.

karsten at torproject.org karsten at torproject.org
Mon Feb 22 07:28:20 UTC 2010


Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Mon, 22 Feb 2010 08:26:14 +0100
Subject: Make use of values in config file.
Commit: ed7514ce2f6e95def779ed25dfd169a158effeb9

---
 config                   |   14 ++----
 download.sh              |    3 -
 import.sh                |    3 -
 run.sh                   |    3 +
 src/Configuration.java   |   34 ++++-----------
 src/GetTorProcessor.java |    4 +-
 src/Main.java            |  103 +++++++++++++++++++++------------------------
 7 files changed, 66 insertions(+), 98 deletions(-)
 delete mode 100755 download.sh
 delete mode 100755 import.sh
 create mode 100755 run.sh

diff --git a/config b/config
index 5289c2a..a54d71c 100644
--- a/config
+++ b/config
@@ -36,12 +36,6 @@
 ## Write bridge stats to disk
 #WriteBridgeStats 1
 
-## Write torperf stats to disk
-#WriteTorperfStats 1
-
-## Write GetTor stats to disk
-#WriteGettorStats 1
-
 ## Write directory archives to disk
 #WriteDirectoryArchives 1
 
@@ -54,8 +48,8 @@
 ## Import bridge snapshots from disk, if available
 #ImportBridgeSnapshots 1
 
-## Import torperf stats from disk, if available
-#ImportTorperfStats 1
+## Import torperf data, if available, and write stats to disk
+#ImportWriteTorperfStats 1
 
 ## Download relay descriptors from directory authorities, if required
 #DownloadRelayDescriptors 0
@@ -64,8 +58,8 @@
 ## download missing relay descriptors from
 #DownloadFromDirectoryAuthorities 86.59.21.38,194.109.206.212,80.190.246.100:8180
 
-## Download GetTor stats
-#DownloadGetTorStats 0
+## Download and process GetTor stats
+#DownloadProcessGetTorStats 0
 
 ## URL to download GetTor stats from
 #GetTorStatsURL = http://gettor.torproject.org:8080/~gettor/gettor_stats.txt
diff --git a/download.sh b/download.sh
deleted file mode 100755
index c2b2479..0000000
--- a/download.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar -Djava.util.logging.config.file=logging.properties Main download
-
diff --git a/import.sh b/import.sh
deleted file mode 100755
index c4e88a8..0000000
--- a/import.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar -Djava.util.logging.config.file=logging.properties Main import
-
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..c86e8bb
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+java -cp bin/:lib/commons-codec-1.4.jar:lib/commons-compress-1.0.jar -Djava.util.logging.config.file=logging.properties Main
+
diff --git a/src/Configuration.java b/src/Configuration.java
index b08debc..6bc95fe 100644
--- a/src/Configuration.java
+++ b/src/Configuration.java
@@ -17,17 +17,15 @@ public class Configuration {
       Arrays.asList("8522EB98C91496E80EC238E732594D1509158E77,"
       + "9695DFC35FFEB861329B9F1AB04C46397020CE31"));
   private boolean writeBridgeStats = true;
-  private boolean writeTorperfStats = true;
-  private boolean writeGettorStats = true;
   private boolean writeDirectoryArchives = true;
   private boolean importDirectoryArchives = true;
   private boolean importSanitizedBridges = true;
   private boolean importBridgeSnapshots = true;
-  private boolean importTorperfStats = true;
+  private boolean importWriteTorperfStats = true;
   private boolean downloadRelayDescriptors = false;
   private List<String> downloadFromDirectoryAuthorities = Arrays.asList(
       "86.59.21.38,194.109.206.212,80.190.246.100:8180".split(","));
-  private boolean downloadGetTorStats = false;
+  private boolean downloadProcessGetTorStats = false;
   private String getTorStatsUrl = "http://gettor.torproject.org:8080/"
       + "~gettor/gettor_stats.txt";
   public Configuration() {
@@ -64,12 +62,6 @@ public class Configuration {
         } else if (line.startsWith("WriteBridgeStats")) {
           this.writeBridgeStats = Integer.parseInt(
               line.split(" ")[1]) != 0;
-        } else if (line.startsWith("WriteTorperfStats")) {
-          this.writeTorperfStats = Integer.parseInt(
-              line.split(" ")[1]) != 0;
-        } else if (line.startsWith("WriteGettorStats")) {
-          this.writeGettorStats = Integer.parseInt(
-              line.split(" ")[1]) != 0;
         } else if (line.startsWith("WriteDirectoryArchives")) {
           this.writeDirectoryArchives = Integer.parseInt(
               line.split(" ")[1]) != 0;
@@ -82,8 +74,8 @@ public class Configuration {
         } else if (line.startsWith("ImportBridgeSnapshots")) {
           this.importBridgeSnapshots = Integer.parseInt(
               line.split(" ")[1]) != 0;
-        } else if (line.startsWith("ImportTorperfStats")) {
-          this.importTorperfStats = Integer.parseInt(
+        } else if (line.startsWith("ImportWriteTorperfStats")) {
+          this.importWriteTorperfStats = Integer.parseInt(
               line.split(" ")[1]) != 0;
         } else if (line.startsWith("DownloadRelayDescriptors")) {
           this.downloadRelayDescriptors = Integer.parseInt(
@@ -101,8 +93,8 @@ public class Configuration {
             new URL("http://" + dir + "/");
             this.downloadFromDirectoryAuthorities.add(dir);
           }
-        } else if (line.startsWith("DownloadGetTorStats")) {
-          this.downloadGetTorStats = Integer.parseInt(
+        } else if (line.startsWith("DownloadProcessGetTorStats")) {
+          this.downloadProcessGetTorStats = Integer.parseInt(
               line.split(" ")[1]) != 0;
         } else if (line.startsWith("GetTorStatsURL")) {
           String newUrl = line.split(" ")[1];
@@ -152,12 +144,6 @@ public class Configuration {
   public boolean getWriteBridgeStats() {
     return this.writeBridgeStats;
   }
-  public boolean getWriteTorperfStats() {
-    return this.writeTorperfStats;
-  }
-  public boolean getWriteGettorStats() {
-    return this.writeGettorStats;
-  }
   public boolean getWriteDirectoryArchives() {
     return this.writeDirectoryArchives;
   }
@@ -170,8 +156,8 @@ public class Configuration {
   public boolean getImportBridgeSnapshots() {
     return this.importBridgeSnapshots;
   }
-  public boolean getImportTorperfStats() {
-    return this.importTorperfStats;
+  public boolean getImportWriteTorperfStats() {
+    return this.importWriteTorperfStats;
   }
   public boolean getDownloadRelayDescriptors() {
     return this.downloadRelayDescriptors;
@@ -179,8 +165,8 @@ public class Configuration {
   public List<String> getDownloadFromDirectoryAuthorities() {
     return this.downloadFromDirectoryAuthorities;
   }
-  public boolean getDownloadGetTorStats() {
-    return this.downloadGetTorStats;
+  public boolean getDownloadProcessGetTorStats() {
+    return this.downloadProcessGetTorStats;
   }
   public String getGetTorStatsUrl() {
     return this.getTorStatsUrl;
diff --git a/src/GetTorProcessor.java b/src/GetTorProcessor.java
index a37932a..910eea4 100644
--- a/src/GetTorProcessor.java
+++ b/src/GetTorProcessor.java
@@ -4,9 +4,7 @@ import java.util.*;
 import java.util.logging.*;
 
 public class GetTorProcessor {
-  private final String gettorStatsUrl =
-      "http://gettor.torproject.org:8080/~gettor/gettor_stats.txt";
-  public GetTorProcessor(String statsDirectory) {
+  public GetTorProcessor(String statsDirectory, String gettorStatsUrl) {
     Logger logger = Logger.getLogger(TorperfProcessor.class.getName());
     String unparsed = null;
     try {
diff --git a/src/Main.java b/src/Main.java
index 6144f55..e4d2f35 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -24,77 +24,70 @@ public class Main {
       System.exit(1);
     }
 
-    // Should we only import from disk or only download descriptors?
-    boolean importOnly = args.length > 0
-        && args[0].equals("import");
-    boolean downloadOnly = args.length > 0
-        && args[0].equals("download");
-
     // Define which stats we are interested in
-    SortedSet<String> countries = new TreeSet<String>();
-    countries.add("bh");
-    countries.add("cn");
-    countries.add("cu");
-    countries.add("et");
-    countries.add("ir");
-    countries.add("mm");
-    countries.add("sa");
-    countries.add("sy");
-    countries.add("tn");
-    countries.add("tm");
-    countries.add("uz");
-    countries.add("vn");
-    countries.add("ye");
-    SortedSet<String> directories = new TreeSet<String>();
-    directories.add("8522EB98C91496E80EC238E732594D1509158E77");
-    directories.add("9695DFC35FFEB861329B9F1AB04C46397020CE31");
+    SortedSet<String> countries = config.getDirreqBridgeCountries();
+    SortedSet<String> directories = config.getDirreqDirectories();
 
     // Prepare stats file handlers which will be initialized by the
     // importing/downloading classes
     String statsDirectory = "stats";
-    ConsensusStatsFileHandler csfh = new ConsensusStatsFileHandler(
-        statsDirectory);
-    BridgeStatsFileHandler bsfh = new BridgeStatsFileHandler(
-        statsDirectory, countries);
-    DirreqStatsFileHandler dsfh = new DirreqStatsFileHandler(
-        statsDirectory, countries);
+    ConsensusStatsFileHandler csfh = config.getWriteConsensusStats() ?
+        new ConsensusStatsFileHandler(statsDirectory) : null;
+    BridgeStatsFileHandler bsfh = config.getWriteBridgeStats() ?
+        new BridgeStatsFileHandler(statsDirectory, countries) : null;
+    DirreqStatsFileHandler dsfh = config.getWriteDirreqStats() ?
+        new DirreqStatsFileHandler(statsDirectory, countries) : null;
 
     // Prepare parsers
+    // TODO handle cases bsfh==NULL, csfh==NULL, dsfh==NULL
     RelayDescriptorParser rdp = new RelayDescriptorParser(csfh, bsfh,
         dsfh, countries, directories);
     BridgeDescriptorParser bdp = new BridgeDescriptorParser(csfh, bsfh,
         countries);
 
-    // Read files in archives/ and bridges/ directory
-    if (!downloadOnly) {
-      logger.info("Importing data...");
-      ArchiveReader ar = new ArchiveReader(rdp, "archives");
-      SanitizedBridgesReader sbr = new SanitizedBridgesReader(bdp,
-          "bridges", countries);
-      BridgeSnapshotReader bsr = new BridgeSnapshotReader(bdp,
-          "bridge-directories", statsDirectory, countries);
-      TorperfProcessor tp = new TorperfProcessor(statsDirectory,
-          "torperf");
-      logger.info("Finished importing data.");
-    }
+    // TODO WriteDirectoryArchives
 
-    // Download current descriptors
-    if (!importOnly) {
-      logger.info("Downloading descriptors...");
-      new RelayDescriptorDownloader(rdp, "86.59.21.38", directories);
-      new RelayDescriptorDownloader(rdp, "194.109.206.212", directories);
-      new RelayDescriptorDownloader(rdp, "80.190.246.100:8180",
-          directories);
-      new GetTorProcessor(statsDirectory);
-      logger.info("Finished downloading descriptors.");
+    // import and/or download relay and bridge descriptors
+    if (config.getImportDirectoryArchives()) {
+      new ArchiveReader(rdp, "archives");
+    }
+    if (config.getDownloadRelayDescriptors()) {
+      // TODO make this smarter by letting rdd ask rdp which descriptors
+      // are still missing and only download those
+      for (String directoryAuthority : 
+          config.getDownloadFromDirectoryAuthorities()) {
+        new RelayDescriptorDownloader(rdp, directoryAuthority,
+            directories);
+      }
+    }
+    if (config.getImportSanitizedBridges()) {
+      new SanitizedBridgesReader(bdp, "bridges", countries);
+    }
+    if (config.getImportBridgeSnapshots()) {
+      new BridgeSnapshotReader(bdp, "bridge-directories",
+          statsDirectory, countries);
     }
 
     // Write updated stats files to disk
-    logger.info("Writing updated stats files to disk...");
-    bsfh.writeFile();
-    csfh.writeFile();
-    dsfh.writeFile();
-    logger.info("Finished writing updated stats files to disk.");
+    if (bsfh != null) {
+      bsfh.writeFile();
+    }
+    if (csfh != null) {
+      csfh.writeFile();
+    }
+    if (dsfh != null) {
+      dsfh.writeFile();
+    }
+
+    // Import and process torperf stats
+    if (config.getImportWriteTorperfStats()) {
+      new TorperfProcessor(statsDirectory, "torperf");
+    }
+
+    // Download and process GetTor stats
+    if (config.getDownloadProcessGetTorStats()) {
+      new GetTorProcessor(statsDirectory, config.getGetTorStatsUrl());
+    }
 
     // Remove lock file
     lf.releaseLock();
-- 
1.6.5



More information about the tor-commits mailing list