mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Get better numbers out of HT_REP_OK
svn:r6924
This commit is contained in:
parent
3770685498
commit
45c3a4365f
@ -100,7 +100,7 @@ ht_string_hash(const char *s)
|
|||||||
#define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \
|
#define HT_PROTOTYPE(name, type, field, hashfn, eqfn) \
|
||||||
int name##_HT_GROW(struct name *ht, unsigned min_capacity); \
|
int name##_HT_GROW(struct name *ht, unsigned min_capacity); \
|
||||||
void name##_HT_CLEAR(struct name *ht); \
|
void name##_HT_CLEAR(struct name *ht); \
|
||||||
int _##name##_HT_REP_OK(struct name *ht); \
|
int _##name##_HT_REP_IS_BAD(struct name *ht); \
|
||||||
/* Helper: returns a pointer to the right location in the table \
|
/* Helper: returns a pointer to the right location in the table \
|
||||||
* 'head' to find or insert the element 'elm'. */ \
|
* 'head' to find or insert the element 'elm'. */ \
|
||||||
static INLINE struct type ** \
|
static INLINE struct type ** \
|
||||||
@ -346,38 +346,41 @@ ht_string_hash(const char *s)
|
|||||||
head->hth_table_length = 0; \
|
head->hth_table_length = 0; \
|
||||||
HT_INIT(head); \
|
HT_INIT(head); \
|
||||||
} \
|
} \
|
||||||
/* Debugging helper: return true iff the representation of 'head' is \
|
/* Debugging helper: return false iff the representation of 'head' is \
|
||||||
* internally consistent. */ \
|
* internally consistent. */ \
|
||||||
int \
|
int \
|
||||||
_##name##_HT_REP_OK(struct name *head) \
|
_##name##_HT_REP_IS_BAD(struct name *head) \
|
||||||
{ \
|
{ \
|
||||||
unsigned n, i; \
|
unsigned n, i; \
|
||||||
struct type *elm; \
|
struct type *elm; \
|
||||||
if (!head->hth_table_length) { \
|
if (!head->hth_table_length) { \
|
||||||
return !head->hth_table && !head->hth_n_entries && \
|
if (!head->hth_table && !head->hth_n_entries && \
|
||||||
!head->hth_load_limit && head->hth_prime_idx == -1; \
|
!head->hth_load_limit && head->hth_prime_idx == -1) \
|
||||||
|
return 0; \
|
||||||
|
else \
|
||||||
|
return 1; \
|
||||||
} \
|
} \
|
||||||
if (!head->hth_table || head->hth_prime_idx < 0 || \
|
if (!head->hth_table || head->hth_prime_idx < 0 || \
|
||||||
!head->hth_load_limit) \
|
!head->hth_load_limit) \
|
||||||
return 0; \
|
return 2; \
|
||||||
if (head->hth_n_entries > head->hth_load_limit) \
|
if (head->hth_n_entries > head->hth_load_limit) \
|
||||||
return 0; \
|
return 3; \
|
||||||
if (head->hth_table_length != name##_PRIMES[head->hth_prime_idx]) \
|
if (head->hth_table_length != name##_PRIMES[head->hth_prime_idx]) \
|
||||||
return 0; \
|
return 4; \
|
||||||
if (head->hth_load_limit != (unsigned)(load*head->hth_table_length)) \
|
if (head->hth_load_limit != (unsigned)(load*head->hth_table_length)) \
|
||||||
return 0; \
|
return 5; \
|
||||||
for (n = i = 0; i < head->hth_table_length; ++i) { \
|
for (n = i = 0; i < head->hth_table_length; ++i) { \
|
||||||
for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \
|
for (elm = head->hth_table[i]; elm; elm = elm->field.hte_next) { \
|
||||||
if (elm->field.hte_hash != hashfn(elm)) \
|
if (elm->field.hte_hash != hashfn(elm)) \
|
||||||
return 0; \
|
return 1000 + i; \
|
||||||
if ((elm->field.hte_hash % head->hth_table_length) != i) \
|
if ((elm->field.hte_hash % head->hth_table_length) != i) \
|
||||||
return 0; \
|
return 10000 + i; \
|
||||||
++n; \
|
++n; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
if (n != head->hth_n_entries) \
|
if (n != head->hth_n_entries) \
|
||||||
return 0; \
|
return 6; \
|
||||||
return 1; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1216,7 +1216,11 @@ static void
|
|||||||
assert_cache_ok(void)
|
assert_cache_ok(void)
|
||||||
{
|
{
|
||||||
cached_resolve_t **resolve;
|
cached_resolve_t **resolve;
|
||||||
tor_assert(_cache_map_HT_REP_OK(&cache_root));
|
int bad_rep = _cache_map_HT_REP_IS_BAD(&cache_root);
|
||||||
|
if (bad_rep) {
|
||||||
|
log_err(LD_BUG, "Bad rep type %d on dns cache hash table", bad_rep);
|
||||||
|
tor_assert(!bad_rep);
|
||||||
|
}
|
||||||
|
|
||||||
HT_FOREACH(resolve, cache_map, &cache_root) {
|
HT_FOREACH(resolve, cache_map, &cache_root) {
|
||||||
assert_resolve_ok(*resolve);
|
assert_resolve_ok(*resolve);
|
||||||
|
Loading…
Reference in New Issue
Block a user