[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] publish advertised_bandwidth in descriptor



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	main.c or.h router.c 
Log Message:
publish advertised_bandwidth in descriptor


Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.304
retrieving revision 1.305
diff -u -d -r1.304 -r1.305
--- main.c	22 Jul 2004 00:13:42 -0000	1.304
+++ main.c	22 Jul 2004 04:20:26 -0000	1.305
@@ -416,7 +416,10 @@
  * - We believe we are reachable from the outside.
  */
 static int decide_if_publishable_server(time_t now) {
-  int r;
+  int bw;
+
+  bw = rep_hist_bandwidth_assess(now);
+  router_set_advertised_bandwidth(bw);
 
   if(options.ClientOnly)
     return 0;
@@ -433,12 +436,10 @@
     return 0;
   }
 
-  r = rep_hist_bandwidth_assess(now);
 
 
-//  set_advertised_bandwidth(r);
 
-  if(r < MIN_BW_TO_PUBLISH_DESC)
+  if(bw < MIN_BW_TO_PUBLISH_DESC)
     return 0;
   if(options.AuthoritativeDir)
     return 1;
@@ -467,10 +468,13 @@
   return (options.ORPort != 0);
 }
 
+/** Remember if we've advertised ourselves to the dirservers. */
+static int server_is_advertised=0;
+
 /** Return true iff we have published our descriptor lately.
  */
 int advertised_server_mode(void) {
-  return (options.ORPort != 0);
+  return server_is_advertised;
 }
 
 /** Return true iff we are trying to be a socks proxy. */
@@ -506,8 +510,8 @@
     if (router_rebuild_descriptor()<0) {
       log_fn(LOG_WARN, "Couldn't rebuild router descriptor");
     }
-    /* XXX008 only if advertised_server_mode */
-    router_upload_dir_desc_to_dirservers();
+    if(advertised_server_mode())
+      router_upload_dir_desc_to_dirservers();
   }
 
   /** 1b. Every MAX_SSL_KEY_LIFETIME seconds, we change our TLS context. */
@@ -532,8 +536,11 @@
   if(time_to_fetch_directory < now) {
 
     if(decide_if_publishable_server(now)) {
+      server_is_advertised = 1;
       router_rebuild_descriptor();
       router_upload_dir_desc_to_dirservers();
+    } else {
+      server_is_advertised = 0;
     }
 
     routerlist_remove_old_routers(); /* purge obsolete entries */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.390
retrieving revision 1.391
diff -u -d -r1.390 -r1.391
--- or.h	21 Jul 2004 00:44:04 -0000	1.390
+++ or.h	22 Jul 2004 04:20:27 -0000	1.391
@@ -1346,6 +1346,8 @@
 int init_keys(void);
 crypto_pk_env_t *init_key_from_file(const char *fname);
 void rotate_onion_key(void);
+void router_set_advertised_bandwidth(int bw);
+int router_get_advertised_bandwidth(void);
 
 void router_retry_connections(void);
 int router_is_clique_mode(routerinfo_t *router);

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- router.c	21 Jul 2004 23:43:47 -0000	1.72
+++ router.c	22 Jul 2004 04:20:27 -0000	1.73
@@ -124,6 +124,21 @@
   log_fn(LOG_WARN, "Couldn't rotate onion key.");
 }
 
+/** The last calculated bandwidth usage for our node. */
+static int advertised_bw = 0;
+
+/** Tuck <b>bw</b> away so we can produce it when somebody
+ * calls router_get_advertised_bandwidth() below.
+ */
+void router_set_advertised_bandwidth(int bw) {
+  advertised_bw = bw;
+}
+
+/** Return the value we tucked away above, or zero by default. */
+int router_get_advertised_bandwidth(void) {
+  return advertised_bw;
+}
+
 /* Read an RSA secret key key from a file that was once named fname_old,
  * but is now named fname_new.  Rename the file from old to new as needed.
  */
@@ -513,6 +528,7 @@
   ri->platform = tor_strdup(platform);
   ri->bandwidthrate = options.BandwidthRate;
   ri->bandwidthburst = options.BandwidthBurst;
+  ri->advertisedbandwidth = router_get_advertised_bandwidth();
   ri->exit_policy = NULL; /* zero it out first */
   router_add_exit_policy_from_config(ri);
   ri->is_trusted_dir = authdir_mode();