mirror of
https://github.com/3proxy/3proxy.git
synced 2026-04-19 18:50:12 +08:00
Add hashcompact
This commit is contained in:
parent
a0d580b36d
commit
98604b5421
24
src/hash.c
24
src/hash.c
@ -1,7 +1,7 @@
|
|||||||
#include "proxy.h"
|
#include "proxy.h"
|
||||||
|
|
||||||
|
|
||||||
unsigned hashindex(struct hashtable *ht, const unsigned char* hash){
|
static unsigned hashindex(struct hashtable *ht, const unsigned char* hash){
|
||||||
unsigned t1, t2, t3, t4;
|
unsigned t1, t2, t3, t4;
|
||||||
t1 = *(unsigned *)hash;
|
t1 = *(unsigned *)hash;
|
||||||
t2 = *(unsigned *)(hash + sizeof(unsigned));
|
t2 = *(unsigned *)(hash + sizeof(unsigned));
|
||||||
@ -80,6 +80,25 @@ int inithashtable(struct hashtable *ht, unsigned nhashsize){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void hashcompact(struct hashtable *ht){
|
||||||
|
int i;
|
||||||
|
struct hashentry *he, **hep;
|
||||||
|
|
||||||
|
if((conf.time - ht->compacted) < 60) return;
|
||||||
|
for(i = 0; i < ht->hashsize; i++){
|
||||||
|
for(hep = ht->hashtable + i; (he = *hep)!=NULL; ){
|
||||||
|
if(he->expires < conf.time ) {
|
||||||
|
(*hep) = he->next;
|
||||||
|
he->expires = 0;
|
||||||
|
he->next = ht->hashempty;
|
||||||
|
ht->hashempty = he;
|
||||||
|
}
|
||||||
|
else hep=&(he->next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ht->compacted = conf.time;
|
||||||
|
}
|
||||||
|
|
||||||
void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires){
|
void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires){
|
||||||
struct hashentry * hen, *he;
|
struct hashentry * hen, *he;
|
||||||
struct hashentry ** hep;
|
struct hashentry ** hep;
|
||||||
@ -87,6 +106,9 @@ void hashadd(struct hashtable *ht, const void* name, const void* value, time_t e
|
|||||||
unsigned index;
|
unsigned index;
|
||||||
|
|
||||||
pthread_mutex_lock(&hash_mutex);
|
pthread_mutex_lock(&hash_mutex);
|
||||||
|
if(!ht->hashempty){
|
||||||
|
hashcompact(ht);
|
||||||
|
}
|
||||||
if(!ht||!value||!name||!ht->hashtable||!ht->hashempty) {
|
if(!ht||!value||!name||!ht->hashtable||!ht->hashempty) {
|
||||||
pthread_mutex_unlock(&hash_mutex);
|
pthread_mutex_unlock(&hash_mutex);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -244,8 +244,6 @@ void genchallenge(struct clientparam *param, char * challenge, char *buf);
|
|||||||
void mschap(const unsigned char *win_password,
|
void mschap(const unsigned char *win_password,
|
||||||
const unsigned char *challenge, unsigned char *response);
|
const unsigned char *challenge, unsigned char *response);
|
||||||
|
|
||||||
struct hashtable;
|
|
||||||
unsigned hashindex(struct hashtable *ht, const unsigned char* hash);
|
|
||||||
void destroyhashtable(struct hashtable *ht);
|
void destroyhashtable(struct hashtable *ht);
|
||||||
int inithashtable(struct hashtable *ht, unsigned nhashsize);
|
int inithashtable(struct hashtable *ht, unsigned nhashsize);
|
||||||
void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires);
|
void hashadd(struct hashtable *ht, const void* name, const void* value, time_t expires);
|
||||||
|
|||||||
@ -770,6 +770,7 @@ struct hashtable {
|
|||||||
struct hashentry * hashempty;
|
struct hashentry * hashempty;
|
||||||
void (*index2hash)(const void *index, unsigned char *hash, const unsigned char *rnd);
|
void (*index2hash)(const void *index, unsigned char *hash, const unsigned char *rnd);
|
||||||
int grow;
|
int grow;
|
||||||
|
time_t compacted;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct hashtable dns_table;
|
extern struct hashtable dns_table;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user