[or-cvs] r10873: Initial code to manipulate vote timing correctly. (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Wed Jul 18 20:46:13 UTC 2007


Author: nickm
Date: 2007-07-18 16:46:12 -0400 (Wed, 18 Jul 2007)
New Revision: 10873

Modified:
   tor/trunk/
   tor/trunk/src/or/dirserv.c
   tor/trunk/src/or/dirvote.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/routerlist.c
Log:
 r13821 at catbus:  nickm | 2007-07-18 16:29:17 -0400
 Initial code to manipulate vote timing correctly.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r13821] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-07-18 20:46:10 UTC (rev 10872)
+++ tor/trunk/src/or/dirserv.c	2007-07-18 20:46:12 UTC (rev 10873)
@@ -1752,6 +1752,7 @@
   time_t now = time(NULL);
   time_t cutoff = now - ROUTER_MAX_AGE_TO_PUBLISH;
   networkstatus_voter_info_t *voter = NULL;
+  vote_timing_t timing;
 
   /* check that everything is deallocated XXXX020 */
 
@@ -1818,12 +1819,15 @@
   tor_assert(v3_out);
   memset(v3_out, 0, sizeof(networkstatus_vote_t));
   v3_out->is_vote = 1;
-  v3_out->published = time(NULL);
-  v3_out->valid_after = time(NULL); /* XXXX020 not right. */
-  v3_out->fresh_until = time(NULL); /* XXXX020 not right. */
-  v3_out->valid_until = time(NULL); /* XXXX020 not right. */
-  v3_out->vote_seconds = 600; /* XXXX020 not right. */
-  v3_out->dist_seconds = 600; /* XXXX020 not right. */
+  dirvote_get_preferred_voting_intervals(&timing);
+  v3_out->published = now;
+  v3_out->valid_after =
+    dirvote_get_start_of_next_interval(now, timing.vote_interval);
+  v3_out->fresh_until = v3_out->valid_after + timing.vote_interval;
+  v3_out->valid_until = v3_out->valid_after +
+    (timing.vote_interval * timing.n_intervals_valid);
+  v3_out->vote_seconds = timing.vote_delay;
+  v3_out->dist_seconds = timing.dist_delay;
 
   v3_out->client_versions = client_versions;
   v3_out->server_versions = server_versions;

Modified: tor/trunk/src/or/dirvote.c
===================================================================
--- tor/trunk/src/or/dirvote.c	2007-07-18 20:46:10 UTC (rev 10872)
+++ tor/trunk/src/or/dirvote.c	2007-07-18 20:46:12 UTC (rev 10873)
@@ -10,8 +10,13 @@
 
 /**
  * \file dirvote.c
+ * \brief Functions to compute directory consensus, and schedule voting.
  **/
 
+/* =====
+ * Voting and consensus generation
+ * ===== */
+
 /** Clear all storage held in <b>ns</b>. */
 void
 networkstatus_vote_free(networkstatus_vote_t *ns)
@@ -747,6 +752,10 @@
   return 0;
 }
 
+/* =====
+ * Certificate functions
+ * ===== */
+
 /** Free storage held in <b>cert</b>. */
 void
 authority_cert_free(authority_cert_t *cert)
@@ -783,3 +792,77 @@
   return out;
 }
 
+/* =====
+ * Vote scheduling
+ * ===== */
+
+/** DOCDOC */
+void
+dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out)
+{
+  tor_assert(timing_out);
+
+  /* XXXX020 make these configurable. */
+  timing_out->vote_interval = 3600;
+  timing_out->n_intervals_valid = 3;
+  timing_out->vote_delay = 300;
+  timing_out->dist_delay = 300;
+}
+
+/** DOCDOC */
+time_t
+dirvote_get_start_of_next_interval(time_t now, int interval)
+{
+  struct tm tm;
+  time_t midnight_today;
+  time_t midnight_tomorrow;
+  time_t next;
+
+  tor_gmtime_r(&now, &tm);
+  tm.tm_hour = 0;
+  tm.tm_min = 0;
+  tm.tm_sec = 0;
+
+  midnight_today = tor_timegm(&tm);
+  midnight_tomorrow = midnight_today + (24*60*60);
+
+  next = midnight_today + ((now-midnight_today)/interval + 1)*interval;
+
+  if (next > midnight_tomorrow)
+    next = midnight_tomorrow;
+
+  return next;
+}
+
+/** DOCDOC */
+static struct {
+  time_t voting_starts;
+  time_t voting_ends;
+  time_t interval_starts;
+} voting_schedule;
+
+/** DOCDOC */
+void
+dirvote_recalculate_timing(time_t now)
+{
+  int interval, vote_delay, dist_delay;
+  time_t start;
+  networkstatus_vote_t *consensus = networkstatus_get_latest_consensus();
+
+  if (consensus) {
+    /* XXXX020 sanity-check these somewhere! */
+    interval = consensus->fresh_until - consensus->valid_after;
+    vote_delay = consensus->vote_seconds;
+    vote_delay = consensus->dist_seconds;
+  } else {
+    /* XXXX020 is this correct according the the spec? */
+    interval = 3600;
+    vote_delay = dist_delay = 300;
+  }
+
+  start = voting_schedule.interval_starts =
+    dirvote_get_start_of_next_interval(now,interval);
+  voting_schedule.voting_ends = start - vote_delay;
+  voting_schedule.voting_starts = start - vote_delay - dist_delay;
+}
+

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2007-07-18 20:46:10 UTC (rev 10872)
+++ tor/trunk/src/or/or.h	2007-07-18 20:46:12 UTC (rev 10873)
@@ -2782,6 +2782,17 @@
 void authority_cert_free(authority_cert_t *cert);
 authority_cert_t *authority_cert_dup(authority_cert_t *cert);
 
+/** DOCDOC */
+typedef struct vote_timing_t {
+  int vote_interval;
+  int n_intervals_valid;
+  int vote_delay;
+  int dist_delay;
+} vote_timing_t;
+void dirvote_get_preferred_voting_intervals(vote_timing_t *timing_out);
+time_t dirvote_get_start_of_next_interval(time_t now, int interval);
+void dirvote_recalculate_timing(time_t now);
+
 #ifdef DIRVOTE_PRIVATE
 int networkstatus_check_voter_signature(networkstatus_vote_t *consensus,
                                         networkstatus_voter_info_t *voter,
@@ -3349,6 +3360,10 @@
 local_routerstatus_t *router_get_combined_status_by_descriptor_digest(
                                                           const char *digest);
 
+/* for consensuses. */
+networkstatus_vote_t *networkstatus_get_latest_consensus(void);
+networkstatus_vote_t *networkstatus_get_live_consensus(time_t now);
+
 //routerstatus_t *routerstatus_get_by_hexdigest(const char *hexdigest);
 int should_delay_dir_fetches(or_options_t *options);
 void update_networkstatus_downloads(time_t now);

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2007-07-18 20:46:10 UTC (rev 10872)
+++ tor/trunk/src/or/routerlist.c	2007-07-18 20:46:12 UTC (rev 10873)
@@ -65,6 +65,9 @@
  * about.  This list is kept sorted by published_on. */
 static smartlist_t *networkstatus_list = NULL;
 
+/** DOCDOC */
+static networkstatus_vote_t *current_consensus = NULL;
+
 /** Global list of local_routerstatus_t for each router, known or unknown.
  * Kept sorted by digest. */
 static smartlist_t *routerstatus_list = NULL;
@@ -3726,6 +3729,22 @@
   return NULL;
 }
 
+/** DOCDOC */
+networkstatus_vote_t *
+networkstatus_get_latest_consensus(void)
+{
+  return current_consensus;
+}
+
+/** DOCDOC */
+networkstatus_vote_t *
+networkstatus_get_live_consensus(time_t now)
+{
+  /* XXXX020 check for liveness */
+  (void)now;
+  return current_consensus;
+}
+
 /** We believe networkstatuses more recent than this when they tell us that
  * our server is broken, invalid, obsolete, etc. */
 #define SELF_OPINION_INTERVAL (90*60)



More information about the tor-commits mailing list