From 4ee7f71fb9afb44d1d05cf03defb3cdb9f52493e Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Fri, 17 Apr 2026 21:15:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20tablesize=20=D0=B2=20=D1=85?= =?UTF-8?q?=D0=B5=D1=88=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hash.c | 17 ++++++++++------- src/structures.h | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hash.c b/src/hash.c index ba53fc3..5745bba 100644 --- a/src/hash.c +++ b/src/hash.c @@ -7,7 +7,7 @@ static unsigned hashindex(struct hashtable *ht, const unsigned char* hash){ t2 = *(unsigned *)(hash + sizeof(unsigned)); t3 = *(unsigned *)(hash + (2*sizeof(unsigned))); t4 = *(unsigned *)(hash + (3*sizeof(unsigned))); - return (t1 + (t2 * 7) + (t3 * 17) + (t4 * 29) ) % (ht->hashsize >> 2); + return (t1 + (t2 * 7) + (t3 * 17) + (t4 * 29) ) % (ht->tablesize); } @@ -22,10 +22,12 @@ void destroyhashtable(struct hashtable *ht){ ht->hashvalues = NULL; } ht->hashsize = 0; + ht->tablesize = 0; pthread_mutex_unlock(&hash_mutex); } -#define hvalue(I) ((struct hashentry *)((char *)ht->hashvalues + (I)*(sizeof(struct hashentry) + ht->recsize - 4))) +#define hvalue(ht,I) ((struct hashentry *)(ht->hashvalues + (I)*(sizeof(struct hashentry) + ht->recsize - 4))) + int inithashtable(struct hashtable *ht, unsigned nhashsize){ unsigned i; clock_t c; @@ -65,17 +67,18 @@ int inithashtable(struct hashtable *ht, unsigned nhashsize){ return 3; } ht->hashsize = nhashsize; + ht->tablesize = (nhashsize>>2); ht->rnd[0] = myrand(&tb, sizeof(tb)); ht->rnd[1] = myrand(ht->hashtable, sizeof(ht->hashtable)); ht->rnd[2] = myrand(&c, sizeof(c)); ht->rnd[3] = myrand(ht->hashvalues,sizeof(ht->hashvalues)); - memset(ht->hashtable, 0, (ht->hashsize>>2) * sizeof(struct hashentry *)); - memset(ht->hashvalues, 0, ht->hashsize * (sizeof(struct hashentry) + ht->recsize -4)); + memset(ht->hashtable, 0, ht->tablesize * sizeof(struct hashentry *)); + memset(ht->hashvalues, 0, ht->hashsize * (sizeof(struct hashentry) + ht->recsize - 4)); for(i = 0; i< (ht->hashsize - 1); i++) { - hvalue(i)->next = hvalue(i+1); + hvalue(ht,i)->next = hvalue(ht,i+1); } - ht->hashempty = ht->hashvalues; + ht->hashempty = (struct hashentry *)ht->hashvalues; pthread_mutex_unlock(&hash_mutex); return 0; } @@ -85,7 +88,7 @@ static void hashcompact(struct hashtable *ht){ struct hashentry *he, **hep; if((conf.time - ht->compacted) < 60) return; - for(i = 0; i < ht->hashsize; i++){ + for(i = 0; i < ht->tablesize; i++){ for(hep = ht->hashtable + i; (he = *hep)!=NULL; ){ if(he->expires < conf.time ) { (*hep) = he->next; diff --git a/src/structures.h b/src/structures.h index ffd90aa..7d1a083 100644 --- a/src/structures.h +++ b/src/structures.h @@ -766,11 +766,12 @@ struct hashtable { unsigned recsize; unsigned rnd[4]; struct hashentry ** hashtable; - void * hashvalues; + uint8_t * hashvalues; struct hashentry * hashempty; void (*index2hash)(const void *index, unsigned char *hash, const unsigned char *rnd); int grow; time_t compacted; + int tablesize; }; extern struct hashtable dns_table;