/* Copyright 2011 The Tor Project
 * See LICENSE for licensing information */
package org.torproject.onionoo;

import java.util.*;

/* Update search data and status data files by reading local network
 * status consensuses and downloading the current network status from the
 * directory authorities. */
public class Main {
  public static void main(String[] args) {

    printStatus("Reading the internal search data file from disk (if "
        + "present).");
    SearchDataWriter sedw = new SearchDataWriter();
    SearchData sd = sedw.readRelaySearchDataFile();

    printStatus("Reading network statuses from disk (if present).");
    NetworkStatusReader nsr = new NetworkStatusReader();
    Set<NetworkStatusData> loadedConsensuses = nsr.loadConsensuses();
    Set<BridgeNetworkStatusData> loadedBridgeNetworkStatuses =
        nsr.loadBridgeNetworkStatuses();

    printStatus("Downloading current network status consensus from "
        + "directory authorities.");
    NetworkStatusDownloader nsd = new NetworkStatusDownloader();
    NetworkStatusData downloadedConsensus = nsd.downloadConsensus();

    printStatus("Updating search data.");
    sd.updateAll(loadedConsensuses);
    sd.updateBridgeNetworkStatuses(loadedBridgeNetworkStatuses);
    sd.update(downloadedConsensus);

    printStatus("(Over-)writing search data file on disk.");
    sedw.writeRelaySearchDataFile(sd);

    /* TODO Status files are not implemented yet.
    printStatus("(Over-)writing status data files on disk.");
    StatusDataWriter stdw = new StatusDataWriter();
    stdw.writeAll(loadedConsensuses);
    stdw.write(downloadedConsensus);

    printStatus("Deleting status data files that are older than two "
        + "weeks.");
    stdw.deleteOldStatusDataFiles();    
    */

    printStatus("Terminating.");
    System.exit(0);
  }

  private static void printStatus(String message) {
    System.out.println(message);
  }
}


@@ -236,33 +236,18 @@
 ing 
-the current network statu
+descriptor
 s fr
@@ -252,19 +252,16 @@
 from the
-%0A *
  directo
@@ -254,32 +254,35 @@
 om the directory
+%0A *
  authorities. */
@@ -350,208 +350,8 @@
  %7B%0A%0A
-    printStatus(%22Reading the internal search data file from disk (if %22%0A        + %22present).%22);%0A    SearchDataWriter sedw = new SearchDataWriter();%0A    SearchData sd = sedw.readRelaySearchDataFile();%0A%0A
     
@@ -401,21 +401,8 @@
 disk
- (if present)
 .%22);
@@ -667,59 +667,25 @@
 ing 
-current network status consensus from %22%0A        + %22
+descriptors from 
 dire
@@ -879,24 +879,128 @@
 ch data.%22);%0A
+    SearchDataWriter sedw = new SearchDataWriter();%0A    SearchData sd = sedw.readRelaySearchDataFile();%0A
     sd.updat
@@ -1128,70 +1128,8 @@
 us);
-%0A%0A    printStatus(%22(Over-)writing search data file on disk.%22);
 %0A   
@@ -1236,18 +1236,12 @@
 us(%22
-(Over-)wri
+Upda
 ting
@@ -1256,22 +1256,8 @@
 data
- files on disk
 .%22);
@@ -1387,100 +1387,8 @@
 us);
-%0A%0A    printStatus(%22Deleting status data files that are older than two %22%0A        + %22weeks.%22);
 %0A   

Clean up the main class a bit.