From 06b72cc8f285b894d97fc155e2038e60de044956 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Thu, 22 Jul 2004 04:20:27 +0000 Subject: [PATCH] publish advertised_bandwidth in descriptor svn:r2095 --- src/or/main.c | 21 ++++++++++++++------- src/or/or.h | 2 ++ src/or/router.c | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/or/main.c b/src/or/main.c index 054097b7fb..9844150b48 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -416,7 +416,10 @@ static void run_connection_housekeeping(int i, time_t now) { * - 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 @@ static int decide_if_publishable_server(time_t now) { 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 @@ int server_mode(void) { 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 @@ static void run_scheduled_events(time_t now) { 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 @@ static void run_scheduled_events(time_t now) { 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 */ diff --git a/src/or/or.h b/src/or/or.h index 95b40e840e..47ff398995 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1346,6 +1346,8 @@ void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last); 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); diff --git a/src/or/router.c b/src/or/router.c index 475742c22c..5e295bfbc1 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -124,6 +124,21 @@ void rotate_onion_key(void) log_fn(LOG_WARN, "Couldn't rotate onion key."); } +/** The last calculated bandwidth usage for our node. */ +static int advertised_bw = 0; + +/** Tuck bw 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 @@ int router_rebuild_descriptor(void) { 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();