[or-cvs] [metrics-db/master] Fix consensus-health.html.

karsten at torproject.org karsten at torproject.org
Tue Jan 18 06:41:26 UTC 2011


commit 975a9c2bf3c92e207355cc50f9fc900277ffc817
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Tue Jan 18 07:38:01 2011 +0100

    Fix consensus-health.html.
    
    When we extended CachedRelayDescriptorReader to read vote documents, we
    didn't make sure that ConsensusHealthChecker can process consensuses and
    votes in arbitrary order.  Fixing the latter.
---
 .../ernie/db/ConsensusHealthChecker.java           |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/org/torproject/ernie/db/ConsensusHealthChecker.java b/src/org/torproject/ernie/db/ConsensusHealthChecker.java
index 69a7902..5e02118 100644
--- a/src/org/torproject/ernie/db/ConsensusHealthChecker.java
+++ b/src/org/torproject/ernie/db/ConsensusHealthChecker.java
@@ -35,23 +35,33 @@ public class ConsensusHealthChecker {
   }
 
   public void processConsensus(String validAfterTime, byte[] data) {
-    if (this.mostRecentValidAfterTime == null ||
-        this.mostRecentValidAfterTime.compareTo(validAfterTime) < 0) {
-      this.mostRecentValidAfterTime = validAfterTime;
+    if (this.mostRecentValidAfterTime != null &&
+        this.mostRecentValidAfterTime.compareTo(validAfterTime) > 0) {
+      /* We already have a more recent consensus. */
+      return;
+    }
+    /* The votes we know are older than this consensus.  Discard them. */
+    if (this.mostRecentValidAfterTime.compareTo(validAfterTime) < 0) {
       this.mostRecentVotes.clear();
-      this.mostRecentConsensus = data;
     }
+    /* Store this consensus. */
+    this.mostRecentValidAfterTime = validAfterTime;
+    this.mostRecentConsensus = data;
   }
 
   public void processVote(String validAfterTime, String dirSource,
       byte[] data) {
     if (this.mostRecentValidAfterTime == null ||
         this.mostRecentValidAfterTime.compareTo(validAfterTime) < 0) {
+      /* This vote is more recent than the known consensus.  Discard the
+       * consensus and all currently known votes. */
       this.mostRecentValidAfterTime = validAfterTime;
       this.mostRecentVotes.clear();
       this.mostRecentConsensus = null;
     }
     if (this.mostRecentValidAfterTime.equals(validAfterTime)) {
+      /* Store this vote which belongs to the known consensus and/or
+       * other votes. */
       this.mostRecentVotes.put(dirSource, data);
     }
   }



More information about the tor-commits mailing list