[or-cvs] Implement new (reduced-frequency) upload rules. arma, you s...

Nick Mathewson nickm at seul.org
Mon Aug 22 03:10:55 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv30882/src/or

Modified Files:
	main.c or.h router.c 
Log Message:
Implement new (reduced-frequency) upload rules. arma, you should review this.

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.535
retrieving revision 1.536
diff -u -d -r1.535 -r1.536
--- main.c	15 Aug 2005 23:46:18 -0000	1.535
+++ main.c	22 Aug 2005 03:10:53 -0000	1.536
@@ -94,6 +94,7 @@
 #define nt_service_is_stopped() (0)
 #endif
 
+#define FORCE_REGENERATE_DESCRIPTOR_INTERVAL 24*60*60 /* 1 day. */
 #define CHECK_DESCRIPTOR_INTERVAL 60 /* one minute */
 #define BUF_SHRINK_INTERVAL 60 /* one minute */
 #define TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT (20*60) /* 20 minutes */
@@ -720,10 +721,8 @@
   }
 
   if (time_to_force_upload_descriptor < now) {
-    consider_publishable_server(now, 1);
-
+    /*XXXX this should go elsewhere. */
     rend_cache_clean(); /* this should go elsewhere? */
-
     time_to_force_upload_descriptor = now + options->DirPostPeriod;
   }
 
@@ -731,6 +730,9 @@
    * one is inaccurate. */
   if (time_to_check_descriptor < now) {
     time_to_check_descriptor = now + CHECK_DESCRIPTOR_INTERVAL;
+    check_descriptor_bandwidth_changed(now);
+    mark_my_descriptor_dirty_if_older_than(
+                                    now - FORCE_REGENERATE_DESCRIPTOR_INTERVAL);
     consider_publishable_server(now, 0);
     /* also, check religiously for reachability, if it's within the first
      * 20 minutes of our uptime. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.648
retrieving revision 1.649
diff -u -d -r1.648 -r1.649
--- or.h	22 Aug 2005 00:18:45 -0000	1.648
+++ or.h	22 Aug 2005 03:10:53 -0000	1.649
@@ -1904,7 +1904,9 @@
 void router_retry_connections(void);
 int router_is_clique_mode(routerinfo_t *router);
 void router_upload_dir_desc_to_dirservers(int force);
+void mark_my_descriptor_dirty_if_older_than(time_t when);
 void mark_my_descriptor_dirty(void);
+void check_descriptor_bandwidth_changed(time_t now);
 int router_compare_to_my_exit_policy(connection_t *conn);
 routerinfo_t *router_get_my_routerinfo(void);
 const char *router_get_my_descriptor(void);

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.186
retrieving revision 1.187
diff -u -d -r1.186 -r1.187
--- router.c	8 Aug 2005 21:58:48 -0000	1.186
+++ router.c	22 Aug 2005 03:10:53 -0000	1.187
@@ -443,6 +443,7 @@
       log(LOG_NOTICE,"Your ORPort is reachable from the outside. Excellent.%s",
           get_options()->NoPublish ? "" : " Publishing server descriptor.");
     can_reach_or_port = 1;
+    mark_my_descriptor_dirty();
     consider_publishable_server(time(NULL), 1);
   }
 }
@@ -554,7 +555,7 @@
 {
   if (decide_if_publishable_server(now)) {
     set_server_advertised(1);
-    if (router_rebuild_descriptor(force) == 0)
+    if (router_rebuild_descriptor(0) == 0)
       router_upload_dir_desc_to_dirservers(force);
   } else {
     set_server_advertised(0);
@@ -612,8 +613,9 @@
 
 /** My routerinfo. */
 static routerinfo_t *desc_routerinfo = NULL;
-/** Boolean: do we need to regenerate the above? */
-static int desc_is_dirty = 1;
+/** Since when has our descriptor been "clean"?  0 if we need to regenerate it
+ * now. */
+static time_t desc_clean_since = 0;
 /** Boolean: do we need to regenerate the above? */
 static int desc_needs_upload = 0;
 
@@ -716,7 +718,7 @@
   or_options_t *options = get_options();
   char addrbuf[INET_NTOA_BUF_LEN];
 
-  if (!desc_is_dirty && !force)
+  if (desc_clean_since && !force)
     return 0;
 
   if (resolve_my_address(options, &addr) < 0) {
@@ -770,16 +772,48 @@
     routerinfo_free(desc_routerinfo);
   desc_routerinfo = ri;
 
-  desc_is_dirty = 0;
+  desc_clean_since = time(NULL);
   desc_needs_upload = 1;
   return 0;
 }
 
+/** Mark descriptor out of date if it's older than <b>when</b> */
+void
+mark_my_descriptor_dirty_if_older_than(time_t when)
+{
+  if (desc_clean_since < when)
+    mark_my_descriptor_dirty();
+}
+
 /** Call when the current descriptor is out of date. */
 void
 mark_my_descriptor_dirty(void)
 {
-  desc_is_dirty = 1;
+  desc_clean_since = 0;
+}
+
+#define MAX_BANDWIDTH_CHANGE_FREQ 45*60
+/** Check whether bandwidth has changed a lot since the last time we announced
+ * bandwidth.  If so, mark our descriptor dirty.*/
+void
+check_descriptor_bandwidth_changed(time_t now)
+{
+  static time_t last_changed = 0;
+  uint64_t prev, cur;
+  if (!desc_routerinfo)
+    return;
+
+  prev = desc_routerinfo->bandwidthcapacity;
+  cur = we_are_hibernating() ? 0 : rep_hist_bandwidth_assess();
+  if ((prev != cur && (!prev || !cur)) ||
+      cur > prev*2 ||
+      cur < prev/2) {
+    if (last_changed+MAX_BANDWIDTH_CHANGE_FREQ < now) {
+      log_fn(LOG_INFO,"Measured bandwidth has changed; rebuilding descriptor.");
+      mark_my_descriptor_dirty();
+      last_changed = now;
+    }
+  }
 }
 
 /** Set <b>platform</b> (max length <b>len</b>) to a NUL-terminated short



More information about the tor-commits mailing list