summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-04-03 06:23:24 +0000
committerNick Mathewson <nickm@torproject.org>2006-04-03 06:23:24 +0000
commiteba6204315eb8ae21ace848cbc2f4abf765386be (patch)
treed10e0fca5d9de53dd57bc654543c479eaeeb149f
parent2cb3aeb4e1f4464c126df0911cf4408e6bc29f57 (diff)
downloadtor-eba6204315eb8ae21ace848cbc2f4abf765386be.tar.gz
tor-eba6204315eb8ae21ace848cbc2f4abf765386be.zip
fix some xxxs.
svn:r6307
-rw-r--r--src/or/dirserv.c2
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/routerlist.c20
-rw-r--r--src/or/routerparse.c18
4 files changed, 32 insertions, 10 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 5c44739e52..43fa17df15 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -736,7 +736,7 @@ format_versions_list(config_line_t *ln)
smartlist_split_string(versions, ln->value, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
}
- sort_version_list(versions);
+ sort_version_list(versions, 1);
result = smartlist_join_strings(versions,",",0,NULL);
SMARTLIST_FOREACH(versions,char *,s,tor_free(s));
smartlist_free(versions);
diff --git a/src/or/or.h b/src/or/or.h
index b466762f5c..3ed8e6cd4f 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2435,7 +2435,7 @@ version_status_t version_status_join(version_status_t a, version_status_t b);
int tor_version_parse(const char *s, tor_version_t *out);
int tor_version_as_new_as(const char *platform, const char *cutoff);
int tor_version_compare(tor_version_t *a, tor_version_t *b);
-void sort_version_list(smartlist_t *lst);
+void sort_version_list(smartlist_t *lst, int remove_duplicates);
void assert_addr_policy_ok(addr_policy_t *t);
networkstatus_t *networkstatus_parse_from_string(const char *s);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 275e12d7f2..59911dca23 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -1481,8 +1481,6 @@ router_set_status(const char *digest, int up)
* This function should be called *after*
* routers_update_status_from_networkstatus; subsequently, you should call
* router_rebuild_store and control_event_descriptors_changed.
- *
- * XXXX never replace your own descriptor.
*/
int
router_add_to_routerlist(routerinfo_t *router, const char **msg,
@@ -1547,6 +1545,13 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
rs->need_to_mirror = 0;
});
+ /* Probably, there's no way to actually pass this function our own
+ * descriptor, but in case there is, don't replace our own descriptor. */
+ if (router_is_me(router)) {
+ routerinfo_free(router);
+ return 0;
+ }
+
/* If we have a router with this name, and the identity key is the same,
* choose the newer one. If the identity key has changed, and one of the
* routers is named, drop the unnamed ones. (If more than one are named,
@@ -2606,6 +2611,8 @@ compute_recommended_versions(time_t now, int client)
SMARTLIST_FOREACH(networkstatus_list, networkstatus_t *, ns,
{
const char *vers;
+ smartlist_t *versions;
+ int i;
if (! ns->recommends_versions)
continue;
if (ns->received_on + SELF_OPINION_INTERVAL < now)
@@ -2614,13 +2621,13 @@ compute_recommended_versions(time_t now, int client)
vers = client ? ns->client_versions : ns->server_versions;
if (!vers)
continue;
- /* XXX Attack: a single dirserver can make a version recommended
- * by repeating it many times in his recommended list. -RD */
- smartlist_split_string(combined, vers, ",",
+ versions = smartlist_create();
+ smartlist_split_string(versions, vers, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ sort_version_list(versions, 1);
});
- sort_version_list(combined);
+ sort_version_list(combined, 0);
current = NULL;
n_seen = 0;
@@ -2733,7 +2740,6 @@ routers_update_all_from_networkstatus(void)
}
});
if (n_recent > 2 && n_recommended < n_recent/2) {
-/* XXX Should this be n_recommended <= n_recent/2 ? -RD */
if (consensus == VS_NEW || consensus == VS_NEW_IN_SERIES) {
if (!have_warned_about_new_version) {
char *rec = compute_recommended_versions(now, !is_server);
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 1ee0594a73..48a5aa7efb 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1926,8 +1926,24 @@ _compare_tor_version_str_ptr(const void **_a, const void **_b)
/** Sort a list of string-representations of versions in ascending order. */
void
-sort_version_list(smartlist_t *versions)
+sort_version_list(smartlist_t *versions, int remove_duplicates)
{
+ int i;
+
smartlist_sort(versions, _compare_tor_version_str_ptr);
+ if (!remove_duplicates)
+ return;
+
+ for (i = 1; i < smartlist_len(versions); ++i) {
+ void *a, *b;
+ a = smartlist_get(versions, i-1);
+ b = smartlist_get(versions, i);
+ /* use version_cmp so we catch multiple representations of the same
+ * version */
+ if (_compare_tor_version_str_ptr(a,b) == 0) {
+ tor_free(smartlist_get(versions, i));
+ smartlist_del(versions, i--);
+ }
+ }
}