diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-08-22 03:10:53 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-08-22 03:10:53 +0000 |
commit | dc09c7fc736378e9cf19bf751516e9aed97501da (patch) | |
tree | 735df5b2e11e1a7721fd738b6ad5836116a1cbb9 | |
parent | a966100a63390e447337749800f70ac3f1c225cf (diff) | |
download | tor-dc09c7fc736378e9cf19bf751516e9aed97501da.tar.gz tor-dc09c7fc736378e9cf19bf751516e9aed97501da.zip |
Implement new (reduced-frequency) upload rules. arma, you should review this.
svn:r4806
-rw-r--r-- | doc/TODO | 7 | ||||
-rw-r--r-- | src/or/main.c | 8 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/router.c | 46 |
4 files changed, 52 insertions, 11 deletions
@@ -172,8 +172,11 @@ r - kill dns workers more slowly before we approve them - other? - dirservers publish router-status with all these flags. - - Servers publish new descriptors when options change, when 12-24 hours - have passed, when uptime is reset, or when bandwidth changes a lot. + o Servers publish new descriptors when: + o options change + o when 12-24 hours have passed + o when uptime is reset + o When bandwidth changes a lot. - alices fetch many router-statuses and update descriptors as needed. - add if-newer-than fetch options - dirservers allow people to lookup by N descriptors, or to fetch all. diff --git a/src/or/main.c b/src/or/main.c index f6080c7618..2d3666cde4 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -94,6 +94,7 @@ static char* nt_strerror(uint32_t errnum); #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 @@ run_scheduled_events(time_t now) } 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 @@ run_scheduled_events(time_t now) * 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. */ diff --git a/src/or/or.h b/src/or/or.h index f147d24f22..550d5aa540 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1904,7 +1904,9 @@ int proxy_mode(or_options_t *options); 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); diff --git a/src/or/router.c b/src/or/router.c index 16a65ed8d1..247913c1e6 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -443,6 +443,7 @@ router_orport_found_reachable(void) 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 @@ consider_publishable_server(time_t now, int force) { 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 @@ router_is_clique_mode(routerinfo_t *router) /** 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 @@ router_rebuild_descriptor(int force) 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 @@ router_rebuild_descriptor(int force) 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 |