summaryrefslogtreecommitdiff
path: root/src/or/routerparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-09-15 04:27:58 +0000
committerNick Mathewson <nickm@torproject.org>2006-09-15 04:27:58 +0000
commite58b9c1151c0591a95ebb97e21db315698e0bb27 (patch)
treed6ff16e0cdc481cd271d22c6a364cde9634a71f4 /src/or/routerparse.c
parentce83f4362934bbe87341a88d55ff0a1e80014cd5 (diff)
downloadtor-e58b9c1151c0591a95ebb97e21db315698e0bb27.tar.gz
tor-e58b9c1151c0591a95ebb97e21db315698e0bb27.zip
r8819@Kushana: nickm | 2006-09-15 00:27:45 -0400
Implement a smartlist_uniq() that will with luck not end the world. svn:r8396
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r--src/or/routerparse.c44
1 files changed, 14 insertions, 30 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 69b1738a6b..ce564a5115 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1075,6 +1075,15 @@ _compare_routerstatus_entries(const void **_a, const void **_b)
return memcmp(a->identity_digest, b->identity_digest, DIGEST_LEN);
}
+static void
+_free_duplicate_routerstatus_entry(void *e)
+{
+ log_warn(LD_DIR,
+ "Network-status has two entries for the same router. "
+ "Dropping one.");
+ routerstatus_free(e);
+}
+
/** Given a versioned (v2 or later) network-status object in <b>s</b>, try to
* parse it and return the result. Return NULL on failure. Check the
* signature of the network status, but do not (yet) check the signing key for
@@ -1217,20 +1226,8 @@ networkstatus_parse_from_string(const char *s)
smartlist_add(ns->entries, rs);
}
smartlist_sort(ns->entries, _compare_routerstatus_entries);
-
- /* Kill duplicate entries. */
- for (i=0; i < smartlist_len(ns->entries)-1; ++i) {
- routerstatus_t *rs1 = smartlist_get(ns->entries, i);
- routerstatus_t *rs2 = smartlist_get(ns->entries, i+1);
- if (!memcmp(rs1->identity_digest,
- rs2->identity_digest, DIGEST_LEN)) {
- log_warn(LD_DIR,
- "Network-status has two entries for the same router. "
- "Dropping one.");
- smartlist_del_keeporder(ns->entries, i--);
- routerstatus_free(rs1);
- }
- }
+ smartlist_uniq(ns->entries, _compare_routerstatus_entries,
+ _free_duplicate_routerstatus_entry);
if (tokenize_string(s, NULL, tokens, NETSTATUS)) {
log_warn(LD_DIR, "Error tokenizing network-status footer.");
@@ -1922,22 +1919,9 @@ _compare_tor_version_str_ptr(const void **_a, const void **_b)
void
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) {
- const 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_keeporder(versions, i--);
- }
- }
+
+ if (remove_duplicates)
+ smartlist_uniq(versions, _compare_tor_version_str_ptr, NULL);
}