fix some xxxs.

svn:r6307
This commit is contained in:
Nick Mathewson 2006-04-03 06:23:24 +00:00
parent 2cb3aeb4e1
commit eba6204315
4 changed files with 32 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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