publish advertised_bandwidth in descriptor

svn:r2095
This commit is contained in:
Roger Dingledine 2004-07-22 04:20:27 +00:00
parent eb0a19c475
commit 06b72cc8f2
3 changed files with 32 additions and 7 deletions

View File

@ -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,7 +510,7 @@ 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 */
if(advertised_server_mode())
router_upload_dir_desc_to_dirservers();
}
@ -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 */

View File

@ -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);

View File

@ -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 <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 @@ 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();