[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] enable code to remove members of old_routers when it gets b...
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv373
Modified Files:
main.c or.h routerlist.c
Log Message:
enable code to remove members of old_routers when it gets big.
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.585
retrieving revision 1.586
diff -u -d -r1.585 -r1.586
--- main.c 29 Oct 2005 18:19:37 -0000 1.585
+++ main.c 1 Nov 2005 17:34:17 -0000 1.586
@@ -719,7 +719,7 @@
* (if we've passed our internal checks). */
if (time_to_fetch_directory < now) {
/* purge obsolete entries */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
networkstatus_list_clean(now);
if (authdir_mode(options)) {
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.729
retrieving revision 1.730
diff -u -d -r1.729 -r1.730
--- or.h 29 Oct 2005 19:13:48 -0000 1.729
+++ or.h 1 Nov 2005 17:34:17 -0000 1.730
@@ -2159,7 +2159,7 @@
void routerlist_free_all(void);
routerinfo_t *routerinfo_copy(const routerinfo_t *router);
void router_mark_as_down(const char *digest);
-void routerlist_remove_old_routers(int age);
+void routerlist_remove_old_routers(void);
void networkstatus_list_clean(time_t now);
int router_add_to_routerlist(routerinfo_t *router, const char **msg,
int from_cache);
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.359
retrieving revision 1.360
diff -u -d -r1.359 -r1.360
--- routerlist.c 1 Nov 2005 03:50:14 -0000 1.359
+++ routerlist.c 1 Nov 2005 17:34:17 -0000 1.360
@@ -199,7 +199,7 @@
return 0;
/* Don't save deadweight. */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
options = get_options();
fname_len = strlen(options->DataDirectory)+32;
@@ -281,7 +281,7 @@
tor_free(fname);
/* Don't cache expired routers. */
- routerlist_remove_old_routers(ROUTER_MAX_AGE);
+ routerlist_remove_old_routers();
if (router_journal_len) {
/* Always clear the journal on startup.*/
@@ -1172,7 +1172,7 @@
// routerlist_assert_ok(rl);
}
-void
+static void
routerlist_remove_old(routerlist_t *rl, routerinfo_t *ri, int idx)
{
routerinfo_t *ri_tmp;
@@ -1495,30 +1495,6 @@
#define MAX_DESCRIPTORS_PER_ROUTER 5
-/** Remove any routers from the routerlist that are more than <b>age</b>
- * seconds old.
- */
-void
-routerlist_remove_old_routers(int age)
-{
- int i;
- time_t cutoff;
- routerinfo_t *router;
- if (!routerlist)
- return;
-
- cutoff = time(NULL) - age;
- for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
- router = smartlist_get(routerlist->routers, i);
- if (router->published_on <= cutoff) {
- /* Too old. Remove it. */
- info(LD_DIR, "Forgetting obsolete (too old) routerinfo for router '%s'",
- router->nickname);
- routerlist_remove(routerlist, router, i--, 1);
- }
- }
-}
-
static int
_compare_old_routers_by_identity(const void **_a, const void **_b)
{
@@ -1622,18 +1598,36 @@
tor_free(lifespans);
}
+/** Deactivate any routers from the routerlist that are more than <b>age</b>
+ * seconds old; remove old routers from the list of cached routers if we have
+ * too many.
+ */
void
-routerlist_remove_old_cached_routers(void)
+routerlist_remove_old_routers(void)
{
int i, hi=-1;
const char *cur_id = NULL;
time_t cutoff;
+ routerinfo_t *router;
if (!routerlist)
return;
- /* First, check whether we have too many router descriptors, total. We're
- * okay with having too many for some given router, so long as the total
- * number doesn't much exceed
+ cutoff = time(NULL) - ROUTER_MAX_AGE;
+ /* Remove old members of routerlist->routers. */
+ for (i = 0; i < smartlist_len(routerlist->routers); ++i) {
+ router = smartlist_get(routerlist->routers, i);
+ if (router->published_on <= cutoff) {
+ /* Too old. Remove it. */
+ info(LD_DIR, "Forgetting obsolete (too old) routerinfo for router '%s'",
+ router->nickname);
+ routerlist_remove(routerlist, router, i--, 1);
+ }
+ }
+
+ /* Now we're looking at routerlist->old_routers. First, check whether
+ * we have too many router descriptors, total. We're okay with having too
+ * many for some given router, so long as the total number doesn't approach
+ * MAX_DESCRIPTORS_PER_ROUTER*len(router).
*/
if (smartlist_len(routerlist->old_routers) <
smartlist_len(routerlist->routers) * (MAX_DESCRIPTORS_PER_ROUTER - 1))
@@ -1641,8 +1635,6 @@
smartlist_sort(routerlist->old_routers, _compare_old_routers_by_identity);
- cutoff = time(NULL) - ROUTER_MAX_AGE;
-
/* Iterate through the list from back to front, so when we remove descriptors
* we don't mess up groups we haven't gotten to. */
for (i = smartlist_len(routerlist->old_routers)-1; i >= 0; --i) {
@@ -1656,7 +1648,9 @@
hi = i;
}
}
- routerlist_remove_old_cached_routers_with_id(cutoff, 0, hi);
+ if (hi>=0)
+ routerlist_remove_old_cached_routers_with_id(cutoff, 0, hi);
+ routerlist_assert_ok(routerlist);
}
/**